comparison app/controllers/projects_controller.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 1aee31f54e13 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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.
41 helper :queries 41 helper :queries
42 include QueriesHelper 42 include QueriesHelper
43 helper :repositories 43 helper :repositories
44 include RepositoriesHelper 44 include RepositoriesHelper
45 include ProjectsHelper 45 include ProjectsHelper
46 helper :members
46 include ActivitiesHelper 47 include ActivitiesHelper
47 helper :activities 48 helper :activities
48 49
49 # Lists visible projects. Paginator is for top-level projects only 50 # Lists visible projects. Paginator is for top-level projects only
50 # (subprojects belong to them) 51 # (subprojects belong to them)
68 # @projects = scope.visible.order('lft').all 69 # @projects = scope.visible.order('lft').all
69 } 70 }
70 format.api { 71 format.api {
71 @offset, @limit = api_offset_and_limit 72 @offset, @limit = api_offset_and_limit
72 @project_count = Project.visible.count 73 @project_count = Project.visible.count
73 @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => 'lft') 74 @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
74 } 75 }
75 format.atom { 76 format.atom {
76 projects = Project.visible.find(:all, :order => 'created_on DESC', 77 projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
77 :limit => Setting.feeds_limit.to_i)
78 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") 78 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
79 } 79 }
80 end 80 end
81 end 81 end
82 82
89 } 89 }
90 end 90 end
91 end 91 end
92 92
93 def new 93 def new
94 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") 94 @issue_custom_fields = IssueCustomField.sorted.all
95 @trackers = Tracker.sorted.all 95 @trackers = Tracker.sorted.all
96 @project = Project.new 96 @project = Project.new
97 @project.safe_attributes = params[:project] 97 @project.safe_attributes = params[:project]
98 end 98 end
99 99
100 def create 100 def create
101 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") 101 @issue_custom_fields = IssueCustomField.sorted.all
102 @trackers = Tracker.sorted.all 102 @trackers = Tracker.sorted.all
103 @project = Project.new 103 @project = Project.new
104 @project.safe_attributes = params[:project] 104 @project.safe_attributes = params[:project]
105 105
106 if validate_is_public_key && validate_parent_id && @project.save 106 if validate_is_public_key && validate_parent_id && @project.save
112 @project.members << m 112 @project.members << m
113 end 113 end
114 respond_to do |format| 114 respond_to do |format|
115 format.html { 115 format.html {
116 flash[:notice] = l(:notice_successful_create) 116 flash[:notice] = l(:notice_successful_create)
117 redirect_to(params[:continue] ? 117 if params[:continue]
118 {:controller => 'projects', :action => 'new', :project => {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}} : 118 attrs = {:parent_id => @project.parent_id}.reject {|k,v| v.nil?}
119 {:controller => 'projects', :action => 'settings', :id => @project} 119 redirect_to new_project_path(attrs)
120 ) 120 else
121 redirect_to settings_project_path(@project)
122 end
121 } 123 }
122 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } 124 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
123 end 125 end
124 else 126 else
125 respond_to do |format| 127 respond_to do |format|
126 format.html { render :action => 'new' } 128 format.html { render :action => 'new' }
127 format.api { render_validation_errors(@project) } 129 format.api { render_validation_errors(@project) }
128 end 130 end
129 end 131 end
130
131 end 132 end
132 133
133 def copy 134 def copy
134 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") 135 @issue_custom_fields = IssueCustomField.sorted.all
135 @trackers = Tracker.sorted.all 136 @trackers = Tracker.sorted.all
136 @root_projects = Project.find(:all,
137 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
138 :order => 'name')
139 @source_project = Project.find(params[:id]) 137 @source_project = Project.find(params[:id])
140 if request.get? 138 if request.get?
141 @project = Project.copy_from(@source_project) 139 @project = Project.copy_from(@source_project)
142 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? 140 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
143 else 141 else
145 @project = Project.new 143 @project = Project.new
146 @project.safe_attributes = params[:project] 144 @project.safe_attributes = params[:project]
147 if validate_parent_id && @project.copy(@source_project, :only => params[:only]) 145 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
148 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') 146 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
149 flash[:notice] = l(:notice_successful_create) 147 flash[:notice] = l(:notice_successful_create)
150 redirect_to :controller => 'projects', :action => 'settings', :id => @project 148 redirect_to settings_project_path(@project)
151 elsif !@project.new_record? 149 elsif !@project.new_record?
152 # Project was created 150 # Project was created
153 # But some objects were not copied due to validation failures 151 # But some objects were not copied due to validation failures
154 # (eg. issues from disabled trackers) 152 # (eg. issues from disabled trackers)
155 # TODO: inform about that 153 # TODO: inform about that
156 redirect_to :controller => 'projects', :action => 'settings', :id => @project 154 redirect_to settings_project_path(@project)
157 end 155 end
158 end 156 end
159 end 157 end
160 rescue ActiveRecord::RecordNotFound 158 rescue ActiveRecord::RecordNotFound
161 # source_project not found 159 # source_project not found
162 render_404 160 render_404
163 end 161 end
164 162
165 # Show @project 163 # Show @project
166 def show 164 def show
167 if params[:jump] 165 # try to redirect to the requested menu item
168 # try to redirect to the requested menu item 166 if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
169 redirect_to_project_menu_item(@project, params[:jump]) && return 167 return
170 end 168 end
171 169
172 @users_by_role = @project.users_by_role 170 @users_by_role = @project.users_by_role
173 @subprojects = @project.children.visible.all 171 @subprojects = @project.children.visible.all
174 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") 172 @news = @project.news.limit(5).includes(:author, :project).reorder("#{News.table_name}.created_on DESC").all
175 @trackers = @project.rolled_up_trackers 173 @trackers = @project.rolled_up_trackers
176 174
177 cond = @project.project_condition(Setting.display_subprojects_issues?) 175 cond = @project.project_condition(Setting.display_subprojects_issues?)
178 176
179 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) 177 @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker)
190 format.api 188 format.api
191 end 189 end
192 end 190 end
193 191
194 def settings 192 def settings
195 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") 193 @issue_custom_fields = IssueCustomField.sorted.all
196 @issue_category ||= IssueCategory.new 194 @issue_category ||= IssueCategory.new
197 @member ||= @project.members.new 195 @member ||= @project.members.new
198 @trackers = Tracker.sorted.all 196 @trackers = Tracker.sorted.all
199 @wiki ||= @project.wiki 197 @wiki ||= @project.wiki
200 end 198 end
207 if validate_parent_id && @project.save 205 if validate_parent_id && @project.save
208 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') 206 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
209 respond_to do |format| 207 respond_to do |format|
210 format.html { 208 format.html {
211 flash[:notice] = l(:notice_successful_update) 209 flash[:notice] = l(:notice_successful_update)
212 redirect_to :action => 'settings', :id => @project 210 redirect_to settings_project_path(@project)
213 } 211 }
214 format.api { render_api_ok } 212 format.api { render_api_ok }
215 end 213 end
216 else 214 else
217 respond_to do |format| 215 respond_to do |format|
233 end 231 end
234 232
235 def modules 233 def modules
236 @project.enabled_module_names = params[:enabled_module_names] 234 @project.enabled_module_names = params[:enabled_module_names]
237 flash[:notice] = l(:notice_successful_update) 235 flash[:notice] = l(:notice_successful_update)
238 redirect_to :action => 'settings', :id => @project, :tab => 'modules' 236 redirect_to settings_project_path(@project, :tab => 'modules')
239 end 237 end
240 238
241 def archive 239 def archive
242 if request.post? 240 if request.post?
243 unless @project.archive 241 unless @project.archive
244 flash[:error] = l(:error_can_not_archive_project) 242 flash[:error] = l(:error_can_not_archive_project)
245 end 243 end
246 end 244 end
247 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) 245 redirect_to admin_projects_path(:status => params[:status])
248 end 246 end
249 247
250 def unarchive 248 def unarchive
251 @project.unarchive if request.post? && !@project.active? 249 @project.unarchive if request.post? && !@project.active?
252 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) 250 redirect_to admin_projects_path(:status => params[:status])
253 end 251 end
254 252
255 def close 253 def close
256 @project.close 254 @project.close
257 redirect_to project_path(@project) 255 redirect_to project_path(@project)
266 def destroy 264 def destroy
267 @project_to_destroy = @project 265 @project_to_destroy = @project
268 if api_request? || params[:confirm] 266 if api_request? || params[:confirm]
269 @project_to_destroy.destroy 267 @project_to_destroy.destroy
270 respond_to do |format| 268 respond_to do |format|
271 format.html { redirect_to :controller => 'admin', :action => 'projects' } 269 format.html { redirect_to admin_projects_path }
272 format.api { render_api_ok } 270 format.api { render_api_ok }
273 end 271 end
274 end 272 end
275 # hide project in layout 273 # hide project in layout
276 @project = nil 274 @project = nil