添加了需求的fork功能

This commit is contained in:
fanqiang 2013-09-26 09:06:29 +08:00
parent 436569c88d
commit 781fa32dbb
8 changed files with 95 additions and 4 deletions

View File

@ -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

View File

@ -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)
# <option value = '0'>#{l(:label_choose_reward)}</option>
html = ''
courses.each do |course|
html << "<option value = #{course.id}>"
html << course.name
html << "</option>"
end
html.html_safe
end
end

View File

@ -0,0 +1,20 @@
<!-- fq -->
<%= error_messages_for 'bid' %>
<!--[form:project]-->
<p><%= l(:label_homeworks_form_new_description) %></p>
<p><%= select_tag 'course', course_options_for_select(@courses) %></p>
<p><%= f.text_field :name, :required => true, :size => 60, :style => "width:490px;", :maxlength => Bid::NAME_LENGTH_LIMIT, :value => @bid.name %></p>
<p style="margin-left:-10px;padding-right: 20px;">
<%= 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 %></p>
<!-- <p><%= select_tag 'bid_reward_type', "<option value = '0'>#{l(:label_choose_reward)}</option><option value = '1'>#{l(:label_money)}</option><option value = '3'>#{l(:label_bids_credit)}</option><option value = '2'>#{l(:label_reward_1)}</option>".html_safe,
:onChange => "show('bid_reward_type', 'bid_budget', '"+l(:label_bids_reward_what)+"','"+l(:label_bids_new_money)+"','"+l(:label_bids_new_credit)+"','"+l(:label_bids_new_content)+"')" %>
<%= f.text_field :budget, :required => true, :size => 60, :style => "width:350px;", :placeholder => l(:label_bids_reward_what) %>
</p> -->
<p><%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>
</p>
<p><%= f.select :homework_type, homework_type_option %>
</p>
<fieldset><legend><%= l(:label_attachment_plural) %></legend>
<p><%= render :partial => 'attachments/form', :locals => {:container => @homework} %></p>
</fieldset>

View File

@ -0,0 +1,10 @@
<!-- fq -->
<h3><%=l(:label_new_call)%></h3>
<%= labelled_form_for @new_bid, :url => {:controller => 'bids', :action => 'create_fork', :id => @bid.id} do |f| %>
<div class="box tabular">
<%= render :partial => 'fork_form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<!-- <%= javascript_tag "$('#bid_name').focus();" %> -->
<% end %>
</div>

View File

@ -38,7 +38,7 @@
<td class="info_font" style=" word-wrap: break-word; word-break: break-all"><%= h @bid.name %></td>
</tr>
<tr>
<td align="center"> <%= watcher_link(@bid, User.current) %> </td>
<td align="center"> <%= watcher_link(@bid, User.current) %> <%= link_to("选为作业", fork_path(@bid)) %></td>
</tr>
</table></td>
</tr>

View File

@ -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'

View File

@ -0,0 +1,5 @@
class AddParentIdToBid < ActiveRecord::Migration
def change
add_column :bids, :parent_id, :integer
end
end

View File

@ -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|