From 781fa32dbb4b4a03d706edfc7920315d8f63ae89 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Thu, 26 Sep 2013 09:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E7=9A=84fork=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 44 ++++++++++++++++++- app/helpers/bids_helper.rb | 13 +++++- app/views/bids/_fork_form.html.erb | 20 +++++++++ app/views/bids/fork.html.erb | 10 +++++ app/views/layouts/base_bids.html.erb | 2 +- config/routes.rb | 2 + .../20130926005448_add_parent_id_to_bid.rb | 5 +++ db/schema.rb | 3 +- 8 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 app/views/bids/_fork_form.html.erb create mode 100644 app/views/bids/fork.html.erb create mode 100644 db/migrate/20130926005448_add_parent_id_to_bid.rb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 2e6f4b59d..d6417df6c 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -6,11 +6,12 @@ class BidsController < ApplicationController menu_item :homework_respond, :only => :homework_respond menu_item :homework_statistics, :only => :homework_statistics #Ended by young - before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new, :homework_respond, :add_homework, :homework_statistics] + before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add, :new, :homework_respond, :add_homework, :homework_statistics, :fork, :create_fork] helper :watchers helper :attachments include AttachmentsHelper + helper :projects def index # Modified by nie @@ -82,6 +83,46 @@ class BidsController < ApplicationController # end # #end end + + def fork + @new_bid = Bid.new + @new_bid.safe_attributes = params[:bid] + @courses = [] + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + if membership.project.project_type == 1 + @courses << membership.project + end + end + end + + def create_fork + @homework = Bid.new + @homework.name = params[:bid][:name] + @homework.description = params[:bid][:description] + @homework.reward_type = 3 + # @bid.budget = params[:bid][:budget] + @homework.deadline = params[:bid][:deadline] + @homework.budget = 0 + @homework.author_id = User.current.id + @homework.commit = 0 + @homework.homework_type = params[:bid][:homework_type] + @homework.parent_id = @bid.id + @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) + # @bid. + if @homework.save + HomeworkForCourse.create(:project_id => params[:course], :bid_id => @homework.id) + unless @bid.watched_by?(User.current) + if @bid.add_watcher(User.current) + flash[:notice] = l(:label_bid_succeed) + end + end + redirect_to respond_path(@homework) + else + @homework.safe_attributes = params[:bid] + render :action => 'fork' + end + end def show @user = @bid.author @@ -426,6 +467,7 @@ class BidsController < ApplicationController def find_bid if params[:id] @bid = Bid.find(params[:id]) + @user = @bid.author end rescue render_404 diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 89dbdd85f..8ebd07751 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -37,7 +37,7 @@ module BidsHelper Bid.tagged_with(tag_name).order('updated_on desc') end - def sort_bid(state) + def sort_bid(state) content = ''.html_safe case state when 0 @@ -52,4 +52,15 @@ module BidsHelper content_tag('div', content, :class => "tabs") end + def course_options_for_select(courses) + # + html = '' + courses.each do |course| + html << "" + end + html.html_safe + end + end \ No newline at end of file diff --git a/app/views/bids/_fork_form.html.erb b/app/views/bids/_fork_form.html.erb new file mode 100644 index 000000000..2fbc10b3b --- /dev/null +++ b/app/views/bids/_fork_form.html.erb @@ -0,0 +1,20 @@ + +<%= error_messages_for 'bid' %> + +

<%= l(:label_homeworks_form_new_description) %>

+

<%= select_tag 'course', course_options_for_select(@courses) %>

+

<%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :value => @bid.name %>

+ +

+<%= f.text_area :description, :rows => 8, :value => @bid.description, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;", :maxlength => Bid::DESCRIPTION_LENGTH_LIMIT %>

+ +

<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%> +

+

<%= f.select :homework_type, homework_type_option %> +

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

<%= render :partial => 'attachments/form', :locals => {:container => @homework} %>

+
\ No newline at end of file diff --git a/app/views/bids/fork.html.erb b/app/views/bids/fork.html.erb new file mode 100644 index 000000000..d87221aca --- /dev/null +++ b/app/views/bids/fork.html.erb @@ -0,0 +1,10 @@ + +

<%=l(:label_new_call)%>

+ +<%= labelled_form_for @new_bid, :url => {:controller => 'bids', :action => 'create_fork', :id => @bid.id} do |f| %> +
+ <%= render :partial => 'fork_form', :locals => { :f => f } %> + <%= submit_tag l(:button_create) %> + + <% end %> +
\ No newline at end of file diff --git a/app/views/layouts/base_bids.html.erb b/app/views/layouts/base_bids.html.erb index 36be8c5f0..4ebe4a0eb 100644 --- a/app/views/layouts/base_bids.html.erb +++ b/app/views/layouts/base_bids.html.erb @@ -38,7 +38,7 @@ <%= h @bid.name %> - <%= watcher_link(@bid, User.current) %> + <%= watcher_link(@bid, User.current) %> <%= link_to("选为作业", fork_path(@bid)) %> diff --git a/config/routes.rb b/config/routes.rb index b0c06bd77..2384c382a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -444,6 +444,8 @@ RedmineApp::Application.routes.draw do match 'calls/create_homework', :to => 'bids#create_homework' match 'calls/:id/homework_respond', :to => 'bids#homework_respond' match 'calls/:id/homework_statistics', :to => 'bids#homework_statistics' + match 'calls/:id/fork', :to => 'bids#fork', :as => 'fork' + match 'calls/:id/create_fork', :to => 'bids#create_fork' post 'join_in/join', :to => 'courses#join', :as => 'join' delete 'join_in/join', :to => 'courses#unjoin' diff --git a/db/migrate/20130926005448_add_parent_id_to_bid.rb b/db/migrate/20130926005448_add_parent_id_to_bid.rb new file mode 100644 index 000000000..1bdd7fd3d --- /dev/null +++ b/db/migrate/20130926005448_add_parent_id_to_bid.rb @@ -0,0 +1,5 @@ +class AddParentIdToBid < ActiveRecord::Migration + def change + add_column :bids, :parent_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 48a20c70d..2b058a663 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 => 20130925031313) do +ActiveRecord::Schema.define(:version => 20130926005448) do create_table "a_user_watchers", :force => true do |t| t.string "name" @@ -91,6 +91,7 @@ ActiveRecord::Schema.define(:version => 20130925031313) do t.integer "commit" t.integer "reward_type" t.integer "homework_type" + t.integer "parent_id" end create_table "boards", :force => true do |t|