2014-04-04 17:54:20 +08:00
|
|
|
class SoftapplicationsController < ApplicationController
|
2014-04-22 10:59:50 +08:00
|
|
|
before_filter :find_softapplication, only: [:edit, :update, :destroy]
|
|
|
|
before_filter :editable, only: [:edit, :update]
|
|
|
|
before_filter :destroyable, only: :destroy
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
# GET /softapplications
|
|
|
|
# GET /softapplications.json
|
|
|
|
def index
|
|
|
|
@softapplications = Softapplication.all
|
2014-04-29 14:40:39 +08:00
|
|
|
|
|
|
|
#new added fenyefunction
|
2014-04-29 14:34:45 +08:00
|
|
|
@limit = 5
|
|
|
|
@softapplication_count = @softapplications.count
|
|
|
|
@softapplication_pages = Paginator.new @softapplication_count, @limit, params['page']
|
|
|
|
@offset ||= @softapplication_pages.offset
|
|
|
|
#@softapplications = @softapplications[@offset,@limit]
|
2014-04-29 18:21:07 +08:00
|
|
|
#new added end
|
|
|
|
|
|
|
|
#new added sort
|
|
|
|
if params[:softapplication_sort_type].present?
|
|
|
|
case params[:softapplication_sort_type]
|
|
|
|
when '0'
|
|
|
|
@softapplications = @softapplications[@offset, @limit]
|
|
|
|
@s_state = 0
|
|
|
|
when '1'
|
|
|
|
@softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
|
|
|
|
@s_state = 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
|
|
|
|
@s_state = 1
|
|
|
|
end
|
|
|
|
#new added end
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.json { render json: @softapplications }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /softapplications/1
|
|
|
|
# GET /softapplications/1.json
|
2014-04-30 08:07:08 +08:00
|
|
|
|
|
|
|
def percent_of(num, percent)
|
|
|
|
num.to_f / percent.to_f * 100.0
|
|
|
|
end
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
def show
|
|
|
|
@softapplication = Softapplication.find(params[:id])
|
2014-05-19 17:39:51 +08:00
|
|
|
@project = Project.find_by_identifier(@softapplication.deposit_project)
|
2014-04-30 08:07:08 +08:00
|
|
|
# 打分统计
|
|
|
|
stars_reates = @softapplication.
|
|
|
|
rates(:quality)
|
|
|
|
stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
|
|
|
|
stars_status = stars_reates.select("stars, count(*) as scount").
|
|
|
|
group("stars")
|
|
|
|
|
|
|
|
@stars_status_map = Hash.new(0.0)
|
|
|
|
stars_status.each do |star_status|
|
2014-05-05 10:01:08 +08:00
|
|
|
percent = percent_of(star_status.scount, stars_reates_count).to_f
|
|
|
|
percent_m = format("%.2f", percent)
|
2014-04-30 08:07:08 +08:00
|
|
|
@stars_status_map["star#{star_status.stars.to_i}".to_sym] =
|
2014-05-05 10:01:08 +08:00
|
|
|
percent_m.to_s + "%"
|
2014-04-30 08:07:08 +08:00
|
|
|
end
|
2014-04-10 08:33:30 +08:00
|
|
|
@jours = @softapplication.journals_for_messages.order('created_on DESC')
|
2014-04-11 17:16:22 +08:00
|
|
|
@image_results = []
|
|
|
|
@softapplication.attachments.each do |f|
|
2014-04-21 19:36:05 +08:00
|
|
|
f.image? ? @image_results << f : @image_results
|
2014-04-11 17:16:22 +08:00
|
|
|
end
|
2014-04-21 19:36:05 +08:00
|
|
|
@app_items = []
|
2014-04-14 15:54:10 +08:00
|
|
|
@softapplication.attachments.each do |f|
|
2014-04-21 19:36:05 +08:00
|
|
|
f.pack? ? @app_items << f : @app_items
|
2014-04-14 15:54:10 +08:00
|
|
|
end
|
2014-04-10 08:33:30 +08:00
|
|
|
@limit = 10
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
2014-04-21 19:36:05 +08:00
|
|
|
@state = false
|
2014-04-04 17:54:20 +08:00
|
|
|
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
|
2014-05-19 17:39:51 +08:00
|
|
|
|
|
|
|
#添加当前用户创建过的项目作为托管项目(下拉项目列表)
|
|
|
|
project = Project.find(params[:user_id])
|
|
|
|
#end
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
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
|
2014-05-13 11:44:29 +08:00
|
|
|
# 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
|
2014-04-04 17:54:20 +08:00
|
|
|
def create
|
|
|
|
@softapplication = Softapplication.new(params[:softapplication])
|
2014-04-10 08:33:30 +08:00
|
|
|
@softapplication.user = User.current
|
2014-05-19 17:39:51 +08:00
|
|
|
@softapplication.deposit_project = params[:project]
|
|
|
|
|
2014-04-09 09:25:24 +08:00
|
|
|
@softapplication.save_attachments(params[:attachments])
|
2014-05-19 17:39:51 +08:00
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
respond_to do |format|
|
|
|
|
if @softapplication.save
|
2014-05-13 11:44:29 +08:00
|
|
|
ContestingSoftapplication.create(:contest_id => params[:contest_id], :softapplication_id => @softapplication.id)
|
2014-05-10 10:15:51 +08:00
|
|
|
format.js
|
2014-05-13 11:44:29 +08:00
|
|
|
format.html { redirect_to show_attendingcontest_contest_path(:id => params[:contest_id]) }
|
2014-05-10 10:15:51 +08:00
|
|
|
# format.json { render json: @softapplication, status: :created, location: @softapplication }
|
2014-04-04 17:54:20 +08:00
|
|
|
else
|
2014-05-10 10:15:51 +08:00
|
|
|
format.js { render status: 406 }
|
2014-04-04 17:54:20 +08:00
|
|
|
format.html { render action: "new" }
|
2014-05-10 10:15:51 +08:00
|
|
|
# format.json { render json: @softapplication.errors, status: :unprocessable_entity }
|
2014-04-04 17:54:20 +08:00
|
|
|
end
|
|
|
|
end
|
2014-05-13 11:44:29 +08:00
|
|
|
#关联新建的参赛作品
|
|
|
|
|
|
|
|
# @contesting_softapplication = paginateHelper @contest.contesting_softapplications
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
end
|
|
|
|
# PUT /softapplications/1
|
|
|
|
# PUT /softapplications/1.json
|
|
|
|
def update
|
2014-04-22 10:59:50 +08:00
|
|
|
# @softapplication = Softapplication.find(params[:id])
|
2014-04-23 16:16:17 +08:00
|
|
|
@softapplication.attachments.map{|attach| attach.destroy }
|
|
|
|
@softapplication.save_attachments(params[:attachments])
|
2014-04-04 17:54:20 +08:00
|
|
|
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
|
2014-04-21 19:36:05 +08:00
|
|
|
|
2014-04-09 09:25:24 +08:00
|
|
|
def add_attach
|
|
|
|
@softapplication = Softapplication.find(params[:id])
|
2014-04-21 19:36:05 +08:00
|
|
|
@softapplication.save_attachments(params[:attachments])
|
2014-04-09 09:25:24 +08:00
|
|
|
end
|
2014-04-04 17:54:20 +08:00
|
|
|
|
|
|
|
# DELETE /softapplications/1
|
|
|
|
# DELETE /softapplications/1.json
|
|
|
|
def destroy
|
2014-04-22 10:59:50 +08:00
|
|
|
# @softapplication = Softapplication.find(params[:id])
|
2014-04-04 17:54:20 +08:00
|
|
|
@softapplication.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
2014-04-22 19:27:31 +08:00
|
|
|
format.html { redirect_to home_path }
|
2014-04-04 17:54:20 +08:00
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
2014-04-21 19:36:05 +08:00
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
#应用评价涉及到的方法
|
|
|
|
def new_message
|
|
|
|
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
|
|
|
if @jour
|
2014-04-21 19:36:05 +08:00
|
|
|
user = @jour.user
|
|
|
|
text = @jour.notes
|
2014-04-10 08:33:30 +08:00
|
|
|
else
|
2014-04-21 19:36:05 +08:00
|
|
|
user = @softapplication.user
|
|
|
|
text = @softapplication.description
|
2014-04-10 08:33:30 +08:00
|
|
|
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
|
2014-04-21 19:36:05 +08:00
|
|
|
end
|
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
#新建评价
|
2014-04-21 19:36:05 +08:00
|
|
|
def create_message
|
2014-04-10 08:33:30 +08:00
|
|
|
|
2014-04-21 19:36:05 +08:00
|
|
|
if params[:reference_content]
|
2014-04-10 08:33:30 +08:00
|
|
|
message = params[:softapplication_message][:message] + "\n" + params[:reference_content]
|
2014-04-21 19:36:05 +08:00
|
|
|
else
|
2014-04-10 08:33:30 +08:00
|
|
|
message = params[:softapplication_message][:message]
|
|
|
|
end
|
2014-04-21 19:36:05 +08:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
@user = @softapplication.user
|
|
|
|
@jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
2014-04-21 19:36:05 +08:00
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
@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
|
2014-04-21 19:36:05 +08:00
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
#
|
|
|
|
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
|
2014-04-21 19:36:05 +08:00
|
|
|
|
2014-04-10 08:33:30 +08:00
|
|
|
#
|
|
|
|
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
|
2014-04-22 10:59:50 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
def find_softapplication
|
|
|
|
@softapplication = Softapplication.find_by_id(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def editable
|
|
|
|
unless @softapplication.editable_by? User.current
|
|
|
|
render_403
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroyable
|
|
|
|
unless @softapplication.destroyable_by? User.current
|
|
|
|
render_403
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-04 17:54:20 +08:00
|
|
|
end
|