187 lines
5.8 KiB
Ruby
187 lines
5.8 KiB
Ruby
class HomeworkAttachController < ApplicationController
|
|
###############################
|
|
def index
|
|
@homeworks = HomeworkAttach.all
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @homeworks }
|
|
end
|
|
end
|
|
|
|
def add_users users
|
|
if users != nil && users.count > 0
|
|
users.each do |user|
|
|
@homework.homework_users.build(:user_id => user.id)
|
|
@homework.save
|
|
end
|
|
end
|
|
end
|
|
|
|
def create
|
|
#if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)
|
|
user_id = params[:user_id]
|
|
bid_id = params[:bid_id]
|
|
sta = 0
|
|
name = params[:new_form][:name]
|
|
description = params[:new_form][:description]
|
|
options = {
|
|
:user_id => user_id,
|
|
:state => sta,
|
|
:name => name,
|
|
:description => description,
|
|
:bid_id => bid_id
|
|
}
|
|
|
|
#@bid = Bid.find bid_id
|
|
#@homework_list = @bid.homeworks
|
|
|
|
@homework = HomeworkAttach.new(options)
|
|
@homework.save_attachments(params[:attachments])
|
|
render_attachment_warning_if_needed(@homework)
|
|
|
|
if @homework.save
|
|
respond_to do |format|
|
|
format.html { redirect_to project_for_bid_path @homework.bid }
|
|
format.json { head :no_content }
|
|
end
|
|
else
|
|
|
|
end
|
|
#end
|
|
end
|
|
|
|
def new
|
|
@homework = HomeworkAttach.new
|
|
@bid = Bid.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.json { render json: @homework }
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@homework = HomeworkAttach.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@homework = HomeworkAttach.find(params[:id])
|
|
name = params[:homework_name]
|
|
description = params[:homework_description]
|
|
@homework.name = name
|
|
@homework.description = description
|
|
if params[:attachments]
|
|
@homework.save_attachments(params[:attachments])
|
|
end
|
|
if @homework.save
|
|
respond_to do |format|
|
|
format.html { redirect_to project_for_bid_path @homework.bid }
|
|
format.json { head :no_content }
|
|
end
|
|
else
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@homework = HomeworkAttach.find(params[:id])
|
|
if @homework.destroy
|
|
respond_to do |format|
|
|
format.html { redirect_to project_for_bid_path @homework.bid }
|
|
format.json { head :no_content }
|
|
end
|
|
else
|
|
end
|
|
end
|
|
|
|
#显示作业信息
|
|
def show
|
|
@homework = HomeworkAttach.find(params[:id])
|
|
# 打分统计
|
|
stars_reates = @homework.
|
|
rates(:quality)
|
|
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
|
|
stars_status = stars_reates.select("stars, count(*) as scount").
|
|
group("stars")
|
|
@stars_status_map = Hash.new(0.0)
|
|
stars_status.each do |star_status|
|
|
percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f
|
|
percent_m = format("%.2f", percent)
|
|
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
|
|
percent_m.to_s + "%"
|
|
end
|
|
@limit = 10
|
|
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
|
|
@feedback_count = @jours.count
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
@offset ||= @feedback_pages.offset
|
|
@jour = @jours[@offset, @limit]
|
|
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
|
end
|
|
|
|
#删除留言
|
|
def destroy_jour
|
|
@journal_destroyed = JournalsForMessage.delete_message(params[:object_id])
|
|
#@homework = HomeworkAttach.find(params[:id])
|
|
#@jours = @homework.journals_for_messages.order("created_on DESC")
|
|
#@limit = 10
|
|
#@feedback_count = @jours.count
|
|
#@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
#@offset ||= @feedback_pages.offset
|
|
#@jour = @jours[@offset, @limit]
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
#添加留言
|
|
def addjours
|
|
@homework = HomeworkAttach.find(params[:jour_id])
|
|
@add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
|
|
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
|
|
@limit = 10
|
|
@feedback_count = @jours.count
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
@offset ||= @feedback_pages.offset
|
|
@jour = @jours[@offset, @limit]
|
|
@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
|
|
respond_to do |format|
|
|
format.js
|
|
end
|
|
end
|
|
|
|
#获取指定作业的平均得分
|
|
def score
|
|
#stars_reates = @homework.rates(:quality)
|
|
#percent = 0
|
|
#stars_reates.each do |star_reates|
|
|
# percent = percent + star_reates.stars
|
|
#end
|
|
#stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
|
|
#result = percent * 1.0 / stars_reates_count
|
|
#result
|
|
end
|
|
|
|
#添加回复
|
|
def add_jour_reply
|
|
parent_id = params[:reference_id]
|
|
author_id = User.current.id
|
|
reply_user_id = params[:reference_user_id]
|
|
reply_id = params[:reference_message_id] # 暂时不实现
|
|
content = params[:user_notes]
|
|
options = {:user_id => author_id,
|
|
:m_parent_id => parent_id,
|
|
:m_reply_id => reply_id,
|
|
:reply_id => reply_user_id,
|
|
:notes => content,
|
|
:is_readed => false}
|
|
@jfm = JournalsForMessage.new(options)
|
|
@jfm.save
|
|
respond_to do |format|
|
|
format.js{
|
|
@save_succ = true if @jfm.errors.empty?
|
|
}
|
|
end
|
|
end
|
|
end
|
|
|