From 97a4aaf8aba3be3b49381bb3b2f36a670541aa69 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 17 Jun 2014 18:49:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?homework=5Fattach=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=97project=5Fid=E5=8F=8A=E7=9B=B8=E5=85=B3=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=81=E7=A7=BB=20=E7=BC=96=E8=BE=91=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=85=B3=E8=81=94=E9=A1=B9=E7=9B=AE=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 4 +++- app/helpers/homework_attach_helper.rb | 12 ++++++++++++ app/views/homework_attach/edit.html.erb | 9 +++++++-- ...92219_add_project_id_to_homework_attach.rb | 5 +++++ db/schema.rb | 19 +++++++++---------- 5 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20140617092219_add_project_id_to_homework_attach.rb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index d10f09ff..48187bdc 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -177,8 +177,10 @@ class HomeworkAttachController < ApplicationController if User.current.admin? || User.current.member_of?(course) name = params[:homework_name] description = params[:homework_description] + project_id = params[:homework_attach][:project_id] @homework.name = name @homework.description = description + @homework.project_id = project_id if params[:attachments] @homework.save_attachments(params[:attachments]) end @@ -196,7 +198,7 @@ class HomeworkAttachController < ApplicationController def destroy #@homework = HomeworkAttach.find(params[:id]) - if User.current.admin? || User.current == @homework + if User.current.admin? || User.current == @homework.user if @homework.destroy respond_to do |format| format.html { redirect_to project_for_bid_path @homework.bid } diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 28bb48d3..4fbedb3a 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -54,4 +54,16 @@ module HomeworkAttachHelper raise RuntimeError, 'unknow type, Please input you type into this helper.' end end + + def user_projects_option + projects = Project.where("id < 8") + type = [] + projects.each do |project| + option = [] + option << project.name + option << project.id + type << option + end + type + end end \ No newline at end of file diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb index f7104840..e5e3e005 100644 --- a/app/views/homework_attach/edit.html.erb +++ b/app/views/homework_attach/edit.html.erb @@ -42,11 +42,16 @@
- 标 题: + 标 题: <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%>
- 描 述: + 关联项目: + <%= f.select :project_id, options_for_select(user_projects_option),:name => "project_id", :required => true%> + <%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %> +
++ 描 述: <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> diff --git a/db/migrate/20140617092219_add_project_id_to_homework_attach.rb b/db/migrate/20140617092219_add_project_id_to_homework_attach.rb new file mode 100644 index 00000000..d18bf3c3 --- /dev/null +++ b/db/migrate/20140617092219_add_project_id_to_homework_attach.rb @@ -0,0 +1,5 @@ +class AddProjectIdToHomeworkAttach < ActiveRecord::Migration + def change + add_column :homework_attaches, :project_id, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index c8cf7128..b7de4e0b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140617013146) do +ActiveRecord::Schema.define(:version => 20140617092219) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -348,12 +348,13 @@ ActiveRecord::Schema.define(:version => 20140617013146) do create_table "homework_attaches", :force => true do |t| t.integer "bid_id" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "reward" t.string "name" t.string "description" t.integer "state" + t.integer "project_id", :default => 0 end create_table "homework_for_courses", :force => true do |t| @@ -960,13 +961,11 @@ ActiveRecord::Schema.define(:version => 20140617013146) do end create_table "user_scores", :force => true do |t| - t.integer "user_id", :null => false - t.integer "collaboration" - t.integer "influence" - t.integer "skill" - t.integer "active" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "user_id" + t.integer "collaboration" + t.integer "influence" + t.integer "skill" + t.integer "activity" end create_table "user_statuses", :force => true do |t| From efb6c1fd19c15760f657ff0ea8f923e94ac32300 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 18 Jun 2014 10:07:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BD=9C=E4=B8=9A=E5=A2=9E=E5=8A=A0=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=80=89=E9=A1=B9(=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA)=202.homework=5Fattach=E4=B8=8Eproject?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 4 +++- app/models/homework_attach.rb | 3 ++- app/models/project.rb | 1 + app/views/homework_attach/edit.html.erb | 5 +++-- app/views/homework_attach/new.html.erb | 6 ++++++ db/schema.rb | 12 +++++++----- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 48187bdc..652025fc 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -77,6 +77,7 @@ class HomeworkAttachController < ApplicationController if bid.homeworks.where("user_id = ?",User.current).count == 0 user_id = params[:user_id] bid_id = params[:bid_id] + project_id = params[:new_form][:project_id] sta = 0 name = params[:new_form][:name] description = params[:new_form][:description] @@ -85,7 +86,8 @@ class HomeworkAttachController < ApplicationController :state => sta, :name => name, :description => description, - :bid_id => bid_id + :bid_id => bid_id, + :project_id => project_id } diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index e60d4230..99d540bd 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -9,6 +9,7 @@ class HomeworkAttach < ActiveRecord::Base has_many :homework_users, :dependent => :destroy has_many :users, :through => :homework_users seems_rateable :allow_update => true, :dimensions => :quality + belongs_to :project safe_attributes "bid_id", "user_id" @@ -30,7 +31,7 @@ class HomeworkAttach < ActiveRecord::Base result end - def project + def project_for_homework work = HomeworkForCourse.find_by_bid_id(self.bid_id) if work work.project diff --git a/app/models/project.rb b/app/models/project.rb index b8e11d99..ee9f7b2f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -30,6 +30,7 @@ class Project < ActiveRecord::Base # Specific overidden Activities + belongs_to :homework_attach 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}" has_many :memberships, :class_name => 'Member' diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb index e5e3e005..bfcf1f64 100644 --- a/app/views/homework_attach/edit.html.erb +++ b/app/views/homework_attach/edit.html.erb @@ -46,9 +46,10 @@ <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%>
- 关联项目: - <%= f.select :project_id, options_for_select(user_projects_option),:name => "project_id", :required => true%> + 提交项目: + <%= f.select :project_id, options_for_select(user_projects_option,@homework.project.id),:name => "project_id", :required => true%> <%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %> +
提交项目可以为空
描 述: diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb index 618fc15a..c74d17bd 100644 --- a/app/views/homework_attach/new.html.erb +++ b/app/views/homework_attach/new.html.erb @@ -26,6 +26,12 @@ 标 题: <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %>
++ 提交项目: + <%= f.select :project_id, options_for_select(user_projects_option),:name => "project_id", :required => true%> + <%= link_to '创建项目', new_project_path(course: 0, project_type: 0), :target => '_blank' %> +
提交项目可以为空
+描 述: diff --git a/db/schema.rb b/db/schema.rb index b7de4e0b..fc215116 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -961,11 +961,13 @@ ActiveRecord::Schema.define(:version => 20140617092219) do end create_table "user_scores", :force => true do |t| - t.integer "user_id" - t.integer "collaboration" - t.integer "influence" - t.integer "skill" - t.integer "activity" + t.integer "user_id", :null => false + t.integer "collaboration" + t.integer "influence" + t.integer "skill" + t.integer "active" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "user_statuses", :force => true do |t| From 8f78177d47c198eec194a9ca6a68910089ad62e4 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Wed, 18 Jun 2014 11:51:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...18020535_remove_data_to_homework_attach.rb | 25 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140618020535_remove_data_to_homework_attach.rb diff --git a/db/migrate/20140618020535_remove_data_to_homework_attach.rb b/db/migrate/20140618020535_remove_data_to_homework_attach.rb new file mode 100644 index 00000000..16a1b491 --- /dev/null +++ b/db/migrate/20140618020535_remove_data_to_homework_attach.rb @@ -0,0 +1,25 @@ +class RemoveDataToHomeworkAttach < ActiveRecord::Migration + def up + bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3") + bidding_projects.each do |biding| + homework = HomeworkAttach.new + homework.project_id = biding.project_id + homework.bid_id = biding.bid_id + homework.created_at = biding.created_at + homework.updated_at = biding.updated_at + homework.reward = biding.reward + homework.description = biding.description + homework.user_id = biding.user_id + homework.state = 0 + homework.save + end + end + + def down + bidding_projects = BidingProject.joins(:bid).where("bids.reward_type = 3") + bidding_projects.each do |biding| + homework = HomeworkAttach.where("bid_id = #{biding.bid_id} and user_id = #{biding.user_id}") + homework.first.destroy + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fc215116..18cc2a71 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140617092219) do +ActiveRecord::Schema.define(:version => 20140618020535) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false