修改contests_controller.rb,contest.rb, contest_project.rb,contests_helper.rb,

attachments_helper.rb, application_helper.rb.
主要修改内容: 书写规范, for循环用 each 代替, if 语句的合并, unless 转换成if,
		函数名称拼写错误。

Signed-off-by: alan <547533434@qq.com>
alan_competition
alan 11 years ago
parent 02c72c68ca
commit 70b079041c

@ -2,33 +2,44 @@
# class BidsController < ApplicationController
class ContestsController < ApplicationController
layout "contest_base"
menu_item :respond
menu_item :project, :only => :show_project
menu_item :application, :only => :show_softapplication
menu_item :attendingcontests, :only => :show_attendingcontest
menu_item :contestnotifications, :only => :index
before_filter :can_show_contest,except: []
before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :index, :set_reward_project, :set_reward_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]
before_filter :can_show_contest, :except => [] # modified by alan
# modified by longjun
before_filter :find_contest, :only => [
:show_contest, :show_project, :show_softapplication,
:show_attendingcontest, :index, :set_reward_project,
:set_reward_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
]
# end longjun
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
before_filter :require_login,:only => [:set_reward, :destroy, :add, :new, ]
before_filter :require_login,:only => [:set_reward, :destroy, :add, :new ]
helper :watchers
helper :attachments
include AttachmentsHelper
include ApplicationHelper
helper :projects
helper :words
include AttachmentsHelper
include ApplicationHelper
def index
# @contests = Contest.visible
# @contests ||= []
@offset, @limit = api_offset_and_limit({:limit => 10})
@offset, @limit = api_offset_and_limit(:limit => 10)
#@contests = Contest.visible
#@contests = @contests.like(params[:name]) if params[:name].present?
@contests = Contest.visible.where("name like '%#{params[:name]}%'")
@ -42,7 +53,10 @@ class ContestsController < ApplicationController
if params[:contest_sort_type].present?
case params[:contest_sort_type]
when '0'
unless @offset == 0
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
else
limit = @contest_count % @limit
@ -51,7 +65,10 @@ class ContestsController < ApplicationController
end
@s_state = 0
when '1'
unless @offset == 0
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
else
limit = @contest_count % @limit
@ -60,7 +77,10 @@ class ContestsController < ApplicationController
end
@s_state = 1
when '2'
unless @offset == 0
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@contests = @contests.offset(@offset).limit(@limit).all.reverse
else
limit = @contest_count % @limit
@ -70,7 +90,10 @@ class ContestsController < ApplicationController
@s_state = 0
end
else
unless @offset == 0
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
else
limit = @contest_count % @limit
@ -93,7 +116,10 @@ class ContestsController < ApplicationController
@bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.reverse_offset
unless @offset == 0
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@ -149,10 +175,7 @@ class ContestsController < ApplicationController
end
end
def new_join
end
def show_participator
render :layout => 'base_newcontest'
@ -186,26 +209,43 @@ class ContestsController < ApplicationController
def show_contest_project
contests = Contest.where('parent_id = ?', @contest.id)
@projects = []
for contest in contests
# Modified by longjun
# 用 arr.each 替换 for [ according to the style guide ]
# for contest in contests
# @projects += contest.contesting_projects
# end
contests.each do |contest|
@projects += contest.contesting_projects
end
# end
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
def show_contest_softapplication
contests = Contest.where('parent_id = ?', @contest.id)
@softapplications = []
for contest in contests
# Modified by Longjun
# for contest in contests
# @softapplications += contest.contesting_softapplications
contests.each do |contest|
@softapplications += contest.contesting_softapplications
end
# end
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
@ -218,11 +258,20 @@ class ContestsController < ApplicationController
def show_contest_user
contests = Contest.find(:all)
@users = []
for contest in contests
for project in contest.projects
@users += project.users
# Modified by Longjun
# for contest in contests
# for project in contest.projects
# @users += project.users
# end
contests.each do |contest|
contest.projects.each do |project|
@uers += project.users
end
end
# end
respond_to do |format|
format.html {
@ -239,11 +288,20 @@ class ContestsController < ApplicationController
# @contesting_project_count = @contesting_project_all.count
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
@membership.each do |membership|
unless(membership.project.project_type==1)
if User.current.allowed_to?(:quote_project, membership.project)
# Modified by Longjun
# 将两个判断语句合并
# unless membership.project.project_type==1
# if User.current.allowed_to?(:quote_project, membership.project)
# @option << membership.project
# end
# end
if membership.project.project_type != 1 && User.current.allowed_to?(:quote_project, membership.project)
@option << membership.project
end
end
# end
end
@user = @contest.author
@contesting_project = @contest.contesting_projects.all
@ -262,16 +320,19 @@ class ContestsController < ApplicationController
@temp = []
@contesting_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
end
# modified by longjun
# if pro.project && pro.project.project_status
# @temp << pro
# end
@temp << pro if pro.project && pro.project.project_status
# end longjun
@temp
end
if @temp.size > 0
@contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
end
@contesting_project = paginateHelper @contesting_project
@contesting_project = paginateHelper(@contesting_project)
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
@ -290,7 +351,7 @@ class ContestsController < ApplicationController
@softapplication = Softapplication.all
@contesting_softapplication = @contest.contesting_softapplications
@contesting_softapplication = paginateHelper @contesting_softapplication, 10
@contesting_softapplication = paginateHelper(@contesting_softapplication, 10)
# @temp = []
# @softapplicationt.each do |pro|
@ -328,7 +389,7 @@ class ContestsController < ApplicationController
# @contesting_project_count = @contesting_project_all.count
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
@membership.each do |membership|
unless(membership.project.project_type==1)
unless membership.project.project_type==1
#拥有编辑项目权限的可将该项目参赛
if User.current.allowed_to?(:quote_project, membership.project)
@option << membership.project
@ -352,27 +413,31 @@ class ContestsController < ApplicationController
@temp = []
@contesting_project.each do |pro|
if pro.project && pro.project.project_status
@temp << pro
end
# modified by longjun
# if pro.project && pro.project.project_status
# @temp << pro
# end
@temp << pro if pro.project && pro.project.project_status
# end longjun
@temp
end
if @temp.size > 0
@contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
end
##取出参赛应用 --应用列表
# 取出参赛应用 --应用列表
@softapplication = Softapplication.all
@contesting_softapplication = @contest.contesting_softapplications.
joins("LEFT JOIN softapplications ON contesting_softapplications.softapplication_id=softapplications.id").
joins("LEFT JOIN (
SELECT * FROM seems_rateable_cached_ratings WHERE cacheable_type='Softapplication' AND DIMENSION = 'quality') AS cached
SELECT * FROM seems_rateable_cached_ratings
WHERE cacheable_type='Softapplication' AND DIMENSION = 'quality') AS cached
ON cached.cacheable_id=softapplications.id").
order("cached.avg").reverse_order
@contesting_softapplication = paginateHelper @contesting_softapplication, 10
##引用base_newcontest整体样式
#引用base_newcontest整体样式
@contest = Contest.find_by_id(params[:id])
respond_to do |format|
format.html {
@ -384,7 +449,7 @@ class ContestsController < ApplicationController
###end
def show_notification
def show_notification
@contest = Contest.find_by_id(params[:id])
respond_to do |format|
format.html {
@ -392,7 +457,7 @@ def show_notification
}
format.api
end
end
end
def set_reward_project
@ -437,7 +502,11 @@ end
project = Project.find(params[:contest])
contest_message = params[:contest_for_save][:contest_message]
if ContestingProject.where("project_id = ? and contest_id = ?", project.id, @contest.id).size == 0
if ContestingProject.cerate_contesting(@contest.id, project.id, contest_message)
# modified by longjun, create 写错了
# if ContestingProject.cerate_contesting(@contest.id, project.id, contest_message)
if ContestingProject.create_contesting(@contest.id, project.id, contest_message)
# end longjun
flash.now[:notice] = l(:label_bidding_contest_succeed)
end
else
@ -633,9 +702,7 @@ end
end
def manage
end
private

@ -33,8 +33,8 @@ module ApplicationHelper
extend Forwardable
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
#Added by young
#Define the course menu's link class
# Added by young
# Define the course menu's link class
# 不是数组的转化成数组然后判断当前menu_item是否在给定的列表
# REVIEW: 目测menu的机制貌似不是很需要转换再说
def link_class(label)

@ -22,6 +22,9 @@ module AttachmentsHelper
# Options:
# :author -- author names are not displayed if set to false
# :thumbails -- display thumbnails if enabled in settings
include Redmine::Pagination
def link_to_attachments(container, options = {})
options.assert_valid_keys(:author, :thumbnails)
@ -171,7 +174,9 @@ module AttachmentsHelper
s.html_safe
end
def private_filter resultSet
# Modified by Longjun
# 有参数的方法要加()
def private_filter(resultSet)
result = resultSet.to_a.dup
# modify by nwb
@ -190,8 +195,12 @@ module AttachmentsHelper
result
end
include Redmine::Pagination
def paginateHelper obj, pre_size=10
# Modified by Longjun
# include 应放在class/model 的开始处
# include Redmine::Pagination
# end
def paginateHelper (obj, pre_size=10)
@obj_count = obj.count
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation

@ -100,7 +100,10 @@ module ContestsHelper
def count_contest_project
contests = Contest.find(:id)
@projects = []
for contest in contests
# Modified by alan
# for contest in contests
contests.each do |contest|
# end alan
@projects += contest.contesting_projects
end
@projects.count
@ -109,7 +112,10 @@ module ContestsHelper
def count_contest_softapplication
contests = Contest.find(:id)
@softapplications = []
for contest in contests
# Modified by alan
# for contest in contests
contests.each do |contest|
# end alan
@softapplications += contest.contesting_softapplications
end
@projects.count
@ -119,19 +125,29 @@ module ContestsHelper
def count_contest_user
contests = Contest.find(:id)
@users = []
for contest in contests
for project in contest.projects
# Modified by alan
# for contest in contests
contests.each do |contest|
contest.projects.each do |project|
@users += project.users
end
end
# end alan
@users.count
end
def count_contest_softapplication_user
contests = Contest.find(:id)
@users = []
for contest in contests
for project in contest.softapplications
# Modified by alan
# for contest in contests
contests.each do |contest|
contest.projects.each do |softapplications|
# for project in contest.softapplications
@users += softapplication.users
end
end

@ -142,7 +142,7 @@ module ProjectsHelper
# end
#Added by young
# Added by young
def course_settings_tabs
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'},
#{:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural, :project_type => 1},
@ -151,7 +151,7 @@ module ProjectsHelper
]
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
end
#Ended by young
# Ended by young
@ -174,20 +174,37 @@ module ProjectsHelper
def render_project_hierarchy(projects)
render_project_nested_lists(projects) do |project|
#Modified by young
if (project.try(:project_type) == Project::ProjectType_course )
unless project.is_public == 1
if project.try(:project_type) == Project::ProjectType_course
# modified by longjun
# never use unless and else
# unless project.is_public == 1
if project.is_public != 1
s = "<span class='private_project'>#{l(:lable_private)}</span>".html_safe
else
s = "".html_safe
end
s += link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}").html_safe
# end longjun
# modified by Longjun
s += link_to_project(project, {},
:class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}").html_safe
# end longjun
else
unless project.is_public
# modified by longjun
# unless project.is_public
if !project.is_public
# end longjun
s = "<span class='private_project'>#{l(:lable_private)}</span>".html_safe
else
s = "".html_safe
end
s += link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
# modified by longjun
s += link_to_project(project, {},
:class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
# end longjun
end
#Ended by young
if project.description.present?
@ -254,9 +271,14 @@ module ProjectsHelper
def is_manager?(user_id,project_id)
@result = false
@user_id = ProjectInfo.find_by_project_id(project_id)
if @user_id == user.id
@result = true
end
# modified by longjun
# if @user_id == user.id
# @result = true
# end
@result = true if @user_id = user.id
# end longjun
return @result
end
@ -341,9 +363,9 @@ module ProjectsHelper
return true if (project.nil? && project.course_extra.nil?)
courses_year = project.course_extra.time
current_year = Time.now.year
if(courses_year >= current_year)
if courses_year >= current_year
return false
elsif( (courses_year < current_year) && (Time.now.month < 3) )
elsif (courses_year < current_year) && (Time.now.month < 3)
return false
else
return true

@ -72,10 +72,13 @@ class Contest < ActiveRecord::Base
end
end
def self.creat_contests(budget, deadline, name, description=nil)
self.create(:author_id => User.current.id, :budget => budget,
:deadline => deadline, :name => name, :description => description, :commit => 0)
end
# modified by longjun
# 这个函数没有用到
# def self.creat_contests(budget, deadline, name, description=nil)
# self.create(:author_id => User.current.id, :budget => budget,
# :deadline => deadline, :name => name, :description => description, :commit => 0)
# end
# end longjun
def update_contests(budget, deadline, name, description=nil)
if(User.current.id == self.author_id)

@ -14,7 +14,7 @@ class ContestingProject < ActiveRecord::Base
validate :validate_project
validates_uniqueness_of :contest_id, :scope => :project_id
def self.cerate_contesting(contest_id, project_id, description = nil)
def self.create_contesting(contest_id, project_id, description = nil)
self.create(:user_id => User.current.id, :contest_id => contest_id,
:project_id => project_id, :description => description)
end

@ -30,7 +30,18 @@
<% if User.current.logged? %>
<table border="0" width="525px" align="center" >
<tr>
<td><%= f.text_area 'message', :rows => 3, :cols => 65, :placeholder => l(:label_my_respond), :style => "resize: none;", :class => 'noline'%></td>
<!-- modified by longjun 修改格式 -->
<td>
<%= f.text_area 'message',
:rows => 3,
:cols => 65,
:placeholder => l(:label_my_respond),
:style => "resize: none;",
:class => 'noline'
%>
</td>
<!-- end longjun -->
</tr>
</table>
@ -39,8 +50,23 @@
<!-- modified by bai -->
<table border="0" width="525px" align="center">
<tr>
<td align="right"> <%= submit_tag l(:button_leave_meassge), :name => nil , :class => "contest_btn", :onmouseout => "this.style.backgroundPosition = 'left top'", :onmouseover => "this.style.backgroundPosition = 'left -31px'"%>
<%= submit_tag l(:button_clear_meassge), :name => nil, :onclick => "clearMessage('contest_message_message');", :type => 'button', :class => "bid_btn", :onmouseout => "this.style.backgroundPosition = 'left top'", :onmouseover => "this.style.backgroundPosition = 'left -31px'" %> </td>
<!-- modified by longjun 修改格式 -->
<td align="right">
<%= submit_tag l(:button_leave_meassge),
:name => nil ,
:class => "contest_btn",
:onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -31px'"
%>
<%= submit_tag l(:button_clear_meassge),
:name => nil,
:onclick => "clearMessage('contest_message_message');",
:type => 'button', :class => "bid_btn",
:onmouseout => "this.style.backgroundPosition = 'left top'",
:onmouseover => "this.style.backgroundPosition = 'left -31px'"
%>
</td>
<!-- end longjun -->
</tr>
</table>
<!-- end -->

Loading…
Cancel
Save