修改竞赛和参与竞赛的新建应用之间的关联关系

This commit is contained in:
wanglinchun 2014-04-11 16:40:09 +08:00
parent b97cdd6b0d
commit a4df4cf893
12 changed files with 39 additions and 20 deletions

View File

@ -157,7 +157,7 @@ class ContestsController < ApplicationController
contests = Contest.where('parent_id = ?', @contest.id) contests = Contest.where('parent_id = ?', @contest.id)
@softapplications = [] @softapplications = []
for contest in contests for contest in contests
@softapplications += contest.softapplications @softapplications += contest.contesting_softapplications
end end
respond_to do |format| respond_to do |format|
@ -240,6 +240,7 @@ class ContestsController < ApplicationController
# @user = @contest.user # @user = @contest.user
@softapplication = Softapplication.all @softapplication = Softapplication.all
@contesting_softapplication = @contest.contesting_softapplications
# @temp = [] # @temp = []
# @softapplicationt.each do |pro| # @softapplicationt.each do |pro|
@ -292,15 +293,15 @@ class ContestsController < ApplicationController
def add_softapplication def add_softapplication
softapplication = Softapplication.find(params[:contest]) softapplication = Softapplication.find(params[:contest])
contest_message = params[:contest_for_save][:contest_message] contest_message = params[:contest_for_save][:contest_message]
if Softapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0
if Softapplication.create_contesting(@contest.id, softapplication.id, contest_message) if ContestingSoftapplication.create_contesting(@contest.id, softapplication.id, contest_message)
flash.now[:notice] = l(:label_bidding_contest_succeed) flash.now[:notice] = l(:label_bidding_contest_succeed)
end end
else else
flash.now[:error] = l(:label_bidding_fail) flash.now[:error] = l(:label_bidding_fail)
end end
@softapplication = @contest.softapplications @contesting_softapplication = @contest.contesting_softapplications
render :text => params.to_json render :text => params.to_json
# respond_to do |format| # respond_to do |format|

View File

@ -105,7 +105,7 @@ module ContestsHelper
contests = Contest.find(:id) contests = Contest.find(:id)
@softapplications = [] @softapplications = []
for contest in contests for contest in contests
@softapplications += contest.contesting_projects @softapplications += contest.contesting_softapplications
end end
@projects.count @projects.count
end end
@ -122,6 +122,16 @@ module ContestsHelper
@users.count @users.count
end end
def count_contest_softapplication_user
contests = Contest.find(:id)
@users = []
for contest in contests
for project in contest.softapplications
@users += softapplication.users
end
end
@users.count
end
def im_watching_student_id? contest def im_watching_student_id? contest
people = [] people = []
people << contest.author people << contest.author
@ -152,8 +162,8 @@ module ContestsHelper
end end
def select_option_app_helper options def select_option_app_helper options
tmp = Hash.new tmp = Hash.new
options.each do |project| options.each do |option|
tmp[project.name] = project.id tmp[option.name] = option.id
end end
tmp tmp
end end

View File

@ -5,8 +5,8 @@ class Contest < ActiveRecord::Base
belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :author, :class_name => 'User', :foreign_key => :author_id
has_many :contesting_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy
has_many :projects, :through => :contesting_projects has_many :projects, :through => :contesting_projects
has_many :softapplications, :dependent => :destroy has_many :contesting_softapplications, :dependent => :destroy
# has_many :softapplications, :through => :softapplications has_many :softapplications, :through => :contesting_softapplications
has_many :projects_member, :class_name => 'User', :through => :projects has_many :projects_member, :class_name => 'User', :through => :projects
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy

View File

@ -19,6 +19,11 @@ class ContestingProject < ActiveRecord::Base
:project_id => project_id, :description => description) :project_id => project_id, :description => description)
end end
def self.cerate_softapplication_contesting(contest_id, softapplication_id, description = nil)
self.create_softapplication(:user_id => User.current.id, :contest_id => contest_id,
:softapplication_id => softapplication_id, :description => description)
end
def update_reward(which) def update_reward(which)
self.update_attribute(:reward,which) self.update_attribute(:reward,which)
end end

View File

@ -2,6 +2,7 @@ class Softapplication < ActiveRecord::Base
attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id
acts_as_attachable acts_as_attachable
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :contesting_softapplications, :dependent => :destroy
belongs_to :user belongs_to :user
belongs_to :contest belongs_to :contest

View File

@ -79,6 +79,7 @@ class User < Principal
## added by xianbo for delete ## added by xianbo for delete
has_many :biding_projects, :dependent => :destroy has_many :biding_projects, :dependent => :destroy
has_many :contesting_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy
has_many :contesting_softapplications, :dependent => :destroy
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
##ended by xianbo ##ended by xianbo

View File

@ -18,9 +18,10 @@
</tr> </tr>
<tr> <tr>
<td><span class="font_lighter"><%= l(:label_x_biding_project, :count => contest.contesting_projects.count) %>(<strong><span style="font-size: 17px"><%= link_to contest.contesting_projects.count %></span></strong>)</span> <td><span class="font_lighter"><%= l(:label_contest_project, :count => contest.contesting_projects.count) %>(<strong><span style="font-size: 17px"><%= link_to contest.contesting_projects.count %></span></strong>)</span>
<span class="font_lighter"><%= l(:label_x_bids_responses, :count => contest.commit) %>(<strong><span style="font-size: 17px"><%= link_to contest.commit, respond_path(contest) %></span></strong>)</span> <span class="font_lighter"><%= l(:label_contest_softapplication, :count => contest.contesting_softapplications.count) %>(<strong><span style="font-size: 17px"><%= link_to contest.contesting_softapplications.count %></span></strong>)</span>
<span class="font_lighter"><%= l(:label_x_followers, :count => contest.watcher_users.count) %>(<strong><span style="font-size: 17px"><%= link_to contest.watcher_users.count, respond_path(contest) %></span></strong>)</span> <span class="font_lighter"><%= l(:label_contest_response, :count => contest.commit) %>(<strong><span style="font-size: 17px"><%= link_to contest.commit, respond_path(contest) %></span></strong>)</span>
<span class="font_lighter"><%= l(:label_contest_watchers, :count => contest.watcher_users.count) %>(<strong><span style="font-size: 17px"><%= link_to contest.watcher_users.count, respond_path(contest) %></span></strong>)</span>
</td> </td>
</tr> </tr>

View File

@ -12,5 +12,4 @@
</td> </td>
<% end %> <% end %>
</table> </table>
<!-- <%= @contest.softapplications.to_json %> --> <%= render :partial=> "list_softapplications",:locals => {:contesting_softapplication => contesting_softapplication,:contest => @contest }%>
<%= render :partial=> "list_softapplications",:locals => {:softapplication => softapplication,:contest => @contest }%>

View File

@ -60,7 +60,7 @@
<!--我要以发布应用的形式参加竞赛-弹出框--> <!--我要以发布应用的形式参加竞赛-弹出框-->
<div id = 'flash' style="float:left; width: 100%; display: nonea" ></div> <div id = 'flash' style="float:left; width: 100%; display: nonea" ></div>
<div id="put-bid-form" style="display: nonea"> <div id="put-bid-form" style="display: nonea">
<%= form_for "contest_for_save", :remote=>true, :url => {:controller => 'contests', :action => 'add_softapplication'}, :update => "softapplication_list", :complete => '$("#put-bid-form").hide();' do |f| %> <%= form_for "contest_for_save", :remote=>true, :url => {:controller => 'contests', :action => 'add_softapplication'}, :update => "contesting_softapplication_list", :complete => '$("#put-bid-form").hide();' do |f| %>
<table id="contesting_table" border="0" width="100%" style="margin-left: 40px;"> <!--该table为点击我要参加后弹出的--> <table id="contesting_table" border="0" width="100%" style="margin-left: 40px;"> <!--该table为点击我要参加后弹出的-->
<tr> <tr>
<td><%= select_tag 'contest', options_for_select(select_option_app_helper(@softapplication)), :name => 'contest', :class => 'grayline' %></td> <td><%= select_tag 'contest', options_for_select(select_option_app_helper(@softapplication)), :name => 'contest', :class => 'grayline' %></td>
@ -97,6 +97,6 @@
<div id='contesting_project_list'> <div id='contesting_project_list'>
<%#= render :partial => 'softapplication_list', :locals => {:softapplication => @softapplication,:contest => @contest} %> <%= render :partial => 'softapplication_list', :locals => {:contesting_softapplication => @contesting_softapplication,:contest => @contest} %>
</div> </div>

View File

@ -16,10 +16,7 @@
<td>开发者:<%= @softapplication.user.name %></td> <td>开发者:<%= @softapplication.user.name %></td>
<td>系统支持:<%= @softapplication.android_min_version_available %></td> <td>系统支持:<%= @softapplication.android_min_version_available %></td>
</tr> </tr>
<tr>
<td>已提交竞赛: <%= @softapplication.contest.name%></td>
<td></td>
</tr>
</table> </table>
</td> </td>

View File

@ -1823,6 +1823,9 @@ zh:
label_nextstep: 下一步 label_nextstep: 下一步
label_participate: 参赛者 label_participate: 参赛者
label_contest_project: 参赛项目 label_contest_project: 参赛项目
label_contest_softapplication: 参赛应用
label_contest_response: 用户反馈
label_contest_watchers: 关注人员
label_contest_application: 参赛应用 label_contest_application: 参赛应用
button_contesting_as_project: 我要参赛(新建项目) button_contesting_as_project: 我要参赛(新建项目)
button_contesting_as_application: 我要参赛(发布应用) button_contesting_as_application: 我要参赛(发布应用)

View File

@ -45,6 +45,7 @@ RedmineApp::Application.routes.draw do
match 'show_softapplication', via: :get match 'show_softapplication', via: :get
match 'show_participator' , via: :get match 'show_participator' , via: :get
match 'add' , via: [:get, :post] match 'add' , via: [:get, :post]
match 'add_softapplication' , via: [:get, :post]
match 'create' , via: :post match 'create' , via: :post
match 'settings' , via: [:get, :post] match 'settings' , via: [:get, :post]
end end