From b97cdd6b0da76dc690651c2c321c98ff3d5e2528 Mon Sep 17 00:00:00 2001 From: wanglinchun Date: Fri, 11 Apr 2014 09:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E8=B5=9B=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E4=B8=AD=E5=BA=94=E7=94=A8=E5=92=8C=E7=AB=9E=E8=B5=9B?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E8=81=94=E5=89=8D=EF=BC=8C=E7=9B=AE=E5=89=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=E7=94=B1=E4=BA=8E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=A1=A8=E5=8F=8A=E5=85=B3=E8=81=94=E6=B2=A1=E8=80=83?= =?UTF-8?q?=E8=99=91=E6=B8=85=E6=A5=9A=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=85=B3=E8=81=94=EF=BC=8C=E4=B8=8B=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=EF=BC=8C=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=EF=BC=8C=E5=AE=8C=E6=88=90=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=8F=8A=E5=BA=94=E7=94=A8=E7=9A=84=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/contests_controller.rb | 65 +++++++++++++++- app/helpers/application_helper.rb | 10 ++- app/helpers/contests_helper.rb | 33 ++++---- app/helpers/welcome_helper.rb | 4 +- app/models/contest.rb | 2 + app/models/softapplication.rb | 3 +- .../contests/_softapplication_list.html.erb | 4 +- app/views/contests/show_project.html.erb | 2 +- .../contests/show_softapplication.html.erb | 43 ++++++++++- app/views/softapplications/show.html.erb | 6 +- app/views/welcome/contest.html.erb | 75 ++++++------------- config/locales/zh.yml | 1 + config/routes.rb | 3 +- db/schema.rb | 48 ++++-------- 14 files changed, 186 insertions(+), 113 deletions(-) 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? %> + +
+
+ <%= form_for "contest_for_save", :remote=>true, :url => {:controller => 'contests', :action => 'add_softapplication'}, :update => "softapplication_list", :complete => '$("#put-bid-form").hide();' do |f| %> + + + +
+
+ + + + + + + + + + +
<%= select_tag 'contest', options_for_select(select_option_app_helper(@softapplication)), :name => 'contest', :class => 'grayline' %> +

+

+ <%= link_to '创建应用', new_softapplication_path(:target=>'_blank') %> +
+

+
<%= f.text_area :contest_message, :id => "contest_message", :required => true, :rows => 4, :cols => 40, :placeholder => l(:label_bid_reason), :style => "resize: none;", :class => 'noline'%>
+ <%= submit_tag l(:button_add), :name => nil , :class => "enterprise", + :onmouseout => "this.style.backgroundPosition = 'left top'", + :onmouseover => "this.style.backgroundPosition = 'left -30px'"%> + <%= submit_tag l(:button_cancel), :name => nil, :onclick => "cancel();", + :type => 'button', :class => "enterprise", :onmouseout => "this.style.backgroundPosition = 'left top'", + :onmouseover => "this.style.backgroundPosition = 'left -30px'" %> +
+ <% end %> +
+ <% end %> -
- <%= render :partial => 'softapplication_list' %> + + +
+ <%#= render :partial => 'softapplication_list', :locals => {:softapplication => @softapplication,:contest => @contest} %>
diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index 89048983..d0043564 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -10,12 +10,16 @@ 所属类别:<%= @softapplication.app_type_name %> - 发布时间:<%=@softapplication.created_at %> + 发布时间:<%=format_time @softapplication.created_at %> 开发者:<%= @softapplication.user.name %> 系统支持:<%= @softapplication.android_min_version_available %> + + 已提交竞赛: <%= @softapplication.contest.name%> + + diff --git a/app/views/welcome/contest.html.erb b/app/views/welcome/contest.html.erb index 5b00d4d1..b1c009c9 100644 --- a/app/views/welcome/contest.html.erb +++ b/app/views/welcome/contest.html.erb @@ -119,18 +119,14 @@
- - - +
- <%= form_tag( method: 'post') do %> + + <%= form_tag({controller: 'contests', action: 'index'}, method: :get) do %> <%= text_field_tag 'name', params[:name], placeholder:'请输入要搜索的关键字', name: "name", :class => 'blueinputbar', :style => 'width:400px;'%>   - <%= submit_tag l(:label_search), :class => "enterprise"%> + <%= hidden_field_tag 'project_type', params[:project_type] %> + <%= submit_tag l(:label_search), :class => "enterprise" , :name => nil%> <% end %>
竞赛相关内容搜索,如竞赛题目,参赛题目,参赛人名等。
@@ -180,7 +176,26 @@ +
+

最新参赛应用

+ <%= link_to "更多>>", {:controller => 'bids', :action => 'contest', :project_type => 1, :host => Setting.contest_domain}, :target => "_blank" %> +
+
    + <% find_all_hot_contest.map do |contest| break if(contest == find_all_hot_contest[10]) %> +
  • +

    + <%= 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 %> +

    +
  • + <% end %> +
+
+
- - - - - -
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 78f5e972..352afe2a 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1837,3 +1837,4 @@ zh: label_softapplication_developer: 开发者 label_softapplication_name_condition: 25个汉字以内(50个字符) label_user_login_softapplication_board: 您还没有登录,请登录后参与应用评价。 + label_contest_description_no: 暂无描述。 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 41524a5d..c5397187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do - + ##new added by linchun #以发布应用的形式参与竞赛 resources :softapplications do collection do @@ -38,6 +38,7 @@ RedmineApp::Application.routes.draw do match 'new' , via: :post end member do + match 'add_softapplication' match 'update_contest' , via: [:put] match 'show_contest' , via: :get match 'show_project' , via: :get diff --git a/db/schema.rb b/db/schema.rb index dab01aed..8b443264 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 => 20140404030103) do +ActiveRecord::Schema.define(:version => 20140411005214) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -23,11 +23,6 @@ ActiveRecord::Schema.define(:version => 20140404030103) do add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type" add_index "activities", ["user_id"], :name => "index_activities_on_user_id" - create_table "andoidcontests", :force => true do |t| - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "attachments", :force => true do |t| t.integer "container_id" t.string "container_type", :limit => 30 @@ -172,6 +167,16 @@ ActiveRecord::Schema.define(:version => 20140404030103) do t.string "reward" end + create_table "contesting_softapplications", :force => true do |t| + t.integer "softapplication_id" + t.integer "contest_id" + t.integer "user_id" + t.string "description" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "reward" + end + create_table "contests", :force => true do |t| t.string "name" t.integer "budget" @@ -528,19 +533,6 @@ ActiveRecord::Schema.define(:version => 20140404030103) do t.string "salt", :null => false end - create_table "open_source_projects", :force => true do |t| - t.string "name" - t.string "description", :default => "" - t.integer "commit_count", :default => 0 - t.integer "code_line", :default => 0 - t.integer "users_count", :default => 0 - t.date "last_commit_time" - t.string "url" - t.date "date_collected" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "praise_tread_caches", :force => true do |t| t.integer "object_id", :null => false t.string "object_type" @@ -620,21 +612,6 @@ ActiveRecord::Schema.define(:version => 20140404030103) do add_index "queries", ["project_id"], :name => "index_queries_on_project_id" add_index "queries", ["user_id"], :name => "index_queries_on_user_id" - create_table "relative_memos", :force => true do |t| - t.integer "osp_id", :null => false - t.integer "parent_id" - t.string "subject", :null => false - t.text "content", :null => false - t.integer "author_id" - t.integer "replies_count", :default => 0 - t.integer "last_reply_id" - t.boolean "lock", :default => false - t.boolean "sticky", :default => false - t.boolean "is_quote", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "repositories", :force => true do |t| t.integer "project_id", :default => 0, :null => false t.string "url", :default => "", :null => false @@ -716,6 +693,9 @@ ActiveRecord::Schema.define(:version => 20140404030103) do t.integer "user_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.integer "contest_id" + t.integer "softapplication_id" + t.integer "is_public" end create_table "students_for_courses", :force => true do |t|