diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 73d1e357c..c325639f9 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -247,7 +247,7 @@ module Mobile end get "course_dynamic/:id" do cs = CoursesService.new - count = cs.course_dynamic(params,current_user) + count = cs.all_course_dynamics(params,current_user) present :data, count, with: Mobile::Entities::CourseDynamic present :status, 0 end diff --git a/app/api/mobile/entities/attachment.rb b/app/api/mobile/entities/attachment.rb index 080b24558..b7424fac9 100644 --- a/app/api/mobile/entities/attachment.rb +++ b/app/api/mobile/entities/attachment.rb @@ -1,13 +1,18 @@ module Mobile module Entities class Attachment < Grape::Entity + include Redmine::I18n def self.attachment_expose(field) expose field do |f,opt| if f.is_a?(Hash) && f.key?(field) f[field] elsif f.is_a?(::Attachment) if f.respond_to?(field) - f.send(field) + if field == :created_on + format_time(f.send(field)) + else + f.send(field) + end else #case field # when "" @@ -21,6 +26,7 @@ module Mobile attachment_expose :description attachment_expose :downloads attachment_expose :quotes + attachment_expose :created_on end end end \ No newline at end of file diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index b6e4630e4..f086f1dd1 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -6,6 +6,62 @@ module Mobile expose field do |c,opt| if field == :update_time (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) + elsif field == :news_count + obj = nil + c[:dynamics].each do |d| + if d[:type] == 1 + obj = d[:count] + end + end + obj + elsif field == :document_count + obj = nil + c[:dynamics].each do |d| + if d[:type] == 3 + obj = d[:count] + end + end + obj + elsif field == :topic_count + obj = nil + c[:dynamics].each do |d| + if d[:type] == 2 + obj = d[:count] + end + end + obj + elsif field == :homework_count + obj = nil + c[:dynamics].each do |d| + if d[:type] == 4 + obj = d[:count] + end + end + obj + elsif field == :homework_submit_num + obj = nil + c[:dynamics].each do |d| + if d[:type] == 4 + obj = d[:submit_count] + end + end + obj + elsif field == :homework_submit_students + obj = nil + c[:dynamics].each do |d| + if d[:type] == 4 + obj = d[:studentlist] + end + end + obj + elsif field == :homework_status + obj = nil + c[:dynamics].each do |d| + if d[:type] == 4 + obj = d[:homework_status] + end + end + obj else c[field] if (c.is_a?(Hash) && c.key?(field)) end @@ -21,6 +77,53 @@ module Mobile course_dynamic_expose :course_img_url course_dynamic_expose :message course_dynamic_expose :update_time + course_dynamic_expose :count + course_dynamic_expose :news_count + course_dynamic_expose :document_count + course_dynamic_expose :topic_count + course_dynamic_expose :homework_count + course_dynamic_expose :homework_submit_students + course_dynamic_expose :homework_submit_num + course_dynamic_expose :homework_status + #在dynamics里解析出四种动态 + expose :document,using:Mobile::Entities::Attachment do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 3 + obj = d[:documents] + end + end + obj + end + expose :topic,using:Mobile::Entities::Message do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 2 + obj = d[:topic] + end + end + obj + end + expose :homework,using:Mobile::Entities::Homework do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 4 + obj = d[:homework] + end + end + obj + end + + expose :news,using:Mobile::Entities::News do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 1 + obj = d + end + end + obj + end + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/homework.rb b/app/api/mobile/entities/homework.rb index ee623d9ff..e2c181048 100644 --- a/app/api/mobile/entities/homework.rb +++ b/app/api/mobile/entities/homework.rb @@ -1,3 +1,4 @@ +# 这个模块由于作业模块的改变,里边的注释以及属性不可信 module Mobile module Entities class Homework < Grape::Entity @@ -14,7 +15,12 @@ module Mobile if f.respond_to?(field) f.send(field) else - + case field + when :homework_name + f.send(:name) + when :homework_notsubmit_num + f.course.members.count - f.student_works.count + end end end end @@ -60,6 +66,12 @@ module Mobile f[:homework_for_anonymous_comments] if f.is_a?(Hash) && f.key?(:homework_for_anonymous_comments) end + homework_expose :homework_notsubmit_num + + expose :submit_student_list ,using:Mobile::Entities::User do |f,opt| + f[:studentlist] + end + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb new file mode 100644 index 000000000..6a2ca1fb0 --- /dev/null +++ b/app/api/mobile/entities/message.rb @@ -0,0 +1,46 @@ +module Mobile + module Entities + class Message < Grape::Entity + include ApplicationHelper + include ApiHelper + def self.message_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + elsif u.is_a?(::Message) + if u.respond_to?(f) + if f == :created_on + format_time( u.send(f)) + else + u.send(f) + end + else + # case f + # when :xx + # # + # end + end + end + + end + end + + expose :user, using: Mobile::Entities::User do |c, opt| + if c.is_a?(::Message) + c.author + end + end + message_expose :board_id + message_expose :subject + message_expose :content + message_expose :replies_count + message_expose :created_on + message_expose :id + expose :message_children,using:Mobile::Entities::Message do |c,opt| + if c.is_a? (::Message) + c.children + end + end + end + end +end \ No newline at end of file diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index f189771e3..7399ebb4c 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -26,13 +26,15 @@ module Mobile news_expose :title expose :author,using: Mobile::Entities::User do |f, opt| - n = f[:news] - n.author if n.respond_to?(:author) + n = f[:author] + #n.author if n.respond_to?(:author) end #作者id news_expose :author_id #作者名 news_expose :author_name + #作者头像url + news_expose :author_img_url #新闻内容 news_expose :description #发布时间 diff --git a/app/controllers/git_usage_controller.rb b/app/controllers/git_usage_controller.rb index 4f9a96d6f..56aaa56f1 100644 --- a/app/controllers/git_usage_controller.rb +++ b/app/controllers/git_usage_controller.rb @@ -1,6 +1,6 @@ #added by baiyu class GitUsageController < ApplicationController - layout "project_base" + layout "new_base" def ch_usage end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index d5e62127d..5cd55e23b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -206,7 +206,7 @@ class HomeworkCommonController < ApplicationController #当前用户是不是课程的成员 def member_of_course - render_403 unless User.current.member_of_course?(@course) || User.current.admin? + render_403 unless @course.is_public || User.current.member_of_course?(@course) || User.current.admin? end def get_assigned_homeworks(student_works, n, index) diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index fb62821d8..68713aa43 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class IssueCategoriesController < ApplicationController - layout "project_base" + layout "base_projects" menu_item :settings model_object IssueCategory before_filter :find_model_object, :except => [:index, :new, :create] diff --git a/app/controllers/organization_controller.rb b/app/controllers/organization_controller.rb index db8295e44..62e6b85f6 100644 --- a/app/controllers/organization_controller.rb +++ b/app/controllers/organization_controller.rb @@ -1,5 +1,5 @@ class OrganizationController < ApplicationController - layout 'project_base' + layout 'base_projects' before_filter :require_admin, :except => [:index] def index diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6ad450315..e6e93947c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -438,9 +438,9 @@ class ProjectsController < ApplicationController case params[:role] when '1' @subPage_title = l :label_teacher_list - @members = searchTeacherAndAssistant(@project) + @members = searchTeacherAndAssistant(@project) when '2' - @subPage_title = l :label_student_list + @subPage_title = l :label_student_list @members = searchStudent(@project) else @subPage_title = '' @@ -578,7 +578,7 @@ class ProjectsController < ApplicationController format.api { render_api_ok } end else - render :layout => "project_base" + render :layout => "base_projects" end # hide project in layout @project = nil @@ -586,7 +586,7 @@ class ProjectsController < ApplicationController def show_projects_score respond_to do |format| - format.html { render :layout => "project_base"} + format.html { render :layout => "base_projects"} format.js end end @@ -674,10 +674,10 @@ class ProjectsController < ApplicationController private def memberAccess - # 是课程,则判断当前用户是否参加了课程 - # return 0 if @project.project_type == Project::ProjectType_project - # currentUser = User.current - render_403 unless User.current.member_of?(@project) + # 如果是私有项目,项目成员不对外公开,公开项目成员列表对外公开。 + unless @project.is_public? + render_403 unless User.current.member_of?(@project) + end end def toggleCourse diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 53d437574..e695a6fb0 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -284,13 +284,13 @@ class StudentWorkController < ApplicationController #是不是当前课程的成员 #当前课程成员才可以看到作品列表 def member_of_course - render_403 unless User.current.member_of_course? @course + render_403 unless User.current.member_of_course?(@course) || User.current.admin? end #判断是不是当前作品的提交者 #提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品 def author_of_work - render_403 unless User.current.id == @work.user_id && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) + render_403 unless (User.current.id == @work.user_id || User.current.admin?) && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 ) end #根据条件过滤作业结果 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 13012a70c..a0bd18582 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -35,7 +35,7 @@ module CoursesHelper #生成课程老师成员链接 def course_teacher_link teacher_num - if User.current.member_of_course?(@course) + if User.current.member_of_course?(@course) || User.current.admin? link_to "#{teacher_num}", course_member_path(@course, :role => 1), :class => 'info_foot_num c_blue' else content_tag 'span',teacher_num, :class => 'info_foot_num c_blue' @@ -44,7 +44,7 @@ module CoursesHelper #生成课程学生列表连接 def course_student_link student_num - if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) + if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin? link_to "#{student_num}", course_member_path(@course, :role => 2), :class => 'info_foot_num c_blue' else content_tag 'span',student_num, :class => 'info_foot_num c_blue' diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e4f9a7a81..aae150728 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -361,16 +361,15 @@ module IssuesHelper end end - # 之所以注释是因为该功能冗余了 if detail.property == 'attr' && detail.prop_key == 'description' s = l(:text_journal_changed_no_detail, :label => label) - # unless no_html - # diff_link = link_to l(:label_diff), - # {:controller => 'journals', :action => 'diff', :id => detail.journal_id, - # :detail_id => detail.id, :only_path => options[:only_path]}, - # :title => l(:label_view_diff) - # s << " (#{ diff_link })" - # end + unless no_html + diff_link = link_to l(:label_diff), + {:controller => 'journals', :action => 'diff', :id => detail.journal_id, + :detail_id => detail.id, :only_path => options[:only_path]}, + :title => l(:label_view_diff) + s << " (#{ diff_link })" + end s.html_safe elsif detail.value.present? case detail.property diff --git a/app/models/mailer.rb b/app/models/mailer.rb index d0ee99421..0d0b82752 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -124,8 +124,8 @@ class Mailer < ActionMailer::Base attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC') @bids += bids if bids.count > 0 @attachments += attachments if attachments.count > 0 - end + @bids.sort {|a, b| a.created_at <=> b.created_at} end # 项目附件 diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index d4a197aff..f5ff2670f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -123,7 +123,7 @@ class CoursesService scope = @course ? @course.news.course_visible(current_user) : News.course_visible(current_user) news = [] scope.each do |n| - news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} + news << {:id => n.id,:title => n.title,:author_name => n.author.name,:author_id => n.author.id, :author=>n.author, :description => n.description,:created_on => format_time(n.created_on),:comments_count => n.comments_count} end news end @@ -330,7 +330,7 @@ class CoursesService def homework_list params,current_user course = Course.find(params[:id]) if course.is_public != 0 || current_user.member_of_course?(course) - bids = course.homework_commons.order('end_time DESC') + bids = course.homework_commons.page(1).per(3).order('created_at DESC') bids = bids.like(params[:name]) if params[:name].present? homeworks = [] bids.each do |bid| @@ -540,14 +540,35 @@ class CoursesService #student_questions_count = bid.journals_for_messages.where('m_parent_id IS NULL').count description = bid.description #if is_course_teacher(User.current, course) && @bid.open_anonymous_evaluation == 1 && @bid.homeworks.count >= 2 - state = bid.homework_detail_manual.comment_status + #state = bid.homework_detail_manual.comment_status + if !bid.nil? + if bid.homework_type == 1 && bid.homework_detail_manual + case bid.homework_detail_manual.comment_status + when 1 + state = show_homework_deadline bid + when 2 + state = "正在匿评中" + when 3 + state = "匿评已结束" + end + elsif bid.homework_type == 0 + state = "未启用匿评" + elsif bid.homework_type == 2 + state = "编程作业" + else + end + end + studentlist = [] + bid.student_works.order("created_at desc").page(1).per(6).each do |work| + studentlist << work.user + end unless is_course_teacher homework_for_anonymous_comments = get_student_batch_homework_list bid,current_user end #end open_anonymous_evaluation = bid.homework_detail_manual.comment_status {:course_name => course.name,:course_id => course.id,:id => bid.id, :author => bid.user,:author_real_name => author_real_name, :homework_times => many_times, :homework_name => name, :homework_count => homework_count,:student_questions_count => 0, - :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time} + :description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation,:homework_for_anonymous_comments => homework_for_anonymous_comments,:created_on => bid.created_at,:deadline => bid.end_time,:studentlist => studentlist} end @@ -615,9 +636,103 @@ class CoursesService homework_scores end + #app新版api + # + # + #课程动态 + public + def all_course_dynamics params, current_user + #获取当前用户的所有课程 + @user = User.find(params[:id]) + if current_user.nil? && !current_user.admin? && !@user.active? + raise '404' + return + end + if current_user == @user || current_user.admin? + membership = @user.coursememberships.page(1).per(10) + else + membership = @user.coursememberships.page(1).per(10).all(:conditions => Course.visible_condition(current_user)) + end + if membership.nil? || membership.count == 0 + raise l(:label_no_courses, :locale => get_user_language(current_user)) + end + membership.sort! { |older, newer| newer.created_on <=> older.created_on } + #定义一个数组集合,存放hash数组,该hash数组包括课程的信息,并包含课程的最新发布的资源,最新的讨论区留言,最新的作业,最新的通知 + result = [] + #对用户所有的课程进行循环,找到每个课程最新发布的资源,最新的讨论区留言,最新的作业,最新的通知,并存进数组 + membership.each do |mp| + course = mp.course + latest_course_dynamics = [] + dynamics_count = 0 + # 课程通知 + latest_news = course.news.order("created_on desc").first + unless latest_news.nil? + latest_course_dynamics << {:type => 1, :time => latest_news.created_on,:count=>course.news.count, + :news => latest_news} + dynamics_count += 1 + end + # 课程讨论区 + latest_message = course.boards.first.topics[0] + unless latest_message.nil? + latest_course_dynamics << {:type => 2, :time => latest_message.created_on, :count =>course.boards.nil? ? 0 : course.boards.first.topics.count, + :topic => latest_message} + dynamics_count += 1 + end + # 课程资源 + latest_attachment = course.attachments.order("created_on desc").first + unless latest_attachment.nil? + latest_course_dynamics << {:type => 3, :time => latest_attachment.created_on,:count =>course.attachments.count , :documents=>latest_attachment} + dynamics_count += 1 + end + #课程作业 已经交的学生列表(暂定显示6人),未交的学生列表,作业的状态 + homework = course.homework_commons.order('created_at desc').first + homework_status = ""; + # 判断作业所处的状态,如果是刚发布,就获取剩余时间 + #如果是匿评状态,显示正在匿评 + #如果是匿评结束,显示匿评结束 + #获取作业提交的前6个人,不足6个显示所有 + studentlist = [] + if !homework.nil? + if homework.homework_type == 1 && homework.homework_detail_manual + case homework.homework_detail_manual.comment_status + when 1 + homework_status = show_homework_deadline homework + when 2 + homework_status = "正在匿评中" + when 3 + homework_status = "匿评已结束" + end + elsif homework.homework_type == 0 + homework_status = "未启用匿评" + elsif homework.homework_type == 2 + homework_status = "编程作业" + else + end + # 获取提交作业的前六个学生的名字 和 头像路径 + homework.student_works.order("created_at desc").page(1).per(6).each do |work| + studentlist << {:image_url=> url_to_avatar(work.user),:user_name=>work.user.realname} + end + latest_course_dynamics << {:type => 4, :time => homework.updated_at, :count=>course.homework_commons.count,:submit_count => homework.student_works.count , :homework => homework, :homework_status => homework_status, :studentlist => studentlist} + dynamics_count += 1 + end + latest_course_dynamics.sort! { |order, newer| newer[:time] <=> order[:time] } + latest_course_dynamic = latest_course_dynamics.first + unless latest_course_dynamic.nil? + result << {:course_name => course.name, :course_id => course.id, :course_img_url => url_to_avatar(course), :course_time => course.time, :course_term => course.term,:message => dynamics_count, :dynamics => latest_course_dynamics, :count => dynamics_count} + end + end + #返回数组集合 + result.sort! { |order, newer| newer[:update_time] <=> order[:update_time] } + result + end + + #计算作业的截止日期,剩余日期 + def show_homework_deadline homework + "距作业截止还有" << (Date.parse(Time.now.to_s) - Date.parse(homework.end_time.to_s)).to_i.to_s << "天" + end + end -end \ No newline at end of file diff --git a/app/views/courses/_history.html.erb b/app/views/courses/_history.html.erb index 0e4598193..df2737337 100644 --- a/app/views/courses/_history.html.erb +++ b/app/views/courses/_history.html.erb @@ -1,55 +1,56 @@ <% reply_allow = JournalsForMessage.create_by_user? User.current %> -<% if journals.size > 0 %> - <% for journal in journals %> -
- <%= journal.notes.html_safe %> -
-+ <%= journal.notes.html_safe %> +
+开启匿评后学生将不能对作品进行 修改、删除 - 等操作,目前有 + 等操作,开启匿评后的提交作品,将 + 不能参与匿评, + 匿评评分将被记为 + 0分 + 。目前有 <%= @totle_size%>个 学生,共提交了 <%= @cur_size %> diff --git a/app/views/mailer/send_for_user_activities.html.erb b/app/views/mailer/send_for_user_activities.html.erb index 98abc00f7..22eb23bf7 100644 --- a/app/views/mailer/send_for_user_activities.html.erb +++ b/app/views/mailer/send_for_user_activities.html.erb @@ -7,7 +7,7 @@
+ 当前作业 + 已开启匿评 + 您提交作品后将 + 不会收到任何匿评作品, + 您的作品也 + 不会被其他用户匿评. + 如需获得最终成绩,请您联系主讲老师对您的作品单独进行评分 +
+ 确定 +据说雷锋做完好事是从来不留名的呢,我们这次评分也不留名!!!但是,但是,您给的分数一定要公正哦,老天爷看不到,我们的系统可是清楚得很!
+别怪我没告诉你,系统分配给你的作品不评价可是要扣分的哈!
+ 匿名评分 + 冒着扣分的危险残忍拒绝 +