diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 0fdb1b2c..53df54e9 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -69,6 +69,8 @@ class PraiseTreadController < ApplicationController @obj = Project.find_by_id(id) when 'Bid' @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) end return @obj end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d3481e2a..81135865 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -68,6 +68,8 @@ class ProjectsController < ApplicationController helper :bids include BidsHelper + helper :contests + include ContestsHelper helper :sort include SortHelper helper :custom_fields @@ -567,6 +569,7 @@ class ProjectsController < ApplicationController "show_messages" => true, "show_news" => true, "show_bids" => true, + "show_contests" => true, "show_journals_for_messages" => true } @date_to ||= Date.today + 1 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5fcac2d5..e9e64918 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -23,19 +23,20 @@ class UsersController < ApplicationController menu_item :user_homework, :only => :user_homeworks menu_item :user_project, :only => [:user_projects, :watch_projects] menu_item :requirement_focus, :only => :watch_bids + menu_item :requirement_focus, :only => :watch_contests menu_item :user_newfeedback, :only => :user_newfeedback #Ended by young - before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, + before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info, :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index] #edit has been deleted by huang, 2013-9-23 before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, - :watch_bids, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, + :watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index] accept_api_auth :index, :show, :create, :update, :destroy,:tag_save @@ -116,6 +117,28 @@ class UsersController < ApplicationController format.api end end + +#new add by linchun + def watch_contests + @bids = Contest.watched_by(@user) + @offset, @limit = api_offset_and_limit({:limit => 10}) + @contest_count = @contests.count + @contest_pages = Paginator.new @contest_count, @limit, params['page'] + @offset ||= @contest_pages.reverse_offset + unless @offset == 0 + @contest = @contests.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @contest = @contests.offset(@offset).limit(limit).all.reverse + end + + respond_to do |format| + format.html { + render :layout => 'base_users' + } + format.api + end + end # added by fq def user_activities diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 904920c5..d35be75d 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -81,7 +81,7 @@ class WelcomeController < ApplicationController end def contest - + end def search @@ -120,7 +120,7 @@ class WelcomeController < ApplicationController def entry_select_contest if request.original_url.match(/contest\.trustie\.net/) contest - render :contest, layout: false + render :contest return 0 end end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index be1e3177..416b40db 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -190,6 +190,8 @@ class WordsController < ApplicationController obj = User.find_by_id(obj_id) elsif ( referer.match(/bids/) || referer.match(/calls/) ) obj = Bid.find_by_id(obj_id) + elsif ( referer.match(/contests/) || referer.match(/contests/) ) #new added + obj = Contest.find_by_id(obj_id) else raise 'create reply obj unknow type.' end @@ -204,6 +206,8 @@ class WordsController < ApplicationController Project.add_new_jour(nil, nil, obj.id, options) elsif obj.kind_of? Bid obj.add_jour(nil, nil, nil, options) + elsif obj.kind_of? Contest + obj.add_jour(nil, nil, obj.id, options) #new added else raise 'create reply obj unknow type.' end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6047fcf2..c606d053 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1410,6 +1410,50 @@ module ApplicationHelper end html.html_safe end + +#display contest project + def show_more_contest_project?(contest) + if contest.projects.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 + html << (content_tag "p", l(:label_no_bid_project), :class => "font_lighter") + else + contest.projects.where('is_public = 1').take(12).each do |project| + html << (link_to image_tag(url_to_avatar(project), :class => "avatar", :title => project.name), project_path(project), :class => "avatar") + end + end + html.html_safe + end + + def show_contest_project(contest) + html = '' + if contest.projects.where('is_public = 1').count == 0 + html << (content_tag "p", l(:label_no_bid_project), :class => "font_lighter") + else + contest.projects.where('is_public = 1').take(12).each do |project| + html << (link_to image_tag(url_to_avatar(project), :class => "avatar", :title => project.name), project_path(project), :class => "avatar") + end + end + html.html_safe + end + def show_contest_fans_picture(obj) + html = '' + if obj.watcher_users.count == 0 + html << (content_tag "span", l(:label_project_no_follow)) + else + obj.watcher_users.take(12).each do |user| + html << (link_to image_tag(url_to_avatar(user), :class => "avatar"), user_path(user), :class => "avatar", :title => user.name) + end + end + html.html_safe + end #display fans picture def show_more_fans?(obj) @@ -1500,7 +1544,7 @@ module ApplicationHelper courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1, :host => Setting.course_domain} projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain} users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index', :host => Setting.user_domain} - contest_link = link_to l(:label_contest_innovate), {:controller => 'bids', :action => 'contest', :project_type => 1 , :host => Setting.contest_domain} + contest_link = link_to l(:label_contest_innovate), {:controller => 'contests', :action => 'index'} bids_link = link_to l(:label_requirement_enterprise), {:controller => 'bids', :action => 'index'} forum_link = link_to l(:label_project_module_forums), {:controller => "forums", :action => "index"} stores_link = link_to l(:label_stores_index), {:controller => 'stores', :action=> 'index'} diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index e05ef6eb..fcaf6360 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -30,7 +30,7 @@ module WatchersHelper objects = Array.wrap(objects) watched = objects.any? {|object| object.watched_by?(user)} - @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Bid))) + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or objects.first.instance_of?(Contest) or (objects.first.instance_of?(Bid))) css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) @@ -46,6 +46,27 @@ module WatchersHelper link_to text, url, :remote => true, :method => method, :class => css end + ############## added by linchun + def new_watcher_link(objects, user, options=[]) + return '' unless user && user.logged? + objects = Array.wrap(objects) + + watched = objects.any? {|object| object.watched_by?(user)} + @watch_flag = (objects.first.instance_of?(User) or objects.first.instance_of?(Project) or (objects.first.instance_of?(Contest))) + css = @watch_flag ? ([watcher_css(objects), watched ? 'icon ' : 'icon '].join(' ') << options[0].to_s) : + ([watcher_css(objects), watched ? 'icon icon-fav ' : 'icon icon-fav-off '].join(' ') << options[0].to_s) + + text = @watch_flag ? + (watched ? l(:button_unfollow) : l(:button_follow)) : (watched ? l(:button_unwatch) : l(:button_watch)) + + url = watch_path( + :object_type => objects.first.class.to_s.underscore, + :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort) + ) + method = watched ? 'delete' : 'post' + + link_to text, url, :remote => true, :method => method, :class => css + end # added by fq, modify nyan # Somebody may use option params def join_in_course(course, user, options=[]) @@ -93,8 +114,40 @@ module WatchersHelper end end end - - + ##new add by linchun + def join_in_contest(contest, user, options=[]) + return '' unless user && user.logged? + joined = user.join_in_contest?(contest) + text = joined ? l(:label_exit_contest) : l(:label_join_contest) + url_t = join_in_contest_path(:id => contest.id) + url_f = try_join_in_contest_path(:id => contest.id) + # url = join_in_contest_path(:id => contest.id) + method = joined ? 'delete' : 'post' + if joined + link_to text, url_t, :remote => true, :method => method, :id => "#{contest.id}", :confirm => l(:text_are_you_sure_out), :class => []+options + else + link_to text, url_f, :remote => true, :method => method, :id => "#{contest.id}", :class => []+options + end + end + + # liuwanwei 的需求, 新竞赛 + # 新路由命名为 competition + def join_in_competition(competition, user) + return '' unless user && user.logged? + joined = JoinInCompetition.where('competition_id = ? AND user_id = ?', competition.id, user.id).count>0 + text = joined ? l(:label_exit_contest) : l(:label_join_contest) + url_f = new_join_contests_path(:id => competition.id) + url_t = unjoin_in_contest_contests_path(:id => competition.id) + method = joined ? 'delete' : 'post' + if joined + # 退出竞赛用 + link_to text, url_t, :remote => true, :method => method, :id => "#{competition.id}", :confirm => l(:text_are_you_sure_out) + else + # 加入竞赛用 + link_to text, url_f, :remote => true, :method => method, :id => "#{competition.id}" + end + end + # Returns the css class used to identify watch links for a given +object+ def watcher_css(objects) objects = Array.wrap(objects) diff --git a/app/models/project.rb b/app/models/project.rb index fd576b63..0f68d3ab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -55,6 +55,7 @@ class Project < ActiveRecord::Base has_many :changesets, :through => :repository #added by xianbo for delete biding_project has_many :biding_projects, :dependent => :destroy + has_many :contesting_projects, :dependent => :destroy #ended by xianbo # added by fq has_many :journals_for_messages, :as => :jour, :dependent => :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 4042fd84..8c867512 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -78,11 +78,13 @@ class User < Principal belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang ## added by xianbo for delete has_many :biding_projects, :dependent => :destroy + has_many :contesting_projects, :dependent => :destroy ##ended by xianbo #####fq has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :bids, :foreign_key => 'author_id', :dependent => :destroy + has_many :contests, :foreign_key => 'author_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" has_many :journal_replies, :dependent => :destroy diff --git a/app/views/welcome/contest.html.erb b/app/views/welcome/contest.html.erb index 6a0a8413..a343f2ea 100644 --- a/app/views/welcome/contest.html.erb +++ b/app/views/welcome/contest.html.erb @@ -1,8 +1,244 @@ +<%= stylesheet_link_tag 'welcome' %> + + + +
-
- 正在升级中。。。。。。。。。。。。 + +
+
+ <%= l(:label_welcome_trustie) %><%= l(:label_welcome_trustie_contest) %> , <%= l(:label_welcome_trustie_contest_description) %> +
+ +
+ +
+ +
+

热门项目

+ <%= link_to "更多>>", { :controller => 'projects', :action => 'index', :project_type => 0, :host => Setting.project_domain}, :target => "_blank" %> +
+
    + <% find_miracle_project(10, 3).map do |project| %> +
  • +
    + <%= image_tag(get_project_avatar(project), :class => "avatar-4") %> +
    + +
    + <%= link_to( project.name, project_path(project.id), :class => "d-g-blue d-p-project-name",:title => "#{project.name}" )%> + (<%= link_to "#{projectCount(project)}人", project_member_path(project) ,:course =>'0' %>) +
    +
    + ><%=project.description.truncate(50, omission: '...')%> +
    +
    + <%= content_tag "span", show_grade(project), + :style => "cursor: pointer; display: inline-block; float: right; color: #ec6300; ", + :title => "项目得分,综合考虑了项目的各项活动,反映了该项目的活跃程度", + :class => "tooltip", + :id => "tooltip-#{project.id}" %> +

    +
    +
  • + <% end; reset_cycle %> +
+
+
+ +
+ +
+ +
+ +
+ + + + + + + + +
+
+ + +






diff --git a/app/views/words/destroy.js.erb b/app/views/words/destroy.js.erb index c583e044..d3f3acc9 100644 --- a/app/views/words/destroy.js.erb +++ b/app/views/words/destroy.js.erb @@ -1,6 +1,6 @@ <% if @journal_destroyed.nil? %> alert('<%=l(:notice_failed_delete)%>'); -<% elsif (['Principal','Project', 'Bid'].include? @journal_destroyed.jour_type)%> +<% elsif (['Principal','Project', 'Bid', 'Contest'].include? @journal_destroyed.jour_type)%> var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>') destroyedItem.fadeOut(600,function(){ destroyedItem.remove(); diff --git a/config/locales/zh.yml b/config/locales/zh.yml index a006ae53..e2b69082 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1549,8 +1549,10 @@ zh: label_welcome_trustie: Trustie label_welcome_trustie_project: 在线项目托管平台 label_welcome_trustie_course: 在线课程实践平台 + label_welcome_trustie_contest: 在线竞赛实战平台 label_welcome_trustie_project_description: 面向中国大学生与软件从业者,提供社交化的项目管理、代码托管、资源共享、合作交流。 label_welcome_trustie_course_description: 面向中国高校教师与大学生,提供社交化的课程管理、资源共享、合作实验、协同研究。 + label_welcome_trustie_contest_description: 面向中国大学生与编程爱好者,提供社交化的竞赛管理、应用管理、代码托管、合作交流。 label_user_project: 项目 label_user_course: 课程 label_user_homework: 作业 @@ -1811,3 +1813,14 @@ zh: label_contest_reason: 参赛宣言: label_notification: 通知 label_sumbit_empty: 搜索内容不能为空 + + #add by linchun (竞赛相关) + label_upload_files: 上传文件 + label_upload_softwarepackage: 上传软件包 + label_upload_cuttingphoto: 上传截图 + label_contests_reward_method: 奖励方式 + label_system_platform: 系统平台 + label_nextstep: 下一步 + label_participate: 参赛者 + label_contest_project: 参赛项目 + label_contest_application: 参赛应用 diff --git a/config/routes.rb b/config/routes.rb index 8ad29472..e72f83ac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,28 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do + ## new added by linchun #新竞赛相关 + resources :contests, only: [:index] do + collection do + match 'new_contest' , via: :get + match 'join_in_contest' , via: :post + match 'unjoin_in_contest' , via: :delete + match 'create_contest' , via: :post + match 'new_join' , via: :post + match 'new' , via: :post + end + member do + match 'update_contest' , via: [:put] + match 'show_contest' , via: :get + match 'show_project' , via: :get + match 'show_application' , via: :get + match 'show_participator' , via: :get + match 'add' , via: [:get, :post] + match 'create' , via: :post + match 'settings' , via: [:get, :post] + end + end + resources :stores do collection do match 'search', via: [:get, :post] diff --git a/lib/redmine.rb b/lib/redmine.rb index 0f8b3acc..cce178a5 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -276,6 +276,16 @@ Redmine::MenuManager.map :bid_menu do |menu| # menu.push :result, { :controller => 'bids', :action => 'show_results' }, # :caption => :label_bidding_results,:if => Proc.new{ |p| User.current.id == p } end +###new add by linchun +Redmine::MenuManager.map :contest_menu do |menu| + menu.push :respond, :show_contest_contest_path, :caption => :label_user_response + menu.push :project, :show_project_contest_path, :caption => :label_contest_project + menu.push :application, :show_application_contest_path, :caption => :label_contest_application + # menu.push :result, { :controller => 'bids', :action => 'show_results' }, + # :caption => :label_bidding_results,:if => Proc.new{ |p| User.current.id == p } +end + +#### Redmine::MenuManager.map :application_menu do |menu| # Empty end