2015-05-19 17:12:43 +08:00
|
|
|
class StudentWorkController < ApplicationController
|
|
|
|
layout "base_courses"
|
2015-05-26 18:14:53 +08:00
|
|
|
include StudentWorkHelper
|
2015-05-20 17:53:01 +08:00
|
|
|
before_filter :find_homework, :only => [:new, :index, :create]
|
2015-05-23 11:24:24 +08:00
|
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score]
|
|
|
|
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score]
|
2015-05-20 17:53:01 +08:00
|
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
2015-05-19 17:12:43 +08:00
|
|
|
|
|
|
|
def index
|
2015-05-21 17:17:54 +08:00
|
|
|
@stundet_works = @homework.student_works.order("final_score desc")
|
2015-05-19 17:12:43 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-05-21 17:28:38 +08:00
|
|
|
student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
|
|
|
if student_work.nil?
|
|
|
|
@stundet_work = StudentWork.new
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_403
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-21 15:52:27 +08:00
|
|
|
if params[:student_work]
|
|
|
|
stundet_work = StudentWork.new
|
|
|
|
stundet_work.name = params[:student_work][:name]
|
|
|
|
stundet_work.description = params[:student_work][:description]
|
|
|
|
stundet_work.project_id = params[:student_work][:project_id]
|
|
|
|
stundet_work.homework_common_id = @homework.id
|
|
|
|
stundet_work.user_id = User.current.id
|
|
|
|
stundet_work.save_attachments(params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(stundet_work)
|
|
|
|
if stundet_work.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
redirect_to student_work_index_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_failed_create)
|
|
|
|
redirect_to new_student_work_url(:homework => @homework.id)
|
|
|
|
}
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-20 17:53:01 +08:00
|
|
|
def show
|
2015-05-27 08:55:33 +08:00
|
|
|
@score = student_work_score @work,User.current
|
2015-05-21 17:17:54 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-20 17:53:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#添加评分,已评分则为修改评分
|
2015-05-22 14:45:01 +08:00
|
|
|
def add_score
|
2015-05-27 16:01:00 +08:00
|
|
|
@score = student_work_score @work,User.current
|
|
|
|
if @score
|
|
|
|
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
|
|
|
@score.score = params[:score] if params[:score]
|
|
|
|
@is_new = false
|
2015-05-26 18:14:53 +08:00
|
|
|
else
|
2015-05-27 16:01:00 +08:00
|
|
|
@score = StudentWorksScore.new
|
|
|
|
@score.score = params[:score] if params[:score]
|
|
|
|
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
|
|
|
@score.user_id = User.current.id
|
|
|
|
@score.student_work_id = @work.id
|
|
|
|
@score.reviewer_role = 1
|
|
|
|
@is_new = true
|
2015-05-26 18:14:53 +08:00
|
|
|
end
|
2015-05-26 17:51:56 +08:00
|
|
|
|
2015-05-27 16:01:00 +08:00
|
|
|
@score.save_attachments(params[:attachments])
|
|
|
|
render_attachment_warning_if_needed(@score)
|
2015-05-26 18:14:53 +08:00
|
|
|
|
2015-05-27 16:01:00 +08:00
|
|
|
if @score.save
|
2015-05-26 18:14:53 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-23 11:24:24 +08:00
|
|
|
end
|
|
|
|
end
|
2015-05-22 14:45:01 +08:00
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#添加评分的回复
|
2015-05-23 11:24:24 +08:00
|
|
|
def add_score_reply
|
2015-05-27 15:11:11 +08:00
|
|
|
@score = StudentWorksScore.find params[:score_id]
|
2015-05-27 14:58:55 +08:00
|
|
|
@jour = @score.journals_for_messages.new(:user_id => User.current.id,:notes =>params[:message], :reply_id => 0)
|
|
|
|
if @jour.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-23 11:24:24 +08:00
|
|
|
end
|
2015-05-22 14:45:01 +08:00
|
|
|
end
|
|
|
|
|
2015-05-27 11:25:32 +08:00
|
|
|
#删除评分的回复
|
|
|
|
def destroy_score_reply
|
2015-05-27 15:11:11 +08:00
|
|
|
@jour = JournalsForMessage.find params[:jour_id]
|
|
|
|
if @jour.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2015-05-27 11:25:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-19 17:12:43 +08:00
|
|
|
private
|
|
|
|
#获取作业
|
|
|
|
def find_homework
|
|
|
|
@homework = HomeworkCommon.find params[:homework]
|
|
|
|
@course = @homework.course
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
#获取作品
|
|
|
|
def find_work
|
|
|
|
@work = StudentWork.find params[:id]
|
2015-05-21 17:33:54 +08:00
|
|
|
@homework = @work.homework_common
|
|
|
|
@course = @homework.course
|
2015-05-19 17:12:43 +08:00
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
2015-05-20 17:53:01 +08:00
|
|
|
|
|
|
|
#是不是当前课程的成员
|
|
|
|
#当前课程成员才可以看到作品列表
|
|
|
|
def member_of_course
|
|
|
|
render_403 unless User.current.member_of_course? @course
|
|
|
|
end
|
|
|
|
|
|
|
|
#判断是不是当前作品的提交者
|
|
|
|
#提交者可以编辑作品
|
|
|
|
def author_of_work
|
2015-05-21 17:33:54 +08:00
|
|
|
render_403 unless User.current.id == @work.user_id && (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 1 )
|
2015-05-20 17:53:01 +08:00
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|