diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 4a9e3bb1f..b2ecf7cba 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -4,14 +4,61 @@ class HomeworkAttachController < ApplicationController ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project - before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework] + before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours] 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] #获取未批作业列表 def get_not_batch_homework - @homeworks = HomeworkAttach.all + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取已评作业列表 + def get_batch_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取所有作业列表 + def get_homeworks + teachers = find_course_teachers @course + limit = 10 + start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit + @homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).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 bid_id = #{@bid.id} + ORDER BY s_score DESC,created_at ASC + limit #{start_item}, #{limit}") + respond_to do |format| + format.js + end + end + + #获取作业的留言列表 + def get_homework_jours respond_to do |format| format.js end @@ -328,7 +375,7 @@ class HomeworkAttachController < ApplicationController def find_course_by_bid_id @bid = Bid.find(params[:id]) - @course = @bid.courses[0] + @course = @bid.courses.first rescue ActiveRecord::RecordNotFound render_404 end @@ -337,5 +384,19 @@ class HomeworkAttachController < ApplicationController @homework = HomeworkAttach.find(params[:id]) @course = @homework.bid.courses[0] end + + #获取课程的老师列表 + def find_course_teachers course + teachers = "(" + teacher_members = searchTeacherAndAssistant(course) + teacher_members.each do |member| + if member == teacher_members.last + teachers += member.user_id.to_s + ")" + else + teachers += member.user_id.to_s + "," + end + end + teachers + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 947dd455f..46bdf4b3d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -2,20 +2,8 @@ 作业列表页_老师界面 <%= stylesheet_link_tag 'css', :media => 'all' %> @@ -28,97 +16,24 @@
  • <%= link_to "未批作业", get_not_batch_homework_homework_attach_path(@bid), {:remote => true}%>
  • -
  • 已改作业
  • -
  • 全部作业
  • +
  • + <%= link_to "已改作业", get_batch_homeworks_homework_attach_path(@bid), {:remote => true}%> +
  • +
  • + <%= link_to "全部作业", get_homeworks_homework_attach_path(@bid), {:remote => true}%> +
  • 作业下载
  • -
  • 留言(23)
  • +
  • + <%= link_to "留言", get_homework_jours_homework_attach_path(@bid), {:remote => true}%> + (23) +
  • - <%= render :partial => 'homework_attach/not_batch_homwork', :locals => {:homeworks => homework}%> + <%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => homework}%>
    -
    -
    作品列表(2)按 评分 / 时间 排序
    -
    - -
    - -
    - -
    -
    -
    -
    作品列表(3)按 评分 / 时间 排序
    -
    - -
    - -
    - -
    - -
    -
    -
    -
    -
    -

    留言内容

    - - 取  消留  言 - -
    -
    -
    -
    diff --git a/app/views/homework_attach/_homework_jours.html.erb b/app/views/homework_attach/_homework_jours.html.erb new file mode 100644 index 000000000..1c48dfb3a --- /dev/null +++ b/app/views/homework_attach/_homework_jours.html.erb @@ -0,0 +1,7 @@ +
    +

    留言内容

    + + 取  消留  言 + +
    +
    \ No newline at end of file diff --git a/app/views/homework_attach/_not_batch_homwork.html.erb b/app/views/homework_attach/_homeworks_list.html.erb similarity index 100% rename from app/views/homework_attach/_not_batch_homwork.html.erb rename to app/views/homework_attach/_homeworks_list.html.erb diff --git a/app/views/homework_attach/get_batch_homeworks.js.erb b/app/views/homework_attach/get_batch_homeworks.js.erb new file mode 100644 index 000000000..bcd6e9550 --- /dev/null +++ b/app/views/homework_attach/get_batch_homeworks.js.erb @@ -0,0 +1 @@ +$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>'); \ No newline at end of file diff --git a/app/views/homework_attach/get_homework_jours.js.erb b/app/views/homework_attach/get_homework_jours.js.erb new file mode 100644 index 000000000..c2e9bc572 --- /dev/null +++ b/app/views/homework_attach/get_homework_jours.js.erb @@ -0,0 +1 @@ +$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homework_jours' )) %>'); \ No newline at end of file diff --git a/app/views/homework_attach/get_homeworks.js.erb b/app/views/homework_attach/get_homeworks.js.erb new file mode 100644 index 000000000..6ee4e9265 --- /dev/null +++ b/app/views/homework_attach/get_homeworks.js.erb @@ -0,0 +1,2 @@ +$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>'); + diff --git a/app/views/homework_attach/get_not_batch_homework.js.erb b/app/views/homework_attach/get_not_batch_homework.js.erb new file mode 100644 index 000000000..bcd6e9550 --- /dev/null +++ b/app/views/homework_attach/get_not_batch_homework.js.erb @@ -0,0 +1 @@ +$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 43181d6db..535f9aa9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,9 @@ RedmineApp::Application.routes.draw do end member do get 'get_not_batch_homework' + get 'get_batch_homeworks' + get 'get_homeworks' + get 'get_homework_jours' match 'add_homework_users', :via => [:get,:post] match 'destory_homework_users', :via => [:get,:post] end