Mercurial > hg > soundsoftware-site
comparison app/controllers/projects_controller.rb @ 912:5e80956cc792 cannam_integration
Merge from branch "redmine-1.3"
author | Chris Cannam |
---|---|
date | Mon, 27 Feb 2012 13:53:18 +0000 |
parents | 7614169e14ed cbb26bc654de |
children | 2a68662d5adf |
comparison
equal
deleted
inserted
replaced
911:487d96eac004 | 912:5e80956cc792 |
---|---|
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 ProjectsController < ApplicationController | 18 class ProjectsController < ApplicationController |
19 menu_item :overview | 19 menu_item :overview |
20 menu_item :roadmap, :only => :roadmap | 20 menu_item :roadmap, :only => :roadmap |
21 menu_item :settings, :only => :settings | 21 menu_item :settings, :only => :settings |
22 | 22 |
23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] | 23 before_filter :find_project, :except => [ :index, :list, :new, :create, :copy ] |
24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] | 24 before_filter :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy] |
25 before_filter :authorize_global, :only => [:new, :create] | 25 before_filter :authorize_global, :only => [:new, :create] |
26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] | 26 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
27 accept_rss_auth :index | 27 accept_rss_auth :index |
34 end | 34 end |
35 | 35 |
36 helper :sort | 36 helper :sort |
37 include SortHelper | 37 include SortHelper |
38 helper :custom_fields | 38 helper :custom_fields |
39 include CustomFieldsHelper | 39 include CustomFieldsHelper |
40 helper :issues | 40 helper :issues |
41 helper :queries | 41 helper :queries |
42 include QueriesHelper | 42 include QueriesHelper |
43 helper :repositories | 43 helper :repositories |
44 include RepositoriesHelper | 44 include RepositoriesHelper |
46 | 46 |
47 # Lists visible projects. Paginator is for top-level projects only | 47 # Lists visible projects. Paginator is for top-level projects only |
48 # (subprojects belong to them) | 48 # (subprojects belong to them) |
49 def index | 49 def index |
50 respond_to do |format| | 50 respond_to do |format| |
51 format.html { | 51 format.html { |
52 sort_init 'name' | 52 sort_init 'name' |
53 sort_update %w(name lft created_on updated_on) | 53 sort_update %w(name lft created_on updated_on) |
54 @limit = per_page_option | 54 @limit = per_page_option |
55 @project_count = Project.visible_roots.count | 55 @project_count = Project.visible_roots.count |
56 @project_pages = Paginator.new self, @project_count, @limit, params['page'] | 56 @project_pages = Paginator.new self, @project_count, @limit, params['page'] |
73 :limit => Setting.feeds_limit.to_i) | 73 :limit => Setting.feeds_limit.to_i) |
74 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") | 74 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
75 } | 75 } |
76 end | 76 end |
77 end | 77 end |
78 | 78 |
79 def new | 79 def new |
80 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 80 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
81 @trackers = Tracker.all | 81 @trackers = Tracker.all |
82 @project = Project.new(params[:project]) | 82 @project = Project.new(params[:project]) |
83 end | 83 end |
106 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first | 106 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
107 m = Member.new(:user => User.current, :roles => [r]) | 107 m = Member.new(:user => User.current, :roles => [r]) |
108 @project.members << m | 108 @project.members << m |
109 end | 109 end |
110 respond_to do |format| | 110 respond_to do |format| |
111 format.html { | 111 format.html { |
112 flash[:notice] = l(:notice_successful_create) | 112 flash[:notice] = l(:notice_successful_create) |
113 redirect_to :controller => 'projects', :action => 'settings', :id => @project | 113 redirect_to(params[:continue] ? |
114 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} : | |
115 {:controller => 'projects', :action => 'settings', :id => @project} | |
116 ) | |
114 } | 117 } |
115 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } | 118 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } |
116 end | 119 end |
117 else | 120 else |
118 respond_to do |format| | 121 respond_to do |format| |
119 format.html { render :action => 'new' } | 122 format.html { render :action => 'new' } |
120 format.api { render_validation_errors(@project) } | 123 format.api { render_validation_errors(@project) } |
121 end | 124 end |
122 end | 125 end |
123 | 126 |
124 end | 127 end |
125 | 128 |
126 def copy | 129 def copy |
127 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | 130 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
128 @trackers = Tracker.all | 131 @trackers = Tracker.all |
129 @root_projects = Project.find(:all, | 132 @root_projects = Project.find(:all, |
130 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | 133 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
134 @project = Project.copy_from(@source_project) | 137 @project = Project.copy_from(@source_project) |
135 if @project | 138 if @project |
136 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? | 139 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
137 else | 140 else |
138 redirect_to :controller => 'admin', :action => 'projects' | 141 redirect_to :controller => 'admin', :action => 'projects' |
139 end | 142 end |
140 else | 143 else |
141 Mailer.with_deliveries(params[:notifications] == '1') do | 144 Mailer.with_deliveries(params[:notifications] == '1') do |
142 @project = Project.new | 145 @project = Project.new |
143 @project.safe_attributes = params[:project] | 146 @project.safe_attributes = params[:project] |
144 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) | 147 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) |
162 def show | 165 def show |
163 if params[:jump] | 166 if params[:jump] |
164 # try to redirect to the requested menu item | 167 # try to redirect to the requested menu item |
165 redirect_to_project_menu_item(@project, params[:jump]) && return | 168 redirect_to_project_menu_item(@project, params[:jump]) && return |
166 end | 169 end |
167 | 170 |
168 @users_by_role = @project.users_by_role | 171 @users_by_role = @project.users_by_role |
169 @subprojects = @project.children.visible.all | 172 @subprojects = @project.children.visible.all |
170 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | 173 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
171 @trackers = @project.rolled_up_trackers | 174 @trackers = @project.rolled_up_trackers |
172 | 175 |
173 cond = @project.project_condition(Setting.display_subprojects_issues?) | 176 cond = @project.project_condition(Setting.display_subprojects_issues?) |
174 | 177 |
175 @open_issues_by_tracker = Issue.visible.count(:group => :tracker, | 178 @open_issues_by_tracker = Issue.visible.count(:group => :tracker, |
176 :include => [:project, :status, :tracker], | 179 :include => [:project, :status, :tracker], |
177 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) | 180 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
178 @total_issues_by_tracker = Issue.visible.count(:group => :tracker, | 181 @total_issues_by_tracker = Issue.visible.count(:group => :tracker, |
179 :include => [:project, :status, :tracker], | 182 :include => [:project, :status, :tracker], |
180 :conditions => cond) | 183 :conditions => cond) |
181 | 184 |
182 if User.current.allowed_to?(:view_time_entries, @project) | 185 if User.current.allowed_to?(:view_time_entries, @project) |
183 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f | 186 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f |
184 end | 187 end |
185 | 188 |
186 @key = User.current.rss_key | 189 @key = User.current.rss_key |
187 | 190 |
188 respond_to do |format| | 191 respond_to do |format| |
189 format.html | 192 format.html |
190 format.api | 193 format.api |
191 end | 194 end |
192 end | 195 end |
197 @member ||= @project.members.new | 200 @member ||= @project.members.new |
198 @trackers = Tracker.all | 201 @trackers = Tracker.all |
199 @repository ||= @project.repository | 202 @repository ||= @project.repository |
200 @wiki ||= @project.wiki | 203 @wiki ||= @project.wiki |
201 end | 204 end |
202 | 205 |
203 def edit | 206 def edit |
204 end | 207 end |
205 | 208 |
206 # TODO: convert to PUT only | 209 # TODO: convert to PUT only |
207 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } | 210 verify :method => [:post, :put], :only => :update, :render => {:nothing => true, :status => :method_not_allowed } |
208 def update | 211 def update |
209 @project.safe_attributes = params[:project] | 212 @project.safe_attributes = params[:project] |
210 if validate_parent_id && @project.save | 213 if validate_parent_id && @project.save |
211 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') | 214 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') |
212 respond_to do |format| | 215 respond_to do |format| |
213 format.html { | 216 format.html { |
214 flash[:notice] = l(:notice_successful_update) | 217 flash[:notice] = l(:notice_successful_update) |
215 redirect_to :action => 'settings', :id => @project | 218 redirect_to :action => 'settings', :id => @project |
216 } | 219 } |
217 format.api { head :ok } | 220 format.api { head :ok } |
218 end | 221 end |
219 else | 222 else |
220 respond_to do |format| | 223 respond_to do |format| |
221 format.html { | 224 format.html { |
222 settings | 225 settings |
223 render :action => 'settings' | 226 render :action => 'settings' |
224 } | 227 } |
225 format.api { render_validation_errors(@project) } | 228 format.api { render_validation_errors(@project) } |
226 end | 229 end |
249 flash[:error] = l(:error_can_not_archive_project) | 252 flash[:error] = l(:error_can_not_archive_project) |
250 end | 253 end |
251 end | 254 end |
252 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 255 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
253 end | 256 end |
254 | 257 |
255 def unarchive | 258 def unarchive |
256 @project.unarchive if request.post? && !@project.active? | 259 @project.unarchive if request.post? && !@project.active? |
257 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) | 260 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
258 end | 261 end |
259 | 262 |
260 # Delete @project | 263 # Delete @project |
261 def destroy | 264 def destroy |
262 @project_to_destroy = @project | 265 @project_to_destroy = @project |
263 if request.get? | 266 if request.get? |
264 # display confirmation view | 267 # display confirmation view |