From 6dcc97d5d1fb2fb7c648b7fb508b852948877707 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 30 Oct 2015 13:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=9C=E4=B8=9A=E7=9A=84?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 8 ++++++ app/controllers/users_controller.rb | 20 ++++++++++++--- app/models/homework_common.rb | 25 ++++++++++++++----- app/views/homework_common/edit.html.erb | 1 + app/views/homework_common/index.html.erb | 1 + .../users/_user_homework_detail.html.erb | 8 ++++-- app/views/users/_user_homework_form.html.erb | 4 +++ app/views/users/user_homeworks.html.erb | 1 + ...006_update_homework_common_publish_time.rb | 16 ++++++++++++ db/schema.rb | 6 ++--- lib/tasks/homework_publishtime.rake | 23 +++++++++++++++++ public/javascripts/course.js | 24 ++++++++++++++++++ public/javascripts/new_user.js | 25 +++++++++++++++++++ 13 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20151029030006_update_homework_common_publish_time.rb create mode 100644 lib/tasks/homework_publishtime.rake diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 55807886b..3db7ada2b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -47,10 +47,18 @@ class HomeworkCommonController < ApplicationController if params[:homework_common] @homework.name = params[:homework_common][:name] @homework.description = params[:homework_common][:description] + if params[:homework_common][:publish_time] == "" + @homework.publish_time = Date.today + else + @homework.publish_time = params[:homework_common][:publish_time] + end @homework.end_time = params[:homework_common][:end_time] || Time.now @homework.course_id = params[:course_id] homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new + if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0 + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? @homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7c41dd038..133fcd94c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -368,8 +368,12 @@ class UsersController < ApplicationController if User.current == @user @page = params[:page] ? params[:page].to_i + 1 : 0 user_course_ids = @user.courses.empty? ? "(-1)" :"(" + @user.courses.visible.map{|course| course.id}.join(",") + ")" - @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) @is_teacher = User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true) + if @is_teacher + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids}").order("created_at desc").limit(10).offset(@page * 10) + else + @homework_commons = HomeworkCommon.where("course_id in #{user_course_ids} and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + end @is_in_course = params[:is_in_course].to_i || 0 respond_to do |format| format.js @@ -493,8 +497,12 @@ class UsersController < ApplicationController homework = HomeworkCommon.new homework.name = params[:homework_common][:name] homework.description = params[:homework_common][:description] - homework.end_time = params[:homework_common][:end_time] || Time.now - homework.publish_time = Time.now + homework.end_time = params[:homework_common][:end_time] || Date.today + if params[:homework_common][:publish_time] == "" + homework.publish_time = Date.today + else + homework.publish_time = params[:homework_common][:publish_time] + end homework.homework_type = params[:homework_type].to_i || 1 homework.late_penalty = 10 homework.teacher_priority = 1 @@ -506,7 +514,11 @@ class UsersController < ApplicationController homework_detail_manual = HomeworkDetailManual.new homework_detail_manual.ta_proportion = homework.homework_type == 1 ? 0.6 : 0.3 - homework_detail_manual.comment_status = 1 + if homework.publish_time > Date.today + homework_detail_manual.comment_status = 0 + else + homework_detail_manual.comment_status = 1 + end homework_detail_manual.evaluation_start = params[:evaluation_start].blank? ? homework.end_time + 7 : params[:evaluation_start] homework_detail_manual.evaluation_end = params[:evaluation_end].blank? ? homework_detail_manual.evaluation_start + 7 : params[:evaluation_end] homework_detail_manual.evaluation_num = params[:evaluation_num] || 3 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 03a7644a2..8d421a98f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -23,7 +23,8 @@ class HomeworkCommon < ActiveRecord::Base :description => :description, :author => :author, :url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}} - after_create :act_as_activity, :send_mail, :act_as_course_activity, :act_as_course_message + after_create :act_as_activity, :send_mail, :act_as_course_message + after_save :act_as_course_activity after_destroy :delete_kindeditor_assets def act_as_activity @@ -33,17 +34,27 @@ class HomeworkCommon < ActiveRecord::Base #课程动态公共表记录 def act_as_course_activity if self.course - self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + if self.homework_detail_manual.comment_status == 0 + self.course_acts.destroy_all + else + if self.course_acts.size == 0 + self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) + end + end end end #课程作业消息记录 def act_as_course_message if self.course - self.course.members.each do |m| - # if m.user_id != self.user_id + if self.homework_detail_manual.comment_status == 0 + self.course_messages.destroy_all + else + self.course.members.each do |m| + # if m.user_id != self.user_id self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false) - # end + # end + end end end end @@ -54,7 +65,9 @@ class HomeworkCommon < ActiveRecord::Base end def send_mail - Mailer.run.homework_added(self) + if self.homework_detail_manual.comment_status != 0 + Mailer.run.homework_added(self) + end end def is_program_homework? diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb index 5fc11728b..79692207f 100644 --- a/app/views/homework_common/edit.html.erb +++ b/app/views/homework_common/edit.html.erb @@ -1,6 +1,7 @@