91 lines
2.9 KiB
Ruby
91 lines
2.9 KiB
Ruby
class HomeworkAttachController < ApplicationController
|
|
#显示作业信息
|
|
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
|
|
@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]
|
|
end
|
|
|
|
#删除留言
|
|
def destroy
|
|
@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])
|
|
@homework.addjours User.current.id, params[:new_form][:user_message],0
|
|
@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 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
|
|
|