You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

softapplications_controller.rb 10 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. class SoftapplicationsController < ApplicationController
  2. before_filter :find_softapplication, only: [:edit, :update, :destroy]
  3. before_filter :editable, only: [:edit, :update]
  4. before_filter :destroyable, only: :destroy
  5. # GET /softapplications
  6. # GET /softapplications.json
  7. def index
  8. @softapplications = Softapplication.all
  9. #new added fenyefunction
  10. @limit = 5
  11. @softapplication_count = @softapplications.count
  12. @softapplication_pages = Paginator.new @softapplication_count, @limit, params['page']
  13. @offset ||= @softapplication_pages.offset
  14. #@softapplications = @softapplications[@offset,@limit]
  15. #new added end
  16. #new added sort
  17. if params[:softapplication_sort_type].present?
  18. case params[:softapplication_sort_type]
  19. when '0'
  20. @softapplications = @softapplications[@offset, @limit]
  21. @s_state = 0
  22. when '1'
  23. @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
  24. @s_state = 1
  25. end
  26. else
  27. @softapplications = @softapplications.sort { |x, y| y[:created_at] <=> x[:created_at]}[@offset, @limit]
  28. @s_state = 1
  29. end
  30. #new added end
  31. respond_to do |format|
  32. format.html # index.html.erb
  33. format.json { render json: @softapplications }
  34. end
  35. end
  36. # GET /softapplications/1
  37. # GET /softapplications/1.json
  38. def percent_of(num, percent)
  39. num.to_f / percent.to_f * 100.0
  40. end
  41. def show
  42. @softapplication = Softapplication.find(params[:id])
  43. @project = @softapplication.project
  44. # 打分统计
  45. stars_reates = @softapplication.
  46. rates(:quality)
  47. stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
  48. stars_status = stars_reates.select("stars, count(*) as scount").
  49. group("stars")
  50. @stars_status_map = Hash.new(0.0)
  51. stars_status.each do |star_status|
  52. percent = percent_of(star_status.scount, stars_reates_count).to_f
  53. percent_m = format("%.2f", percent)
  54. @stars_status_map["star#{star_status.stars.to_i}".to_sym] =
  55. percent_m.to_s + "%"
  56. end
  57. @jours = @softapplication.journals_for_messages.order('created_on DESC')
  58. @image_results = []
  59. @softapplication.attachments.each do |f|
  60. f.image? ? @image_results << f : @image_results
  61. end
  62. @app_items = []
  63. @softapplication.attachments.each do |f|
  64. f.pack? ? @app_items << f : @app_items
  65. end
  66. @limit = 10
  67. @feedback_count = @jours.count
  68. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  69. @offset ||= @feedback_pages.offset
  70. @jour = @jours[@offset, @limit]
  71. @state = false
  72. respond_to do |format|
  73. format.html # show.html.erb
  74. format.json { render json: @softapplication }
  75. end
  76. end
  77. # GET /softapplications/new
  78. # GET /softapplications/new.json
  79. def new
  80. @softapplication = Softapplication.new
  81. #添加当前用户创建过的项目作为托管项目(下拉项目列表)
  82. project = Project.find(params[:user_id])
  83. #end
  84. respond_to do |format|
  85. format.html # new.html.erb
  86. format.json { render json: @softapplication }
  87. end
  88. end
  89. # GET /softapplications/1/edit
  90. def edit
  91. @softapplication = Softapplication.find(params[:id])
  92. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  93. @option = []
  94. # @contesting_project_count = @contesting_project_all.count
  95. # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
  96. @membership.each do |membership|
  97. unless(membership.project.project_type==1)
  98. #membership.member_roles.each{|role|
  99. # if(role.role_id == 3)
  100. # @option << membership.project
  101. # end
  102. #}
  103. #拥有编辑项目权限的可操作该项目
  104. if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false)
  105. @option << membership.project
  106. end
  107. end
  108. end
  109. end
  110. # POST /softapplications
  111. # POST /softapplications.json
  112. # def create
  113. # @softapplication = Softapplication.new(params[:softapplication])
  114. # @softapplication.user = User.current
  115. # @softapplication.save_attachments(params[:attachments])
  116. # respond_to do |format|
  117. # if @softapplication.save
  118. # format.js
  119. # format.html { redirect_to @softapplication, notice: 'Softapplication was successfully created.' }
  120. # # format.json { render json: @softapplication, status: :created, location: @softapplication }
  121. # else
  122. # format.js { render status: 406 }
  123. # format.html { render action: "new" }
  124. # # format.json { render json: @softapplication.errors, status: :unprocessable_entity }
  125. # end
  126. # end
  127. # end
  128. #new changed created function
  129. def create
  130. @softapplication = Softapplication.new(params[:softapplication])
  131. @softapplication.user = User.current
  132. #@softapplication.deposit_project = params[:project]
  133. @softapplication.project = Project.find_by_id(params[:project])
  134. @softapplication.save_attachments(params[:attachments])
  135. respond_to do |format|
  136. if @softapplication.save
  137. ContestingSoftapplication.create(:contest_id => params[:contest_id], :softapplication_id => @softapplication.id)
  138. #ProjectingSoftapplication.create_softapplication_projecting(:project_id => params[:project_id], :softapplication_id => @softapplication.id)
  139. #ProjectingSoftapplication.create_softapplication_projecting(@project.id, softapplication.id)
  140. format.html { redirect_to show_attendingcontest_contest_path(:id => params[:contest_id]), notice: l(:notice_attendingcontest_work_successfully_created) }
  141. # format.json { render json: @softapplication, status: :created, location: @softapplication }
  142. else
  143. format.js { render status: 406 }
  144. format.html { render action: "new" }
  145. # format.json { render json: @softapplication.errors, status: :unprocessable_entity }
  146. end
  147. end
  148. #关联新建的参赛作品
  149. # @contesting_softapplication = paginateHelper @contest.contesting_softapplications
  150. end
  151. # PUT /softapplications/1
  152. # PUT /softapplications/1.json
  153. def update
  154. # @softapplication = Softapplication.find(params[:id])
  155. @softapplication.attachments.map{|attach| attach.destroy }
  156. @softapplication.save_attachments(params[:attachments])
  157. #@softapplication.deposit_project = params[:project]
  158. @softapplication.project = Project.find_by_id(params[:project])
  159. respond_to do |format|
  160. if @softapplication.update_attributes(params[:softapplication])
  161. format.html { redirect_to @softapplication, notice: l(:notice_softapplication_was_successfully_updated) }
  162. format.json { head :no_content }
  163. else
  164. format.html { render action: "edit" }
  165. format.json { render json: @softapplication.errors, status: :unprocessable_entity }
  166. end
  167. end
  168. end
  169. def add_attach
  170. @softapplication = Softapplication.find(params[:id])
  171. @softapplication.save_attachments(params[:attachments])
  172. end
  173. # DELETE /softapplications/1
  174. # DELETE /softapplications/1.json
  175. def destroy
  176. # @softapplication = Softapplication.find(params[:id])
  177. @softapplication.destroy
  178. respond_to do |format|
  179. format.html { redirect_to home_path }
  180. format.json { head :no_content }
  181. end
  182. end
  183. #应用评价涉及到的方法
  184. def new_message
  185. @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
  186. if @jour
  187. user = @jour.user
  188. text = @jour.notes
  189. else
  190. user = @softapplication.user
  191. text = @softapplication.description
  192. end
  193. text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
  194. @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
  195. @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  196. @id = user.id
  197. rescue ActiveRecord::RecordNotFound
  198. render_404
  199. end
  200. #新建评价
  201. def create_message
  202. if params[:reference_content]
  203. message = params[:softapplication_message][:message] + "\n" + params[:reference_content]
  204. else
  205. message = params[:softapplication_message][:message]
  206. end
  207. refer_user_id = params[:softapplication_message][:reference_user_id].to_i
  208. @softapplication = Softapplication.find(params[:id])
  209. @softapplication.add_jour(User.current, message, refer_user_id)
  210. @user = @softapplication.user
  211. @jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  212. @limit = 10
  213. @feedback_count = @jours.count
  214. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  215. @offset ||= @feedback_pages.offset
  216. @jour = @jours[@offset, @limit]
  217. #@softapplication.set_commit(@feedback_count)
  218. respond_to do |format|
  219. format.js
  220. end
  221. end
  222. ##删除评价
  223. def destroy_message
  224. @user = @softapplication.user
  225. if User.current.admin? || User.current.id == @user.id
  226. JournalsForMessage.delete_message(params[:object_id])
  227. end
  228. @jours = @softapplication.journals_for_messages.reverse
  229. @limit = 10
  230. @feedback_count = @jours.count
  231. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  232. @offset ||= @feedback_pages.offset
  233. @jour = @jours[@offset, @limit]
  234. @softapplication.set_commit(@feedback_count)
  235. respond_to do |format|
  236. format.js
  237. end
  238. end
  239. #
  240. def more
  241. @jour = @softapplication.journals_for_messages
  242. @jour.each_with_index {|j,i| j.indice = i+1}
  243. @state = true
  244. respond_to do |format|
  245. format.html { redirect_to :back }
  246. format.js
  247. #format.api { render_api_ok }
  248. end
  249. end
  250. #
  251. def back
  252. @jour = @softapplication.journals_for_messages
  253. @jour.each_with_index {|j,i| j.indice = i+1}
  254. @state = false
  255. respond_to do |format|
  256. format.html { redirect_to :back }
  257. format.js
  258. #format.api { render_api_ok }
  259. end
  260. end
  261. private
  262. def find_softapplication
  263. @softapplication = Softapplication.find_by_id(params[:id])
  264. end
  265. def editable
  266. unless @softapplication.editable_by? User.current
  267. render_403
  268. return false
  269. end
  270. end
  271. def destroyable
  272. unless @softapplication.destroyable_by? User.current
  273. render_403
  274. return false
  275. end
  276. end
  277. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...