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.

versions_controller.rb 13 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
10 years ago
​
​
10 years ago
10 years ago
10 years ago
10 years ago
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class VersionsController < ApplicationController
  18. layout "base_projects"
  19. menu_item :roadmap
  20. model_object Version
  21. before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
  22. #before_filter :find_model_object_contest, :except => [:index, :new, :create]
  23. before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
  24. before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed]
  25. before_filter :authorize
  26. accept_api_auth :index, :show, :create, :update, :destroy
  27. helper :custom_fields
  28. helper :projects
  29. helper :project_score
  30. def index
  31. # 顶部导航
  32. @project_menu_type = 7
  33. type = params[:type]
  34. case type
  35. when nil,"1"
  36. @versions = @project.versions.reorder('updated_on desc')
  37. when "2"
  38. @versions = @project.versions.where(:status => 'open').reorder('updated_on desc')
  39. when "3"
  40. @versions = @project.versions.where(:status => 'locked').reorder('updated_on desc')
  41. when "4"
  42. @versions = @project.versions.where(:status => 'closed').reorder('updated_on desc')
  43. end
  44. @versions_count = Version.where(:project_id => @project.id).count
  45. @versions_open_count = Version.where(:project_id => @project.id, :status => "open").count
  46. @versions_locked_count = Version.where(:project_id => @project.id, :status => "locked").count
  47. @versions_closed_count = Version.where(:project_id => @project.id, :status => "closed").count
  48. @versions_count = version_type_count(type, @versions_count, @versions_open_count, @versions_locked_count, @versions_closed_count)
  49. @limit = 10
  50. @is_remote = true
  51. @version_pages = Paginator.new @versions_count, @limit, params['page'] || 1
  52. @offset ||= @version_pages.offset
  53. @versions = paginateHelper @versions, @limit
  54. respond_to do |format|
  55. format.html
  56. format.js
  57. format.api
  58. # format.html {
  59. # @trackers = @project.trackers.sorted.all
  60. # retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
  61. # @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
  62. # project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
  63. #
  64. # @versions = @project.shared_versions || []
  65. # @versions += @project.rolled_up_versions.visible if @with_subprojects
  66. # #added by young
  67. # @versions = @versions.uniq.reverse#Modified by young
  68. # unless params[:completed]
  69. # @completed_versions = @versions.select {|version| version.closed? || version.completed? }
  70. # @versions -= @completed_versions
  71. # end
  72. # @offset, @limit = api_offset_and_limit({:limit => 4})
  73. # @versions_count = @versions.count
  74. # @versions_pages = Paginator.new @versions_count, @limit, params['page']
  75. # @offset ||= @versions_pages.offset
  76. # @versions = @versions.slice(@offset, @limit)
  77. # #end by young
  78. #
  79. # @issues_by_version = {}
  80. # if @selected_tracker_ids.any? && @versions.any?
  81. # issues = Issue.visible.all(
  82. # :include => [:project, :status, :tracker, :priority, :fixed_version],
  83. # :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
  84. # :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
  85. # )
  86. # @issues_by_version = issues.group_by(&:fixed_version)
  87. # end
  88. # @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
  89. # }
  90. # format.api {
  91. # @versions = @project.shared_versions.all
  92. # }
  93. end
  94. end
  95. # 统计各种类型数量
  96. def version_type_count type, all_count, opened_count, locked_count, closed_count
  97. case type
  98. when nil, "1"
  99. all_count
  100. when "2"
  101. opened_count
  102. when "3"
  103. locked_count
  104. when "4"
  105. closed_count
  106. end
  107. end
  108. def show
  109. # 顶部导航
  110. @project_menu_type = 7
  111. respond_to do |format|
  112. @version_issues = @version.fixed_issues.visible.
  113. includes(:status, :tracker, :priority).
  114. reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
  115. all
  116. @issue_count = @version_issues.count
  117. @limit = 20
  118. @issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
  119. # @offset ||= @issue_pages.offset
  120. @issues = paginateHelper @version_issues, @limit
  121. @version_issue_assigned_name = @version_issues.sort_by{ |i| Issue.where(:project_id => @project.id ,
  122. :assigned_to_id => i.assigned_to_id, :fixed_version_id => @version.id).count }.reverse.group_by(&:assigned_to_id)
  123. format.html {
  124. # @issues = @version.fixed_issues.visible.
  125. # includes(:status, :tracker, :priority).
  126. # reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
  127. # all
  128. }
  129. format.api
  130. format.xls {
  131. @issues = @version.fixed_issues.visible.includes(:status, :tracker, :priority).reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").all
  132. filename = "#{@version.name.to_s}_#{l(:label_issue_list_xls)}.xls"
  133. send_data(issue_list_xls(@issues), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
  134. }
  135. end
  136. end
  137. def new
  138. # @version = @project.versions.build
  139. # @version.safe_attributes = params[:version]
  140. #
  141. respond_to do |format|
  142. @is_setting = params[:is_setting]
  143. @is_create = params[:is_create]
  144. @is_issue = params[:is_issue]
  145. @issue_project_id = params[:issue_project_id]
  146. #@@issue = Issue.find(params[:issue].to_i)
  147. format.js
  148. end
  149. end
  150. def create
  151. # 项目配置中新建
  152. @is_setting = params[:is_setting]
  153. @is_issue = params[:is_issue]
  154. @is_create = params[:is_create]
  155. @issue_project_id = params[:issue_project_id]
  156. # @issue = current_issue
  157. @version = @project.versions.build
  158. if params[:version]
  159. attributes = params[:version].dup
  160. attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
  161. @version.safe_attributes = attributes
  162. @version.user_id = User.current.id
  163. end
  164. if request.post?
  165. if @version.save
  166. respond_to do |format|
  167. format.html{
  168. if @is_create
  169. redirect_to project_versions_path(@project)
  170. elsif @is_issue
  171. redirect_to new_project_issue_path(@project)
  172. end
  173. }
  174. format.js
  175. format.api do
  176. render :action => 'show', :status => :created, :location => version_url(@version)
  177. end
  178. end
  179. else
  180. respond_to do |format|
  181. format.html { flash[:error] = @version.errors.full_messages.flatten.to_s
  182. redirect_to settings_project_url(@project, :tab => 'versions') }
  183. format.js { render :action => 'new' }
  184. format.api { render_validation_errors(@version) }
  185. end
  186. end
  187. end
  188. end
  189. def edit
  190. @is_setting = params[:is_setting]
  191. @is_create = params[:is_create]
  192. @is_index = params[:is_index]
  193. end
  194. def update
  195. @is_setting = params[:is_setting]
  196. @is_create = params[:is_create]
  197. @is_index = params[:is_index]
  198. @flag = params[:flag]
  199. if request.put? && params[:version]
  200. # 处理里程碑里面的更新
  201. if @flag.to_i == 1
  202. @version.update_attribute(:status, params[:status])
  203. if @version.save
  204. respond_to do |format|
  205. format.html {
  206. flash[:notice] = l(:notice_successful_update)
  207. redirect_to settings_project_path(@project, :tab => 'versions')
  208. }
  209. format.js
  210. format.api { render_api_ok }
  211. end
  212. else
  213. respond_to do |format|
  214. format.html { render :action => 'edit' }
  215. format.api { render_validation_errors(@version) }
  216. end
  217. end
  218. else
  219. attributes = params[:version].dup
  220. attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
  221. @version.safe_attributes = attributes
  222. @is_setting = params[:is_setting]
  223. if @version.save
  224. # 为了再setting里面局部刷新
  225. if @is_setting
  226. @versions = @version.project.shared_versions.sort
  227. end
  228. respond_to do |format|
  229. format.html {
  230. if @is_create
  231. redirect_to version_path(@version)
  232. elsif @is_index
  233. redirect_to project_versions_path(@project)
  234. end
  235. }
  236. format.js
  237. format.api { render_api_ok }
  238. end
  239. else
  240. respond_to do |format|
  241. format.html { render :action => 'edit' }
  242. format.js
  243. format.api { render_validation_errors(@version) }
  244. end
  245. end
  246. end
  247. end
  248. end
  249. def close_completed
  250. if request.put?
  251. @project.close_completed_versions
  252. end
  253. redirect_to settings_project_url(@project, :tab => 'versions')
  254. end
  255. def close_completed_contest
  256. if request.put?
  257. @contest.close_completed_versions
  258. end
  259. redirect_to settings_contest_url(@contest, :tab => 'versions')
  260. end
  261. def destroy
  262. begin
  263. project = @version.project
  264. issues = Issue.where(:fixed_version_id => @version.id)
  265. @version.destroy
  266. issues.update_all(:fixed_version_id, nil)
  267. rescue Exception => e
  268. puts e
  269. end
  270. respond_to do |format|
  271. format.js
  272. format.html { redirect_to project_versions_path(project)}
  273. format.api { render_api_ok }
  274. end
  275. end
  276. def status_by
  277. respond_to do |format|
  278. format.html { render :action => 'show' }
  279. format.js
  280. end
  281. end
  282. private
  283. def issue_list_xls issues
  284. xls_report = StringIO.new
  285. book = Spreadsheet::Workbook.new
  286. sheet1 = book.create_worksheet :name => "issues"
  287. blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
  288. sheet1.row(0).default_format = blue
  289. sheet1.row(0).concat([l(:issue_xls_id),l(:issue_xls_tracker_id),l(:issue_xls_title),l(:issue_xls_description),l(:issue_xls_status),l(:issue_xls_assign),l(:issue_xls_priority),l(:issue_xls_author),l(:issue_xls_created_at),l(:milestone),l(:issue_xls_start),l(:issue_xls_due),l(:issue_xls_ratio)])
  290. count_row = 1
  291. issues.each do |issue|
  292. sheet1[count_row,0] = issue.id
  293. sheet1[count_row,1] = issue_tracker_change(issue.tracker_id)
  294. sheet1[count_row,2] = issue.subject
  295. sheet1[count_row,3] = (issue.description.gsub(/<\/?.*?>/,"")).html_safe
  296. sheet1[count_row,4] = issue_status_change(issue.status_id)
  297. sheet1[count_row,5] = issue.assigned_to.try(:show_name)
  298. sheet1[count_row,6] = issue_priority_change(issue.priority_id)
  299. sheet1[count_row,7] = issue.author.show_name
  300. sheet1[count_row,8] = issue.created_on.nil? ? issue.created_on : issue.created_on.strftime('%Y-%m-%d %H:%M:%S')
  301. sheet1[count_row,9] = issue.fixed_version.try(:name)
  302. sheet1[count_row,10] = issue.start_date.nil? ? issue.start_date : issue.start_date.strftime('%Y-%m-%d')
  303. sheet1[count_row,11] = issue.due_date.nil? ? issue.due_date : issue.due_date.strftime('%Y-%m-%d')
  304. sheet1[count_row,12] = issue_ratio_change(issue.done_ratio, issue.status_id)
  305. count_row += 1
  306. end
  307. book.write xls_report
  308. xls_report.string
  309. end
  310. def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
  311. if ids = params[:tracker_ids]
  312. @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
  313. else
  314. @selected_tracker_ids = (selectable_trackers).collect {|t| t.id.to_s }
  315. end
  316. end
  317. end

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