Conflicts: Gemfile app/controllers/tags_controller.rb app/views/layouts/_base_header.html.erb config/routes.rb db/schema.rbexceptionHandle
commit
9ac0cbe6a3
@ -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.
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
@ -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
|
@ -0,0 +1,2 @@
|
||||
module SoftapplicationsHelper
|
||||
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
|
@ -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…
Reference in new issue