diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 7741333a8..debda938f 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -5,7 +5,7 @@ class ContestsController < ApplicationController menu_item :project, :only => :show_project menu_item :application, :only => :show_softapplication menu_item :attendingcontest, :only => :show_attendingcontest - before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, + before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :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] # added by fq @@ -335,7 +335,12 @@ class ContestsController < ApplicationController end ##取出参赛应用 @softapplication = Softapplication.all - @contesting_softapplication = @contest.contesting_softapplications.reverse + @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 + ON cached.cacheable_id=softapplications.id"). + order("cached.avg").reverse_order @contesting_softapplication = paginateHelper @contesting_softapplication, 10 @@ -350,6 +355,44 @@ class ContestsController < ApplicationController end ###end + + def set_reward_project + @c_p = nil + @contesting_project_id = nil + + if params[:set_reward_project][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) + # @bid_id = params[:id] + @contesting_project_id = params[:set_reward_project][:c_id] + @c_p = ContestingProject.find_by_id(@contesting_project_id) + + # 把字段存进表中 + @c_p.update_reward(params[:set_reward_project][:reward].to_s) + end + + respond_to do |format| + format.js + end + end + + def set_reward_softapplication + @c_sa = nil + @contesting_softapplication_id = nil + + if params[:set_reward_softapplication][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) + # @bid_id = params[:id] + @contesting_softapplication_id = params[:set_reward_softapplication][:c_id] + @c_sa = ContestingSoftapplication.find_by_id(@contesting_softapplication_id) + + # 把字段存进表中 + @c_sa.update_reward(params[:set_reward_softapplication][:reward].to_s) + end + + respond_to do |format| + format.js + end + end + + ###添加已创建的参赛项目 def add project = Project.find(params[:contest]) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index 9ede52489..6860bfa6a 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -100,14 +100,34 @@ class SoftapplicationsController < ApplicationController # 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.js + # format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' } + # # format.json { render json: @softapplication, status: :created, location: @softapplication } + # else + # format.js { render status: 406 } + # format.html { render action: "new" } + # # format.json { render json: @softapplication.errors, status: :unprocessable_entity } + # end + # end + # end + + +#new changed created function def create @softapplication = Softapplication.new(params[:softapplication]) @softapplication.user = User.current @softapplication.save_attachments(params[:attachments]) respond_to do |format| if @softapplication.save + ContestingSoftapplication.create(:contest_id => params[:contest_id], :softapplication_id => @softapplication.id) format.js - format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' } + format.html { redirect_to show_attendingcontest_contest_path(:id => params[:contest_id]) } # format.json { render json: @softapplication, status: :created, location: @softapplication } else format.js { render status: 406 } @@ -115,8 +135,13 @@ class SoftapplicationsController < ApplicationController # format.json { render json: @softapplication.errors, status: :unprocessable_entity } end end + #关联新建的参赛作品 + + # @contesting_softapplication = paginateHelper @contest.contesting_softapplications + + + end - # PUT /softapplications/1 # PUT /softapplications/1.json def update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6b8525a00..0c4514769 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -182,11 +182,27 @@ module ApplicationHelper end def thumbnail_tag(attachment) - link_to image_tag(thumbnail_path(attachment)), - named_attachment_path(attachment, attachment.filename), + imagepath = named_attachment_path(attachment, attachment.filename) + link_to image_tag(imagepath), + imagepath , :title => attachment.filename end + # 图片缩略图链接 + def thumbnail_small_tag(attachment) + imagesize = attachment.thumbnail(:size => "200*200") + imagepath = named_attachment_path(attachment, attachment.filename) + if imagesize + link_to image_tag(imagesize), + imagepath, + :title => attachment.filename + else + link_to image_tag(imagepath , height: '200', width: '250'), + imagepath, + :title => attachment.filename + end + end + def toggle_link(name, id, options={}) onclick = "$('##{id}').toggle(); " onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ") diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index 36f2351cb..fff2f785a 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -91,6 +91,10 @@ module ContestsHelper def get_prize(c_project) c_project.get_reward end + + def get_prize(c_softapplication) + c_softapplication.get_reward + end def count_contest_project contests = Contest.find(:id) diff --git a/app/helpers/open_source_projects_helper.rb b/app/helpers/open_source_projects_helper.rb index f758580d9..ce1593cf1 100644 --- a/app/helpers/open_source_projects_helper.rb +++ b/app/helpers/open_source_projects_helper.rb @@ -34,4 +34,8 @@ module OpenSourceProjectsHelper def get_open_source_projects_by_tag(tag_name) OpenSourceProject.tagged_with(tag_name).order('created_at desc') end + + def show_origin(url) + + end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 661762e5c..aff63439e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -228,7 +228,6 @@ class Attachment < ActiveRecord::Base end size = 100 unless size > 0 target = File.join(self.class.thumbnails_storage_path, "#{id}_#{digest}_#{size}.thumb") - begin Redmine::Thumbnail.generate(self.diskfile, target, size) rescue => e diff --git a/app/models/contesting_softapplication.rb b/app/models/contesting_softapplication.rb index 93aea2658..f880818d9 100644 --- a/app/models/contesting_softapplication.rb +++ b/app/models/contesting_softapplication.rb @@ -11,5 +11,18 @@ class ContestingSoftapplication < ActiveRecord::Base self.create(:user_id => User.current.id, :contest_id => contest_id, :softapplication_id => softapplication_id, :description => description) end + + def self.create_work_contesting(contest_id, softapplication_id) + self.create(:user_id => User.current.id, :contest_id => contest_id, + :softapplication_id => softapplication_id) + end + + def update_reward(which) + self.update_attribute(:reward,which) + end + + def get_reward + self.reward + end end diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index 6782b2436..3911424e9 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -1,5 +1,5 @@ class Softapplication < ActiveRecord::Base - attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id, :application_developers + attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id, :contest_id, :application_developers, :deposit_project_url acts_as_attachable seems_rateable :allow_update => true, :dimensions => :quality diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index c135ee214..f73df8fb4 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -33,7 +33,7 @@ <% if images.any? %>