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