From 7684a6b25372fc76d022befb75e3b4bac4e2085a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 19 May 2015 17:12:43 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=9E=E7=8E=B0=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=E9=A1=B5=E9=9D=A2=202?= =?UTF-8?q?=E3=80=81=E6=96=B0=E5=BB=BA=E4=BD=9C=E4=B8=9A=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BD=9C=E4=B8=9A=E3=80=81=E5=BC=80=E5=90=AF/?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=8C=BF=E8=AF=84=E8=B7=AF=E7=94=B1=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=203=E3=80=81?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89bid=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=204=E3=80=81=E4=BD=9C=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E6=96=B0=E5=BB=BA=E4=BD=9C=E5=93=81=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BD=9C=E5=93=81=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E8=B7=AF=E7=94=B1=E5=8F=8A=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 68 +++++++++ app/controllers/student_work_controller.rb | 45 ++++++ app/helpers/application_helper.rb | 2 +- app/helpers/courses_helper.rb | 130 +----------------- app/helpers/homework_common_helper.rb | 58 ++++++++ app/models/course.rb | 3 +- app/models/homework_common.rb | 2 + app/models/student_work.rb | 2 + app/models/student_works_score.rb | 2 + .../alert_anonymous_comment.js.erb | 1 + app/views/homework_common/edit.html.erb | 1 + app/views/homework_common/index.html.erb | 67 +++++++++ app/views/homework_common/new.html.erb | 1 + .../layouts/_user_homework_list.html.erb | 7 - app/views/layouts/base_courses.html.erb | 6 +- app/views/student_work/index.html.erb | 1 + app/views/student_work/new.html.erb | 1 + config/routes.rb | 108 ++++++++------- 18 files changed, 316 insertions(+), 189 deletions(-) create mode 100644 app/controllers/homework_common_controller.rb create mode 100644 app/controllers/student_work_controller.rb create mode 100644 app/helpers/homework_common_helper.rb create mode 100644 app/views/homework_common/alert_anonymous_comment.js.erb create mode 100644 app/views/homework_common/edit.html.erb create mode 100644 app/views/homework_common/index.html.erb create mode 100644 app/views/homework_common/new.html.erb create mode 100644 app/views/student_work/index.html.erb create mode 100644 app/views/student_work/new.html.erb diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb new file mode 100644 index 000000000..b9a55028d --- /dev/null +++ b/app/controllers/homework_common_controller.rb @@ -0,0 +1,68 @@ +class HomeworkCommonController < ApplicationController + layout "base_courses" + before_filter :find_course, :only => [:index,:new] + + def index + homeworks = @course.homework_commons + @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) + @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) + @homeworks = paginateHelper homeworks,10 + respond_to do |format| + format.html + end + end + + def new + respond_to do |format| + format.html + end + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + + #开启匿评 + def start_anonymous_comment + + end + + #关闭匿评 + def stop_anonymous_comment + + end + + #提示 + def alert_anonymous_comment + respond_to do |format| + format.js + end + end + + private + #获取课程 + def find_course + @course = Course.find params[:course] + rescue + render_404 + end + #获取作业 + def find_homework + @homework = HomeworkCommon.find params[:id] + @course = @homework.course + rescue + render_404 + end +end \ No newline at end of file diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb new file mode 100644 index 000000000..f0538b799 --- /dev/null +++ b/app/controllers/student_work_controller.rb @@ -0,0 +1,45 @@ +class StudentWorkController < ApplicationController + layout "base_courses" + before_filter :find_homework, :only => [:new, :index] + + def index + respond_to do |format| + format.html + end + end + + def new + + respond_to do |format| + format.html + end + end + + def create + + end + + def edit + + end + + def update + + end + + private + #获取作业 + def find_homework + @homework = HomeworkCommon.find params[:homework] + @course = @homework.course + rescue + render_404 + end + #获取作品 + def find_work + @work = StudentWork.find params[:id] + @course = @work.homework_common.course + rescue + render_404 + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0836bf307..571886e17 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2110,7 +2110,7 @@ module ApplicationHelper # courses_link = link_to l(:label_course_practice), {:controller => 'courses', :action => 'index'} #users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.host_user} # contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} - bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} + # bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} forum_link = link_to l(:label_forum_all), {:controller => "forums", :action => "index"} stores_link = link_to l(:label_stores_index), {:controller => 'stores', :action=> 'index'} school_all_school_link = link_to l(:label_school_all), {:controller => 'school', :action => 'index'} diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index babd8cb12..8b13f507b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -428,40 +428,19 @@ module CoursesHelper now > cTime end + def find_by_extra_from_project extra Course.find_by_extra(try(extra)) end + #判断指定用户是不是当前课程的老师 def is_course_teacher (user,course) - #course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{user.id}", {:role_id => TeacherRoles}).count != 0 user.allowed_to?(:as_teacher,course) - #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 - #is_teacher = false - #@membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) - #@membership.each do |membership| - # unless(membership.project.project_type==0) - # if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) - # is_teacher = true - # end - # end - #end - #is_teacher end + #当前用户是不是指定课程的学生 def is_cur_course_student course - #course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{User.current.id}", {:role_id => StudentRoles}).count != 0 User.current.logged? && User.current.member_of_course?(course) && !(User.current.allowed_to?(:as_teacher,course)) - #修改:能新建占位且不能新建任务的角色判定为学生 - #is_student = false - #@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) - #@membership.each do |membership| - # unless(membership.project.project_type==0) - # if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) - # is_student = true - # end - # end - #end - #is_student end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid @@ -479,61 +458,6 @@ module CoursesHelper homework.nil? ? [] : (homework.users + [homework.user]) end - #获取指定作业的最终评分 - #最终评分 = 学生评分的平均分 * 0.4 +教师评分 * 0.6 - def score_for_homework homework - if homework.bid.is_evaluation == 1 || homework.bid.is_evaluation == nil - return format("%.2f",(homework.bid.proportion * 1.0 / 100) * (teacher_score_for_homework(homework).to_f) + (1 - homework.bid.proportion * 1.0 / 100) * (student_score_for_homework(homework).to_f)) - else - return teacher_score_for_homework homework - end - end - def score_for_homework_new homework - if teacher_score_for_homework(homework) != 0 - return teacher_score_for_homework homework - else - return student_score_for_homework homework - end - end - #获取作业的互评得分 - def student_score_for_homework homework - #member = searchTeacherAndAssistant(homework.bid.courses.first).first#searchPeopleByRoles(homework.bid.courses.first,TeacherRoles).first - #if member.nil? - # return "0.00" - #end - #student_stars = homework.rates(:quality).where("rater_id <> #{member.user_id}").select("stars") - members = searchStudent(homework.bid.courses.first) - user_ids = [] - members.each do |user| - user_ids << user.user_id - end - student_stars = homework.rates(:quality).where("rater_id in (:user_ids)",{:user_ids => user_ids}).select("stars") - student_stars_count = 0 - student_stars.each do |star| - student_stars_count = student_stars_count + star.stars - end - return format("%.2f",student_stars_count / (student_stars.count == 0 ? 1 : student_stars.count)) - - - - end - - #获取作业的教师评分 - #多个教师只获取一份教师评分 - def teacher_score_for_homework homework - members = searchTeacherAndAssistant(homework.bid.courses.first) - teacher_ids = [] - members.each do |user| - teacher_ids << user.user_id - end - teacher_stars = homework.rates(:quality).where("rater_id in (:teacher_ids)",{:teacher_ids => teacher_ids}).select("stars") - teacher_stars_count = 0 - teacher_stars.each do |star| - teacher_stars_count = teacher_stars_count + star.stars - end - return format("%.2f",teacher_stars.count > 0 ? teacher_stars_count/teacher_stars.count : 0) - end - #获取指定项目的得分 def project_score project issue_count = project.issues.count @@ -739,54 +663,6 @@ module CoursesHelper link.html_safe end - def bid_anonymous_comment bid - if bid.open_anonymous_evaluation == 1 - if bid.homeworks.count >= 2 - case bid.comment_status - when 0 - link = link_to '启动匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' - when 1 - link = link_to '关闭匿评', alert_anonymous_comment_bid_path(bid), id: "#{bid.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit' - when 2 - link = "匿评结束".html_safe - end - else - link = "启动匿评".html_safe - end - else - link = "启动匿评".html_safe - end - link - end - - def student_new_homework bid - user_homework = cur_user_homework_for_bid bid - if user_homework && user_homework.empty? - link_to l(:label_commit_homework), new_exercise_book_path(bid),:class => 'fr mr10 work_edit' - else - if bid.comment_status == 1 && bid.open_anonymous_evaluation == 1 - "#{l(:label_edit_homework)}".html_safe - else - link_to l(:label_edit_homework), edit_homework_attach_path(user_homework.first.id),:class => 'fr mr10 work_edit' - end - end - end - - def student_anonymous_comment bid - if bid.open_anonymous_evaluation == 1 - case bid.comment_status - when 0 - "未开启匿评".html_safe - when 1 - "正在匿评中".html_safe - when 2 - "匿评已结束".html_safe - end - else - "未启用匿评".html_safe - end - end - def visable_attachemnts_incourse course return[] unless course result = [] diff --git a/app/helpers/homework_common_helper.rb b/app/helpers/homework_common_helper.rb new file mode 100644 index 000000000..39de45bbd --- /dev/null +++ b/app/helpers/homework_common_helper.rb @@ -0,0 +1,58 @@ +# encoding: utf-8 +module HomeworkCommonHelper + #获取匿评相关连接代码 + def homework_anonymous_comment homework + if homework.homework_type == 2 && homework.homework_detail_manual #匿评作业 + if homework.student_works.count >= 2 #作业份数大于2 + case homework.homework_detail_manual.comment_status + when 1 + link = link_to '启动匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'fr mr10 work_edit' + when 2 + link = link_to '关闭匿评', alert_anonymous_comment_homework_common_path(homework), id: "#{homework.id}_stop_anonymous_comment", remote: true,:class => 'fr mr10 work_edit' + when 3 + link = "匿评结束".html_safe + end + else + link = "启动匿评".html_safe + end + else + link = "启动匿评".html_safe + end + link + end + + def student_new_homework homework + work = cur_user_works_for_homework homework + if work.nil? + link_to l(:label_commit_homework), new_student_work_path(:homework => homework.id),:class => 'fr mr10 work_edit' + else + if homework.homework_type == 2 && homework.homework_detail_manual && homework.homework_detail_manual.comment_status != 1 #匿评作业,且作业状态不是在开启匿评之前 + "#{l(:label_edit_homework)}".html_safe + else + link_to l(:label_edit_homework), edit_student_work_path(work.id),:class => 'fr mr10 work_edit' + end + end + end + + def student_anonymous_comment homework + if homework.homework_type == 2 + case homework.homework_detail_manual.comment_status + when 1 + "未开启匿评".html_safe + when 2 + "正在匿评中".html_safe + when 3 + "匿评已结束".html_safe + end + elsif homework.homework_type == 1 + "未启用匿评".html_safe + elsif homework.homework_type == 3 + "编程作业".html_safe + end + end + + #获取当前用户在指定作业下提交的作业的集合 + def cur_user_works_for_homework homework + homework.student_works.where("user_id = ?",User.current).first + end +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 6265a90e1..6d71ad967 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -20,7 +20,7 @@ class Course < ActiveRecord::Base has_many :users, :through => :members # has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy - has_many :homework_for_courses, :dependent => :destroy + # has_many :homework_for_courses, :dependent => :destroy has_many :student, :class_name => 'StudentsForCourse', :source => :user has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy has_many :enabled_modules, :dependent => :delete_all @@ -30,6 +30,7 @@ class Course < ActiveRecord::Base has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy has_many :homework_commons, :dependent => :destroy + has_many :student_works, :through => :homework_commons, :dependent => :destroy has_many :course_groups, :dependent => :destroy diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d932f641e..ce11fedb1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -10,4 +10,6 @@ class HomeworkCommon < ActiveRecord::Base has_many :homework_tests, :dependent => :destroy has_many :student_works, :dependent => :destroy has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 + + acts_as_attachable end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index f3573c139..e46e70a2b 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -6,4 +6,6 @@ class StudentWork < ActiveRecord::Base belongs_to :user has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy + + acts_as_attachable end diff --git a/app/models/student_works_score.rb b/app/models/student_works_score.rb index 6d4fba281..a4592dd3e 100644 --- a/app/models/student_works_score.rb +++ b/app/models/student_works_score.rb @@ -3,4 +3,6 @@ class StudentWorksScore < ActiveRecord::Base belongs_to :user belongs_to :student_work + + acts_as_attachable end diff --git a/app/views/homework_common/alert_anonymous_comment.js.erb b/app/views/homework_common/alert_anonymous_comment.js.erb new file mode 100644 index 000000000..f1f6527c1 --- /dev/null +++ b/app/views/homework_common/alert_anonymous_comment.js.erb @@ -0,0 +1 @@ +alert(1111); \ No newline at end of file diff --git a/app/views/homework_common/edit.html.erb b/app/views/homework_common/edit.html.erb new file mode 100644 index 000000000..76299b5a3 --- /dev/null +++ b/app/views/homework_common/edit.html.erb @@ -0,0 +1 @@ +编辑作业 \ No newline at end of file diff --git a/app/views/homework_common/index.html.erb b/app/views/homework_common/index.html.erb new file mode 100644 index 000000000..e97938633 --- /dev/null +++ b/app/views/homework_common/index.html.erb @@ -0,0 +1,67 @@ +
+

+ <%= l(:label_homework)%> +

+
+
+

+ <%= l(:label_totle)%> + <%= @obj_count%> + <%= l(:label_homework_count)%> +

+ <%= link_to( l(:label_course_homework_new), new_homework_common_path(:course => @course.id), :class => 'problem_new_btn fl c_dorange') if @is_teacher %> +
+
+<% @homeworks.each do |homework|%> +
+ <%= link_to(image_tag(url_to_avatar(homework.user), :width => "42", :height => "42"), user_path(homework.user), :class => "problem_pic fl") %> +
+ <%= link_to(homework.user.lastname+homework.user.firstname, user_path(homework.user),:class => 'problem_name fl') %> + <%= l(:label_user_create_project_homework) %>: + <%= link_to(homework.name, student_work_index_path(:homework => homework.id), :class => 'problem_tit fl fb c_dblue') %> +
+

+ <%= l(:lebel_homework_commit)%> + ( <%= link_to homework.student_works.count, student_work_index_path(:homework => homework.id), :class => 'c_red'%> ) +

+ <% if @is_teacher%> + <%= homework_anonymous_comment(homework)%> + <%= link_to(l(:button_edit),edit_homework_common_path(homework), :class => "fr mr10 work_edit") %> + <% elsif @is_student%> + <%= student_anonymous_comment homework %> + <%= student_new_homework homework %> + <% end %> +
+ +
+
+ <%= homework.description.html_safe %> +
+
+ + <%= l(:label_end_time)%>:<%= homework.end_time%> + <% if betweentime(homework.end_time) < 0 %> + + <%= l(:label_commit_limit)%> + + <% else %> + +
+
+ <% end %> +
+
+
+<% end%> + + +
\ No newline at end of file diff --git a/app/views/homework_common/new.html.erb b/app/views/homework_common/new.html.erb new file mode 100644 index 000000000..101648660 --- /dev/null +++ b/app/views/homework_common/new.html.erb @@ -0,0 +1 @@ +发布作业 \ No newline at end of file diff --git a/app/views/layouts/_user_homework_list.html.erb b/app/views/layouts/_user_homework_list.html.erb index 446222bd3..12f37e04d 100644 --- a/app/views/layouts/_user_homework_list.html.erb +++ b/app/views/layouts/_user_homework_list.html.erb @@ -1,12 +1,5 @@ <% if course %>
  • <%= link_to course.name, course_path(course.id, host: Setting.host_course) %> -
  • <% end %> \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 6820ccaf3..99084de3f 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -116,9 +116,9 @@ <%= link_to "(#{course_activity_count @course})", course_path(@course), :class => "subnav_num c_orange"%>