diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index f6568662..acc87475 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -4,7 +4,7 @@ class ContestsController < ApplicationController menu_item :respond menu_item :project, :only => :show_project menu_item :application, :only => :show_softapplication - before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :create,:destroy,:more,:back,:add,:new,:show_results, :set_reward, + before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, :show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] # added by fq @@ -153,6 +153,22 @@ class ContestsController < ApplicationController end end + def show_contest_softapplication + contests = Contest.where('parent_id = ?', @contest.id) + @softapplications = [] + for contest in contests + @softapplications += contest.softapplications + end + + respond_to do |format| + format.html { + render :layout => 'base_newcontest' + } + format.api + + end + end + def show_contest_user contests = Contest.find(:all) @users = [] @@ -219,6 +235,31 @@ class ContestsController < ApplicationController ############ ##显示参赛的应用 def show_softapplication + # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + # @option = [] + + # @user = @contest.user + @softapplication = Softapplication.all + + # @temp = [] + # @softapplicationt.each do |pro| + # if pro.project && pro.project.project_status + # @temp << pro + # end + # @temp + + # if @temp.size > 0 + # @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} + # end + # end + # respond_to do |format| + # format.html { + # render :layout => 'base_newcontest' + # } + # format.api + # end +########################## + @contest = Contest.find_by_id(params[:id]) respond_to do |format| format.html { render :layout => 'base_newcontest' @@ -227,7 +268,7 @@ class ContestsController < ApplicationController end end - ###添加应标项目 + ###添加已创建的参赛项目 def add project = Project.find(params[:contest]) contest_message = params[:contest_for_save][:contest_message] @@ -247,7 +288,27 @@ class ContestsController < ApplicationController format.js end end + ###添加已发布的参赛应用 + 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) + flash.now[:notice] = l(:label_bidding_contest_succeed) + end + else + flash.now[:error] = l(:label_bidding_fail) + end + + @softapplication = @contest.softapplications + + render :text => params.to_json + # respond_to do |format| + # format.html { redirect_to :back } + # format.js + # end + end ## 新建留言 def create diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c606d053..344238e8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1419,7 +1419,15 @@ module ApplicationHelper return false end end - + + def show_more_contest_softapplication?(contest) + if contest.softapplications.where('is_public = 1').count > 12 + return true + else + return false + end + end + def show_contest_project(bid) html = '' if contest.projects.where('is_public = 1').count == 0 diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index e13641b1..d48342b5 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -56,21 +56,7 @@ module ContestsHelper end #end - # def sort_bid(state, project_type) - # content = ''.html_safe - # case state - # when 0 - # content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type))) - # content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") -# - # when 1 - # content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") - # content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type))) - # end - # content = content_tag('ul', content) - # content_tag('div', content, :class => "tabs") - # end - + #huang def sort_contest(state) content = ''.html_safe @@ -115,6 +101,16 @@ module ContestsHelper @projects.count end + def count_contest_softapplication + contests = Contest.find(:id) + @softapplications = [] + for contest in contests + @softapplications += contest.contesting_projects + end + @projects.count + end + + def count_contest_user contests = Contest.find(:id) @users = [] @@ -154,5 +150,12 @@ module ContestsHelper end tmp end + def select_option_app_helper options + tmp = Hash.new + options.each do |project| + tmp[project.name] = project.id + end + tmp + end end \ No newline at end of file diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 9d36f2bd..f56281d6 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -97,8 +97,8 @@ module WelcomeHelper sort_bid_by_hot end - def find_all_hot_contest - sort_contest_by_hot + def find_all_hot_contest limit=10 + Contest.all.take limit end def cal_memos_count event diff --git a/app/models/contest.rb b/app/models/contest.rb index a4427d24..b3e6c4f7 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -5,6 +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 :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/softapplication.rb b/app/models/softapplication.rb index 70983a48..4cf76001 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -1,8 +1,9 @@ class Softapplication < ActiveRecord::Base - attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id + 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 belongs_to :user + belongs_to :contest def add_jour(user, notes, reference_user_id = 0, options = {}) if options.count == 0 diff --git a/app/views/contests/_softapplication_list.html.erb b/app/views/contests/_softapplication_list.html.erb index 9a257683..895926e3 100644 --- a/app/views/contests/_softapplication_list.html.erb +++ b/app/views/contests/_softapplication_list.html.erb @@ -12,5 +12,5 @@ <% end %> - -<%#= render :partial=> "list_projects" %> + +<%= render :partial=> "list_softapplications",:locals => {:softapplication => softapplication,:contest => @contest }%> diff --git a/app/views/contests/show_project.html.erb b/app/views/contests/show_project.html.erb index f43d5048..07ddd621 100644 --- a/app/views/contests/show_project.html.erb +++ b/app/views/contests/show_project.html.erb @@ -89,7 +89,7 @@ :onmouseover => "this.style.backgroundPosition = 'left -30px'" %> - + <% end %> <% end %> diff --git a/app/views/contests/show_softapplication.html.erb b/app/views/contests/show_softapplication.html.erb index b3e38d5f..72599206 100644 --- a/app/views/contests/show_softapplication.html.erb +++ b/app/views/contests/show_softapplication.html.erb @@ -56,8 +56,47 @@ } + <% if User.current.logged? %> + +
+ + <% end %> -+ <%= link_to( contest.name, respond_path(contest.id), :class => "d-g-blue d-p-project-name", :title => "#{contest.name}", + :style => "margin-left: 28px;", :target => "_blank") %> +
++ <%= content_tag "span", contest.description.truncate(50, omission: '...'), :class => "d-p-project-intro" , :title => contest.description %> +
+