@@ -1,433 +1,440 | |||
|
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 | layout 'base' |
|
20 | 20 | menu_item :overview |
|
21 | 21 | menu_item :activity, :only => :activity |
|
22 | 22 | menu_item :roadmap, :only => :roadmap |
|
23 | 23 | menu_item :files, :only => [:list_files, :add_file] |
|
24 | 24 | menu_item :settings, :only => :settings |
|
25 | 25 | menu_item :issues, :only => [:changelog] |
|
26 | 26 | |
|
27 | 27 | before_filter :find_project, :except => [ :index, :list, :add, :activity ] |
|
28 | 28 | before_filter :find_optional_project, :only => :activity |
|
29 | 29 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ] |
|
30 | 30 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
31 | 31 | accept_key_auth :activity, :calendar |
|
32 | 32 | |
|
33 | 33 | helper :sort |
|
34 | 34 | include SortHelper |
|
35 | 35 | helper :custom_fields |
|
36 | 36 | include CustomFieldsHelper |
|
37 | 37 | helper :ifpdf |
|
38 | 38 | include IfpdfHelper |
|
39 | 39 | helper :issues |
|
40 | 40 | helper IssuesHelper |
|
41 | 41 | helper :queries |
|
42 | 42 | include QueriesHelper |
|
43 | 43 | helper :repositories |
|
44 | 44 | include RepositoriesHelper |
|
45 | 45 | include ProjectsHelper |
|
46 | 46 | |
|
47 | 47 | def index |
|
48 | 48 | list |
|
49 | 49 | render :action => 'list' unless request.xhr? |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | # Lists visible projects |
|
53 | 53 | def list |
|
54 | 54 | projects = Project.find :all, |
|
55 | 55 | :conditions => Project.visible_by(User.current), |
|
56 | 56 | :include => :parent |
|
57 | 57 | @project_tree = projects.group_by {|p| p.parent || p} |
|
58 | 58 | @project_tree.each_key {|p| @project_tree[p] -= [p]} |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | # Add a new project |
|
62 | 62 | def add |
|
63 | 63 | @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
64 | 64 | @trackers = Tracker.all |
|
65 | 65 | @root_projects = Project.find(:all, |
|
66 | 66 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
67 | 67 | :order => 'name') |
|
68 | 68 | @project = Project.new(params[:project]) |
|
69 | 69 | if request.get? |
|
70 | 70 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
71 | 71 | @project.trackers = Tracker.all |
|
72 | 72 | @project.is_public = Setting.default_projects_public? |
|
73 | 73 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
74 | 74 | else |
|
75 | 75 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
76 | 76 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } |
|
77 | 77 | @project.custom_values = @custom_values |
|
78 | 78 | @project.enabled_module_names = params[:enabled_modules] |
|
79 | 79 | if @project.save |
|
80 | 80 | flash[:notice] = l(:notice_successful_create) |
|
81 | 81 | redirect_to :controller => 'admin', :action => 'projects' |
|
82 | 82 | end |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | # Show @project |
|
87 | 87 | def show |
|
88 | 88 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") |
|
89 | 89 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
90 | 90 | @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current)) |
|
91 | 91 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
92 | 92 | @trackers = @project.rolled_up_trackers |
|
93 | 93 | |
|
94 | 94 | cond = @project.project_condition(Setting.display_subprojects_issues?) |
|
95 | 95 | Issue.visible_by(User.current) do |
|
96 | 96 | @open_issues_by_tracker = Issue.count(:group => :tracker, |
|
97 | 97 | :include => [:project, :status, :tracker], |
|
98 | 98 | :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false]) |
|
99 | 99 | @total_issues_by_tracker = Issue.count(:group => :tracker, |
|
100 | 100 | :include => [:project, :status, :tracker], |
|
101 | 101 | :conditions => cond) |
|
102 | 102 | end |
|
103 | 103 | TimeEntry.visible_by(User.current) do |
|
104 | 104 | @total_hours = TimeEntry.sum(:hours, |
|
105 | 105 | :include => :project, |
|
106 | 106 | :conditions => cond).to_f |
|
107 | 107 | end |
|
108 | 108 | @key = User.current.rss_key |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def settings |
|
112 | 112 | @root_projects = Project.find(:all, |
|
113 | 113 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], |
|
114 | 114 | :order => 'name') |
|
115 | 115 | @custom_fields = IssueCustomField.find(:all) |
|
116 | 116 | @issue_category ||= IssueCategory.new |
|
117 | 117 | @member ||= @project.members.new |
|
118 | 118 | @trackers = Tracker.all |
|
119 | 119 | @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
120 | 120 | @repository ||= @project.repository |
|
121 | 121 | @wiki ||= @project.wiki |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | # Edit @project |
|
125 | 125 | def edit |
|
126 | 126 | if request.post? |
|
127 | 127 | if params[:custom_fields] |
|
128 | 128 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
129 | 129 | @project.custom_values = @custom_values |
|
130 | 130 | end |
|
131 | 131 | @project.attributes = params[:project] |
|
132 | 132 | if @project.save |
|
133 | 133 | flash[:notice] = l(:notice_successful_update) |
|
134 | 134 | redirect_to :action => 'settings', :id => @project |
|
135 | 135 | else |
|
136 | 136 | settings |
|
137 | 137 | render :action => 'settings' |
|
138 | 138 | end |
|
139 | 139 | end |
|
140 | 140 | end |
|
141 | 141 | |
|
142 | 142 | def modules |
|
143 | 143 | @project.enabled_module_names = params[:enabled_modules] |
|
144 | 144 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | def archive |
|
148 | 148 | @project.archive if request.post? && @project.active? |
|
149 | 149 | redirect_to :controller => 'admin', :action => 'projects' |
|
150 | 150 | end |
|
151 | 151 | |
|
152 | 152 | def unarchive |
|
153 | 153 | @project.unarchive if request.post? && !@project.active? |
|
154 | 154 | redirect_to :controller => 'admin', :action => 'projects' |
|
155 | 155 | end |
|
156 | 156 | |
|
157 | 157 | # Delete @project |
|
158 | 158 | def destroy |
|
159 | 159 | @project_to_destroy = @project |
|
160 | 160 | if request.post? and params[:confirm] |
|
161 | 161 | @project_to_destroy.destroy |
|
162 | 162 | redirect_to :controller => 'admin', :action => 'projects' |
|
163 | 163 | end |
|
164 | 164 | # hide project in layout |
|
165 | 165 | @project = nil |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | # Add a new issue category to @project |
|
169 | 169 | def add_issue_category |
|
170 | 170 | @category = @project.issue_categories.build(params[:category]) |
|
171 | 171 | if request.post? and @category.save |
|
172 | 172 | respond_to do |format| |
|
173 | 173 | format.html do |
|
174 | 174 | flash[:notice] = l(:notice_successful_create) |
|
175 | 175 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
176 | 176 | end |
|
177 | 177 | format.js do |
|
178 | 178 | # IE doesn't support the replace_html rjs method for select box options |
|
179 | 179 | render(:update) {|page| page.replace "issue_category_id", |
|
180 | 180 | 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]') |
|
181 | 181 | } |
|
182 | 182 | end |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | end |
|
186 | 186 | |
|
187 | 187 | # Add a new version to @project |
|
188 | 188 | def add_version |
|
189 | 189 | @version = @project.versions.build(params[:version]) |
|
190 | 190 | if request.post? and @version.save |
|
191 | 191 | flash[:notice] = l(:notice_successful_create) |
|
192 | 192 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
193 | 193 | end |
|
194 | 194 | end |
|
195 | 195 | |
|
196 | 196 | def add_file |
|
197 | 197 | if request.post? |
|
198 | 198 | @version = @project.versions.find_by_id(params[:version_id]) |
|
199 | 199 | attachments = attach_files(@version, params[:attachments]) |
|
200 | 200 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
201 | 201 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
202 | 202 | end |
|
203 | 203 | @versions = @project.versions.sort |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | def list_files |
|
207 | 207 | sort_init "#{Attachment.table_name}.filename", "asc" |
|
208 | 208 | sort_update |
|
209 | 209 | @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse |
|
210 | 210 | render :layout => !request.xhr? |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | # Show changelog for @project |
|
214 | 214 | def changelog |
|
215 | 215 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
216 | 216 | retrieve_selected_tracker_ids(@trackers) |
|
217 | 217 | @versions = @project.versions.sort |
|
218 | 218 | end |
|
219 | 219 | |
|
220 | 220 | def roadmap |
|
221 | 221 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) |
|
222 | 222 | retrieve_selected_tracker_ids(@trackers) |
|
223 | 223 | @versions = @project.versions.sort |
|
224 | 224 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def activity |
|
228 | 228 | @days = Setting.activity_days_default.to_i |
|
229 | 229 | |
|
230 | 230 | if params[:from] |
|
231 | 231 | begin; @date_to = params[:from].to_date; rescue; end |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | @date_to ||= Date.today + 1 |
|
235 | 235 | @date_from = @date_to - @days |
|
236 | 236 | |
|
237 | 237 | @event_types = %w(issues news files documents changesets wiki_pages messages) |
|
238 | 238 | if @project |
|
239 | 239 | @event_types.delete('wiki_pages') unless @project.wiki |
|
240 | 240 | @event_types.delete('changesets') unless @project.repository |
|
241 | 241 | @event_types.delete('messages') unless @project.boards.any? |
|
242 | 242 | # only show what the user is allowed to view |
|
243 | 243 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} |
|
244 | 244 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
245 | 245 | end |
|
246 | 246 | @scope = @event_types.select {|t| params["show_#{t}"]} |
|
247 | 247 | # default events if none is specified in parameters |
|
248 | 248 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? |
|
249 | 249 | |
|
250 | 250 | @events = [] |
|
251 | 251 | |
|
252 | 252 | if @scope.include?('issues') |
|
253 | 253 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects)) |
|
254 | 254 | cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
255 | 255 | @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions) |
|
256 | 256 | |
|
257 | 257 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects)) |
|
258 | 258 | cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
259 | 259 | @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions) |
|
260 | 260 | end |
|
261 | 261 | |
|
262 | 262 | if @scope.include?('news') |
|
263 | 263 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects)) |
|
264 | 264 | cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
265 | 265 | @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions) |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | if @scope.include?('files') |
|
269 | 269 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects)) |
|
270 | 270 | cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
271 | 271 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", |
|
272 | 272 | :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " + |
|
273 | 273 | "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id", |
|
274 | 274 | :conditions => cond.conditions) |
|
275 | 275 | end |
|
276 | 276 | |
|
277 | 277 | if @scope.include?('documents') |
|
278 | 278 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects)) |
|
279 | 279 | cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
280 | 280 | @events += Document.find(:all, :include => :project, :conditions => cond.conditions) |
|
281 | 281 | |
|
282 | 282 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects)) |
|
283 | 283 | cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
284 | 284 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", |
|
285 | 285 | :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " + |
|
286 | 286 | "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id", |
|
287 | 287 | :conditions => cond.conditions) |
|
288 | 288 | end |
|
289 | 289 | |
|
290 | 290 | if @scope.include?('wiki_pages') |
|
291 | 291 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
292 | 292 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
293 | 293 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
294 | 294 | "#{WikiContent.versioned_table_name}.id" |
|
295 | 295 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
296 | 296 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + |
|
297 | 297 | "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id" |
|
298 | 298 | |
|
299 | 299 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects)) |
|
300 | 300 | cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
301 | 301 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions) |
|
302 | 302 | end |
|
303 | 303 | |
|
304 | 304 | if @scope.include?('changesets') |
|
305 | 305 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects)) |
|
306 | 306 | cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
307 | 307 | @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions) |
|
308 | 308 | end |
|
309 | 309 | |
|
310 | 310 | if @scope.include?('messages') |
|
311 | 311 | cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects)) |
|
312 | 312 | cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
313 | 313 | @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions) |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | @events_by_day = @events.group_by(&:event_date) |
|
317 | 317 | |
|
318 | 318 | respond_to do |format| |
|
319 | 319 | format.html { render :layout => false if request.xhr? } |
|
320 | 320 | format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") } |
|
321 | 321 | end |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | def calendar |
|
325 | 325 | @trackers = @project.rolled_up_trackers |
|
326 | 326 | retrieve_selected_tracker_ids(@trackers) |
|
327 | 327 | |
|
328 | 328 | if params[:year] and params[:year].to_i > 1900 |
|
329 | 329 | @year = params[:year].to_i |
|
330 | 330 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
331 | 331 | @month = params[:month].to_i |
|
332 | 332 | end |
|
333 | 333 | end |
|
334 | 334 | @year ||= Date.today.year |
|
335 | 335 | @month ||= Date.today.month |
|
336 | 336 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
337 | 337 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
338 | 338 | events = [] |
|
339 | 339 | @project.issues_with_subprojects(@with_subprojects) do |
|
340 | 340 | events += Issue.find(:all, |
|
341 | 341 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
342 | 342 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
343 | 343 | ) unless @selected_tracker_ids.empty? |
|
344 | 344 | events += Version.find(:all, :include => :project, |
|
345 | 345 | :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
346 | 346 | end |
|
347 | 347 | @calendar.events = events |
|
348 | 348 | |
|
349 | 349 | render :layout => false if request.xhr? |
|
350 | 350 | end |
|
351 | 351 | |
|
352 | 352 | def gantt |
|
353 | 353 | @trackers = @project.rolled_up_trackers |
|
354 | 354 | retrieve_selected_tracker_ids(@trackers) |
|
355 | 355 | |
|
356 | 356 | if params[:year] and params[:year].to_i >0 |
|
357 | 357 | @year_from = params[:year].to_i |
|
358 | 358 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
359 | 359 | @month_from = params[:month].to_i |
|
360 | 360 | else |
|
361 | 361 | @month_from = 1 |
|
362 | 362 | end |
|
363 | 363 | else |
|
364 | 364 | @month_from ||= Date.today.month |
|
365 | 365 | @year_from ||= Date.today.year |
|
366 | 366 | end |
|
367 | 367 | |
|
368 | 368 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
369 | 369 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
370 | 370 | months = (params[:months] || User.current.pref[:gantt_months]).to_i |
|
371 | 371 | @months = (months > 0 && months < 25) ? months : 6 |
|
372 | 372 | |
|
373 | 373 | # Save gantt paramters as user preference (zoom and months count) |
|
374 | 374 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) |
|
375 | 375 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
376 | 376 | User.current.preference.save |
|
377 | 377 | end |
|
378 | 378 | |
|
379 | 379 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
380 | 380 | @date_to = (@date_from >> @months) - 1 |
|
381 | 381 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
382 | 382 | |
|
383 | 383 | @events = [] |
|
384 | 384 | @project.issues_with_subprojects(@with_subprojects) do |
|
385 | # Issues that have start and due dates | |
|
385 | 386 | @events += Issue.find(:all, |
|
386 | 387 | :order => "start_date, due_date", |
|
387 | 388 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
388 | 389 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] |
|
389 | 390 | ) unless @selected_tracker_ids.empty? |
|
391 | # Issues that don't have a due date but that are assigned to a version with a date | |
|
392 | @events += Issue.find(:all, | |
|
393 | :order => "start_date, effective_date", | |
|
394 | :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version], | |
|
395 | :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] | |
|
396 | ) unless @selected_tracker_ids.empty? | |
|
390 | 397 | @events += Version.find(:all, :include => :project, |
|
391 | 398 | :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
392 | 399 | end |
|
393 | 400 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
394 | 401 | |
|
395 | 402 | if params[:format]=='pdf' |
|
396 | 403 | @options_for_rfpdf ||= {} |
|
397 | 404 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
398 | 405 | render :template => "projects/gantt.rfpdf", :layout => false |
|
399 | 406 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
400 | 407 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
401 | 408 | image.format = 'PNG' |
|
402 | 409 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
403 | 410 | else |
|
404 | 411 | render :template => "projects/gantt.rhtml" |
|
405 | 412 | end |
|
406 | 413 | end |
|
407 | 414 | |
|
408 | 415 | private |
|
409 | 416 | # Find project of id params[:id] |
|
410 | 417 | # if not found, redirect to project list |
|
411 | 418 | # Used as a before_filter |
|
412 | 419 | def find_project |
|
413 | 420 | @project = Project.find(params[:id]) |
|
414 | 421 | rescue ActiveRecord::RecordNotFound |
|
415 | 422 | render_404 |
|
416 | 423 | end |
|
417 | 424 | |
|
418 | 425 | def find_optional_project |
|
419 | 426 | return true unless params[:id] |
|
420 | 427 | @project = Project.find(params[:id]) |
|
421 | 428 | authorize |
|
422 | 429 | rescue ActiveRecord::RecordNotFound |
|
423 | 430 | render_404 |
|
424 | 431 | end |
|
425 | 432 | |
|
426 | 433 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
427 | 434 | if ids = params[:tracker_ids] |
|
428 | 435 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
429 | 436 | else |
|
430 | 437 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
431 | 438 | end |
|
432 | 439 | end |
|
433 | 440 | end |
@@ -1,250 +1,256 | |||
|
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 Issue < ActiveRecord::Base |
|
19 | 19 | belongs_to :project |
|
20 | 20 | belongs_to :tracker |
|
21 | 21 | belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' |
|
22 | 22 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
23 | 23 | belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id' |
|
24 | 24 | belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id' |
|
25 | 25 | belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id' |
|
26 | 26 | belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id' |
|
27 | 27 | |
|
28 | 28 | has_many :journals, :as => :journalized, :dependent => :destroy |
|
29 | 29 | has_many :attachments, :as => :container, :dependent => :destroy |
|
30 | 30 | has_many :time_entries, :dependent => :delete_all |
|
31 | 31 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
32 | 32 | has_many :custom_fields, :through => :custom_values |
|
33 | 33 | has_and_belongs_to_many :changesets, :order => "revision ASC" |
|
34 | 34 | |
|
35 | 35 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
|
36 | 36 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
|
37 | 37 | |
|
38 | 38 | acts_as_watchable |
|
39 | 39 | acts_as_searchable :columns => ['subject', "#{table_name}.description"], :include => :project, :with => {:journal => :issue} |
|
40 | 40 | acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"}, |
|
41 | 41 | :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}} |
|
42 | 42 | |
|
43 | 43 | validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status |
|
44 | 44 | validates_length_of :subject, :maximum => 255 |
|
45 | 45 | validates_inclusion_of :done_ratio, :in => 0..100 |
|
46 | 46 | validates_numericality_of :estimated_hours, :allow_nil => true |
|
47 | 47 | validates_associated :custom_values, :on => :update |
|
48 | 48 | |
|
49 | 49 | def after_initialize |
|
50 | 50 | if new_record? |
|
51 | 51 | # set default values for new records only |
|
52 | 52 | self.status ||= IssueStatus.default |
|
53 | 53 | self.priority ||= Enumeration.default('IPRI') |
|
54 | 54 | end |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def copy_from(arg) |
|
58 | 58 | issue = arg.is_a?(Issue) ? arg : Issue.find(arg) |
|
59 | 59 | self.attributes = issue.attributes.dup |
|
60 | 60 | self.custom_values = issue.custom_values.collect {|v| v.clone} |
|
61 | 61 | self |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | # Move an issue to a new project and tracker |
|
65 | 65 | def move_to(new_project, new_tracker = nil) |
|
66 | 66 | transaction do |
|
67 | 67 | if new_project && project_id != new_project.id |
|
68 | 68 | # delete issue relations |
|
69 | 69 | unless Setting.cross_project_issue_relations? |
|
70 | 70 | self.relations_from.clear |
|
71 | 71 | self.relations_to.clear |
|
72 | 72 | end |
|
73 | 73 | # issue is moved to another project |
|
74 | 74 | self.category = nil |
|
75 | 75 | self.fixed_version = nil |
|
76 | 76 | self.project = new_project |
|
77 | 77 | end |
|
78 | 78 | if new_tracker |
|
79 | 79 | self.tracker = new_tracker |
|
80 | 80 | end |
|
81 | 81 | if save |
|
82 | 82 | # Manually update project_id on related time entries |
|
83 | 83 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
84 | 84 | else |
|
85 | 85 | rollback_db_transaction |
|
86 | 86 | return false |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | return true |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def priority_id=(pid) |
|
93 | 93 | self.priority = nil |
|
94 | 94 | write_attribute(:priority_id, pid) |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def estimated_hours=(h) |
|
98 | 98 | write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def validate |
|
102 | 102 | if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? |
|
103 | 103 | errors.add :due_date, :activerecord_error_not_a_date |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | if self.due_date and self.start_date and self.due_date < self.start_date |
|
107 | 107 | errors.add :due_date, :activerecord_error_greater_than_start_date |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | if start_date && soonest_start && start_date < soonest_start |
|
111 | 111 | errors.add :start_date, :activerecord_error_invalid |
|
112 | 112 | end |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def validate_on_create |
|
116 | 116 | errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker) |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def before_create |
|
120 | 120 | # default assignment based on category |
|
121 | 121 | if assigned_to.nil? && category && category.assigned_to |
|
122 | 122 | self.assigned_to = category.assigned_to |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def before_save |
|
127 | 127 | if @current_journal |
|
128 | 128 | # attributes changes |
|
129 | 129 | (Issue.column_names - %w(id description)).each {|c| |
|
130 | 130 | @current_journal.details << JournalDetail.new(:property => 'attr', |
|
131 | 131 | :prop_key => c, |
|
132 | 132 | :old_value => @issue_before_change.send(c), |
|
133 | 133 | :value => send(c)) unless send(c)==@issue_before_change.send(c) |
|
134 | 134 | } |
|
135 | 135 | # custom fields changes |
|
136 | 136 | custom_values.each {|c| |
|
137 | 137 | next if (@custom_values_before_change[c.custom_field_id]==c.value || |
|
138 | 138 | (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?)) |
|
139 | 139 | @current_journal.details << JournalDetail.new(:property => 'cf', |
|
140 | 140 | :prop_key => c.custom_field_id, |
|
141 | 141 | :old_value => @custom_values_before_change[c.custom_field_id], |
|
142 | 142 | :value => c.value) |
|
143 | 143 | } |
|
144 | 144 | @current_journal.save |
|
145 | 145 | end |
|
146 | 146 | # Save the issue even if the journal is not saved (because empty) |
|
147 | 147 | true |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | def after_save |
|
151 | 151 | # Reload is needed in order to get the right status |
|
152 | 152 | reload |
|
153 | 153 | |
|
154 | 154 | # Update start/due dates of following issues |
|
155 | 155 | relations_from.each(&:set_issue_to_dates) |
|
156 | 156 | |
|
157 | 157 | # Close duplicates if the issue was closed |
|
158 | 158 | if @issue_before_change && !@issue_before_change.closed? && self.closed? |
|
159 | 159 | duplicates.each do |duplicate| |
|
160 | 160 | # Reload is need in case the duplicate was updated by a previous duplicate |
|
161 | 161 | duplicate.reload |
|
162 | 162 | # Don't re-close it if it's already closed |
|
163 | 163 | next if duplicate.closed? |
|
164 | 164 | # Same user and notes |
|
165 | 165 | duplicate.init_journal(@current_journal.user, @current_journal.notes) |
|
166 | 166 | duplicate.update_attribute :status, self.status |
|
167 | 167 | end |
|
168 | 168 | end |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | def custom_value_for(custom_field) |
|
172 | 172 | self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id } |
|
173 | 173 | return nil |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def init_journal(user, notes = "") |
|
177 | 177 | @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) |
|
178 | 178 | @issue_before_change = self.clone |
|
179 | 179 | @issue_before_change.status = self.status |
|
180 | 180 | @custom_values_before_change = {} |
|
181 | 181 | self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } |
|
182 | 182 | @current_journal |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | # Return true if the issue is closed, otherwise false |
|
186 | 186 | def closed? |
|
187 | 187 | self.status.is_closed? |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | 190 | # Users the issue can be assigned to |
|
191 | 191 | def assignable_users |
|
192 | 192 | project.assignable_users |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | # Returns an array of status that user is able to apply |
|
196 | 196 | def new_statuses_allowed_to(user) |
|
197 | 197 | statuses = status.find_new_statuses_allowed_to(user.role_for_project(project), tracker) |
|
198 | 198 | statuses << status unless statuses.empty? |
|
199 | 199 | statuses.uniq.sort |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | # Returns the mail adresses of users that should be notified for the issue |
|
203 | 203 | def recipients |
|
204 | 204 | recipients = project.recipients |
|
205 | 205 | # Author and assignee are always notified unless they have been locked |
|
206 | 206 | recipients << author.mail if author && author.active? |
|
207 | 207 | recipients << assigned_to.mail if assigned_to && assigned_to.active? |
|
208 | 208 | recipients.compact.uniq |
|
209 | 209 | end |
|
210 | 210 | |
|
211 | 211 | def spent_hours |
|
212 | 212 | @spent_hours ||= time_entries.sum(:hours) || 0 |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | def relations |
|
216 | 216 | (relations_from + relations_to).sort |
|
217 | 217 | end |
|
218 | 218 | |
|
219 | 219 | def all_dependent_issues |
|
220 | 220 | dependencies = [] |
|
221 | 221 | relations_from.each do |relation| |
|
222 | 222 | dependencies << relation.issue_to |
|
223 | 223 | dependencies += relation.issue_to.all_dependent_issues |
|
224 | 224 | end |
|
225 | 225 | dependencies |
|
226 | 226 | end |
|
227 | 227 | |
|
228 | 228 | # Returns an array of the duplicate issues |
|
229 | 229 | def duplicates |
|
230 | 230 | relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)} |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | # Returns the due date or the target due date if any | |
|
234 | # Used on gantt chart | |
|
235 | def due_before | |
|
236 | due_date || (fixed_version ? fixed_version.effective_date : nil) | |
|
237 | end | |
|
238 | ||
|
233 | 239 | def duration |
|
234 | 240 | (start_date && due_date) ? due_date - start_date : 0 |
|
235 | 241 | end |
|
236 | 242 | |
|
237 | 243 | def soonest_start |
|
238 | 244 | @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min |
|
239 | 245 | end |
|
240 | 246 | |
|
241 | 247 | def self.visible_by(usr) |
|
242 | 248 | with_scope(:find => { :conditions => Project.visible_by(usr) }) do |
|
243 | 249 | yield |
|
244 | 250 | end |
|
245 | 251 | end |
|
246 | 252 | |
|
247 | 253 | def to_s |
|
248 | 254 | "#{tracker} ##{id}: #{subject}" |
|
249 | 255 | end |
|
250 | 256 | end |
@@ -1,188 +1,188 | |||
|
1 | 1 | <% |
|
2 | 2 | pdf=IfpdfHelper::IFPDF.new(current_language) |
|
3 | 3 | pdf.SetTitle("#{@project.name} - #{l(:label_gantt)}") |
|
4 | 4 | pdf.AliasNbPages |
|
5 | 5 | pdf.footer_date = format_date(Date.today) |
|
6 | 6 | pdf.AddPage("L") |
|
7 | 7 | pdf.SetFontStyle('B',12) |
|
8 | 8 | pdf.SetX(15) |
|
9 | 9 | pdf.Cell(70, 20, @project.name) |
|
10 | 10 | pdf.Ln |
|
11 | 11 | pdf.SetFontStyle('B',9) |
|
12 | 12 | |
|
13 | 13 | subject_width = 70 |
|
14 | 14 | header_heigth = 5 |
|
15 | 15 | |
|
16 | 16 | headers_heigth = header_heigth |
|
17 | 17 | show_weeks = false |
|
18 | 18 | show_days = false |
|
19 | 19 | |
|
20 | 20 | if @months < 7 |
|
21 | 21 | show_weeks = true |
|
22 | 22 | headers_heigth = 2*header_heigth |
|
23 | 23 | if @months < 3 |
|
24 | 24 | show_days = true |
|
25 | 25 | headers_heigth = 3*header_heigth |
|
26 | 26 | end |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | g_width = 210 |
|
30 | 30 | zoom = (g_width) / (@date_to - @date_from + 1) |
|
31 | 31 | g_height = 120 |
|
32 | 32 | t_height = g_height + headers_heigth |
|
33 | 33 | |
|
34 | 34 | y_start = pdf.GetY |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | # |
|
38 | 38 | # Months headers |
|
39 | 39 | # |
|
40 | 40 | month_f = @date_from |
|
41 | 41 | left = subject_width |
|
42 | 42 | height = header_heigth |
|
43 | 43 | @months.times do |
|
44 | 44 | width = ((month_f >> 1) - month_f) * zoom |
|
45 | 45 | pdf.SetY(y_start) |
|
46 | 46 | pdf.SetX(left) |
|
47 | 47 | pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
|
48 | 48 | left = left + width |
|
49 | 49 | month_f = month_f >> 1 |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | # |
|
53 | 53 | # Weeks headers |
|
54 | 54 | # |
|
55 | 55 | if show_weeks |
|
56 | 56 | left = subject_width |
|
57 | 57 | height = header_heigth |
|
58 | 58 | if @date_from.cwday == 1 |
|
59 | 59 | # @date_from is monday |
|
60 | 60 | week_f = @date_from |
|
61 | 61 | else |
|
62 | 62 | # find next monday after @date_from |
|
63 | 63 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
64 | 64 | width = (7 - @date_from.cwday + 1) * zoom-1 |
|
65 | 65 | pdf.SetY(y_start + header_heigth) |
|
66 | 66 | pdf.SetX(left) |
|
67 | 67 | pdf.Cell(width + 1, height, "", "LTR") |
|
68 | 68 | left = left + width+1 |
|
69 | 69 | end |
|
70 | 70 | while week_f <= @date_to |
|
71 | 71 | width = (week_f + 6 <= @date_to) ? 7 * zoom : (@date_to - week_f + 1) * zoom |
|
72 | 72 | pdf.SetY(y_start + header_heigth) |
|
73 | 73 | pdf.SetX(left) |
|
74 | 74 | pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
|
75 | 75 | left = left + width |
|
76 | 76 | week_f = week_f+7 |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | # |
|
81 | 81 | # Days headers |
|
82 | 82 | # |
|
83 | 83 | if show_days |
|
84 | 84 | left = subject_width |
|
85 | 85 | height = header_heigth |
|
86 | 86 | wday = @date_from.cwday |
|
87 | 87 | pdf.SetFontStyle('B',7) |
|
88 | 88 | (@date_to - @date_from + 1).to_i.times do |
|
89 | 89 | width = zoom |
|
90 | 90 | pdf.SetY(y_start + 2 * header_heigth) |
|
91 | 91 | pdf.SetX(left) |
|
92 | 92 | pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C") |
|
93 | 93 | left = left + width |
|
94 | 94 | wday = wday + 1 |
|
95 | 95 | wday = 1 if wday > 7 |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | pdf.SetY(y_start) |
|
100 | 100 | pdf.SetX(15) |
|
101 | 101 | pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | # |
|
105 | 105 | # Tasks |
|
106 | 106 | # |
|
107 | 107 | top = headers_heigth + y_start |
|
108 | 108 | pdf.SetFontStyle('B',7) |
|
109 | 109 | @events.each do |i| |
|
110 | 110 | pdf.SetY(top) |
|
111 | 111 | pdf.SetX(15) |
|
112 | 112 | |
|
113 | 113 | if i.is_a? Issue |
|
114 | 114 | pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR") |
|
115 | 115 | else |
|
116 | 116 | pdf.Cell(subject_width-15, 5, "#{l(:label_version)}: #{i.name}", "LR") |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | pdf.SetY(top) |
|
120 | 120 | pdf.SetX(subject_width) |
|
121 | 121 | pdf.Cell(g_width, 5, "", "LR") |
|
122 | 122 | |
|
123 | 123 | pdf.SetY(top+1.5) |
|
124 | 124 | |
|
125 | 125 | if i.is_a? Issue |
|
126 | 126 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) |
|
127 |
i_end_date = (i.due_ |
|
|
127 | i_end_date = (i.due_before <= @date_to ? i.due_before : @date_to ) | |
|
128 | 128 | |
|
129 |
i_done_date = i.start_date + ((i.due_ |
|
|
129 | i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor | |
|
130 | 130 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) |
|
131 | 131 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) |
|
132 | 132 | |
|
133 | 133 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today |
|
134 | 134 | |
|
135 | 135 | i_left = ((i_start_date - @date_from)*zoom) |
|
136 | 136 | i_width = ((i_end_date - i_start_date + 1)*zoom) |
|
137 | 137 | d_width = ((i_done_date - i_start_date)*zoom) |
|
138 | 138 | l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date |
|
139 | 139 | l_width ||= 0 |
|
140 | 140 | |
|
141 | 141 | pdf.SetX(subject_width + i_left) |
|
142 | 142 | pdf.SetFillColor(200,200,200) |
|
143 | 143 | pdf.Cell(i_width, 2, "", 0, 0, "", 1) |
|
144 | 144 | |
|
145 | 145 | if l_width > 0 |
|
146 | 146 | pdf.SetY(top+1.5) |
|
147 | 147 | pdf.SetX(subject_width + i_left) |
|
148 | 148 | pdf.SetFillColor(255,100,100) |
|
149 | 149 | pdf.Cell(l_width, 2, "", 0, 0, "", 1) |
|
150 | 150 | end |
|
151 | 151 | if d_width > 0 |
|
152 | 152 | pdf.SetY(top+1.5) |
|
153 | 153 | pdf.SetX(subject_width + i_left) |
|
154 | 154 | pdf.SetFillColor(100,100,255) |
|
155 | 155 | pdf.Cell(d_width, 2, "", 0, 0, "", 1) |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | pdf.SetY(top+1.5) |
|
159 | 159 | pdf.SetX(subject_width + i_left + i_width) |
|
160 | 160 | pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%") |
|
161 | 161 | else |
|
162 | 162 | i_left = ((i.start_date - @date_from)*zoom) |
|
163 | 163 | |
|
164 | 164 | pdf.SetX(subject_width + i_left) |
|
165 | 165 | pdf.SetFillColor(50,200,50) |
|
166 | 166 | pdf.Cell(2, 2, "", 0, 0, "", 1) |
|
167 | 167 | |
|
168 | 168 | pdf.SetY(top+1.5) |
|
169 | 169 | pdf.SetX(subject_width + i_left + 3) |
|
170 | 170 | pdf.Cell(30, 2, "#{i.name}") |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | |
|
174 | 174 | top = top + 5 |
|
175 | 175 | pdf.SetDrawColor(200, 200, 200) |
|
176 | 176 | pdf.Line(15, top, subject_width+g_width, top) |
|
177 | 177 | if pdf.GetY() > 180 |
|
178 | 178 | pdf.AddPage("L") |
|
179 | 179 | top = 20 |
|
180 | 180 | pdf.Line(15, top, subject_width+g_width, top) |
|
181 | 181 | end |
|
182 | 182 | pdf.SetDrawColor(0, 0, 0) |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | pdf.Line(15, top, subject_width+g_width, top) |
|
186 | 186 | |
|
187 | 187 | %> |
|
188 | 188 | <%= pdf.Output %> No newline at end of file |
@@ -1,250 +1,250 | |||
|
1 | 1 | <% zoom = 1 |
|
2 | 2 | @zoom.times { zoom = zoom * 2 } |
|
3 | 3 | |
|
4 | 4 | subject_width = 330 |
|
5 | 5 | header_heigth = 18 |
|
6 | 6 | |
|
7 | 7 | headers_height = header_heigth |
|
8 | 8 | show_weeks = false |
|
9 | 9 | show_days = false |
|
10 | 10 | |
|
11 | 11 | if @zoom >1 |
|
12 | 12 | show_weeks = true |
|
13 | 13 | headers_height = 2*header_heigth |
|
14 | 14 | if @zoom > 2 |
|
15 | 15 | show_days = true |
|
16 | 16 | headers_height = 3*header_heigth |
|
17 | 17 | end |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | g_width = (@date_to - @date_from + 1)*zoom |
|
21 | 21 | g_height = [(20 * @events.length + 6)+150, 206].max |
|
22 | 22 | t_height = g_height + headers_height |
|
23 | 23 | %> |
|
24 | 24 | |
|
25 | 25 | <div class="contextual"> |
|
26 | 26 | </div> |
|
27 | 27 | |
|
28 | 28 | <h2><%= l(:label_gantt) %></h2> |
|
29 | 29 | |
|
30 | 30 | <% form_tag(params.merge(:month => nil, :year => nil, :months => nil)) do %> |
|
31 | 31 | <table width="100%"> |
|
32 | 32 | <tr> |
|
33 | 33 | <td align="left"> |
|
34 | 34 | <input type="text" name="months" size="2" value="<%= @months %>" /> |
|
35 | 35 | <%= l(:label_months_from) %> |
|
36 | 36 | <%= select_month(@month_from, :prefix => "month", :discard_type => true) %> |
|
37 | 37 | <%= select_year(@year_from, :prefix => "year", :discard_type => true) %> |
|
38 | 38 | <%= hidden_field_tag 'zoom', @zoom %> |
|
39 | 39 | <%= submit_tag l(:button_submit), :class => "button-small" %> |
|
40 | 40 | </td> |
|
41 | 41 | |
|
42 | 42 | <td align="right"> |
|
43 | 43 | <%= if @zoom < 4 |
|
44 | 44 | link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]} |
|
45 | 45 | else |
|
46 | 46 | image_tag 'zoom_in_g.png' |
|
47 | 47 | end %> |
|
48 | 48 | <%= if @zoom > 1 |
|
49 | 49 | link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]} |
|
50 | 50 | else |
|
51 | 51 | image_tag 'zoom_out_g.png' |
|
52 | 52 | end %> |
|
53 | 53 | </td> |
|
54 | 54 | </tr> |
|
55 | 55 | </table> |
|
56 | 56 | <% end %> |
|
57 | 57 | |
|
58 | 58 | <table width="100%" style="border:0; border-collapse: collapse;"> |
|
59 | 59 | <tr> |
|
60 | 60 | <td style="width:<%= subject_width %>px;"> |
|
61 | 61 | |
|
62 | 62 | <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;"> |
|
63 | 63 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div> |
|
64 | 64 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div> |
|
65 | 65 | <% |
|
66 | 66 | # |
|
67 | 67 | # Tasks subjects |
|
68 | 68 | # |
|
69 | 69 | top = headers_height + 8 |
|
70 | 70 | @events.each do |i| %> |
|
71 | 71 | <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small> |
|
72 | 72 | <% if i.is_a? Issue %> |
|
73 | 73 | <%= h("#{i.project} -") unless @project && @project == i.project %> |
|
74 | 74 | <%= link_to_issue i %>: <%=h i.subject %> |
|
75 | 75 | <% else %> |
|
76 | 76 | <span class="icon icon-package"> |
|
77 | 77 | <%= h("#{i.project} -") unless @project && @project == i.project %> |
|
78 | 78 | <%= link_to_version i %> |
|
79 | 79 | </span> |
|
80 | 80 | <% end %> |
|
81 | 81 | </small></div> |
|
82 | 82 | <% top = top + 20 |
|
83 | 83 | end %> |
|
84 | 84 | </div> |
|
85 | 85 | </td> |
|
86 | 86 | <td> |
|
87 | 87 | |
|
88 | 88 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;"> |
|
89 | 89 | <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div> |
|
90 | 90 | <% |
|
91 | 91 | # |
|
92 | 92 | # Months headers |
|
93 | 93 | # |
|
94 | 94 | month_f = @date_from |
|
95 | 95 | left = 0 |
|
96 | 96 | height = (show_weeks ? header_heigth : header_heigth + g_height) |
|
97 | 97 | @months.times do |
|
98 | 98 | width = ((month_f >> 1) - month_f) * zoom - 1 |
|
99 | 99 | %> |
|
100 | 100 | <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
101 | 101 | <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }, :title => "#{month_name(month_f.month)} #{month_f.year}"%> |
|
102 | 102 | </div> |
|
103 | 103 | <% |
|
104 | 104 | left = left + width + 1 |
|
105 | 105 | month_f = month_f >> 1 |
|
106 | 106 | end %> |
|
107 | 107 | |
|
108 | 108 | <% |
|
109 | 109 | # |
|
110 | 110 | # Weeks headers |
|
111 | 111 | # |
|
112 | 112 | if show_weeks |
|
113 | 113 | left = 0 |
|
114 | 114 | height = (show_days ? header_heigth-1 : header_heigth-1 + g_height) |
|
115 | 115 | if @date_from.cwday == 1 |
|
116 | 116 | # @date_from is monday |
|
117 | 117 | week_f = @date_from |
|
118 | 118 | else |
|
119 | 119 | # find next monday after @date_from |
|
120 | 120 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
121 | 121 | width = (7 - @date_from.cwday + 1) * zoom-1 |
|
122 | 122 | %> |
|
123 | 123 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div> |
|
124 | 124 | <% |
|
125 | 125 | left = left + width+1 |
|
126 | 126 | end %> |
|
127 | 127 | <% |
|
128 | 128 | while week_f <= @date_to |
|
129 | 129 | width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1 |
|
130 | 130 | %> |
|
131 | 131 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
132 | 132 | <small><%= week_f.cweek if width >= 16 %></small> |
|
133 | 133 | </div> |
|
134 | 134 | <% |
|
135 | 135 | left = left + width+1 |
|
136 | 136 | week_f = week_f+7 |
|
137 | 137 | end |
|
138 | 138 | end %> |
|
139 | 139 | |
|
140 | 140 | <% |
|
141 | 141 | # |
|
142 | 142 | # Days headers |
|
143 | 143 | # |
|
144 | 144 | if show_days |
|
145 | 145 | left = 0 |
|
146 | 146 | height = g_height + header_heigth - 1 |
|
147 | 147 | wday = @date_from.cwday |
|
148 | 148 | (@date_to - @date_from + 1).to_i.times do |
|
149 | 149 | width = zoom - 1 |
|
150 | 150 | %> |
|
151 | 151 | <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr"> |
|
152 | 152 | <%= day_name(wday).first %> |
|
153 | 153 | </div> |
|
154 | 154 | <% |
|
155 | 155 | left = left + width+1 |
|
156 | 156 | wday = wday + 1 |
|
157 | 157 | wday = 1 if wday > 7 |
|
158 | 158 | end |
|
159 | 159 | end %> |
|
160 | 160 | |
|
161 | 161 | <% |
|
162 | 162 | # |
|
163 | 163 | # Tasks |
|
164 | 164 | # |
|
165 | 165 | top = headers_height + 10 |
|
166 | 166 | @events.each do |i| |
|
167 | 167 | if i.is_a? Issue |
|
168 | 168 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) |
|
169 |
i_end_date = (i.due_ |
|
|
169 | i_end_date = (i.due_before <= @date_to ? i.due_before : @date_to ) | |
|
170 | 170 | |
|
171 |
i_done_date = i.start_date + ((i.due_ |
|
|
171 | i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor | |
|
172 | 172 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) |
|
173 | 173 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) |
|
174 | 174 | |
|
175 | 175 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today |
|
176 | 176 | |
|
177 | 177 | i_left = ((i_start_date - @date_from)*zoom).floor |
|
178 | 178 | i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders) |
|
179 | 179 | d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width |
|
180 | 180 | l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width |
|
181 | 181 | %> |
|
182 | 182 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div> |
|
183 | 183 | <% if l_width > 0 %> |
|
184 | 184 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div> |
|
185 | 185 | <% end %> |
|
186 | 186 | <% if d_width > 0 %> |
|
187 | 187 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div> |
|
188 | 188 | <% end %> |
|
189 | 189 | <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task"> |
|
190 | 190 | <%= i.status.name %> |
|
191 | 191 | <%= (i.done_ratio).to_i %>% |
|
192 | 192 | </div> |
|
193 | 193 | <% # === tooltip === %> |
|
194 | 194 | <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;"> |
|
195 | 195 | <span class="tip"> |
|
196 | 196 | <%= render_issue_tooltip i %> |
|
197 | 197 | </span></div> |
|
198 | 198 | <% else |
|
199 | 199 | i_left = ((i.start_date - @date_from)*zoom).floor |
|
200 | 200 | %> |
|
201 | 201 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone"> </div> |
|
202 | 202 | <div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task"> |
|
203 | 203 | <%= h("#{i.project} -") unless @project && @project == i.project %> |
|
204 | 204 | <strong><%=h i %></strong> |
|
205 | 205 | </div> |
|
206 | 206 | <% end %> |
|
207 | 207 | <% top = top + 20 |
|
208 | 208 | end %> |
|
209 | 209 | |
|
210 | 210 | <% |
|
211 | 211 | # |
|
212 | 212 | # Today red line (excluded from cache) |
|
213 | 213 | # |
|
214 | 214 | if Date.today >= @date_from and Date.today <= @date_to %> |
|
215 | 215 | <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;"> </div> |
|
216 | 216 | <% end %> |
|
217 | 217 | |
|
218 | 218 | </div> |
|
219 | 219 | </td> |
|
220 | 220 | </tr> |
|
221 | 221 | </table> |
|
222 | 222 | |
|
223 | 223 | <table width="100%"> |
|
224 | 224 | <tr> |
|
225 | 225 | <td align="left"><%= link_to ('« ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td> |
|
226 | 226 | <td align="right"><%= link_to (l(:label_next) + ' »'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td> |
|
227 | 227 | </tr> |
|
228 | 228 | </table> |
|
229 | 229 | |
|
230 | 230 | <p class="other-formats"> |
|
231 | 231 | <%= l(:label_export_to) %> |
|
232 | 232 | <span><%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :format => 'pdf'}, :class => 'pdf' %></span> |
|
233 | 233 | <%= content_tag('span', link_to('PNG', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :format => 'png'}, :class => 'image')) if respond_to?('gantt_image') %> |
|
234 | 234 | </p> |
|
235 | 235 | |
|
236 | 236 | <% content_for :sidebar do %> |
|
237 | 237 | <h3><%= l(:label_gantt) %></h3> |
|
238 | 238 | <% form_tag(params.merge(:tracker_ids => nil, :with_subprojects => nil), :method => :get) do %> |
|
239 | 239 | <% @trackers.each do |tracker| %> |
|
240 | 240 | <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> <%= tracker.name %></label><br /> |
|
241 | 241 | <% end %> |
|
242 | 242 | <% if @project.active_children.any? %> |
|
243 | 243 | <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label> |
|
244 | 244 | <%= hidden_field_tag 'with_subprojects', 0 %> |
|
245 | 245 | <% end %> |
|
246 | 246 | <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p> |
|
247 | 247 | <% end %> |
|
248 | 248 | <% end %> |
|
249 | 249 | |
|
250 | 250 | <% html_title(l(:label_gantt)) -%> |
@@ -1,90 +1,94 | |||
|
1 | 1 | --- |
|
2 | 2 | issues_001: |
|
3 | 3 | created_on: <%= 3.days.ago.to_date.to_s(:db) %> |
|
4 | 4 | project_id: 1 |
|
5 | 5 | updated_on: <%= 1.day.ago.to_date.to_s(:db) %> |
|
6 | 6 | priority_id: 4 |
|
7 | 7 | subject: Can't print recipes |
|
8 | 8 | id: 1 |
|
9 | 9 | fixed_version_id: |
|
10 | 10 | category_id: 1 |
|
11 | 11 | description: Unable to print recipes |
|
12 | 12 | tracker_id: 1 |
|
13 | 13 | assigned_to_id: |
|
14 | 14 | author_id: 2 |
|
15 | 15 | status_id: 1 |
|
16 | start_date: <%= 1.day.ago.to_date.to_s(:db) %> | |
|
17 | due_date: <%= 10.day.from_now.to_date.to_s(:db) %> | |
|
16 | 18 | issues_002: |
|
17 | 19 | created_on: 2006-07-19 21:04:21 +02:00 |
|
18 | 20 | project_id: 1 |
|
19 | 21 | updated_on: 2006-07-19 21:09:50 +02:00 |
|
20 | 22 | priority_id: 5 |
|
21 | 23 | subject: Add ingredients categories |
|
22 | 24 | id: 2 |
|
23 | fixed_version_id: | |
|
25 | fixed_version_id: 2 | |
|
24 | 26 | category_id: |
|
25 | 27 | description: Ingredients of the recipe should be classified by categories |
|
26 | 28 | tracker_id: 2 |
|
27 | 29 | assigned_to_id: 3 |
|
28 | 30 | author_id: 2 |
|
29 | 31 | status_id: 2 |
|
32 | start_date: <%= 2.day.ago.to_date.to_s(:db) %> | |
|
33 | due_date: | |
|
30 | 34 | issues_003: |
|
31 | 35 | created_on: 2006-07-19 21:07:27 +02:00 |
|
32 | 36 | project_id: 1 |
|
33 | 37 | updated_on: 2006-07-19 21:07:27 +02:00 |
|
34 | 38 | priority_id: 4 |
|
35 | 39 | subject: Error 281 when updating a recipe |
|
36 | 40 | id: 3 |
|
37 | 41 | fixed_version_id: |
|
38 | 42 | category_id: |
|
39 | 43 | description: Error 281 is encountered when saving a recipe |
|
40 | 44 | tracker_id: 1 |
|
41 | 45 | assigned_to_id: |
|
42 | 46 | author_id: 2 |
|
43 | 47 | status_id: 1 |
|
44 | 48 | start_date: <%= 1.day.from_now.to_date.to_s(:db) %> |
|
45 | 49 | due_date: <%= 40.day.ago.to_date.to_s(:db) %> |
|
46 | 50 | issues_004: |
|
47 | 51 | created_on: <%= 5.days.ago.to_date.to_s(:db) %> |
|
48 | 52 | project_id: 2 |
|
49 | 53 | updated_on: <%= 2.days.ago.to_date.to_s(:db) %> |
|
50 | 54 | priority_id: 4 |
|
51 | 55 | subject: Issue on project 2 |
|
52 | 56 | id: 4 |
|
53 | 57 | fixed_version_id: |
|
54 | 58 | category_id: |
|
55 | 59 | description: Issue on project 2 |
|
56 | 60 | tracker_id: 1 |
|
57 | 61 | assigned_to_id: |
|
58 | 62 | author_id: 2 |
|
59 | 63 | status_id: 1 |
|
60 | 64 | issues_005: |
|
61 | 65 | created_on: <%= 5.days.ago.to_date.to_s(:db) %> |
|
62 | 66 | project_id: 3 |
|
63 | 67 | updated_on: <%= 2.days.ago.to_date.to_s(:db) %> |
|
64 | 68 | priority_id: 4 |
|
65 | 69 | subject: Subproject issue |
|
66 | 70 | id: 5 |
|
67 | 71 | fixed_version_id: |
|
68 | 72 | category_id: |
|
69 | 73 | description: This is an issue on a cookbook subproject |
|
70 | 74 | tracker_id: 1 |
|
71 | 75 | assigned_to_id: |
|
72 | 76 | author_id: 2 |
|
73 | 77 | status_id: 1 |
|
74 | 78 | issues_006: |
|
75 | 79 | created_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
76 | 80 | project_id: 5 |
|
77 | 81 | updated_on: <%= 1.minute.ago.to_date.to_s(:db) %> |
|
78 | 82 | priority_id: 4 |
|
79 | 83 | subject: Issue of a private subproject |
|
80 | 84 | id: 6 |
|
81 | 85 | fixed_version_id: |
|
82 | 86 | category_id: |
|
83 | 87 | description: This is an issue of a private subproject of cookbook |
|
84 | 88 | tracker_id: 1 |
|
85 | 89 | assigned_to_id: |
|
86 | 90 | author_id: 2 |
|
87 | 91 | status_id: 1 |
|
88 | 92 | start_date: <%= Date.today.to_s(:db) %> |
|
89 | 93 | due_date: <%= 1.days.from_now.to_date.to_s(:db) %> |
|
90 | 94 | No newline at end of file |
@@ -1,26 +1,26 | |||
|
1 | 1 | --- |
|
2 | 2 | versions_001: |
|
3 | 3 | created_on: 2006-07-19 21:00:07 +02:00 |
|
4 | 4 | name: "0.1" |
|
5 | 5 | project_id: 1 |
|
6 | 6 | updated_on: 2006-07-19 21:00:07 +02:00 |
|
7 | 7 | id: 1 |
|
8 | 8 | description: Beta |
|
9 | 9 | effective_date: 2006-07-01 |
|
10 | 10 | versions_002: |
|
11 | 11 | created_on: 2006-07-19 21:00:33 +02:00 |
|
12 | 12 | name: "1.0" |
|
13 | 13 | project_id: 1 |
|
14 | 14 | updated_on: 2006-07-19 21:00:33 +02:00 |
|
15 | 15 | id: 2 |
|
16 | 16 | description: Stable release |
|
17 | effective_date: 2006-07-19 | |
|
17 | effective_date: <%= 20.day.from_now.to_date.to_s(:db) %> | |
|
18 | 18 | versions_003: |
|
19 | 19 | created_on: 2006-07-19 21:00:33 +02:00 |
|
20 | 20 | name: "2.0" |
|
21 | 21 | project_id: 1 |
|
22 | 22 | updated_on: 2006-07-19 21:00:33 +02:00 |
|
23 | 23 | id: 3 |
|
24 | 24 | description: Future version |
|
25 | 25 | effective_date: |
|
26 | 26 | No newline at end of file |
@@ -1,304 +1,313 | |||
|
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'projects_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, |
|
26 | 26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages |
|
27 | 27 | |
|
28 | 28 | def setup |
|
29 | 29 | @controller = ProjectsController.new |
|
30 | 30 | @request = ActionController::TestRequest.new |
|
31 | 31 | @response = ActionController::TestResponse.new |
|
32 | 32 | @request.session[:user_id] = nil |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index |
|
36 | 36 | get :index |
|
37 | 37 | assert_response :success |
|
38 | 38 | assert_template 'list' |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_list |
|
42 | 42 | get :list |
|
43 | 43 | assert_response :success |
|
44 | 44 | assert_template 'list' |
|
45 | 45 | assert_not_nil assigns(:project_tree) |
|
46 | 46 | # Root project as hash key |
|
47 | 47 | assert assigns(:project_tree).has_key?(Project.find(1)) |
|
48 | 48 | # Subproject in corresponding value |
|
49 | 49 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_show_by_id |
|
53 | 53 | get :show, :id => 1 |
|
54 | 54 | assert_response :success |
|
55 | 55 | assert_template 'show' |
|
56 | 56 | assert_not_nil assigns(:project) |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def test_show_by_identifier |
|
60 | 60 | get :show, :id => 'ecookbook' |
|
61 | 61 | assert_response :success |
|
62 | 62 | assert_template 'show' |
|
63 | 63 | assert_not_nil assigns(:project) |
|
64 | 64 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_private_subprojects_hidden |
|
68 | 68 | get :show, :id => 'ecookbook' |
|
69 | 69 | assert_response :success |
|
70 | 70 | assert_template 'show' |
|
71 | 71 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def test_private_subprojects_visible |
|
75 | 75 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
76 | 76 | get :show, :id => 'ecookbook' |
|
77 | 77 | assert_response :success |
|
78 | 78 | assert_template 'show' |
|
79 | 79 | assert_tag :tag => 'a', :content => /Private child/ |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | def test_settings |
|
83 | 83 | @request.session[:user_id] = 2 # manager |
|
84 | 84 | get :settings, :id => 1 |
|
85 | 85 | assert_response :success |
|
86 | 86 | assert_template 'settings' |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def test_edit |
|
90 | 90 | @request.session[:user_id] = 2 # manager |
|
91 | 91 | post :edit, :id => 1, :project => {:name => 'Test changed name', |
|
92 | 92 | :custom_field_ids => ['']} |
|
93 | 93 | assert_redirected_to 'projects/settings/ecookbook' |
|
94 | 94 | project = Project.find(1) |
|
95 | 95 | assert_equal 'Test changed name', project.name |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_get_destroy |
|
99 | 99 | @request.session[:user_id] = 1 # admin |
|
100 | 100 | get :destroy, :id => 1 |
|
101 | 101 | assert_response :success |
|
102 | 102 | assert_template 'destroy' |
|
103 | 103 | assert_not_nil Project.find_by_id(1) |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def test_post_destroy |
|
107 | 107 | @request.session[:user_id] = 1 # admin |
|
108 | 108 | post :destroy, :id => 1, :confirm => 1 |
|
109 | 109 | assert_redirected_to 'admin/projects' |
|
110 | 110 | assert_nil Project.find_by_id(1) |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def test_list_files |
|
114 | 114 | get :list_files, :id => 1 |
|
115 | 115 | assert_response :success |
|
116 | 116 | assert_template 'list_files' |
|
117 | 117 | assert_not_nil assigns(:versions) |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | def test_changelog |
|
121 | 121 | get :changelog, :id => 1 |
|
122 | 122 | assert_response :success |
|
123 | 123 | assert_template 'changelog' |
|
124 | 124 | assert_not_nil assigns(:versions) |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def test_roadmap |
|
128 | 128 | get :roadmap, :id => 1 |
|
129 | 129 | assert_response :success |
|
130 | 130 | assert_template 'roadmap' |
|
131 | 131 | assert_not_nil assigns(:versions) |
|
132 | 132 | # Version with no date set appears |
|
133 | 133 | assert assigns(:versions).include?(Version.find(3)) |
|
134 | 134 | # Completed version doesn't appear |
|
135 | 135 | assert !assigns(:versions).include?(Version.find(1)) |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_roadmap_with_completed_versions |
|
139 | 139 | get :roadmap, :id => 1, :completed => 1 |
|
140 | 140 | assert_response :success |
|
141 | 141 | assert_template 'roadmap' |
|
142 | 142 | assert_not_nil assigns(:versions) |
|
143 | 143 | # Version with no date set appears |
|
144 | 144 | assert assigns(:versions).include?(Version.find(3)) |
|
145 | 145 | # Completed version appears |
|
146 | 146 | assert assigns(:versions).include?(Version.find(1)) |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | def test_project_activity |
|
150 | 150 | get :activity, :id => 1, :with_subprojects => 0 |
|
151 | 151 | assert_response :success |
|
152 | 152 | assert_template 'activity' |
|
153 | 153 | assert_not_nil assigns(:events_by_day) |
|
154 | 154 | assert_not_nil assigns(:events) |
|
155 | 155 | |
|
156 | 156 | # subproject issue not included by default |
|
157 | 157 | assert !assigns(:events).include?(Issue.find(5)) |
|
158 | 158 | |
|
159 | 159 | assert_tag :tag => "h3", |
|
160 | 160 | :content => /#{2.days.ago.to_date.day}/, |
|
161 | 161 | :sibling => { :tag => "dl", |
|
162 | 162 | :child => { :tag => "dt", |
|
163 | 163 | :attributes => { :class => 'issue-edit' }, |
|
164 | 164 | :child => { :tag => "a", |
|
165 | 165 | :content => /(#{IssueStatus.find(2).name})/, |
|
166 | 166 | } |
|
167 | 167 | } |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | get :activity, :id => 1, :from => 3.days.ago.to_date |
|
171 | 171 | assert_response :success |
|
172 | 172 | assert_template 'activity' |
|
173 | 173 | assert_not_nil assigns(:events_by_day) |
|
174 | 174 | |
|
175 | 175 | assert_tag :tag => "h3", |
|
176 | 176 | :content => /#{3.day.ago.to_date.day}/, |
|
177 | 177 | :sibling => { :tag => "dl", |
|
178 | 178 | :child => { :tag => "dt", |
|
179 | 179 | :attributes => { :class => 'issue' }, |
|
180 | 180 | :child => { :tag => "a", |
|
181 | 181 | :content => /#{Issue.find(1).subject}/, |
|
182 | 182 | } |
|
183 | 183 | } |
|
184 | 184 | } |
|
185 | 185 | end |
|
186 | 186 | |
|
187 | 187 | def test_activity_with_subprojects |
|
188 | 188 | get :activity, :id => 1, :with_subprojects => 1 |
|
189 | 189 | assert_response :success |
|
190 | 190 | assert_template 'activity' |
|
191 | 191 | assert_not_nil assigns(:events) |
|
192 | 192 | |
|
193 | 193 | assert assigns(:events).include?(Issue.find(1)) |
|
194 | 194 | assert !assigns(:events).include?(Issue.find(4)) |
|
195 | 195 | # subproject issue |
|
196 | 196 | assert assigns(:events).include?(Issue.find(5)) |
|
197 | 197 | end |
|
198 | 198 | |
|
199 | 199 | def test_global_activity_anonymous |
|
200 | 200 | get :activity |
|
201 | 201 | assert_response :success |
|
202 | 202 | assert_template 'activity' |
|
203 | 203 | assert_not_nil assigns(:events) |
|
204 | 204 | |
|
205 | 205 | assert assigns(:events).include?(Issue.find(1)) |
|
206 | 206 | # Issue of a private project |
|
207 | 207 | assert !assigns(:events).include?(Issue.find(4)) |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def test_global_activity_logged_user |
|
211 | 211 | @request.session[:user_id] = 2 # manager |
|
212 | 212 | get :activity |
|
213 | 213 | assert_response :success |
|
214 | 214 | assert_template 'activity' |
|
215 | 215 | assert_not_nil assigns(:events) |
|
216 | 216 | |
|
217 | 217 | assert assigns(:events).include?(Issue.find(1)) |
|
218 | 218 | # Issue of a private project the user belongs to |
|
219 | 219 | assert assigns(:events).include?(Issue.find(4)) |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | |
|
223 | 223 | def test_global_activity_with_all_types |
|
224 | 224 | get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1 |
|
225 | 225 | assert_response :success |
|
226 | 226 | assert_template 'activity' |
|
227 | 227 | assert_not_nil assigns(:events) |
|
228 | 228 | |
|
229 | 229 | assert assigns(:events).include?(Issue.find(1)) |
|
230 | 230 | assert !assigns(:events).include?(Issue.find(4)) |
|
231 | 231 | assert assigns(:events).include?(Message.find(5)) |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | def test_calendar |
|
235 | 235 | get :calendar, :id => 1 |
|
236 | 236 | assert_response :success |
|
237 | 237 | assert_template 'calendar' |
|
238 | 238 | assert_not_nil assigns(:calendar) |
|
239 | 239 | end |
|
240 | 240 | |
|
241 | 241 | def test_calendar_with_subprojects_should_not_show_private_subprojects |
|
242 | 242 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
243 | 243 | assert_response :success |
|
244 | 244 | assert_template 'calendar' |
|
245 | 245 | assert_not_nil assigns(:calendar) |
|
246 | 246 | assert_no_tag :tag => 'a', :content => /#6/ |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | def test_calendar_with_subprojects_should_show_private_subprojects |
|
250 | 250 | @request.session[:user_id] = 2 |
|
251 | 251 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
252 | 252 | assert_response :success |
|
253 | 253 | assert_template 'calendar' |
|
254 | 254 | assert_not_nil assigns(:calendar) |
|
255 | 255 | assert_tag :tag => 'a', :content => /#6/ |
|
256 | 256 | end |
|
257 | 257 | |
|
258 | 258 | def test_gantt |
|
259 | 259 | get :gantt, :id => 1 |
|
260 | 260 | assert_response :success |
|
261 | 261 | assert_template 'gantt.rhtml' |
|
262 |
|
|
|
262 | events = assigns(:events) | |
|
263 | assert_not_nil events | |
|
264 | # Issue with start and due dates | |
|
265 | i = Issue.find(1) | |
|
266 | assert_not_nil i.due_date | |
|
267 | assert events.include?(Issue.find(1)) | |
|
268 | # Issue with without due date but targeted to a version with date | |
|
269 | i = Issue.find(2) | |
|
270 | assert_nil i.due_date | |
|
271 | assert events.include?(i) | |
|
263 | 272 | end |
|
264 | 273 | |
|
265 | 274 | def test_gantt_with_subprojects_should_not_show_private_subprojects |
|
266 | 275 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
267 | 276 | assert_response :success |
|
268 | 277 | assert_template 'gantt.rhtml' |
|
269 | 278 | assert_not_nil assigns(:events) |
|
270 | 279 | assert_no_tag :tag => 'a', :content => /#6/ |
|
271 | 280 | end |
|
272 | 281 | |
|
273 | 282 | def test_gantt_with_subprojects_should_show_private_subprojects |
|
274 | 283 | @request.session[:user_id] = 2 |
|
275 | 284 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
276 | 285 | assert_response :success |
|
277 | 286 | assert_template 'gantt.rhtml' |
|
278 | 287 | assert_not_nil assigns(:events) |
|
279 | 288 | assert_tag :tag => 'a', :content => /#6/ |
|
280 | 289 | end |
|
281 | 290 | |
|
282 | 291 | def test_gantt_export_to_pdf |
|
283 | 292 | get :gantt, :id => 1, :format => 'pdf' |
|
284 | 293 | assert_response :success |
|
285 | 294 | assert_template 'gantt.rfpdf' |
|
286 | 295 | assert_equal 'application/pdf', @response.content_type |
|
287 | 296 | assert_not_nil assigns(:events) |
|
288 | 297 | end |
|
289 | 298 | |
|
290 | 299 | def test_archive |
|
291 | 300 | @request.session[:user_id] = 1 # admin |
|
292 | 301 | post :archive, :id => 1 |
|
293 | 302 | assert_redirected_to 'admin/projects' |
|
294 | 303 | assert !Project.find(1).active? |
|
295 | 304 | end |
|
296 | 305 | |
|
297 | 306 | def test_unarchive |
|
298 | 307 | @request.session[:user_id] = 1 # admin |
|
299 | 308 | Project.find(1).archive |
|
300 | 309 | post :unarchive, :id => 1 |
|
301 | 310 | assert_redirected_to 'admin/projects' |
|
302 | 311 | assert Project.find(1).active? |
|
303 | 312 | end |
|
304 | 313 | end |
@@ -1,73 +1,73 | |||
|
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'versions_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class VersionsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class VersionsControllerTest < Test::Unit::TestCase |
|
25 | fixtures :projects, :versions, :users, :roles, :members, :enabled_modules | |
|
25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :enabled_modules | |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = VersionsController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_show |
|
35 | 35 | get :show, :id => 2 |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_template 'show' |
|
38 | 38 | assert_not_nil assigns(:version) |
|
39 | 39 | |
|
40 | 40 | assert_tag :tag => 'h2', :content => /1.0/ |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_get_edit |
|
44 | 44 | @request.session[:user_id] = 2 |
|
45 | 45 | get :edit, :id => 2 |
|
46 | 46 | assert_response :success |
|
47 | 47 | assert_template 'edit' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def test_post_edit |
|
51 | 51 | @request.session[:user_id] = 2 |
|
52 | 52 | post :edit, :id => 2, |
|
53 | 53 | :version => { :name => 'New version name', |
|
54 | 54 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
55 | 55 | assert_redirected_to 'projects/settings/ecookbook' |
|
56 | 56 | version = Version.find(2) |
|
57 | 57 | assert_equal 'New version name', version.name |
|
58 | 58 | assert_equal Date.today, version.effective_date |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_destroy |
|
62 | 62 | @request.session[:user_id] = 2 |
|
63 |
post :destroy, :id => |
|
|
63 | post :destroy, :id => 3 | |
|
64 | 64 | assert_redirected_to 'projects/settings/ecookbook' |
|
65 |
assert_nil Version.find_by_id( |
|
|
65 | assert_nil Version.find_by_id(3) | |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_issue_status_by |
|
69 | 69 | xhr :get, :status_by, :id => 2 |
|
70 | 70 | assert_response :success |
|
71 | 71 | assert_template '_issue_counts' |
|
72 | 72 | end |
|
73 | 73 | end |
General Comments 0
You need to be logged in to leave comments.
Login now