@@ -1,345 +1,346 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 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 ProjectsController < ApplicationController |
|
19 | 19 | menu_item :overview |
|
20 | 20 | menu_item :activity, :only => :activity |
|
21 | 21 | menu_item :roadmap, :only => :roadmap |
|
22 | 22 | menu_item :files, :only => [:list_files, :add_file] |
|
23 | 23 | menu_item :settings, :only => :settings |
|
24 | 24 | menu_item :issues, :only => [:changelog] |
|
25 | 25 | |
|
26 | 26 | before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ] |
|
27 | 27 | before_filter :find_optional_project, :only => :activity |
|
28 | 28 | before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ] |
|
29 | 29 | before_filter :authorize_global, :only => :add |
|
30 | 30 | before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ] |
|
31 | 31 | accept_key_auth :activity |
|
32 | 32 | |
|
33 | 33 | after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller| |
|
34 | 34 | if controller.request.post? |
|
35 | 35 | controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt' |
|
36 | 36 | end |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | helper :sort |
|
40 | 40 | include SortHelper |
|
41 | 41 | helper :custom_fields |
|
42 | 42 | include CustomFieldsHelper |
|
43 | 43 | helper :issues |
|
44 | 44 | helper IssuesHelper |
|
45 | 45 | helper :queries |
|
46 | 46 | include QueriesHelper |
|
47 | 47 | helper :repositories |
|
48 | 48 | include RepositoriesHelper |
|
49 | 49 | include ProjectsHelper |
|
50 | 50 | |
|
51 | 51 | # Lists visible projects |
|
52 | 52 | def index |
|
53 | 53 | respond_to do |format| |
|
54 | 54 | format.html { |
|
55 | 55 | @projects = Project.visible.find(:all, :order => 'lft') |
|
56 | 56 | } |
|
57 | 57 | format.atom { |
|
58 | 58 | projects = Project.visible.find(:all, :order => 'created_on DESC', |
|
59 | 59 | :limit => Setting.feeds_limit.to_i) |
|
60 | 60 | render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") |
|
61 | 61 | } |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | # Add a new project |
|
66 | 66 | def add |
|
67 | 67 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
68 | 68 | @trackers = Tracker.all |
|
69 | 69 | @project = Project.new(params[:project]) |
|
70 | 70 | if request.get? |
|
71 | 71 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
|
72 | 72 | @project.trackers = Tracker.all |
|
73 | 73 | @project.is_public = Setting.default_projects_public? |
|
74 | 74 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
75 | 75 | else |
|
76 | 76 | @project.enabled_module_names = params[:enabled_modules] |
|
77 | 77 | if @project.save |
|
78 | 78 | @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id') |
|
79 | 79 | # Add current user as a project member if he is not admin |
|
80 | 80 | unless User.current.admin? |
|
81 | 81 | r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first |
|
82 | 82 | m = Member.new(:user => User.current, :roles => [r]) |
|
83 | 83 | @project.members << m |
|
84 | 84 | end |
|
85 | 85 | flash[:notice] = l(:notice_successful_create) |
|
86 | 86 | redirect_to :controller => 'projects', :action => 'settings', :id => @project |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | def copy |
|
92 | 92 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
93 | 93 | @trackers = Tracker.all |
|
94 | 94 | @root_projects = Project.find(:all, |
|
95 | 95 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
96 | 96 | :order => 'name') |
|
97 | 97 | if request.get? |
|
98 | 98 | @project = Project.copy_from(params[:id]) |
|
99 | 99 | if @project |
|
100 | 100 | @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
|
101 | 101 | else |
|
102 | 102 | redirect_to :controller => 'admin', :action => 'projects' |
|
103 | 103 | end |
|
104 | 104 | else |
|
105 | 105 | @project = Project.new(params[:project]) |
|
106 | 106 | @project.enabled_module_names = params[:enabled_modules] |
|
107 | 107 | if @project.copy(params[:id], :only => params[:only]) |
|
108 | @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id') | |
|
108 | 109 | flash[:notice] = l(:notice_successful_create) |
|
109 | 110 | redirect_to :controller => 'admin', :action => 'projects' |
|
110 | 111 | end |
|
111 | 112 | end |
|
112 | 113 | end |
|
113 | 114 | |
|
114 | 115 | |
|
115 | 116 | # Show @project |
|
116 | 117 | def show |
|
117 | 118 | if params[:jump] |
|
118 | 119 | # try to redirect to the requested menu item |
|
119 | 120 | redirect_to_project_menu_item(@project, params[:jump]) && return |
|
120 | 121 | end |
|
121 | 122 | |
|
122 | 123 | @users_by_role = @project.users_by_role |
|
123 | 124 | @subprojects = @project.children.visible |
|
124 | 125 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
125 | 126 | @trackers = @project.rolled_up_trackers |
|
126 | 127 | |
|
127 | 128 | cond = @project.project_condition(Setting.display_subprojects_issues?) |
|
128 | 129 | |
|
129 | 130 | @open_issues_by_tracker = Issue.visible.count(:group => :tracker, |
|
130 | 131 | :include => [:project, :status, :tracker], |
|
131 | 132 | :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
|
132 | 133 | @total_issues_by_tracker = Issue.visible.count(:group => :tracker, |
|
133 | 134 | :include => [:project, :status, :tracker], |
|
134 | 135 | :conditions => cond) |
|
135 | 136 | |
|
136 | 137 | TimeEntry.visible_by(User.current) do |
|
137 | 138 | @total_hours = TimeEntry.sum(:hours, |
|
138 | 139 | :include => :project, |
|
139 | 140 | :conditions => cond).to_f |
|
140 | 141 | end |
|
141 | 142 | @key = User.current.rss_key |
|
142 | 143 | end |
|
143 | 144 | |
|
144 | 145 | def settings |
|
145 | 146 | @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
146 | 147 | @issue_category ||= IssueCategory.new |
|
147 | 148 | @member ||= @project.members.new |
|
148 | 149 | @trackers = Tracker.all |
|
149 | 150 | @repository ||= @project.repository |
|
150 | 151 | @wiki ||= @project.wiki |
|
151 | 152 | end |
|
152 | 153 | |
|
153 | 154 | # Edit @project |
|
154 | 155 | def edit |
|
155 | 156 | if request.post? |
|
156 | 157 | @project.attributes = params[:project] |
|
157 | 158 | if @project.save |
|
158 | 159 | @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id') |
|
159 | 160 | flash[:notice] = l(:notice_successful_update) |
|
160 | 161 | redirect_to :action => 'settings', :id => @project |
|
161 | 162 | else |
|
162 | 163 | settings |
|
163 | 164 | render :action => 'settings' |
|
164 | 165 | end |
|
165 | 166 | end |
|
166 | 167 | end |
|
167 | 168 | |
|
168 | 169 | def modules |
|
169 | 170 | @project.enabled_module_names = params[:enabled_modules] |
|
170 | 171 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
171 | 172 | end |
|
172 | 173 | |
|
173 | 174 | def archive |
|
174 | 175 | @project.archive if request.post? && @project.active? |
|
175 | 176 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
|
176 | 177 | end |
|
177 | 178 | |
|
178 | 179 | def unarchive |
|
179 | 180 | @project.unarchive if request.post? && !@project.active? |
|
180 | 181 | redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status])) |
|
181 | 182 | end |
|
182 | 183 | |
|
183 | 184 | # Delete @project |
|
184 | 185 | def destroy |
|
185 | 186 | @project_to_destroy = @project |
|
186 | 187 | if request.post? and params[:confirm] |
|
187 | 188 | @project_to_destroy.destroy |
|
188 | 189 | redirect_to :controller => 'admin', :action => 'projects' |
|
189 | 190 | end |
|
190 | 191 | # hide project in layout |
|
191 | 192 | @project = nil |
|
192 | 193 | end |
|
193 | 194 | |
|
194 | 195 | # Add a new issue category to @project |
|
195 | 196 | def add_issue_category |
|
196 | 197 | @category = @project.issue_categories.build(params[:category]) |
|
197 | 198 | if request.post? and @category.save |
|
198 | 199 | respond_to do |format| |
|
199 | 200 | format.html do |
|
200 | 201 | flash[:notice] = l(:notice_successful_create) |
|
201 | 202 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
202 | 203 | end |
|
203 | 204 | format.js do |
|
204 | 205 | # IE doesn't support the replace_html rjs method for select box options |
|
205 | 206 | render(:update) {|page| page.replace "issue_category_id", |
|
206 | 207 | content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') |
|
207 | 208 | } |
|
208 | 209 | end |
|
209 | 210 | end |
|
210 | 211 | end |
|
211 | 212 | end |
|
212 | 213 | |
|
213 | 214 | # Add a new version to @project |
|
214 | 215 | def add_version |
|
215 | 216 | @version = @project.versions.build(params[:version]) |
|
216 | 217 | if request.post? and @version.save |
|
217 | 218 | flash[:notice] = l(:notice_successful_create) |
|
218 | 219 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
219 | 220 | end |
|
220 | 221 | end |
|
221 | 222 | |
|
222 | 223 | def add_file |
|
223 | 224 | if request.post? |
|
224 | 225 | container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) |
|
225 | 226 | attachments = attach_files(container, params[:attachments]) |
|
226 | 227 | if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
227 | 228 | Mailer.deliver_attachments_added(attachments) |
|
228 | 229 | end |
|
229 | 230 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
230 | 231 | return |
|
231 | 232 | end |
|
232 | 233 | @versions = @project.versions.sort |
|
233 | 234 | end |
|
234 | 235 | |
|
235 | 236 | def save_activities |
|
236 | 237 | if request.post? && params[:enumerations] |
|
237 | 238 | Project.transaction do |
|
238 | 239 | params[:enumerations].each do |id, activity| |
|
239 | 240 | @project.update_or_create_time_entry_activity(id, activity) |
|
240 | 241 | end |
|
241 | 242 | end |
|
242 | 243 | end |
|
243 | 244 | |
|
244 | 245 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project |
|
245 | 246 | end |
|
246 | 247 | |
|
247 | 248 | def reset_activities |
|
248 | 249 | @project.time_entry_activities.each do |time_entry_activity| |
|
249 | 250 | time_entry_activity.destroy(time_entry_activity.parent) |
|
250 | 251 | end |
|
251 | 252 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project |
|
252 | 253 | end |
|
253 | 254 | |
|
254 | 255 | def list_files |
|
255 | 256 | sort_init 'filename', 'asc' |
|
256 | 257 | sort_update 'filename' => "#{Attachment.table_name}.filename", |
|
257 | 258 | 'created_on' => "#{Attachment.table_name}.created_on", |
|
258 | 259 | 'size' => "#{Attachment.table_name}.filesize", |
|
259 | 260 | 'downloads' => "#{Attachment.table_name}.downloads" |
|
260 | 261 | |
|
261 | 262 | @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)] |
|
262 | 263 | @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse |
|
263 | 264 | render :layout => !request.xhr? |
|
264 | 265 | end |
|
265 | 266 | |
|
266 | 267 | # Show changelog for @project |
|
267 | 268 | def changelog |
|
268 | 269 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
269 | 270 | retrieve_selected_tracker_ids(@trackers) |
|
270 | 271 | @versions = @project.versions.sort |
|
271 | 272 | end |
|
272 | 273 | |
|
273 | 274 | def roadmap |
|
274 | 275 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) |
|
275 | 276 | retrieve_selected_tracker_ids(@trackers) |
|
276 | 277 | @versions = @project.versions.sort |
|
277 | 278 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
278 | 279 | end |
|
279 | 280 | |
|
280 | 281 | def activity |
|
281 | 282 | @days = Setting.activity_days_default.to_i |
|
282 | 283 | |
|
283 | 284 | if params[:from] |
|
284 | 285 | begin; @date_to = params[:from].to_date + 1; rescue; end |
|
285 | 286 | end |
|
286 | 287 | |
|
287 | 288 | @date_to ||= Date.today + 1 |
|
288 | 289 | @date_from = @date_to - @days |
|
289 | 290 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
290 | 291 | @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) |
|
291 | 292 | |
|
292 | 293 | @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, |
|
293 | 294 | :with_subprojects => @with_subprojects, |
|
294 | 295 | :author => @author) |
|
295 | 296 | @activity.scope_select {|t| !params["show_#{t}"].nil?} |
|
296 | 297 | @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? |
|
297 | 298 | |
|
298 | 299 | events = @activity.events(@date_from, @date_to) |
|
299 | 300 | |
|
300 | 301 | respond_to do |format| |
|
301 | 302 | format.html { |
|
302 | 303 | @events_by_day = events.group_by(&:event_date) |
|
303 | 304 | render :layout => false if request.xhr? |
|
304 | 305 | } |
|
305 | 306 | format.atom { |
|
306 | 307 | title = l(:label_activity) |
|
307 | 308 | if @author |
|
308 | 309 | title = @author.name |
|
309 | 310 | elsif @activity.scope.size == 1 |
|
310 | 311 | title = l("label_#{@activity.scope.first.singularize}_plural") |
|
311 | 312 | end |
|
312 | 313 | render_feed(events, :title => "#{@project || Setting.app_title}: #{title}") |
|
313 | 314 | } |
|
314 | 315 | end |
|
315 | 316 | |
|
316 | 317 | rescue ActiveRecord::RecordNotFound |
|
317 | 318 | render_404 |
|
318 | 319 | end |
|
319 | 320 | |
|
320 | 321 | private |
|
321 | 322 | # Find project of id params[:id] |
|
322 | 323 | # if not found, redirect to project list |
|
323 | 324 | # Used as a before_filter |
|
324 | 325 | def find_project |
|
325 | 326 | @project = Project.find(params[:id]) |
|
326 | 327 | rescue ActiveRecord::RecordNotFound |
|
327 | 328 | render_404 |
|
328 | 329 | end |
|
329 | 330 | |
|
330 | 331 | def find_optional_project |
|
331 | 332 | return true unless params[:id] |
|
332 | 333 | @project = Project.find(params[:id]) |
|
333 | 334 | authorize |
|
334 | 335 | rescue ActiveRecord::RecordNotFound |
|
335 | 336 | render_404 |
|
336 | 337 | end |
|
337 | 338 | |
|
338 | 339 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
339 | 340 | if ids = params[:tracker_ids] |
|
340 | 341 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
341 | 342 | else |
|
342 | 343 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
343 | 344 | end |
|
344 | 345 | end |
|
345 | 346 | end |
General Comments 0
You need to be logged in to leave comments.
Login now