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 6.8 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. def index
  30. respond_to do |format|
  31. format.html {
  32. @trackers = @project.trackers.sorted.all
  33. retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
  34. @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
  35. project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
  36. @versions = @project.shared_versions || []
  37. @versions += @project.rolled_up_versions.visible if @with_subprojects
  38. #added by young
  39. @versions = @versions.uniq.reverse#Modified by young
  40. unless params[:completed]
  41. @completed_versions = @versions.select {|version| version.closed? || version.completed? }
  42. @versions -= @completed_versions
  43. end
  44. @offset, @limit = api_offset_and_limit({:limit => 4})
  45. @versions_count = @versions.count
  46. @versions_pages = Paginator.new @versions_count, @limit, params['page']
  47. @offset ||= @versions_pages.offset
  48. @versions = @versions.slice(@offset, @limit)
  49. #end by young
  50. @issues_by_version = {}
  51. if @selected_tracker_ids.any? && @versions.any?
  52. issues = Issue.visible.all(
  53. :include => [:project, :status, :tracker, :priority, :fixed_version],
  54. :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
  55. :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
  56. )
  57. @issues_by_version = issues.group_by(&:fixed_version)
  58. end
  59. @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
  60. }
  61. format.api {
  62. @versions = @project.shared_versions.all
  63. }
  64. end
  65. end
  66. def show
  67. respond_to do |format|
  68. format.html {
  69. @issues = @version.fixed_issues.visible.
  70. includes(:status, :tracker, :priority).
  71. reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
  72. all
  73. }
  74. format.api
  75. end
  76. end
  77. def new
  78. @version = @project.versions.build
  79. @version.safe_attributes = params[:version]
  80. respond_to do |format|
  81. format.html
  82. format.js
  83. end
  84. end
  85. def create
  86. @version = @project.versions.build
  87. if params[:version]
  88. attributes = params[:version].dup
  89. attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
  90. @version.safe_attributes = attributes
  91. end
  92. if request.post?
  93. if @version.save
  94. respond_to do |format|
  95. format.html do
  96. flash[:notice] = l(:notice_successful_create)
  97. redirect_back_or_default settings_project_path(@project, :tab => 'versions')
  98. end
  99. format.js
  100. format.api do
  101. render :action => 'show', :status => :created, :location => version_url(@version)
  102. end
  103. end
  104. else
  105. respond_to do |format|
  106. format.html { render :action => 'new' }
  107. format.js { render :action => 'new' }
  108. format.api { render_validation_errors(@version) }
  109. end
  110. end
  111. end
  112. end
  113. def edit
  114. end
  115. def update
  116. if request.put? && params[:version]
  117. attributes = params[:version].dup
  118. attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
  119. @version.safe_attributes = attributes
  120. if @version.save
  121. respond_to do |format|
  122. format.html {
  123. flash[:notice] = l(:notice_successful_update)
  124. redirect_back_or_default settings_project_path(@project, :tab => 'versions')
  125. }
  126. format.api { render_api_ok }
  127. end
  128. else
  129. respond_to do |format|
  130. format.html { render :action => 'edit' }
  131. format.api { render_validation_errors(@version) }
  132. end
  133. end
  134. end
  135. end
  136. def close_completed
  137. if request.put?
  138. @project.close_completed_versions
  139. end
  140. redirect_to settings_project_path(@project, :tab => 'versions')
  141. end
  142. def close_completed_contest
  143. if request.put?
  144. @contest.close_completed_versions
  145. end
  146. redirect_to settings_contest_path(@contest, :tab => 'versions')
  147. end
  148. def destroy
  149. if @version.fixed_issues.empty?
  150. @version.destroy
  151. respond_to do |format|
  152. format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
  153. format.api { render_api_ok }
  154. end
  155. else
  156. respond_to do |format|
  157. format.html {
  158. flash[:error] = l(:notice_unable_delete_version)
  159. redirect_to settings_project_path(@project, :tab => 'versions')
  160. }
  161. format.api { head :unprocessable_entity }
  162. end
  163. end
  164. end
  165. def status_by
  166. respond_to do |format|
  167. format.html { render :action => 'show' }
  168. format.js
  169. end
  170. end
  171. private
  172. def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
  173. if ids = params[:tracker_ids]
  174. @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
  175. else
  176. @selected_tracker_ids = (selectable_trackers).collect {|t| t.id.to_s }
  177. end
  178. end
  179. end

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