##// END OF EJS Templates
remove trailing white-spaces from app/controllers/versions_controller.rb....
Toshi MARUYAMA -
r6571:ffcbbca81c0b
parent child
Show More
@@ -1,192 +1,192
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 #
8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 #
13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class VersionsController < ApplicationController
19 19 menu_item :roadmap
20 20 model_object Version
21 21 before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
22 22 before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
23 23 before_filter :find_project, :only => [:index, :new, :create, :close_completed]
24 24 before_filter :authorize
25 25
26 26 accept_api_auth :index, :create, :update, :destroy
27
27
28 28 helper :custom_fields
29 29 helper :projects
30 30
31 31 def index
32 32 respond_to do |format|
33 33 format.html {
34 34 @trackers = @project.trackers.find(:all, :order => 'position')
35 35 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
36 36 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
37 37 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
38
38
39 39 @versions = @project.shared_versions || []
40 40 @versions += @project.rolled_up_versions.visible if @with_subprojects
41 41 @versions = @versions.uniq.sort
42 42 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
43
43
44 44 @issues_by_version = {}
45 45 unless @selected_tracker_ids.empty?
46 46 @versions.each do |version|
47 47 issues = version.fixed_issues.visible.find(:all,
48 48 :include => [:project, :status, :tracker, :priority],
49 49 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
50 50 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
51 51 @issues_by_version[version] = issues
52 52 end
53 53 end
54 54 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
55 55 }
56 56 format.api {
57 57 @versions = @project.shared_versions.all
58 58 }
59 59 end
60 60 end
61
61
62 62 def show
63 63 respond_to do |format|
64 64 format.html {
65 65 @issues = @version.fixed_issues.visible.find(:all,
66 66 :include => [:status, :tracker, :priority],
67 67 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
68 68 }
69 69 format.api
70 70 end
71 71 end
72
72
73 73 def new
74 74 @version = @project.versions.build
75 75 if params[:version]
76 76 attributes = params[:version].dup
77 77 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
78 78 @version.attributes = attributes
79 79 end
80 80 end
81 81
82 82 def create
83 83 # TODO: refactor with code above in #new
84 84 @version = @project.versions.build
85 85 if params[:version]
86 86 attributes = params[:version].dup
87 87 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
88 88 @version.attributes = attributes
89 89 end
90 90
91 91 if request.post?
92 92 if @version.save
93 93 respond_to do |format|
94 94 format.html do
95 95 flash[:notice] = l(:notice_successful_create)
96 96 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
97 97 end
98 98 format.js do
99 99 # IE doesn't support the replace_html rjs method for select box options
100 100 render(:update) {|page| page.replace "issue_fixed_version_id",
101 101 content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
102 102 }
103 103 end
104 104 format.api do
105 105 render :action => 'show', :status => :created, :location => version_url(@version)
106 106 end
107 107 end
108 108 else
109 109 respond_to do |format|
110 110 format.html { render :action => 'new' }
111 111 format.js do
112 112 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
113 113 end
114 114 format.api { render_validation_errors(@version) }
115 115 end
116 116 end
117 117 end
118 118 end
119 119
120 120 def edit
121 121 end
122
122
123 123 def update
124 124 if request.put? && params[:version]
125 125 attributes = params[:version].dup
126 126 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
127 127 if @version.update_attributes(attributes)
128 128 respond_to do |format|
129 129 format.html {
130 130 flash[:notice] = l(:notice_successful_update)
131 131 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
132 132 }
133 133 format.api { head :ok }
134 134 end
135 135 else
136 136 respond_to do |format|
137 137 format.html { render :action => 'edit' }
138 138 format.api { render_validation_errors(@version) }
139 139 end
140 140 end
141 141 end
142 142 end
143
143
144 144 def close_completed
145 145 if request.put?
146 146 @project.close_completed_versions
147 147 end
148 148 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
149 149 end
150 150
151 151 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
152 152 def destroy
153 153 if @version.fixed_issues.empty?
154 154 @version.destroy
155 155 respond_to do |format|
156 156 format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
157 157 format.api { head :ok }
158 158 end
159 159 else
160 160 respond_to do |format|
161 161 format.html {
162 162 flash[:error] = l(:notice_unable_delete_version)
163 163 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
164 164 }
165 165 format.api { head :unprocessable_entity }
166 166 end
167 167 end
168 168 end
169
169
170 170 def status_by
171 171 respond_to do |format|
172 172 format.html { render :action => 'show' }
173 173 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
174 174 end
175 175 end
176 176
177 177 private
178 178 def find_project
179 179 @project = Project.find(params[:project_id])
180 180 rescue ActiveRecord::RecordNotFound
181 181 render_404
182 182 end
183 183
184 184 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
185 185 if ids = params[:tracker_ids]
186 186 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
187 187 else
188 188 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
189 189 end
190 190 end
191 191
192 192 end
General Comments 0
You need to be logged in to leave comments. Login now