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.

open_source_projects_controller.rb 8.8 kB

12 years ago
​
​
​
​
​
12 years ago
​
​
​
​
12 years ago
​
12 years ago
​
​
​
12 years ago
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. class OpenSourceProjectsController < ApplicationController
  2. before_filter :find_osp, :only => [:master_apply, :accept_master_apply, :refuse_master_apply]
  3. before_filter :require_master, :only => [:master_apply, :accept_master_apply, :refuse_master_apply]
  4. helper :sort
  5. include SortHelper
  6. helper :apply_project_masters
  7. include ApplyProjectMastersHelper
  8. helper :no_uses
  9. include NoUsesHelper
  10. # GET /open_source_projects
  11. # GET /open_source_projects.json
  12. def index
  13. @app_dir = params[:app_dir]
  14. @language = params[:language]
  15. @created_at = params[:created_at]
  16. per_page_option = 10
  17. @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at)
  18. @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present?
  19. @os_project_count = @open_source_projects.count
  20. @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page']
  21. @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page)
  22. @bugs = BugToOsp.order('created_at desc').limit(8)
  23. # @open_source_projects = OpenSourceProject.all
  24. respond_to do |format|
  25. format.html # index.html.erb
  26. format.json { render json: @open_source_projects }
  27. end
  28. end
  29. def master_apply
  30. @apply = @open_source_project.apply_tips
  31. @applicants = @open_source_project.applicants
  32. respond_to do |format|
  33. format.html {
  34. render :layout => "base_opensource_p"
  35. }
  36. format.json { render json: @open_source_project }
  37. end
  38. end
  39. # GET /open_source_projects/1
  40. # GET /open_source_projects/1.json
  41. def show
  42. @open_source_project = OpenSourceProject.find(params[:id])
  43. sort_init 'updated_at', 'desc'
  44. sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at",
  45. 'replies' => "#{RelativeMemo.table_name}.replies_count",
  46. 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
  47. @memo = RelativeMemo.new(:open_source_project => @open_source_project)
  48. @topic_count = @open_source_project.topics.count
  49. @topic_pages = Paginator.new @topic_count, 10, params['page']
  50. @memos = @open_source_project.topics.
  51. reorder("#{RelativeMemo.table_name}.sticky DESC").
  52. includes(:last_reply).
  53. limit(@topic_pages.per_page).
  54. offset(@topic_pages.offset).
  55. order(sort_clause).
  56. all
  57. @bugs = @open_source_project.bugs.limit(6)
  58. respond_to do |format|
  59. format.html {
  60. render :layout => "base_opensource_p"
  61. }
  62. format.json { render json: @open_source_project }
  63. end
  64. end
  65. def allbug
  66. @bugs = BugToOsp.visible
  67. @bug_count = @bugs.count
  68. @bug_pages = Paginator.new @bug_count, per_page_option, params['page']
  69. @bugs = @bugs.includes(:bug).reorder("#{RelativeMemo.table_name}.created_at DESC").limit(@bug_pages.per_page).offset(@bug_pages.offset).all
  70. respond_to do |format|
  71. format.html
  72. format.json { render json: @open_source_project }
  73. end
  74. end
  75. def search
  76. end
  77. def showbug
  78. @open_source_project = OpenSourceProject.find(params[:id])
  79. sort_init 'updated_at', 'desc'
  80. sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at",
  81. 'replies' => "#{RelativeMemo.table_name}.replies_count",
  82. 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
  83. @memo = RelativeMemo.new(:open_source_project => @open_source_project)
  84. @topic_count = @open_source_project.bugs.count
  85. @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
  86. @memos = @open_source_project.bugs.
  87. reorder("#{RelativeMemo.table_name}.sticky DESC").
  88. includes(:last_reply).
  89. limit(@topic_pages.per_page).
  90. offset(@topic_pages.offset).
  91. order(sort_clause).
  92. all
  93. respond_to do |format|
  94. format.html {
  95. render :layout => "base_opensource_p"
  96. }
  97. format.json { render json: @open_source_project }
  98. end
  99. end
  100. # added by yiang 暴力添加,请绕道
  101. def showmemo
  102. @open_source_project = OpenSourceProject.find(params[:id])
  103. sort_init 'updated_at', 'desc'
  104. sort_update 'created_at' => "#{RelativeMemo.table_name}.created_at",
  105. 'replies' => "#{RelativeMemo.table_name}.replies_count",
  106. 'updated_at' => "COALESCE (last_replies_relative_memos.created_at, #{RelativeMemo.table_name}.created_at)"
  107. @memo = RelativeMemo.new(:open_source_project => @open_source_project)
  108. @topic_count = @open_source_project.topics.count
  109. @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
  110. @memos = @open_source_project.topics.
  111. reorder("#{RelativeMemo.table_name}.sticky DESC").
  112. includes(:last_reply).
  113. limit(@topic_pages.per_page).
  114. offset(@topic_pages.offset).
  115. order(sort_clause).
  116. all
  117. respond_to do |format|
  118. format.html {
  119. render :layout => "base_opensource_p"
  120. }
  121. format.json { render json: @open_source_project }
  122. end
  123. end
  124. # GET /open_source_projects/new
  125. # GET /open_source_projects/new.json
  126. def new
  127. @open_source_project = OpenSourceProject.new
  128. respond_to do |format|
  129. format.html # new.html.erb
  130. format.json { render json: @open_source_project }
  131. end
  132. end
  133. # GET /open_source_projects/1/edit
  134. def edit
  135. @open_source_project = OpenSourceProject.find(params[:id])
  136. end
  137. # POST /open_source_projects
  138. # POST /open_source_projects.json
  139. def create
  140. @open_source_project = OpenSourceProject.new(params[:open_source_project])
  141. respond_to do |format|
  142. if @open_source_project.save
  143. format.html { redirect_to @open_source_project, notice: 'Open source project was successfully created.' }
  144. format.json { render json: @open_source_project, status: :created, location: @open_source_project }
  145. else
  146. format.html { render action: "new" }
  147. format.json { render json: @open_source_project.errors, status: :unprocessable_entity }
  148. end
  149. end
  150. end
  151. # PUT /open_source_projects/1
  152. # PUT /open_source_projects/1.json
  153. def update
  154. @open_source_project = OpenSourceProject.find(params[:id])
  155. respond_to do |format|
  156. if @open_source_project.update_attributes(params[:open_source_project])
  157. format.html { redirect_to @open_source_project, notice: 'Open source project was successfully updated.' }
  158. format.json { head :no_content }
  159. else
  160. format.html { render action: "edit" }
  161. format.json { render json: @open_source_project.errors, status: :unprocessable_entity }
  162. end
  163. end
  164. end
  165. # DELETE /open_source_projects/1
  166. # DELETE /open_source_projects/1.json
  167. def destroy
  168. @open_source_project = OpenSourceProject.find(params[:id])
  169. @open_source_project.destroy
  170. respond_to do |format|
  171. format.html { redirect_to open_source_projects_url }
  172. format.json { head :no_content }
  173. end
  174. end
  175. def remove_condition
  176. @app_dir = params[:app_dir]
  177. @language = params[:language]
  178. @created_at = params[:created_at]
  179. redirect_to open_source_projects_path(:app_dir => @app_dir, :language => @language, :created_at => @created_at, :name => params[:name])
  180. end
  181. def search
  182. # per_page_option = 10
  183. #
  184. # @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at)
  185. # @open_source_projects = @open_source_projects.like(params[:name]) if params[:name].present?
  186. #
  187. # @os_project_count = @open_source_projects.count
  188. # @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page']
  189. #
  190. # @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page)
  191. redirect_to open_source_projects_path(:name => params[:name])
  192. end
  193. def refuse_master_apply
  194. @apply = ApplyProjectMaster.where("user_id = ? and apply_id = ? and apply_type = 'OpenSourceProject'", params[:user_id], @open_source_project.id)
  195. @apply.first.destory
  196. redirect_to master_apply_open_source_project_path
  197. end
  198. def accept_master_apply
  199. @apply = ApplyProjectMaster.where("user_id = ? and apply_id = ? and apply_type = 'OpenSourceProject'", params[:user_id], @open_source_project.id)
  200. if @apply.count == 1
  201. @apply.first.update_attributes(:status => 2)
  202. end
  203. redirect_to master_apply_open_source_project_path
  204. end
  205. private
  206. def require_master
  207. render_403 unless @open_source_project.admin?(User.current)
  208. end
  209. def find_osp
  210. @open_source_project = OpenSourceProject.find(params[:id])
  211. render_404 unless @open_source_project.present?
  212. end
  213. end

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