@ -4,7 +4,7 @@ class StudentWorksController < ApplicationController
before_action :require_login , :check_auth
before_action :find_homework , only : [ :new , :create , :search_member_list , :check_project , :relate_project ,
:cancel_relate_project ]
:cancel_relate_project , :delete_work ]
before_action :find_work , only : [ :shixun_work_report , :adjust_review_score , :shixun_work , :commit_des , :update_des ,
:adjust_score , :show , :adjust_score , :supply_attachments , :revise_attachment ,
:comment_list , :add_score , :add_score_reply , :destroy_score , :appeal_anonymous_score ,
@ -15,12 +15,12 @@ class StudentWorksController < ApplicationController
before_action :teacher_allowed , only : [ :adjust_score , :adjust_review_score , :deal_appeal_score ]
before_action :course_student , only : [ :new , :commit_des , :update_des , :create , :edit , :update , :search_member_list , :relate_project ,
:cancel_relate_project , :relate_project ]
:cancel_relate_project , :relate_project , :delete_work ]
before_action :my_work , only : [ :commit_des , :update_des , :edit , :update , :revise_attachment , :appeal_anonymous_score ,
:cancel_appeal ]
before_action :edit_duration , only : [ :edit , :update ]
before_action :edit_duration , only : [ :edit , :update , :delete_work ]
before_action :end_or_late , only : [ :new , :create , :search_member_list , :commit_des , :update_des ]
before_action :require_score_id , only : [ :destroy_score , :add_score_reply , :appeal_anonymous_score , :deal_appeal_score , :cancel_appeal ]
@ -60,6 +60,25 @@ class StudentWorksController < ApplicationController
@members = @members . page ( page ) . per ( limit ) . includes ( :course_group , user : :user_extension )
end
def delete_work
ActiveRecord :: Base . transaction do
begin
work = @homework . student_works . find_by! ( user_id : params [ :user_id ] )
tip_exception ( " 只有组长才能删除组员 " ) if work . commit_user_id != current_user . id
work . update_attributes ( description : nil , project_id : 0 ,
late_penalty : 0 , work_status : 0 ,
commit_time : nil , update_time : nil , group_id : 0 ,
commit_user_id : nil , final_score : nil , work_score : nil , teacher_score : nil , teaching_asistant_score : nil )
work . attachments . destroy_all
work . tidings . destroy_all
normal_status ( " 删除成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
end
end
end
def create
student_work = @homework . student_works . find_or_create_by ( user_id : current_user . id )
@ -123,8 +142,9 @@ class StudentWorksController < ApplicationController
@current_user = current_user
if @homework . homework_type == " group "
# todo user_extension
@commit_user_id = @work . commit_user_id
@work_members = @course . students . where ( user_id : @homework . student_works . where ( group_id : @work . group_id ) . pluck ( :user_id ) ) .
order ( " course_members. id=#{ @work . user_id} desc " ) . includes ( :course_group , user : :user_extension )
order ( " course_members. user_ id=#{ @work . commit_ user_id} desc " ) . includes ( :course_group , user : :user_extension )
end
end
@ -136,7 +156,7 @@ class StudentWorksController < ApplicationController
begin
@work . description = params [ :description ]
@work . update_time = Time . now
@work . commit_user_id = current_user . id
# @work.commit_user_id = current_user. id
if @work . save!
Attachment . associate_container ( params [ :attachment_ids ] , @work . id , @work . class )
@ -151,7 +171,8 @@ class StudentWorksController < ApplicationController
# 原成员更新描述、更新时间以及附件
@homework . student_works . where ( group_id : @work . group_id , user_id : ( work_user_ids & params_user_ids ) ) . each do | work |
work . update_attributes ( update_time : Time . now , description : @work . description , commit_user_id : current_user . id )
# work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id)
work . update_attributes ( update_time : Time . now , description : @work . description )
work . attachments . destroy_all
@work . attachments . each do | attachment |
att = attachment . copy
@ -179,7 +200,7 @@ class StudentWorksController < ApplicationController
stu_work . update_attributes ( user_id : user_id , description : @work . description , homework_common_id : @homework . id ,
project_id : @work . project_id , late_penalty : @work . late_penalty ,
work_status : @work . work_status , commit_time : Time . now , update_time : Time . now ,
group_id : @work . group_id , commit_user_id : current_user . id)
group_id : @work . group_id , commit_user_id : @work . commit_user_ id)
@work . attachments . each do | attachment |
att = attachment . copy
att . author_id = attachment . author_id
@ -460,7 +481,7 @@ class StudentWorksController < ApplicationController
filename_ = " #{ @use & . student_id } _ #{ @use & . real_name } _ #{ @shixun & . name } _ #{ Time . now . strftime ( '%Y%m%d_%H%M%S' ) } "
filename = Base64 . urlsafe_encode64 ( filename_ . strip )
stylesheets = %w( shixun_work/shixun_work.css shared/codemirror.css )
render pdf : 'shixun_work/shixun_work' , filename : filename , stylesheets : stylesheets
render pdf : 'shixun_work/shixun_work' , filename : filename , stylesheets : stylesheets , disposition : 'inline' , type : " pdf_attachment.content_type " , stream : false
end
# 作品调分