socialforge/app/controllers/homework_attach_controller.rb

144 lines
4.2 KiB
Ruby
Raw Normal View History

2014-05-16 11:02:25 +08:00
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 create
@homework = HomeworkAttach.new(params[:homework])
respond_to do |format|
if @homework.save
format.html { redirect_to @homework, notice: 'Post was successfully created.' }
format.json { render json: @homework, status: :created, location: @homework }
else
format.html { render action: "new" }
format.json { render json: @homework.errors, status: :unprocessable_entity }
end
end
end
def new
@homework = HomeworkAttach.new
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])
respond_to do |format|
if @post.update_attributes(params[:homework])
format.html { redirect_to @homework, notice: 'Homework was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @homework.errors, status: :unprocessable_entity }
end
end
end
def destroy
end
2014-05-16 11:02:25 +08:00
#显示作业信息
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]
2014-05-16 11:02:25 +08:00
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])
@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
2014-05-16 11:02:25 +08:00
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
2014-05-16 11:02:25 +08:00
end