增加学生进入课程作业界面后相关的路由、界面动态切换显示

This commit is contained in:
sw 2014-11-01 11:02:13 +08:00
parent c045b4682a
commit 58d2306728
9 changed files with 83 additions and 20 deletions

View File

@ -490,7 +490,6 @@ class BidsController < ApplicationController
if @bid.homework_type
@homework = HomeworkAttach.new
@is_teacher = is_course_teacher(User.current,@bid.courses.first)
#if @is_teacher
teachers = "("
teacher_members = searchTeacherAndAssistant(@bid.courses.first)
teacher_members.each do |member|
@ -500,14 +499,22 @@ class BidsController < ApplicationController
teachers += member.user_id.to_s + ","
end
end
if @is_teacher
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1
WHERE table1.t_score IS NULL")
#else
# all_homework_list = HomeworkAttach.all
#end
else
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM(SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score,
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = 3123) AS m_score
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id}) AS table1
WHERE table1.m_score IS NULL")
end
@homework_list = paginateHelper all_homework_list,10

View File

@ -7,7 +7,7 @@ class HomeworkAttachController < ApplicationController
before_filter :can_show_course,except: []
#判断当前角色权限时需先找到当前操作的project
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours]
before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
@ -68,6 +68,46 @@ class HomeworkAttachController < ApplicationController
end
end
#获取学生匿评列表
def get_student_batch_homework
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM(SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score,
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = 3123) AS m_score
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id}) AS table1
WHERE table1.m_score IS NULL")
@homework_list = paginateHelper all_homework_list,10
respond_to do |format|
format.js
end
end
#获取我的作业
def get_my_homework
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
FROM homework_attaches
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}");
#如果我没有创建过作业,就检索我是否参与了某个作业
if all_homework_list.empty?
all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
FROM homework_attaches
INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}")
end
@homework_list = paginateHelper all_homework_list,10
respond_to do |format|
format.js
end
end
#获取作业的留言列表
def get_homework_jours
#@user = @bid.author

View File

@ -28,16 +28,16 @@
</ul>
<% else %>
<ul>
<li id="tb_1" class="hovertab">待评作品
<li id="tb_5" class="hovertab">
<%= link_to "待评作品", get_student_batch_homework_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%>
</li>
<li id="tb_2" class="normaltab">我的作品
<li id="tb_6" class="normaltab">
<%= link_to "我的作品", get_my_homework_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%>
</li>
<li id="tb_3" class="normaltab">
<li id="tb_7" class="normaltab">
<%= link_to "所有作品", get_homeworks_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%>
</li>
<li id="tb_4" class="normaltab">
<li id="tb_8" class="normaltab">
<%= link_to "留言", get_homework_jours_homework_attach_index_path(:bid_id => @bid.id), {:remote => true}%>
(<span class="c_red f_12">23</span>)
</li>

View File

@ -1,3 +1,6 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homework_jours',:locals => { :bid => @bid, :journals => @jour, :state => false} )) %>');
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_4").removeClass().addClass("hovertab");
for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_8").removeClass().addClass("hovertab");

View File

@ -3,3 +3,6 @@ $('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_3").removeClass().addClass("hovertab");
for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_7").removeClass().addClass("hovertab");

View File

@ -0,0 +1,4 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_6").removeClass().addClass("hovertab");

View File

@ -1,4 +1,4 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
for(var i=1;i<=5;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
for(var i=1;i<=4;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_1").removeClass().addClass("hovertab");

View File

@ -0,0 +1,4 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list',
:locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true} )) %>');
for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");}
$("#tb_5").removeClass().addClass("hovertab");

View File

@ -48,6 +48,8 @@ RedmineApp::Application.routes.draw do
get 'get_batch_homeworks'
get 'get_homeworks'
get 'get_homework_jours'
get 'get_student_batch_homework'
get 'get_my_homework'
end
member do
match 'add_homework_users', :via => [:get,:post]