添加作业的发布功能

This commit is contained in:
cxt 2015-10-30 13:58:54 +08:00
parent c4816a0414
commit 6dcc97d5d1
13 changed files with 147 additions and 15 deletions

View File

@ -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]

View File

@ -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
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

View File

@ -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,13 +34,22 @@ class HomeworkCommon < ActiveRecord::Base
#课程动态公共表记录
def act_as_course_activity
if self.course
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
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)
@ -47,6 +57,7 @@ class HomeworkCommon < ActiveRecord::Base
end
end
end
end
#删除对应的图片
def delete_kindeditor_assets
@ -54,8 +65,10 @@ class HomeworkCommon < ActiveRecord::Base
end
def send_mail
if self.homework_detail_manual.comment_status != 0
Mailer.run.homework_added(self)
end
end
def is_program_homework?
self.homework_type == 2 && self.homework_detail_programing

View File

@ -1,6 +1,7 @@
<script type="text/javascript">
function reset_homework(){
$("#homework_name").val("");
$("#homework_publish_time").val("");
$("#homework_end_time").val("");
$("#course_id").val($("#option_select").val());
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => HomeworkCommon.new })%>");

View File

@ -1,6 +1,7 @@
<script type="text/javascript">
function reset_homework(){
$("#homework_name").val("");
$("#homework_publish_time").val("");
$("#homework_end_time").val("");
$("#course_id").val($("#option_select").val());
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => HomeworkCommon.new,:has_program => true })%>");

View File

@ -15,7 +15,9 @@
</span>
<% if homework_common.homework_detail_manual%>
<% if homework_common.homework_detail_manual.comment_status == 1%>
<% if homework_common.homework_detail_manual.comment_status == 0 %>
<span class="grey_btn_cir ml10">未发布</span>
<% elsif homework_common.homework_detail_manual.comment_status == 1%>
<span class="grey_btn_cir ml10">未开启匿评</span>
<% elsif homework_common.homework_detail_manual.comment_status == 2%>
<span class="green_btn_cir ml10">匿评中</span>
@ -72,7 +74,9 @@
<%= link_to("评分设置", score_rule_set_homework_common_path(homework_common, :is_in_course => is_in_course),:class => "postOptionLink", :remote => true) %>
</li>
<li>
<%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common),:class => "postOptionLink", :remote => true) if homework_common.homework_detail_manual.comment_status == 1%>
<% if homework_common.homework_detail_manual.comment_status == 0 || homework_common.homework_detail_manual.comment_status == 1%>
<%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common),:class => "postOptionLink", :remote => true)%>
<% end %>
</li>
<li>
<%= homework_anonymous_comment homework_common %>

View File

@ -18,6 +18,10 @@
<div class=" mt10">
<%= link_to("导入作业", user_import_homeworks_user_path(User.current.id,:select_course => defined?(select_course)),:class => "BlueCirBtn fl mr10",:remote => true) unless edit_mode%>
<div class="calendar_div fl">
<input type="text" name="homework_common[publish_time]" id="homework_publish_time" placeholder="发布日期" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= homework.publish_time%>" >
<%= calendar_for('homework_publish_time')%>
</div>
<div class="calendar_div fl ml10">
<input type="text" name="homework_common[end_time]" id="homework_end_time" placeholder="截止日期" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= homework.end_time%>" >
<%= calendar_for('homework_end_time')%>
</div>

View File

@ -1,6 +1,7 @@
<script type="text/javascript">
function reset_homework(){
$("#homework_name").val("");
$("#homework_publish_time").val("");
$("#homework_end_time").val("");
$("#course_id").val($("#option_select").val());
$("#homework_attachments").html("<%= escape_javascript(render :partial => 'users/user_homework_attachment', :locals => { :container => HomeworkCommon.new,:has_program => true })%>");

View File

@ -0,0 +1,16 @@
class UpdateHomeworkCommonPublishTime < ActiveRecord::Migration
def up
count = HomeworkCommon.all.count / 30 + 2
transaction do
for i in 1 ... count do i
HomeworkCommon.page(i).per(30).each do |homework|
homework.publish_time = homework.created_at.strftime('%d-%b-%Y')
homework.save
end
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151022071804) do
ActiveRecord::Schema.define(:version => 20151029030006) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false

View File

@ -0,0 +1,23 @@
#coding=utf-8
namespace :homework_publishtime do
desc "start publish homework"
task :publish => :environment do
homework_commons = HomeworkCommon.where("publish_time = '#{Date.today}'")
homework_commons.each do |homework|
homework_detail_manual = homework.homework_detail_manual
if homework_detail_manual.comment_status == 0
homework_detail_manual.update_column('comment_status', 1)
course = homework.course
course.members.each do |m|
homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => nil)
end
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
end
# 邮件通知
Mailer.run.homework_added(homework)
end
end
end
end

View File

@ -629,6 +629,9 @@ function submit_homework(id){
else if(!regex_homework_end_time()){
$("#homework_end_time").focus();
}
else if(!regex_homework_end_publish_time()){
$("#homework_end_time").focus();
}
else if(!regex_course_id()){
$("#course_id").focus();
}
@ -654,6 +657,27 @@ function regex_homework_name()
return true;
}
}
//验证发布时间不能大于截止时间
function regex_homework_end_publish_time()
{
var myDate = new Date();
if($.trim($("#homework_publish_time").val()) == "")
{
$("#homework_publish_time").val(myDate.toLocaleDateString());
}
var publish_time = Date.parse($("#homework_publish_time").val());
if(end_time < publish_time)
{
$("#homework_end_time_span").text("截止日期不能小于发布日期");
return false;
}
else
{
$("#homework_end_time_span").text("");
return true;
}
}
//验证截止时间
function regex_homework_end_time()
{

View File

@ -63,6 +63,9 @@ function submit_homework(id){
else if(!regex_homework_end_time()){
$("#homework_end_time").focus();
}
else if(!regex_homework_end_publish_time()){
$("#homework_end_time").focus();
}
else if(!regex_course_id()){
$("#course_id").focus();
}
@ -88,6 +91,28 @@ function regex_homework_name()
return true;
}
}
//验证发布时间不能大于截止时间
function regex_homework_end_publish_time()
{
var myDate = new Date();
if($.trim($("#homework_publish_time").val()) == "")
{
$("#homework_publish_time").val(myDate.toLocaleDateString());
}
var end_time = Date.parse($("#homework_end_time").val());
var publish_time = Date.parse($("#homework_publish_time").val());
if(end_time < publish_time)
{
$("#homework_end_time_span").text("截止日期不能小于发布日期");
return false;
}
else
{
$("#homework_end_time_span").text("");
return true;
}
}
//验证截止时间
function regex_homework_end_time()
{