diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index acc874752..4ca1c1933 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -157,7 +157,7 @@ class ContestsController < ApplicationController contests = Contest.where('parent_id = ?', @contest.id) @softapplications = [] for contest in contests - @softapplications += contest.softapplications + @softapplications += contest.contesting_softapplications end respond_to do |format| @@ -240,6 +240,7 @@ class ContestsController < ApplicationController # @user = @contest.user @softapplication = Softapplication.all + @contesting_softapplication = @contest.contesting_softapplications # @temp = [] # @softapplicationt.each do |pro| @@ -292,15 +293,15 @@ class ContestsController < ApplicationController def add_softapplication softapplication = Softapplication.find(params[:contest]) contest_message = params[:contest_for_save][:contest_message] - if Softapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 - if Softapplication.create_contesting(@contest.id, softapplication.id, contest_message) + if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 + if ContestingSoftapplication.create_contesting(@contest.id, softapplication.id, contest_message) flash.now[:notice] = l(:label_bidding_contest_succeed) end else flash.now[:error] = l(:label_bidding_fail) end - @softapplication = @contest.softapplications + @contesting_softapplication = @contest.contesting_softapplications render :text => params.to_json # respond_to do |format| diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index d48342b59..00fb5b77c 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -105,7 +105,7 @@ module ContestsHelper contests = Contest.find(:id) @softapplications = [] for contest in contests - @softapplications += contest.contesting_projects + @softapplications += contest.contesting_softapplications end @projects.count end @@ -122,6 +122,16 @@ module ContestsHelper @users.count 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 people = [] people << contest.author @@ -152,8 +162,8 @@ module ContestsHelper end def select_option_app_helper options tmp = Hash.new - options.each do |project| - tmp[project.name] = project.id + options.each do |option| + tmp[option.name] = option.id end tmp end diff --git a/app/models/contest.rb b/app/models/contest.rb index b3e6c4f77..edc252574 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -5,8 +5,8 @@ class Contest < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => :author_id has_many :contesting_projects, :dependent => :destroy has_many :projects, :through => :contesting_projects - has_many :softapplications, :dependent => :destroy - # has_many :softapplications, :through => :softapplications + has_many :contesting_softapplications, :dependent => :destroy + has_many :softapplications, :through => :contesting_softapplications has_many :projects_member, :class_name => 'User', :through => :projects has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy diff --git a/app/models/contesting_project.rb b/app/models/contesting_project.rb index 773c04c68..c0c360548 100644 --- a/app/models/contesting_project.rb +++ b/app/models/contesting_project.rb @@ -19,6 +19,11 @@ class ContestingProject < ActiveRecord::Base :project_id => project_id, :description => description) 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) self.update_attribute(:reward,which) end diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 4cf76001a..e63eb428d 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -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 acts_as_attachable has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :contesting_softapplications, :dependent => :destroy belongs_to :user belongs_to :contest diff --git a/app/models/user.rb b/app/models/user.rb index 1aa1e0382..0255b0da6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -79,6 +79,7 @@ class User < Principal ## added by xianbo for delete has_many :biding_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy + has_many :contesting_softapplications, :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy ##ended by xianbo diff --git a/app/views/contests/_contest_list.html.erb b/app/views/contests/_contest_list.html.erb index cdc390410..5a8bf6890 100644 --- a/app/views/contests/_contest_list.html.erb +++ b/app/views/contests/_contest_list.html.erb @@ -18,9 +18,10 @@ - <%= l(:label_x_biding_project, :count => contest.contesting_projects.count) %>(<%= link_to contest.contesting_projects.count %>) - <%= l(:label_x_bids_responses, :count => contest.commit) %>(<%= link_to contest.commit, respond_path(contest) %>) - <%= l(:label_x_followers, :count => contest.watcher_users.count) %>(<%= link_to contest.watcher_users.count, respond_path(contest) %>) + <%= l(:label_contest_project, :count => contest.contesting_projects.count) %>(<%= link_to contest.contesting_projects.count %>) + <%= l(:label_contest_softapplication, :count => contest.contesting_softapplications.count) %>(<%= link_to contest.contesting_softapplications.count %>) + <%= l(:label_contest_response, :count => contest.commit) %>(<%= link_to contest.commit, respond_path(contest) %>) + <%= l(:label_contest_watchers, :count => contest.watcher_users.count) %>(<%= link_to contest.watcher_users.count, respond_path(contest) %>) diff --git a/app/views/contests/_softapplication_list.html.erb b/app/views/contests/_softapplication_list.html.erb index 895926e38..221dc9dcf 100644 --- a/app/views/contests/_softapplication_list.html.erb +++ b/app/views/contests/_softapplication_list.html.erb @@ -12,5 +12,4 @@ <% end %> - -<%= render :partial=> "list_softapplications",:locals => {:softapplication => softapplication,:contest => @contest }%> +<%= render :partial=> "list_softapplications",:locals => {:contesting_softapplication => contesting_softapplication,:contest => @contest }%> diff --git a/app/views/contests/show_softapplication.html.erb b/app/views/contests/show_softapplication.html.erb index 725992062..fd643a0bd 100644 --- a/app/views/contests/show_softapplication.html.erb +++ b/app/views/contests/show_softapplication.html.erb @@ -60,7 +60,7 @@
- <%= 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| %> @@ -97,6 +97,6 @@
- <%#= render :partial => 'softapplication_list', :locals => {:softapplication => @softapplication,:contest => @contest} %> + <%= render :partial => 'softapplication_list', :locals => {:contesting_softapplication => @contesting_softapplication,:contest => @contest} %>
diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index d0043564a..e3e64900c 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -16,10 +16,7 @@ - - - - +
<%= select_tag 'contest', options_for_select(select_option_app_helper(@softapplication)), :name => 'contest', :class => 'grayline' %>开发者:<%= @softapplication.user.name %> 系统支持:<%= @softapplication.android_min_version_available %>
已提交竞赛: <%= @softapplication.contest.name%>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 352afe2a0..f5f120925 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1823,6 +1823,9 @@ zh: label_nextstep: 下一步 label_participate: 参赛者 label_contest_project: 参赛项目 + label_contest_softapplication: 参赛应用 + label_contest_response: 用户反馈 + label_contest_watchers: 关注人员 label_contest_application: 参赛应用 button_contesting_as_project: 我要参赛(新建项目) button_contesting_as_application: 我要参赛(发布应用) diff --git a/config/routes.rb b/config/routes.rb index c5397187b..360c9399e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,7 @@ RedmineApp::Application.routes.draw do match 'show_softapplication', via: :get match 'show_participator' , via: :get match 'add' , via: [:get, :post] + match 'add_softapplication' , via: [:get, :post] match 'create' , via: :post match 'settings' , via: [:get, :post] end