Merge branch 'competition' into develop

Conflicts:
	Gemfile
	app/controllers/tags_controller.rb
	app/views/layouts/_base_header.html.erb
	config/routes.rb
	db/schema.rb
exceptionHandle
wanglinchun 11 years ago
commit 9ac0cbe6a3

@ -79,6 +79,9 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ruby-openid (2.1.8)
seems_rateable (1.0.13)
jquery-rails
rails
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@ -109,3 +112,4 @@ DEPENDENCIES
rails (= 3.2.13)
rdoc (>= 2.4.2)
ruby-openid (~> 2.1.4)
seems_rateable

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

@ -175,7 +175,7 @@ private
@attachment = Attachment.find(params[:id])
# Show 404 if the filename in the url is wrong
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo'
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
@project = @attachment.project
end
rescue ActiveRecord::RecordNotFound

@ -472,22 +472,22 @@ class BidsController < ApplicationController
# added by bai type ==1 需求type==2 竞赛, type==3 作业
if @bid.reward_type == 1
flash[:notice] = l(:label_bidding_succeed)
flash.now[:notice] = l(:label_bidding_succeed)
elsif @bid.reward_type == 2
flash[:notice] = l(:label_bidding_contest_succeed)
flash.now[:notice] = l(:label_bidding_contest_succeed)
else @bid.reward_type == 3
flash[:notice] = l(:label_bidding_homework_succeed)
flash.now[:notice] = l(:label_bidding_homework_succeed)
end
# end
end
else
if @bid.reward_type == 3
flash[:error] = l(:label_bidding_homework_fail)
flash.now[:error] = l(:label_bidding_homework_fail)
else
flash[:error] = l(:label_bidding_fail)
flash.now[:error] = l(:label_bidding_fail)
end
end
@bidding_project = @bid.biding_projects

File diff suppressed because it is too large Load Diff

@ -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

@ -68,6 +68,8 @@ class ProjectsController < ApplicationController
helper :bids
include BidsHelper
helper :contests
include ContestsHelper
helper :sort
include SortHelper
helper :custom_fields
@ -569,6 +571,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

@ -0,0 +1,194 @@
class SoftapplicationsController < ApplicationController
# GET /softapplications
# GET /softapplications.json
def index
@softapplications = Softapplication.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @softapplications }
end
end
# GET /softapplications/1
# GET /softapplications/1.json
def show
@softapplication = Softapplication.find(params[:id])
@jours = @softapplication.journals_for_messages.order('created_on DESC')
@image_results = []
@softapplication.attachments.each do |f|
f.image? ? @image_results << f : @image_results
end
@app_items = []
@softapplication.attachments.each do |f|
f.pack? ? @app_items << f : @app_items
end
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
respond_to do |format|
format.html # show.html.erb
format.json { render json: @softapplication }
end
end
# GET /softapplications/new
# GET /softapplications/new.json
def new
@softapplication = Softapplication.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @softapplication }
end
end
# GET /softapplications/1/edit
def edit
@softapplication = Softapplication.find(params[:id])
end
# POST /softapplications
# POST /softapplications.json
def create
@softapplication = Softapplication.new(params[:softapplication])
@softapplication.user = User.current
@softapplication.save_attachments(params[:attachments])
respond_to do |format|
if @softapplication.save
format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' }
format.json { render json: @softapplication, status: :created, location: @softapplication }
else
format.html { render action: "new" }
format.json { render json: @softapplication.errors, status: :unprocessable_entity }
end
end
end
# PUT /softapplications/1
# PUT /softapplications/1.json
def update
@softapplication = Softapplication.find(params[:id])
respond_to do |format|
if @softapplication.update_attributes(params[:softapplication])
format.html { redirect_to @softapplication, notice: 'Softapplication was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @softapplication.errors, status: :unprocessable_entity }
end
end
end
def add_attach
@softapplication = Softapplication.find(params[:id])
@softapplication.save_attachments(params[:attachments])
end
# DELETE /softapplications/1
# DELETE /softapplications/1.json
def destroy
@softapplication = Softapplication.find(params[:id])
@softapplication.destroy
respond_to do |format|
format.html { redirect_to softapplications_url }
format.json { head :no_content }
end
end
#应用评价涉及到的方法
def new_message
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
user = @jour.user
text = @jour.notes
else
user = @softapplication.user
text = @softapplication.description
end
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404
end
#新建评价
def create_message
if params[:softapplication_message][:message].size>0
if params[:reference_content]
message = params[:softapplication_message][:message] + "\n" + params[:reference_content]
else
message = params[:softapplication_message][:message]
end
refer_user_id = params[:softapplication_message][:reference_user_id].to_i
@softapplication = Softapplication.find(params[:id])
@softapplication.add_jour(User.current, message, refer_user_id)
end
@user = @softapplication.user
@jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
#@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
##删除评价
def destroy_message
@user = @softapplication.user
if User.current.admin? || User.current.id == @user.id
JournalsForMessage.delete_message(params[:object_id])
end
@jours = @softapplication.journals_for_messages.reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@softapplication.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
#
def more
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = true
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
#
def back
@jour = @softapplication.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = false
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
end

@ -11,6 +11,7 @@ class TagsController < ApplicationController
include BidsHelper
include ForumsHelper
include AttachmentsHelper
include ContestsHelper
include ActsAsTaggableOn::TagsHelper
helper :projects
include TagsHelper
@ -30,7 +31,7 @@ class TagsController < ApplicationController
# 最后是2个过滤何种数据显示结果的控制参数params[:obj_id],params[:object_falg]
# 0代表删除tag 1代表增加tag
def index
@obj_id = params[:obj_id]
@obj_flag = params[:object_flag]
@ -44,28 +45,29 @@ class TagsController < ApplicationController
@tag = params[:tag]
@selected_tags = params[:current_selected_tags]
@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
case @do_what
when '0' then
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
when '1' then
# 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag
@selected_tags << @tag
end
# 判断是否已存在该tag 主要用来处理分页的情况
unless @selected_tags.include? @tag
@selected_tags << @tag
end
end
end
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num,@contests_tags_num,
@forum_tags_num, @attachments_tags_num = get_tags_size
# 获取搜索结果
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results,
@attachments_results = refresh_results(@obj_id,@obj_flag,@selected_tags)
@attachments_results,
@contests_tags = refresh_results(@obj_id,@obj_flag,@selected_tags)
# 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil?
@ -74,13 +76,13 @@ class TagsController < ApplicationController
# @selected_tags.each do |i|
# @tags.delete(i)
# end
@related_tags = @tags
@related_tags = @tags
else
return
end
end
# 增加已选的tag
def add_tag
@tag = params[:tag]
@ -90,11 +92,13 @@ class TagsController < ApplicationController
$related_tags.delete(@tag)
# 获取搜索结果
@obj,@obj_pages,@users_results,
@obj,@obj_pages,@results_count,@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results = refresh_results(@obj_id,@show_flag)
@forums_results,
@attachments_results,
@contests_results = refresh_results(@obj_id,@show_flag)
end
# 删除已选tag
@ -110,13 +114,15 @@ class TagsController < ApplicationController
@projects_results,
@issues_results,
@bids_results,
@forums_results = refresh_results(@obj_id,@show_flag)
@forums_results,
@attachments_results,
@contests_results = refresh_results(@obj_id,@show_flag)
end
def show_all
@tags = ActsAsTaggableOn::Tag.find(:all)
@tags = ActsAsTaggableOn::Tag.find(:all)
end
# 完全从数据库删除tag
# 这种删除方式是针对 印有该 tag所有对象来做删除的
# 这样是从整个系统数据库中把该tag删除了
@ -148,24 +154,24 @@ class TagsController < ApplicationController
# if can_remove_tag?(User.current,@taggable_id,@taggable_type)
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
unless @taggings.nil?
@taggings.delete
end
@taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type)
unless @taggings.nil?
@taggings.delete
end
# 是否还有其他记录 引用了 tag_id
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
@tagging = ActsAsTaggableOn::Tagging.find_by_tag_id(@tag_id)
# 如果taggings表中记录已经不存在 那么检查tags表 作删除动作
if @tagging.nil?
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
if @tagging.nil?
@tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
@tag.delete unless @tag.nil?
end
# end
end
end
private
private
# 这里用来刷新搜索结果的区域
# 函数的返回值 前2字段用来处理获取其他tag和分页 另外4个返回值为过滤结果
def refresh_results(obj_id,obj_flag,selected_tags)
@ -173,6 +179,7 @@ private
@projects_results = nil
@issues_results = nil
@bids_results = nil
@contests_results = nil
@forums_results = nil
attachments_results = nil
@obj_pages = nil
@ -203,10 +210,22 @@ private
# this is used to find the attachments that came from the same project and tagged with the same tag.
@result = get_attachments_by_project_tag(selected_tags, @obj)
@obj_pages, attachments_results, @results_count = for_pagination(@result)
when '7'
@obj = Contest.find_by_id(obj_id)
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags))
else
@obj = nil
@obj = nil
end
return @obj,@obj_pages,@results_count,@users_results,@projects_results,@issues_results,@bids_results,@forums_results, attachments_results
return [@obj,
@obj_pages,
@results_count,
@users_results,
@projects_results,
@issues_results,
@bids_results,
@forums_results,
attachments_results,
@contests_results]
end
def for_pagination(results)
@ -226,7 +245,8 @@ private
@bids_tags_num = Bid.tag_counts.size
forum_tags_num = Forum.tag_counts.size
attachment_tags_num = Attachment.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num
@contests_tags_num = Contest.tag_counts.size
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num
end
# 通过数字 来转换出对象的类型
@ -247,6 +267,8 @@ private
return 'Forum'
when '6'
return 'Attachment'
when '7'
return 'Contest'
else
render_error :message => e.message
return

@ -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
@ -633,6 +656,8 @@ class UsersController < ApplicationController
@obj = Forum.find_by_id(@obj_id)
when '6'
@obj = Attachment.find_by_id(@obj_id)
when '7' then
@obj = Contest.find_by_id(@obj_id)
else
@obj = nil
end

@ -80,7 +80,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

@ -190,6 +190,10 @@ 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)
elsif ( referer.match(/softapplications/) || referer.match(/softapplications/) ) #new added
obj = Softapplication.find_by_id(obj_id)
else
raise 'create reply obj unknow type.'
end
@ -204,6 +208,10 @@ 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
elsif obj.kind_of? Softapplication
obj.add_jour(nil, nil, obj.id, options) #new added
else
raise 'create reply obj unknow type.'
end

@ -111,6 +111,14 @@ module ApplicationHelper
link_to text, url, html_options
end
def link_to_attachment_img(attachment, options={})
text = options.delete(:text) || attachment.filename
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path)
url = send(route_method, attachment, attachment.filename, options)
image_tag url, html_options
end
# Generates a link to a SCM revision
# Options:
# * :text - Link text (default to the formatted revision)
@ -1402,6 +1410,71 @@ 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_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
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_softapplication(contest)
html = ''
if contest.softapplications.where('is_public = 1').count == 0
html << (content_tag "p", l(:label_no_contest_softapplication), :class => "font_lighter")
else
contest.softapplications.where('is_public = 1').take(12).each do |softapplication|
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 +1573,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'}
@ -1528,5 +1601,9 @@ module ApplicationHelper
end
content_tag :ul, content_li.html_safe
end
def current_user
User.current
end
end

@ -0,0 +1,172 @@
#enconding:utf-8
# fq
module ContestsHelper
def render_notes(contest, journal, options={})
content = ''
removable = User.current == journal.user || User.current == contest.author
links = []
if !journal.notes.blank?
links << link_to(image_tag('comment.png'),
{:controller => 'contests', :action => 'new', :id => contest, :journal_id => journal},
:remote => true,
:method => 'post',
:title => l(:button_quote)) if options[:reply_links]
if removable
url = {:controller => 'contests',
:action => 'destroy',
:object_id => journal,
:id => contest}
links << ' '
links << link_to(image_tag('delete.png'), url,
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
end
end
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
content << textilizable(journal.notes)
css_classes = "wiki"
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
end
def link_to_in_place_notes_editor(text, field_id, url, options={})
onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;"
link_to text, '#', options.merge(:onclick => onclick)
end
# this method is used to get all projects that tagged one tag
# added by william
def get_contests_by_tag(tag_name)
Contest.tagged_with(tag_name).order('updated_on desc')
end
#added by huang
def sort_contest_enterprise(state, project_type)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:contest_sort_type => '1', :project_type => project_type)))
content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_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(:contest_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_sort_type => '0', :project_type => project_type)))
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs_enterprise")
end
#end
#huang
def sort_contest(state)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'}))
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'}, :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'}, :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'}))
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
#end
# def course_options_for_select(courses)
# # <option value = '0'>#{l(:label_choose_reward)}</option>
# html = ''
# courses.each do |course|
# html << "<option value = #{course.id}>"
# html << course.name
# html << "</option>"
# end
# html.html_safe
# end
# used to get the reward and handle the value which can be used to display in views
# added by william
def get_prize(c_project)
c_project.get_reward
end
def count_contest_project
contests = Contest.find(:id)
@projects = []
for contest in contests
@projects += contest.contesting_projects
end
@projects.count
end
def count_contest_softapplication
contests = Contest.find(:id)
@softapplications = []
for contest in contests
@softapplications += contest.contesting_softapplications
end
@projects.count
end
def count_contest_user
contests = Contest.find(:id)
@users = []
for contest in contests
for project in contest.projects
@users += project.users
end
end
@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
# case bid.reward_type # 天煞的bid分了三用途里面各种hasmany还不定能用
# when 1
# when 2
# bid.join_in_contests.each do |jic|
# people << jic.user
# end
# when 3
# people += bid.courses.first.users.to_a
# else
# raise 'bids_helper: unknow bid type' # 出了错看这里!不知道的抛异常,省的找不到出错的地方!
# end
contest.join_in_contests.each do |jic|
people << jic.user
end
people.include?(User.current)
end
def select_option_helper option
tmp = Hash.new
option.each do |project|
tmp[project.name] = project.identifier
end
tmp
end
def select_option_app_helper options
tmp = Hash.new
options.each do |option|
tmp[option.name] = option.id
end
tmp
end
end

@ -0,0 +1,2 @@
module SoftapplicationsHelper
end

@ -5,15 +5,17 @@ module TagsHelper
@obj = nil
case obj_type
when '1'
@obj = User.find_by_id(obj_id)
@obj = User.find_by_id(obj_id)
when '2'
@obj = Project.find_by_id(obj_id)
when '3'
@obj = Issue.find_by_id(obj_id)
when '4'
@obj = Bid.find_by_id(obj_id)
@obj = Bid.find_by_id(obj_id)
when '6'
@obj = Attachment.find_by_id(obj_id)
when '7'
@obj= Contest.find_by_id(obj_id)
else
raise Exception, '[TagsHelper] ===> tag type unknow.'
end
@ -40,6 +42,10 @@ module TagsHelper
if user.id == obj_id
@result = true
end
when '7'
if user.id == obj_id
@result = true
end
end
return @result
end

@ -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)

@ -97,10 +97,14 @@ module WelcomeHelper
sort_bid_by_hot
end
def find_all_hot_contest
sort_contest_by_hot
def find_all_hot_contest limit=10
Contest.reorder("created_on DESC").all.take limit
end
def find_all_hot_softapplication limit=10
Softapplication.reorder("created_at DESC").all.take limit
end
def cal_memos_count event
return nil if event.parent_id
event.replies_count

@ -21,6 +21,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
validates_presence_of :filename, :author
@ -33,7 +34,7 @@ class Attachment < ActiveRecord::Base
acts_as_event :title => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
acts_as_activity_provider :type => 'files',
acts_as_activity_provider :type => 'files',
:permission => :view_files,
:author_key => :author_id,
:find_options => {:select => "#{Attachment.table_name}.*",
@ -179,6 +180,10 @@ class Attachment < ActiveRecord::Base
!!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i)
end
def pack?
!!(self.filename =~ /\.(zip|rar|tar|gz)$/i)
end
def thumbnailable?
image?
end

@ -0,0 +1,119 @@
class Contest < ActiveRecord::Base
attr_accessible :author_id, :budget, :commit, :deadline, :description, :name, :password
include Redmine::SafeAttributes
belongs_to :author, :class_name => 'User', :foreign_key => :author_id
has_many :contesting_projects, :dependent => :destroy
has_many :projects, :through => :contesting_projects
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
has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy
has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy
acts_as_attachable
NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 250
validates_length_of :name, :maximum => NAME_LENGTH_LIMIT
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :author_id, :name, :deadline
validates_format_of :deadline, :with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/
validates_format_of :budget, :with => /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/
validate :validate_user
after_create :act_as_activity
scope :visible, lambda {|*args|
nil
}
scope :like, lambda {|arg|
if arg.blank?
where(nil)
else
pattern = "%#{arg.to_s.strip.downcase}%"
where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern)
end
}
acts_as_watchable
acts_as_taggable
acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" },
:description => :description,
:author => :author,
:url => Proc.new {|o| {:controller => 'contests', :action => 'show_contest', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:projects, :author]},
:author_key => :author_id
safe_attributes 'name',
'description',
'budget',
'deadline',
'password'
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
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
def update_contests(budget, deadline, name, description=nil)
if(User.current.id == self.author_id)
self.name = name
self.budget = budget
self.deadline = deadline
self.description = description
self.save
end
end
def delete_contests
unless self.nil?
if User.current.id == self.author_id
self.destroy
end
end
end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
private
def validate_user
errors.add :author_id, :invalid if author.nil? || !author.active?
end
def act_as_activity
self.acts << Activity.new(:user_id => self.author_id)
end
def validate_contest_manager(user_id)
unless user_id.nil?
if self.author_id == user_id
return true
else
return false
end
end
end
end

@ -0,0 +1,52 @@
class ContestingProject < ActiveRecord::Base
attr_accessible :contest_id, :description, :project_id, :user_id, :reward
belongs_to :contest
belongs_to :project
belongs_to :user
DESCRIPTION_LENGTH_LIMIT = 500
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
validates_presence_of :user_id, :contest_id, :project_id
validate :validate_user
validate :validate_contest
validate :validate_project
validates_uniqueness_of :contest_id, :scope => :project_id
def self.cerate_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
def update_reward(which)
self.update_attribute(:reward,which)
end
def get_reward
self.reward
end
def cancel_contesting
unless self.nil?
if User.current.id == self.user_id
self.destroy
end
end
end
private
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active?
end
def validate_contest
errors.add :contest_id, :invalid if contest.nil?
end
def validate_project
errors.add :project_id, :invalid if project.nil?
end
end

@ -0,0 +1,15 @@
class ContestingSoftapplication < ActiveRecord::Base
attr_accessible :contest_id, :description, :softapplication_id, :user_id
belongs_to :contest
belongs_to :softapplication
belongs_to :user
def self.create_softapplication_contesting(contest_id, softapplication_id, description = nil)
self.create(:user_id => User.current.id, :contest_id => contest_id,
:softapplication_id => softapplication_id, :description => description)
end
end

@ -1,5 +1,5 @@
class HomeworkAttach < ActiveRecord::Base
include Redmine::SafeAttributes
include Redmine::SafeAttributes
belongs_to :user
belongs_to :bid

@ -0,0 +1,10 @@
# 新竞赛参加关系表
class JoinInCompetition < ActiveRecord::Base
attr_accessible :competition_id, :user_id
belongs_to :user, :class_name => "User", :foreign_key => :user_id
belongs_to :competition, :class_name => "Contest", :foreign_key => :competition_id
validates :user_id, presence: true
validates :competition_id, presence: true
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save