@@ -1,182 +1,182 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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_by_project_id, :only => [:index, :new, :create, :close_completed] |
|
23 | before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed] | |
24 | before_filter :authorize |
|
24 | before_filter :authorize | |
25 |
|
25 | |||
26 | accept_api_auth :index, :show, :create, :update, :destroy |
|
26 | accept_api_auth :index, :show, :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.sorted.to_a |
|
34 | @trackers = @project.trackers.sorted.to_a | |
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.preload(:custom_values) | |
40 | @versions += @project.rolled_up_versions.visible if @with_subprojects |
|
40 | @versions += @project.rolled_up_versions.visible.preload(:custom_values) if @with_subprojects | |
41 | @versions = @versions.uniq.sort |
|
41 | @versions = @versions.uniq.sort | |
42 | unless params[:completed] |
|
42 | unless params[:completed] | |
43 | @completed_versions = @versions.select(&:completed?) |
|
43 | @completed_versions = @versions.select(&:completed?) | |
44 | @versions -= @completed_versions |
|
44 | @versions -= @completed_versions | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | @issues_by_version = {} |
|
47 | @issues_by_version = {} | |
48 | if @selected_tracker_ids.any? && @versions.any? |
|
48 | if @selected_tracker_ids.any? && @versions.any? | |
49 | issues = Issue.visible. |
|
49 | issues = Issue.visible. | |
50 | includes(:project, :tracker). |
|
50 | includes(:project, :tracker). | |
51 | preload(:status, :priority, :fixed_version). |
|
51 | preload(:status, :priority, :fixed_version). | |
52 | where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)). |
|
52 | where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)). | |
53 | order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") |
|
53 | order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") | |
54 | @issues_by_version = issues.group_by(&:fixed_version) |
|
54 | @issues_by_version = issues.group_by(&:fixed_version) | |
55 | end |
|
55 | end | |
56 | @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} |
|
56 | @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} | |
57 | } |
|
57 | } | |
58 | format.api { |
|
58 | format.api { | |
59 | @versions = @project.shared_versions.to_a |
|
59 | @versions = @project.shared_versions.to_a | |
60 | } |
|
60 | } | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def show |
|
64 | def show | |
65 | respond_to do |format| |
|
65 | respond_to do |format| | |
66 | format.html { |
|
66 | format.html { | |
67 | @issues = @version.fixed_issues.visible. |
|
67 | @issues = @version.fixed_issues.visible. | |
68 | includes(:status, :tracker, :priority). |
|
68 | includes(:status, :tracker, :priority). | |
69 | reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id"). |
|
69 | reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id"). | |
70 | to_a |
|
70 | to_a | |
71 | } |
|
71 | } | |
72 | format.api |
|
72 | format.api | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def new |
|
76 | def new | |
77 | @version = @project.versions.build |
|
77 | @version = @project.versions.build | |
78 | @version.safe_attributes = params[:version] |
|
78 | @version.safe_attributes = params[:version] | |
79 |
|
79 | |||
80 | respond_to do |format| |
|
80 | respond_to do |format| | |
81 | format.html |
|
81 | format.html | |
82 | format.js |
|
82 | format.js | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def create |
|
86 | def create | |
87 | @version = @project.versions.build |
|
87 | @version = @project.versions.build | |
88 | if params[:version] |
|
88 | if params[:version] | |
89 | attributes = params[:version].dup |
|
89 | attributes = params[:version].dup | |
90 | attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) |
|
90 | attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) | |
91 | @version.safe_attributes = attributes |
|
91 | @version.safe_attributes = attributes | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | if request.post? |
|
94 | if request.post? | |
95 | if @version.save |
|
95 | if @version.save | |
96 | respond_to do |format| |
|
96 | respond_to do |format| | |
97 | format.html do |
|
97 | format.html do | |
98 | flash[:notice] = l(:notice_successful_create) |
|
98 | flash[:notice] = l(:notice_successful_create) | |
99 | redirect_back_or_default settings_project_path(@project, :tab => 'versions') |
|
99 | redirect_back_or_default settings_project_path(@project, :tab => 'versions') | |
100 | end |
|
100 | end | |
101 | format.js |
|
101 | format.js | |
102 | format.api do |
|
102 | format.api do | |
103 | render :action => 'show', :status => :created, :location => version_url(@version) |
|
103 | render :action => 'show', :status => :created, :location => version_url(@version) | |
104 | end |
|
104 | end | |
105 | end |
|
105 | end | |
106 | else |
|
106 | else | |
107 | respond_to do |format| |
|
107 | respond_to do |format| | |
108 | format.html { render :action => 'new' } |
|
108 | format.html { render :action => 'new' } | |
109 | format.js { render :action => 'new' } |
|
109 | format.js { render :action => 'new' } | |
110 | format.api { render_validation_errors(@version) } |
|
110 | format.api { render_validation_errors(@version) } | |
111 | end |
|
111 | end | |
112 | end |
|
112 | end | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 |
|
115 | |||
116 | def edit |
|
116 | def edit | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def update |
|
119 | def update | |
120 | if params[:version] |
|
120 | if params[:version] | |
121 | attributes = params[:version].dup |
|
121 | attributes = params[:version].dup | |
122 | attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) |
|
122 | attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | |
123 | @version.safe_attributes = attributes |
|
123 | @version.safe_attributes = attributes | |
124 | if @version.save |
|
124 | if @version.save | |
125 | respond_to do |format| |
|
125 | respond_to do |format| | |
126 | format.html { |
|
126 | format.html { | |
127 | flash[:notice] = l(:notice_successful_update) |
|
127 | flash[:notice] = l(:notice_successful_update) | |
128 | redirect_back_or_default settings_project_path(@project, :tab => 'versions') |
|
128 | redirect_back_or_default settings_project_path(@project, :tab => 'versions') | |
129 | } |
|
129 | } | |
130 | format.api { render_api_ok } |
|
130 | format.api { render_api_ok } | |
131 | end |
|
131 | end | |
132 | else |
|
132 | else | |
133 | respond_to do |format| |
|
133 | respond_to do |format| | |
134 | format.html { render :action => 'edit' } |
|
134 | format.html { render :action => 'edit' } | |
135 | format.api { render_validation_errors(@version) } |
|
135 | format.api { render_validation_errors(@version) } | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def close_completed |
|
141 | def close_completed | |
142 | if request.put? |
|
142 | if request.put? | |
143 | @project.close_completed_versions |
|
143 | @project.close_completed_versions | |
144 | end |
|
144 | end | |
145 | redirect_to settings_project_path(@project, :tab => 'versions') |
|
145 | redirect_to settings_project_path(@project, :tab => 'versions') | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def destroy |
|
148 | def destroy | |
149 | if @version.deletable? |
|
149 | if @version.deletable? | |
150 | @version.destroy |
|
150 | @version.destroy | |
151 | respond_to do |format| |
|
151 | respond_to do |format| | |
152 | format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') } |
|
152 | format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') } | |
153 | format.api { render_api_ok } |
|
153 | format.api { render_api_ok } | |
154 | end |
|
154 | end | |
155 | else |
|
155 | else | |
156 | respond_to do |format| |
|
156 | respond_to do |format| | |
157 | format.html { |
|
157 | format.html { | |
158 | flash[:error] = l(:notice_unable_delete_version) |
|
158 | flash[:error] = l(:notice_unable_delete_version) | |
159 | redirect_to settings_project_path(@project, :tab => 'versions') |
|
159 | redirect_to settings_project_path(@project, :tab => 'versions') | |
160 | } |
|
160 | } | |
161 | format.api { head :unprocessable_entity } |
|
161 | format.api { head :unprocessable_entity } | |
162 | end |
|
162 | end | |
163 | end |
|
163 | end | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def status_by |
|
166 | def status_by | |
167 | respond_to do |format| |
|
167 | respond_to do |format| | |
168 | format.html { render :action => 'show' } |
|
168 | format.html { render :action => 'show' } | |
169 | format.js |
|
169 | format.js | |
170 | end |
|
170 | end | |
171 | end |
|
171 | end | |
172 |
|
172 | |||
173 | private |
|
173 | private | |
174 |
|
174 | |||
175 | def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil) |
|
175 | def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil) | |
176 | if ids = params[:tracker_ids] |
|
176 | if ids = params[:tracker_ids] | |
177 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
177 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
178 | else |
|
178 | else | |
179 | @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } |
|
179 | @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 | end |
|
182 | end |
General Comments 0
You need to be logged in to leave comments.
Login now