From 2dc79889b9a4ac359ffc347feac251179bd80a4e Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 1 Nov 2014 14:33:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AE=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=97=B6=E6=A0=B9=E6=8D=AE=E8=A7=92=E8=89=B2=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=90=8C=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=202.=E5=A2=9E=E5=8A=A0=E5=AD=A6=E7=94=9F=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E3=80=81=E5=88=A0=E9=99=A4=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=203.=E4=BF=AE=E6=94=B9=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BD=9C=E4=B8=9A=E6=97=B6=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 18 +++- app/views/bids/_homework.html.erb | 7 -- .../homework_attach/_homeworks_list.html.erb | 96 +++++++++++++++---- app/views/homework_attach/destroy.js.erb | 2 + .../homework_attach/get_my_homework.js.erb | 2 +- .../get_student_batch_homework.js.erb | 2 +- config/routes.rb | 2 +- 7 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 app/views/homework_attach/destroy.js.erb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index e9a7a96be..2f9edc873 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -70,6 +70,7 @@ class HomeworkAttachController < ApplicationController #获取学生匿评列表 def get_student_batch_homework + @is_student_batch_homework = true 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, @@ -87,12 +88,13 @@ class HomeworkAttachController < ApplicationController #获取我的作业 def get_my_homework + @is_my_homework = true 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}"); + 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.*, @@ -314,9 +316,14 @@ class HomeworkAttachController < ApplicationController def destroy if User.current.admin? || User.current == @homework.user if @homework.destroy + #respond_to do |format| + # format.html { redirect_to course_for_bid_url @homework.bid } + # format.json { head :no_content } + #end + @homework_list = [] + @is_my_homework = true respond_to do |format| - format.html { redirect_to course_for_bid_url @homework.bid } - format.json { head :no_content } + format.js end else end @@ -450,7 +457,10 @@ class HomeworkAttachController < ApplicationController def find_course_by_hoemwork_id @homework = HomeworkAttach.find(params[:id]) - @course = @homework.bid.courses[0] + @bid = @homework.bid + @course = @bid.courses.first + rescue ActiveRecord::RecordNotFound + render_404 end #获取课程的老师列表 diff --git a/app/views/bids/_homework.html.erb b/app/views/bids/_homework.html.erb index 99ce5ae06..471ad73b9 100644 --- a/app/views/bids/_homework.html.erb +++ b/app/views/bids/_homework.html.erb @@ -28,13 +28,6 @@ } -<% if User.current.logged? && User.current.member_of_course?(@bid.courses.first) && cur_user_homework_for_bid(@bid).count == 0 && is_cur_course_student(@bid.courses.first) %> -
- <%= link_to l(:label_course_new_homework),new_homework_attach_path %> -   (每一个作业都可以是一个精美的作品) -
-<% end %> -
<%= render :partial => 'homework_list' %>
diff --git a/app/views/homework_attach/_homeworks_list.html.erb b/app/views/homework_attach/_homeworks_list.html.erb index f7e2bee59..53b384e2c 100644 --- a/app/views/homework_attach/_homeworks_list.html.erb +++ b/app/views/homework_attach/_homeworks_list.html.erb @@ -1,21 +1,44 @@ <% is_teacher = is_course_teacher(User.current,@bid.courses.first) %> -
- - <%= l(:label_homework_list)%> - ( +<% is_my_homework ||= false %> +<% is_student_batch_homework ||= false %> + +<% unless is_my_homework || is_student_batch_homework %> +
+ + <%= l(:label_homework_list)%> + ( <%= homework_count%> - ) - - 按  - <%= link_to l(:label_work_rating), sort_homework_path(@bid, 'socre', @direction), {:remote => true}%> -  /  - <%= link_to l(:label_time), sort_homework_path(@bid, 'time', @direction), {:remote => true}%> -  <%= l(:label_sort) %> - -
+
) +
+ 按  + <%= link_to l(:label_work_rating), sort_homework_path(@bid, 'socre', @direction), {:remote => true}%> +  /  + <%= link_to l(:label_time), sort_homework_path(@bid, 'time', @direction), {:remote => true}%> +  <%= l(:label_sort) %> + +
+<% end %>
+ <% unless homeworks.nil? %> + <% if !is_teacher && is_my_homework && homeworks.empty? %> + + +
+ <% end %> + <% homeworks.each do |homework| %>
<% end %> <% else %> <% end %> - \ No newline at end of file + +<% unless is_my_homework || is_student_batch_homework %> + +<% end %> \ No newline at end of file diff --git a/app/views/homework_attach/destroy.js.erb b/app/views/homework_attach/destroy.js.erb new file mode 100644 index 000000000..33d132ed4 --- /dev/null +++ b/app/views/homework_attach/destroy.js.erb @@ -0,0 +1,2 @@ +$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', + :locals => {:homeworks => @homework_list, :bid => @bid, :remote => true, :is_my_homework => @is_my_homework} )) %>'); \ No newline at end of file diff --git a/app/views/homework_attach/get_my_homework.js.erb b/app/views/homework_attach/get_my_homework.js.erb index d841d83ae..cb6288391 100644 --- a/app/views/homework_attach/get_my_homework.js.erb +++ b/app/views/homework_attach/get_my_homework.js.erb @@ -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} )) %>'); + :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true, :is_my_homework => @is_my_homework} )) %>'); for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");} $("#tb_6").removeClass().addClass("hovertab"); \ No newline at end of file diff --git a/app/views/homework_attach/get_student_batch_homework.js.erb b/app/views/homework_attach/get_student_batch_homework.js.erb index 15be005da..158d32817 100644 --- a/app/views/homework_attach/get_student_batch_homework.js.erb +++ b/app/views/homework_attach/get_student_batch_homework.js.erb @@ -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} )) %>'); + :locals => {:homeworks => @homework_list, :homework_count => @obj_count, :bid => @bid, :remote => true, :is_student_batch_homework => @is_student_batch_homework} )) %>'); for(var i=5;i<=8;i++){$("#tb_"+i).removeClass().addClass("normaltab");} $("#tb_5").removeClass().addClass("hovertab"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c86407980..730d4514d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -701,7 +701,7 @@ RedmineApp::Application.routes.draw do match 'contest/new_contest', :to => 'bids#new_contest' #huang match 'calls/:id/show_project', :to => 'bids#show_project', :as => 'project_for_bid' match 'calls/:id/show_course', :to => 'bids#show_courseEx', :as => 'course_for_bid' # nwb added - match 'calls/:id/new_exercise_book', :to => 'homework_attach#new', :as => 'new_homework_attach' + match 'calls/:id/new_exercise_book', :to => 'homework_attach#new', :as => 'new_exercise_book' match 'calls/:id/add', :to => 'bids#add' match 'calls/:id/delete', :to => 'bids#delete' match 'calls/:id/add_homework', :to => 'bids#add_homework', :via => :post