From a9f6e817b49929e9e274de6dc14077bcab44dd87 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 8 Dec 2015 17:37:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 39 +++++- app/helpers/application_helper.rb | 19 +++ app/models/homework_common.rb | 1 + app/models/project.rb | 1 + app/models/student_work.rb | 1 + app/models/student_work_project.rb | 7 ++ app/models/user.rb | 1 + .../_choose_group_member.html.erb | 85 ++++++------- .../student_work/_relate_project.html.erb | 113 +++++++++++++----- app/views/student_work/new.html.erb | 69 +++++------ .../new_student_work_project.js.erb | 5 + app/views/users/_course_homework.html.erb | 5 + config/routes.rb | 2 + ...1208025236_create_student_work_projects.rb | 13 ++ ...32013_add_index_to_student_work_project.rb | 8 ++ db/schema.rb | 19 ++- public/stylesheets/courses.css | 6 +- public/stylesheets/new_user.css | 5 +- spec/factories/student_work_projects.rb | 6 + spec/models/student_work_project_spec.rb | 5 + 20 files changed, 297 insertions(+), 113 deletions(-) create mode 100644 app/models/student_work_project.rb create mode 100644 db/migrate/20151208025236_create_student_work_projects.rb create mode 100644 db/migrate/20151208032013_add_index_to_student_work_project.rb create mode 100644 spec/factories/student_work_projects.rb create mode 100644 spec/models/student_work_project_spec.rb diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 77868c689..6b5573026 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -3,7 +3,7 @@ class StudentWorkController < ApplicationController include StudentWorkHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -540,6 +540,43 @@ class StudentWorkController < ApplicationController end end + def new_student_work_project + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + + #创建作业的关联项目 + def student_work_project + projects = cur_user_projects_for_homework @homework + if projects.nil? + @project = StudentWorkProject.new + @project.homework_common_id = @homework.id + @project.project_id = (Project.find params[:project_id]).id + @project.user_id = User.current.id + if @project.save + @user_activity_id = params[:user_activity_id].to_i + @is_in_course = params[:is_in_course].to_i + @course_activity = params[:course_activity].to_i + respond_to do |format| + format.js + end + end + end + end + + #查找学生创建的项目列表 + def search_user_projects + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + project_ids = Project.where("user_id = #{User.current.id} and ") + end + private def hsd_committed_work?(user, homework) sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 46a20dd4c..174d33f40 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2459,6 +2459,21 @@ module ApplicationHelper end + def relate_project homework,is_teacher,is_in_course,user_activity_id,course_activity + if User.current.member_of_course?(homework.course) + if is_teacher + link_to "项目(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + else + projects = cur_user_projects_for_homework homework + if projects.nil? + link_to "关联项目(#{homework.student_work_projects.count})", new_student_work_project_student_work_index_path(:homework => homework.id,:is_in_course=>is_in_course,:user_activity_id=>user_activity_id,:course_activity=>course_activity),remote: true,:class=> 'c_blue', :title=> '请选择分组作业关联的项目' + else + link_to "已关联项目(#{homework.student_work_projects.count})",student_work_index_path(:homework => homework.id),:class => "c_blue" + end + end + end + end + def student_anonymous_comment homework if homework.homework_detail_manual case homework.homework_detail_manual.comment_status @@ -2476,6 +2491,10 @@ module ApplicationHelper def cur_user_works_for_homework homework homework.student_works.where("user_id = ?",User.current).first end + #获取当前用户在指定作业下关联的项目的集合 + def cur_user_projects_for_homework homework + homework.student_work_projects.where("user_id = ?",User.current).first + end def file_preview_tag(file, html_options={}) if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)} diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 461c7d35b..a665909e2 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -10,6 +10,7 @@ class HomeworkCommon < ActiveRecord::Base has_one :homework_detail_manual, :dependent => :destroy has_one :homework_detail_programing, :dependent => :destroy has_one :homework_detail_group, :dependent => :destroy + has_many :student_work_projects has_many :homework_tests, :dependent => :destroy has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 diff --git a/app/models/project.rb b/app/models/project.rb index ff546e098..3e494a4f0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -43,6 +43,7 @@ class Project < ActiveRecord::Base end end + has_many :student_work_projects has_many :student_works has_many :time_entry_activities has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 884f4a089..59b98b9b2 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -4,6 +4,7 @@ class StudentWork < ActiveRecord::Base belongs_to :homework_common belongs_to :user + has_one :student_work_project has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy belongs_to :project diff --git a/app/models/student_work_project.rb b/app/models/student_work_project.rb new file mode 100644 index 000000000..676071817 --- /dev/null +++ b/app/models/student_work_project.rb @@ -0,0 +1,7 @@ +class StudentWorkProject < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :homework_common + belongs_to :student_work + belongs_to :project + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 9c437a186..fa6f005b6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -107,6 +107,7 @@ class User < Principal has_many :student_works, :dependent => :destroy has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy + has_many :student_work_projects #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, diff --git a/app/views/student_work/_choose_group_member.html.erb b/app/views/student_work/_choose_group_member.html.erb index c14e8a06e..4671dd2a5 100644 --- a/app/views/student_work/_choose_group_member.html.erb +++ b/app/views/student_work/_choose_group_member.html.erb @@ -1,41 +1,44 @@ -
请添加小组成员
- -
-
-
- -
-
-
- -
- -
-
取消
-
确定
-
\ No newline at end of file +
+
+
请添加小组成员
+
+
+
+
+
+ +
+
+ +
+ +
+ + +
+
\ No newline at end of file diff --git a/app/views/student_work/_relate_project.html.erb b/app/views/student_work/_relate_project.html.erb index 06649baba..2db43ec59 100644 --- a/app/views/student_work/_relate_project.html.erb +++ b/app/views/student_work/_relate_project.html.erb @@ -1,30 +1,83 @@ -
关联项目 -
- -
- - - -
-
\ No newline at end of file +
+ 关联项目 + + <%=form_tag url_for(:controller=>'student_work',:action=>'student_work_project',:course_id=>@course_id,:user_activity_id=>@user_activity_id,:is_in_course=>@is_in_course),:id =>'student_work_relate_project',:class=>'resourcesSearchBox',:remote => true do %> + + +
+ + + +
+ <% end %> +
+ \ No newline at end of file diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index 995126cb5..d14da5fa2 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -34,6 +34,34 @@ ) } } + // 添加组成员 + function show_group_member() { + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'student_work/choose_group_member',:locals => {:homework=>@homework}) %>'); + showModal('ajax-modal', '528px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left",""); + $('#ajax-modal').parent().addClass("addMemberCP"); + } + // 关联项目 + function show_project() { + $('#ajax-modal').html('<%= escape_javascript(render :partial => 'student_work/relate_project',:locals => {:homework=>@homework}) %>'); + showModal('ajax-modal', '320px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left",""); + $('#ajax-modal').parent().addClass("groupPopUp"); + } + // 作品校验 + function popupRegex(){ + if(regexStudentWorkName()&®exStudentWorkDescription()) + { + $('#ajax-modal').html("

作品信息完整性校验中,请稍等...

"); + showModal('ajax-modal', '500px'); + $('#ajax-modal').siblings().remove(); + $('#ajax-modal').parent().css("top","").css("left",""); + $('#ajax-modal').parent().addClass("anonymos"); + } + } +
@@ -98,22 +126,15 @@ <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @student_work, :has_program=>false,:has_group=>false} %>
- <% if @homework.homework_type == 3 %> -
+ <%# if @homework.homework_type == 3 %> + + <%# end %> -
+ -
- \ No newline at end of file +
\ No newline at end of file diff --git a/app/views/student_work/new_student_work_project.js.erb b/app/views/student_work/new_student_work_project.js.erb index e69de29bb..51df45f13 100644 --- a/app/views/student_work/new_student_work_project.js.erb +++ b/app/views/student_work/new_student_work_project.js.erb @@ -0,0 +1,5 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'student_work/relate_project') %>'); +showModal('ajax-modal', '320px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("groupPopUp"); \ No newline at end of file diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 309b8b95a..9f2beedd0 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -45,6 +45,11 @@ <% end%> <% end%>
+ <% if activity.homework_type == 3%> +
+ <%= relate_project(activity,is_teacher,-1,user_activity_id,course_activity) %> +
+ <% end %>
<% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> <%= user_for_homework_common activity,is_teacher %> diff --git a/config/routes.rb b/config/routes.rb index 4e64ca505..b375053fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -218,6 +218,8 @@ RedmineApp::Application.routes.draw do end collection do post 'add_score_reply' + post 'student_work_project' + get 'new_student_work_project' get 'delete_work' get 'destroy_score_reply' get 'student_work_absence_penalty' diff --git a/db/migrate/20151208025236_create_student_work_projects.rb b/db/migrate/20151208025236_create_student_work_projects.rb new file mode 100644 index 000000000..134823377 --- /dev/null +++ b/db/migrate/20151208025236_create_student_work_projects.rb @@ -0,0 +1,13 @@ +class CreateStudentWorkProjects < ActiveRecord::Migration + def change + create_table :student_work_projects do |t| + t.integer :homework_common_id + t.integer :student_work_id + t.integer :project_id + t.integer :user_id + t.integer :is_leader + + t.timestamps + end + end +end diff --git a/db/migrate/20151208032013_add_index_to_student_work_project.rb b/db/migrate/20151208032013_add_index_to_student_work_project.rb new file mode 100644 index 000000000..b55c313ff --- /dev/null +++ b/db/migrate/20151208032013_add_index_to_student_work_project.rb @@ -0,0 +1,8 @@ +class AddIndexToStudentWorkProject < ActiveRecord::Migration + def change + add_index :student_work_projects, :homework_common_id + add_index :student_work_projects, :user_id + add_index :student_work_projects, :project_id + add_index :student_work_projects, :student_work_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f130c5c39..4aeed2409 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,8 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151130033906) do +ActiveRecord::Schema.define(:version => 20151208032013) do + create_table "activities", :force => true do |t| t.integer "act_id", :null => false t.string "act_type", :null => false @@ -979,7 +980,6 @@ ActiveRecord::Schema.define(:version => 20151130033906) do t.integer "course_group_id", :default => 0 end - add_index "members", ["course_id"], :name => "index_members_on_course_id" add_index "members", ["project_id"], :name => "index_members_on_project_id" add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true add_index "members", ["user_id"], :name => "index_members_on_user_id" @@ -1508,6 +1508,21 @@ ActiveRecord::Schema.define(:version => 20151130033906) do t.integer "project_id" end + create_table "student_work_projects", :force => true do |t| + t.integer "homework_common_id" + t.integer "student_work_id" + t.integer "project_id" + t.integer "user_id" + t.integer "is_leader" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "student_work_projects", ["homework_common_id"], :name => "index_student_work_projects_on_homework_common_id" + add_index "student_work_projects", ["project_id"], :name => "index_student_work_projects_on_project_id" + add_index "student_work_projects", ["student_work_id"], :name => "index_student_work_projects_on_student_work_id" + add_index "student_work_projects", ["user_id"], :name => "index_student_work_projects_on_user_id" + create_table "student_work_tests", :force => true do |t| t.integer "student_work_id" t.datetime "created_at", :null => false diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 54e550426..0373f24bc 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1182,17 +1182,17 @@ a:hover.testBtn{background: url(/images/course/hwork_icon.png) -81px -5px no-rep a.groupBtn{ background: url(/images/course/hwork_icon.png) -2px -61px no-repeat !important; height:20px; display:block; padding-left:20px; color:#888888; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} a:hover.groupBtn{background: url(/images/course/hwork_icon.png) -80px -61px no-repeat !important; color:#3598db; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} .markInput { outline:none; border:1px solid #e6e6e6; height:30px; width:50px; color:#3d3c3c; margin-right:5px; text-align:center; padding-left:0px;} -.groupPopUp {width:290px; height:auto; padding:15px; background-color:#ffffff; z-index:1000; position:relative;} +.groupPopUp {border:3px solid #269ac9; width:290px; height:auto; padding:15px; background-color:#ffffff; position:fixed !important;left:50%;top:50%;margin:-100px 0 0 -150px; -moz-border-radius:5px;} .popClose {background:url(/images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:2px; top:3px;} a.memberBtn{ background: url(/images/course/hwork_icon.png) -7px -90px no-repeat !important; height:20px; display:block; padding-left:20px; color:#888888; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} a:hover.memberBtn{background: url(/images/course/hwork_icon.png) -80px -90px no-repeat !important; color:#3598db; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} .addMemberC {float:left; max-height:150px; margin-bottom:10px; overflow:auto; overflow-x:hidden; width:227px; background-color:#f1f1f1; min-height:150px; padding-top:10px;} .addMemberC li {padding-left:10px; line-height:18px;} .addMemberC li:hover {cursor:pointer; background-color:#cccccc;} -.addMemberCP {width:514px; height:auto; border:3px solid #269ac9; padding-left:16px; padding-bottom:16px; background-color:#ffffff; position:absolute; z-index:1000;} +.addMemberCP {width:514px; height:auto; border:3px solid #269ac9; padding-left:16px; padding-bottom:16px; background-color:#ffffff; position:fixed !important;left:50%;top:50%;margin:-100px 0 0 -150px; -moz-border-radius:5px;} .rightArrow {margin:50px 15px 0px 15px; float:left;} .relateText {font-size:16px; color:#269ac9; line-height:16px; padding-top:20px; display:inline-block; font-weight: bold;} - +.maxHeight100 {max-height:100px; overflow-x:hidden; overflow-y:auto;} .resubAtt {border-top:1px solid #dddddd; position:relative; margin-top:15px;} .resubTitle {position:absolute; top:-10px; left:5px; background-color:#ffffff; display:block; font-weight:bold; padding:0px 2px;} a.blueCir{ display:inline-block; padding:2px 5px; background-color:#ffffff;border:1px solid #3598db; color:#3598db; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;} diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index a9edee92d..199b38305 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -1355,13 +1355,14 @@ a:hover.testBtn{background: url(/images/course/hwork_icon.png) -81px -5px no-rep a.groupBtn{ background: url(/images/course/hwork_icon.png) -2px -61px no-repeat !important; height:20px; display:block; padding-left:20px; color:#888888; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} a:hover.groupBtn{background: url(/images/course/hwork_icon.png) -80px -61px no-repeat !important; color:#3598db; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} .markInput { outline:none; border:1px solid #e6e6e6; height:30px; width:50px; color:#3d3c3c; margin-right:5px; text-align:center; padding-left:0px;} -.groupPopUp {width:290px; height:auto; padding:15px; background-color:#ffffff; z-index:1000; position:relative;} +.groupPopUp {border:3px solid #269ac9; width:290px; height:auto; padding:15px; background-color:#ffffff;position:fixed !important;left:50%;top:50%;margin:-100px 0 0 -150px; -moz-border-radius:5px;} .popClose {background:url(/images/resource_icon_list.png) 0px -40px no-repeat; width:20px; height:20px; display:inline-block; position: absolute; z-index: 1000; right:2px; top:3px;} a.memberBtn{ background: url(/images/course/hwork_icon.png) -7px -90px no-repeat !important; height:20px; display:block; padding-left:20px; color:#888888; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} a:hover.memberBtn{background: url(/images/course/hwork_icon.png) -80px -90px no-repeat !important; color:#3598db; -moz-transition :all 0s linear 0s; -webkit-transition :all 0s linear 0s; -o-transition:all 0s linear 0s; transition:all 0s linear 0s;} .addMemberC {float:left; max-height:150px; margin-bottom:10px; overflow:auto; overflow-x:hidden; width:227px; background-color:#f1f1f1; min-height:150px; padding-top:10px;} .addMemberC li {padding-left:10px; line-height:18px;} .addMemberC li:hover {cursor:pointer; background-color:#cccccc;} -.addMemberCP {width:514px; height:auto; border:3px solid #269ac9; padding-left:16px; padding-bottom:16px; background-color:#ffffff; position:absolute; z-index:1000;} +.addMemberCP {width:514px; height:auto; border:3px solid #269ac9; padding-left:16px; padding-bottom:16px; background-color:#ffffff; position:fixed !important;left:50%;top:50%;margin:-100px 0 0 -150px; -moz-border-radius:5px;} .rightArrow {margin:50px 15px 0px 15px; float:left;} .relateText {font-size:16px; color:#269ac9; line-height:16px; padding-top:20px; display:inline-block; font-weight: bold;} +.maxHeight100 {max-height:100px; overflow-x:hidden; overflow-y:auto;} diff --git a/spec/factories/student_work_projects.rb b/spec/factories/student_work_projects.rb new file mode 100644 index 000000000..d6ecb2657 --- /dev/null +++ b/spec/factories/student_work_projects.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :student_work_project do + end +end diff --git a/spec/models/student_work_project_spec.rb b/spec/models/student_work_project_spec.rb new file mode 100644 index 000000000..42a65b35e --- /dev/null +++ b/spec/models/student_work_project_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe StudentWorkProject, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end