@@ -1,673 +1,677 | |||
|
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 'csv' |
|
19 | 19 | |
|
20 | 20 | class ProjectsController < ApplicationController |
|
21 | 21 | layout 'base' |
|
22 | 22 | before_filter :find_project, :authorize, :except => [ :index, :list, :add ] |
|
23 | 23 | before_filter :require_admin, :only => [ :add, :destroy ] |
|
24 | 24 | |
|
25 | 25 | helper :sort |
|
26 | 26 | include SortHelper |
|
27 | 27 | helper :custom_fields |
|
28 | 28 | include CustomFieldsHelper |
|
29 | 29 | helper :ifpdf |
|
30 | 30 | include IfpdfHelper |
|
31 | 31 | helper IssuesHelper |
|
32 | 32 | helper :queries |
|
33 | 33 | include QueriesHelper |
|
34 | 34 | |
|
35 | 35 | def index |
|
36 | 36 | list |
|
37 | 37 | render :action => 'list' unless request.xhr? |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | # Lists public projects |
|
41 | 41 | def list |
|
42 | 42 | sort_init 'name', 'asc' |
|
43 | 43 | sort_update |
|
44 | 44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) |
|
45 | 45 | @project_pages = Paginator.new self, @project_count, |
|
46 | 46 | 15, |
|
47 | 47 | params['page'] |
|
48 | 48 | @projects = Project.find :all, :order => sort_clause, |
|
49 | 49 | :conditions => ["is_public=?", true], |
|
50 | 50 | :limit => @project_pages.items_per_page, |
|
51 | 51 | :offset => @project_pages.current.offset |
|
52 | 52 | |
|
53 | 53 | render :action => "list", :layout => false if request.xhr? |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | # Add a new project |
|
57 | 57 | def add |
|
58 | 58 | @custom_fields = IssueCustomField.find(:all) |
|
59 | 59 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
60 | 60 | @project = Project.new(params[:project]) |
|
61 | 61 | if request.get? |
|
62 | 62 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
63 | 63 | else |
|
64 | 64 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
65 | 65 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
66 | 66 | @project.custom_values = @custom_values |
|
67 | 67 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
68 | 68 | @project.repository = Repository.new |
|
69 | 69 | @project.repository.attributes = params[:repository] |
|
70 | 70 | end |
|
71 | 71 | if "1" == params[:wiki_enabled] |
|
72 | 72 | @project.wiki = Wiki.new |
|
73 | 73 | @project.wiki.attributes = params[:wiki] |
|
74 | 74 | end |
|
75 | 75 | if @project.save |
|
76 | 76 | flash[:notice] = l(:notice_successful_create) |
|
77 | 77 | redirect_to :controller => 'admin', :action => 'projects' |
|
78 | 78 | end |
|
79 | 79 | end |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | # Show @project |
|
83 | 83 | def show |
|
84 | 84 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
85 | 85 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') |
|
86 | 86 | @subprojects = @project.children if @project.children.size > 0 |
|
87 | 87 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
88 | 88 | @trackers = Tracker.find(:all, :order => 'position') |
|
89 | 89 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) |
|
90 | 90 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def settings |
|
94 | 94 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
95 | 95 | @custom_fields = IssueCustomField.find(:all) |
|
96 | 96 | @issue_category ||= IssueCategory.new |
|
97 | 97 | @member ||= @project.members.new |
|
98 | 98 | @roles = Role.find(:all, :order => 'position') |
|
99 | 99 | @users = User.find_active(:all) - @project.users |
|
100 | 100 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
101 | 101 | end |
|
102 | 102 | |
|
103 | 103 | # Edit @project |
|
104 | 104 | def edit |
|
105 | 105 | if request.post? |
|
106 | 106 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
107 | 107 | if params[:custom_fields] |
|
108 | 108 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
109 | 109 | @project.custom_values = @custom_values |
|
110 | 110 | end |
|
111 | 111 | if params[:repository_enabled] |
|
112 | 112 | case params[:repository_enabled] |
|
113 | 113 | when "0" |
|
114 | 114 | @project.repository = nil |
|
115 | 115 | when "1" |
|
116 | 116 | @project.repository ||= Repository.new |
|
117 | 117 | @project.repository.update_attributes params[:repository] |
|
118 | 118 | end |
|
119 | 119 | end |
|
120 | 120 | if params[:wiki_enabled] |
|
121 | 121 | case params[:wiki_enabled] |
|
122 | 122 | when "0" |
|
123 | 123 | @project.wiki.destroy if @project.wiki |
|
124 | 124 | when "1" |
|
125 | 125 | @project.wiki ||= Wiki.new |
|
126 | 126 | @project.wiki.update_attributes params[:wiki] |
|
127 | 127 | end |
|
128 | 128 | end |
|
129 | 129 | @project.attributes = params[:project] |
|
130 | 130 | if @project.save |
|
131 | 131 | flash[:notice] = l(:notice_successful_update) |
|
132 | 132 | redirect_to :action => 'settings', :id => @project |
|
133 | 133 | else |
|
134 | 134 | settings |
|
135 | 135 | render :action => 'settings' |
|
136 | 136 | end |
|
137 | 137 | end |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | # Delete @project |
|
141 | 141 | def destroy |
|
142 | 142 | if request.post? and params[:confirm] |
|
143 | 143 | @project.destroy |
|
144 | 144 | redirect_to :controller => 'admin', :action => 'projects' |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | # Add a new issue category to @project |
|
149 | 149 | def add_issue_category |
|
150 | 150 | if request.post? |
|
151 | 151 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
152 | 152 | if @issue_category.save |
|
153 | 153 | flash[:notice] = l(:notice_successful_create) |
|
154 | 154 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
155 | 155 | else |
|
156 | 156 | settings |
|
157 | 157 | render :action => 'settings' |
|
158 | 158 | end |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | # Add a new version to @project |
|
163 | 163 | def add_version |
|
164 | 164 | @version = @project.versions.build(params[:version]) |
|
165 | 165 | if request.post? and @version.save |
|
166 | 166 | flash[:notice] = l(:notice_successful_create) |
|
167 | 167 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
168 | 168 | end |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | # Add a new member to @project |
|
172 | 172 | def add_member |
|
173 | 173 | @member = @project.members.build(params[:member]) |
|
174 | 174 | if request.post? |
|
175 | 175 | if @member.save |
|
176 | 176 | flash[:notice] = l(:notice_successful_create) |
|
177 | 177 | redirect_to :action => 'settings', :tab => 'members', :id => @project |
|
178 | 178 | else |
|
179 | 179 | settings |
|
180 | 180 | render :action => 'settings' |
|
181 | 181 | end |
|
182 | 182 | end |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | # Show members list of @project |
|
186 | 186 | def list_members |
|
187 | 187 | @members = @project.members.find(:all) |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | 190 | # Add a new document to @project |
|
191 | 191 | def add_document |
|
192 | 192 | @categories = Enumeration::get_values('DCAT') |
|
193 | 193 | @document = @project.documents.build(params[:document]) |
|
194 | 194 | if request.post? and @document.save |
|
195 | 195 | # Save the attachments |
|
196 | 196 | params[:attachments].each { |a| |
|
197 | 197 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
198 | 198 | } if params[:attachments] and params[:attachments].is_a? Array |
|
199 | 199 | flash[:notice] = l(:notice_successful_create) |
|
200 | 200 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
201 | 201 | redirect_to :action => 'list_documents', :id => @project |
|
202 | 202 | end |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | # Show documents list of @project |
|
206 | 206 | def list_documents |
|
207 | 207 | @documents = @project.documents.find :all, :include => :category |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | # Add a new issue to @project |
|
211 | 211 | def add_issue |
|
212 | 212 | @tracker = Tracker.find(params[:tracker_id]) |
|
213 | 213 | @priorities = Enumeration::get_values('IPRI') |
|
214 | 214 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
215 | 215 | if request.get? |
|
216 | 216 | @issue.start_date = Date.today |
|
217 | 217 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
218 | 218 | else |
|
219 | 219 | @issue.attributes = params[:issue] |
|
220 | 220 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
221 | 221 | # Multiple file upload |
|
222 | 222 | @attachments = [] |
|
223 | 223 | params[:attachments].each { |a| |
|
224 | 224 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
225 | 225 | } if params[:attachments] and params[:attachments].is_a? Array |
|
226 | 226 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
227 | 227 | @issue.custom_values = @custom_values |
|
228 | 228 | if @issue.save |
|
229 | 229 | @attachments.each(&:save) |
|
230 | 230 | flash[:notice] = l(:notice_successful_create) |
|
231 | 231 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
232 | 232 | redirect_to :action => 'list_issues', :id => @project |
|
233 | 233 | end |
|
234 | 234 | end |
|
235 | 235 | end |
|
236 | 236 | |
|
237 | 237 | # Show filtered/sorted issues list of @project |
|
238 | 238 | def list_issues |
|
239 | 239 | sort_init "#{Issue.table_name}.id", "desc" |
|
240 | 240 | sort_update |
|
241 | 241 | |
|
242 | 242 | retrieve_query |
|
243 | 243 | |
|
244 | 244 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
245 | 245 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
246 | 246 | @results_per_page = params[:per_page].to_i |
|
247 | 247 | session[:results_per_page] = @results_per_page |
|
248 | 248 | else |
|
249 | 249 | @results_per_page = session[:results_per_page] || 25 |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | if @query.valid? |
|
253 | 253 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
254 | 254 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
255 | 255 | @issues = Issue.find :all, :order => sort_clause, |
|
256 | 256 | :include => [ :author, :status, :tracker, :project, :priority ], |
|
257 | 257 | :conditions => @query.statement, |
|
258 | 258 | :limit => @issue_pages.items_per_page, |
|
259 | 259 | :offset => @issue_pages.current.offset |
|
260 | 260 | end |
|
261 | 261 | @trackers = Tracker.find :all, :order => 'position' |
|
262 | 262 | render :layout => false if request.xhr? |
|
263 | 263 | end |
|
264 | 264 | |
|
265 | 265 | # Export filtered/sorted issues list to CSV |
|
266 | 266 | def export_issues_csv |
|
267 | 267 | sort_init "#{Issue.table_name}.id", "desc" |
|
268 | 268 | sort_update |
|
269 | 269 | |
|
270 | 270 | retrieve_query |
|
271 | 271 | render :action => 'list_issues' and return unless @query.valid? |
|
272 | 272 | |
|
273 | 273 | @issues = Issue.find :all, :order => sort_clause, |
|
274 | 274 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], |
|
275 | 275 | :conditions => @query.statement, |
|
276 | 276 | :limit => Setting.issues_export_limit |
|
277 | 277 | |
|
278 | 278 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
279 | 279 | export = StringIO.new |
|
280 | 280 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
281 | 281 | # csv header fields |
|
282 | 282 | headers = [ "#", l(:field_status), |
|
283 | 283 | l(:field_tracker), |
|
284 | 284 | l(:field_priority), |
|
285 | 285 | l(:field_subject), |
|
286 | 286 | l(:field_author), |
|
287 | 287 | l(:field_start_date), |
|
288 | 288 | l(:field_due_date), |
|
289 | 289 | l(:field_done_ratio), |
|
290 | 290 | l(:field_created_on), |
|
291 | 291 | l(:field_updated_on) |
|
292 | 292 | ] |
|
293 | 293 | for custom_field in @project.all_custom_fields |
|
294 | 294 | headers << custom_field.name |
|
295 | 295 | end |
|
296 | 296 | csv << headers.collect {|c| ic.iconv(c) } |
|
297 | 297 | # csv lines |
|
298 | 298 | @issues.each do |issue| |
|
299 | 299 | fields = [issue.id, issue.status.name, |
|
300 | 300 | issue.tracker.name, |
|
301 | 301 | issue.priority.name, |
|
302 | 302 | issue.subject, |
|
303 | 303 | issue.author.display_name, |
|
304 | 304 | issue.start_date ? l_date(issue.start_date) : nil, |
|
305 | 305 | issue.due_date ? l_date(issue.due_date) : nil, |
|
306 | 306 | issue.done_ratio, |
|
307 | 307 | l_datetime(issue.created_on), |
|
308 | 308 | l_datetime(issue.updated_on) |
|
309 | 309 | ] |
|
310 | 310 | for custom_field in @project.all_custom_fields |
|
311 | 311 | fields << (show_value issue.custom_value_for(custom_field)) |
|
312 | 312 | end |
|
313 | 313 | csv << fields.collect {|c| ic.iconv(c.to_s) } |
|
314 | 314 | end |
|
315 | 315 | end |
|
316 | 316 | export.rewind |
|
317 | 317 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
318 | 318 | end |
|
319 | 319 | |
|
320 | 320 | # Export filtered/sorted issues to PDF |
|
321 | 321 | def export_issues_pdf |
|
322 | 322 | sort_init "#{Issue.table_name}.id", "desc" |
|
323 | 323 | sort_update |
|
324 | 324 | |
|
325 | 325 | retrieve_query |
|
326 | 326 | render :action => 'list_issues' and return unless @query.valid? |
|
327 | 327 | |
|
328 | 328 | @issues = Issue.find :all, :order => sort_clause, |
|
329 | 329 | :include => [ :author, :status, :tracker, :priority ], |
|
330 | 330 | :conditions => @query.statement, |
|
331 | 331 | :limit => Setting.issues_export_limit |
|
332 | 332 | |
|
333 | 333 | @options_for_rfpdf ||= {} |
|
334 | 334 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
335 | 335 | render :layout => false |
|
336 | 336 | end |
|
337 | 337 | |
|
338 | 338 | def move_issues |
|
339 | 339 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
340 | 340 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
341 | 341 | @projects = [] |
|
342 | 342 | # find projects to which the user is allowed to move the issue |
|
343 | 343 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)} |
|
344 | 344 | # issue can be moved to any tracker |
|
345 | 345 | @trackers = Tracker.find(:all) |
|
346 | 346 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
347 | 347 | new_project = Project.find(params[:new_project_id]) |
|
348 | 348 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
349 | 349 | @issues.each { |i| |
|
350 | 350 | # project dependent properties |
|
351 | 351 | unless i.project_id == new_project.id |
|
352 | 352 | i.category = nil |
|
353 | 353 | i.fixed_version = nil |
|
354 | 354 | end |
|
355 | 355 | # move the issue |
|
356 | 356 | i.project = new_project |
|
357 | 357 | i.tracker = new_tracker |
|
358 | 358 | i.save |
|
359 | 359 | } |
|
360 | 360 | flash[:notice] = l(:notice_successful_update) |
|
361 | 361 | redirect_to :action => 'list_issues', :id => @project |
|
362 | 362 | end |
|
363 | 363 | end |
|
364 | 364 | |
|
365 | 365 | def add_query |
|
366 | 366 | @query = Query.new(params[:query]) |
|
367 | 367 | @query.project = @project |
|
368 | 368 | @query.user = logged_in_user |
|
369 | 369 | |
|
370 | 370 | params[:fields].each do |field| |
|
371 | 371 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
372 | 372 | end if params[:fields] |
|
373 | 373 | |
|
374 | 374 | if request.post? and @query.save |
|
375 | 375 | flash[:notice] = l(:notice_successful_create) |
|
376 | 376 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project |
|
377 | 377 | end |
|
378 | 378 | render :layout => false if request.xhr? |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | # Add a news to @project |
|
382 | 382 | def add_news |
|
383 | 383 | @news = News.new(:project => @project) |
|
384 | 384 | if request.post? |
|
385 | 385 | @news.attributes = params[:news] |
|
386 | 386 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
387 | 387 | if @news.save |
|
388 | 388 | flash[:notice] = l(:notice_successful_create) |
|
389 | 389 | redirect_to :action => 'list_news', :id => @project |
|
390 | 390 | end |
|
391 | 391 | end |
|
392 | 392 | end |
|
393 | 393 | |
|
394 | 394 | # Show news list of @project |
|
395 | 395 | def list_news |
|
396 | 396 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
397 | 397 | render :action => "list_news", :layout => false if request.xhr? |
|
398 | 398 | end |
|
399 | 399 | |
|
400 | 400 | def add_file |
|
401 | 401 | if request.post? |
|
402 | 402 | @version = @project.versions.find_by_id(params[:version_id]) |
|
403 | 403 | # Save the attachments |
|
404 | 404 | @attachments = [] |
|
405 | 405 | params[:attachments].each { |file| |
|
406 | 406 | next unless file.size > 0 |
|
407 | 407 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
408 | 408 | @attachments << a unless a.new_record? |
|
409 | 409 | } if params[:attachments] and params[:attachments].is_a? Array |
|
410 | 410 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
411 | 411 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
412 | 412 | end |
|
413 | 413 | @versions = @project.versions |
|
414 | 414 | end |
|
415 | 415 | |
|
416 | 416 | def list_files |
|
417 | 417 | @versions = @project.versions |
|
418 | 418 | end |
|
419 | 419 | |
|
420 | 420 | # Show changelog for @project |
|
421 | 421 | def changelog |
|
422 | 422 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
423 | 423 | retrieve_selected_tracker_ids(@trackers) |
|
424 | 424 | |
|
425 | 425 | @fixed_issues = @project.issues.find(:all, |
|
426 | 426 | :include => [ :fixed_version, :status, :tracker ], |
|
427 | 427 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], |
|
428 | 428 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" |
|
429 | 429 | ) unless @selected_tracker_ids.empty? |
|
430 | 430 | @fixed_issues ||= [] |
|
431 | 431 | end |
|
432 | 432 | |
|
433 | 433 | def roadmap |
|
434 | 434 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
435 | 435 | retrieve_selected_tracker_ids(@trackers) |
|
436 | 436 | |
|
437 | 437 | @versions = @project.versions.find(:all, |
|
438 | 438 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], |
|
439 | 439 | :order => "#{Version.table_name}.effective_date ASC" |
|
440 | 440 | ) |
|
441 | 441 | end |
|
442 | 442 | |
|
443 | 443 | def activity |
|
444 | 444 | if params[:year] and params[:year].to_i > 1900 |
|
445 | 445 | @year = params[:year].to_i |
|
446 | 446 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
447 | 447 | @month = params[:month].to_i |
|
448 | 448 | end |
|
449 | 449 | end |
|
450 | 450 | @year ||= Date.today.year |
|
451 | 451 | @month ||= Date.today.month |
|
452 | 452 | |
|
453 | 453 | @date_from = Date.civil(@year, @month, 1) |
|
454 | 454 | @date_to = (@date_from >> 1)-1 |
|
455 | 455 | |
|
456 | 456 | @events_by_day = {} |
|
457 | 457 | |
|
458 | 458 | unless params[:show_issues] == "0" |
|
459 | 459 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
460 | 460 | @events_by_day[i.created_on.to_date] ||= [] |
|
461 | 461 | @events_by_day[i.created_on.to_date] << i |
|
462 | 462 | } |
|
463 | 463 | @show_issues = 1 |
|
464 | 464 | end |
|
465 | 465 | |
|
466 | 466 | unless params[:show_news] == "0" |
|
467 | 467 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
468 | 468 | @events_by_day[i.created_on.to_date] ||= [] |
|
469 | 469 | @events_by_day[i.created_on.to_date] << i |
|
470 | 470 | } |
|
471 | 471 | @show_news = 1 |
|
472 | 472 | end |
|
473 | 473 | |
|
474 | 474 | unless params[:show_files] == "0" |
|
475 | 475 | Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| |
|
476 | 476 | @events_by_day[i.created_on.to_date] ||= [] |
|
477 | 477 | @events_by_day[i.created_on.to_date] << i |
|
478 | 478 | } |
|
479 | 479 | @show_files = 1 |
|
480 | 480 | end |
|
481 | 481 | |
|
482 | 482 | unless params[:show_documents] == "0" |
|
483 | 483 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
484 | 484 | @events_by_day[i.created_on.to_date] ||= [] |
|
485 | 485 | @events_by_day[i.created_on.to_date] << i |
|
486 | 486 | } |
|
487 | 487 | Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i| |
|
488 | 488 | @events_by_day[i.created_on.to_date] ||= [] |
|
489 | 489 | @events_by_day[i.created_on.to_date] << i |
|
490 | 490 | } |
|
491 | 491 | @show_documents = 1 |
|
492 | 492 | end |
|
493 | 493 | |
|
494 | 494 | unless params[:show_wiki_edits] == "0" |
|
495 | 495 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + |
|
496 | 496 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
497 | 497 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
498 | 498 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
499 | 499 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
500 | 500 | @project.id, @date_from, @date_to] |
|
501 | 501 | |
|
502 | 502 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
503 | 503 | # We provide this alias so all events can be treated in the same manner |
|
504 | 504 | def i.created_on |
|
505 | 505 | self.updated_on |
|
506 | 506 | end |
|
507 | 507 | |
|
508 | 508 | @events_by_day[i.created_on.to_date] ||= [] |
|
509 | 509 | @events_by_day[i.created_on.to_date] << i |
|
510 | 510 | } |
|
511 | 511 | @show_wiki_edits = 1 |
|
512 | 512 | end |
|
513 | 513 | |
|
514 | 514 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
515 | 515 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
516 | 516 | def i.created_on |
|
517 | 517 | self.committed_on |
|
518 | 518 | end |
|
519 | 519 | @events_by_day[i.created_on.to_date] ||= [] |
|
520 | 520 | @events_by_day[i.created_on.to_date] << i |
|
521 | 521 | } |
|
522 | 522 | @show_changesets = 1 |
|
523 | 523 | end |
|
524 | 524 | |
|
525 | 525 | render :layout => false if request.xhr? |
|
526 | 526 | end |
|
527 | 527 | |
|
528 | 528 | def calendar |
|
529 | 529 | @trackers = Tracker.find(:all, :order => 'position') |
|
530 | 530 | retrieve_selected_tracker_ids(@trackers) |
|
531 | 531 | |
|
532 | 532 | if params[:year] and params[:year].to_i > 1900 |
|
533 | 533 | @year = params[:year].to_i |
|
534 | 534 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
535 | 535 | @month = params[:month].to_i |
|
536 | 536 | end |
|
537 | 537 | end |
|
538 | 538 | @year ||= Date.today.year |
|
539 | 539 | @month ||= Date.today.month |
|
540 | 540 | |
|
541 | 541 | @date_from = Date.civil(@year, @month, 1) |
|
542 | 542 | @date_to = (@date_from >> 1)-1 |
|
543 | 543 | # start on monday |
|
544 | 544 | @date_from = @date_from - (@date_from.cwday-1) |
|
545 | 545 | # finish on sunday |
|
546 | 546 | @date_to = @date_to + (7-@date_to.cwday) |
|
547 | 547 | |
|
548 | @issues = @project.issues.find(:all, | |
|
549 | :include => [:tracker, :status, :assigned_to, :priority], | |
|
550 | :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to] | |
|
551 | ) unless @selected_tracker_ids.empty? | |
|
548 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
|
549 | @issues = Issue.find(:all, | |
|
550 | :include => [:tracker, :status, :assigned_to, :priority], | |
|
551 | :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to] | |
|
552 | ) unless @selected_tracker_ids.empty? | |
|
553 | end | |
|
552 | 554 | @issues ||=[] |
|
553 | 555 | |
|
554 | 556 | @ending_issues_by_days = @issues.group_by {|issue| issue.due_date} |
|
555 | 557 | @starting_issues_by_days = @issues.group_by {|issue| issue.start_date} |
|
556 | 558 | |
|
557 | 559 | render :layout => false if request.xhr? |
|
558 | 560 | end |
|
559 | 561 | |
|
560 | 562 | def gantt |
|
561 | 563 | @trackers = Tracker.find(:all, :order => 'position') |
|
562 | 564 | retrieve_selected_tracker_ids(@trackers) |
|
563 | 565 | |
|
564 | 566 | if params[:year] and params[:year].to_i >0 |
|
565 | 567 | @year_from = params[:year].to_i |
|
566 | 568 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
567 | 569 | @month_from = params[:month].to_i |
|
568 | 570 | else |
|
569 | 571 | @month_from = 1 |
|
570 | 572 | end |
|
571 | 573 | else |
|
572 | 574 | @month_from ||= (Date.today << 1).month |
|
573 | 575 | @year_from ||= (Date.today << 1).year |
|
574 | 576 | end |
|
575 | 577 | |
|
576 | 578 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
577 | 579 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
578 | 580 | |
|
579 | 581 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
580 | 582 | @date_to = (@date_from >> @months) - 1 |
|
581 | 583 | |
|
582 | @issues = @project.issues.find(:all, | |
|
583 | :order => "start_date, due_date", | |
|
584 | :include => [:tracker, :status, :assigned_to, :priority], | |
|
585 | :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] | |
|
586 | ) unless @selected_tracker_ids.empty? | |
|
584 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
|
585 | @issues = Issue.find(:all, | |
|
586 | :order => "start_date, due_date", | |
|
587 | :include => [:tracker, :status, :assigned_to, :priority], | |
|
588 | :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] | |
|
589 | ) unless @selected_tracker_ids.empty? | |
|
590 | end | |
|
587 | 591 | @issues ||=[] |
|
588 | 592 | |
|
589 | 593 | if params[:output]=='pdf' |
|
590 | 594 | @options_for_rfpdf ||= {} |
|
591 | 595 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
592 | 596 | render :template => "projects/gantt.rfpdf", :layout => false |
|
593 | 597 | else |
|
594 | 598 | render :template => "projects/gantt.rhtml" |
|
595 | 599 | end |
|
596 | 600 | end |
|
597 | 601 | |
|
598 | 602 | def search |
|
599 | 603 | @question = params[:q] || "" |
|
600 | 604 | @question.strip! |
|
601 | 605 | @all_words = params[:all_words] || (params[:submit] ? false : true) |
|
602 | 606 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) |
|
603 | 607 | # tokens must be at least 3 character long |
|
604 | 608 | @tokens = @question.split.uniq.select {|w| w.length > 2 } |
|
605 | 609 | if !@tokens.empty? |
|
606 | 610 | # no more than 5 tokens to search for |
|
607 | 611 | @tokens.slice! 5..-1 if @tokens.size > 5 |
|
608 | 612 | # strings used in sql like statement |
|
609 | 613 | like_tokens = @tokens.collect {|w| "%#{w}%"} |
|
610 | 614 | operator = @all_words ? " AND " : " OR " |
|
611 | 615 | limit = 10 |
|
612 | 616 | @results = [] |
|
613 | 617 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' |
|
614 | 618 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' |
|
615 | 619 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' |
|
616 | 620 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') |
|
617 | 621 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') |
|
618 | 622 | @question = @tokens.join(" ") |
|
619 | 623 | else |
|
620 | 624 | @question = "" |
|
621 | 625 | end |
|
622 | 626 | end |
|
623 | 627 | |
|
624 | 628 | def feeds |
|
625 | 629 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
626 | 630 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
627 | 631 | end |
|
628 | 632 | |
|
629 | 633 | private |
|
630 | 634 | # Find project of id params[:id] |
|
631 | 635 | # if not found, redirect to project list |
|
632 | 636 | # Used as a before_filter |
|
633 | 637 | def find_project |
|
634 | 638 | @project = Project.find(params[:id]) |
|
635 | 639 | @html_title = @project.name |
|
636 | 640 | rescue ActiveRecord::RecordNotFound |
|
637 | 641 | render_404 |
|
638 | 642 | end |
|
639 | 643 | |
|
640 | 644 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
641 | 645 | if ids = params[:tracker_ids] |
|
642 | 646 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
643 | 647 | else |
|
644 | 648 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
645 | 649 | end |
|
646 | 650 | end |
|
647 | 651 | |
|
648 | 652 | # Retrieve query from session or build a new query |
|
649 | 653 | def retrieve_query |
|
650 | 654 | if params[:query_id] |
|
651 | 655 | @query = @project.queries.find(params[:query_id]) |
|
652 | 656 | session[:query] = @query |
|
653 | 657 | else |
|
654 | 658 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
655 | 659 | # Give it a name, required to be valid |
|
656 | 660 | @query = Query.new(:name => "_") |
|
657 | 661 | @query.project = @project |
|
658 | 662 | if params[:fields] and params[:fields].is_a? Array |
|
659 | 663 | params[:fields].each do |field| |
|
660 | 664 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
661 | 665 | end |
|
662 | 666 | else |
|
663 | 667 | @query.available_filters.keys.each do |field| |
|
664 | 668 | @query.add_short_filter(field, params[field]) if params[field] |
|
665 | 669 | end |
|
666 | 670 | end |
|
667 | 671 | session[:query] = @query |
|
668 | 672 | else |
|
669 | 673 | @query = session[:query] |
|
670 | 674 | end |
|
671 | 675 | end |
|
672 | 676 | end |
|
673 | 677 | end |
@@ -1,79 +1,92 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 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 Project < ActiveRecord::Base |
|
19 | 19 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" |
|
20 | 20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" |
|
21 | 21 | has_many :users, :through => :members |
|
22 | 22 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
23 | 23 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] |
|
24 | 24 | has_many :time_entries, :dependent => :delete_all |
|
25 | 25 | has_many :queries, :dependent => :delete_all |
|
26 | 26 | has_many :documents, :dependent => :destroy |
|
27 | 27 | has_many :news, :dependent => :delete_all, :include => :author |
|
28 | 28 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" |
|
29 | 29 | has_one :repository, :dependent => :destroy |
|
30 | 30 | has_one :wiki, :dependent => :destroy |
|
31 | 31 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' |
|
32 | 32 | acts_as_tree :order => "name", :counter_cache => true |
|
33 | 33 | |
|
34 | 34 | validates_presence_of :name, :description, :identifier |
|
35 | 35 | validates_uniqueness_of :name, :identifier |
|
36 | 36 | validates_associated :custom_values, :on => :update |
|
37 | 37 | validates_associated :repository, :wiki |
|
38 | 38 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
39 | 39 | validates_length_of :identifier, :maximum => 12 |
|
40 | 40 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ |
|
41 | 41 | |
|
42 | 42 | def identifier=(identifier) |
|
43 | 43 | super unless identifier_frozen? |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def identifier_frozen? |
|
47 | 47 | errors[:identifier].nil? && !(new_record? || identifier.blank?) |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | def issues_with_subprojects(include_subprojects=false) | |
|
51 | conditions = nil | |
|
52 | if include_subprojects && children.size > 0 | |
|
53 | ids = [id] + children.collect {|c| c.id} | |
|
54 | conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"] | |
|
55 | else | |
|
56 | conditions = ["#{Issue.table_name}.project_id = ?", id] | |
|
57 | end | |
|
58 | Issue.with_scope :find => { :conditions => conditions } do | |
|
59 | yield | |
|
60 | end | |
|
61 | end | |
|
62 | ||
|
50 | 63 | # returns latest created projects |
|
51 | 64 | # non public projects will be returned only if user is a member of those |
|
52 | 65 | def self.latest(user=nil, count=5) |
|
53 | 66 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") |
|
54 | 67 | end |
|
55 | 68 | |
|
56 | 69 | def self.visible_by(user=nil) |
|
57 | 70 | if user && !user.memberships.empty? |
|
58 | 71 | return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true] |
|
59 | 72 | else |
|
60 | 73 | return ["#{Project.table_name}.is_public = ?", true] |
|
61 | 74 | end |
|
62 | 75 | end |
|
63 | 76 | |
|
64 | 77 | # Returns an array of all custom fields enabled for project issues |
|
65 | 78 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
66 | 79 | def custom_fields_for_issues(tracker) |
|
67 | 80 | all_custom_fields.select {|c| tracker.custom_fields.include? c } |
|
68 | 81 | end |
|
69 | 82 | |
|
70 | 83 | def all_custom_fields |
|
71 | 84 | @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq |
|
72 | 85 | end |
|
73 | 86 | |
|
74 | 87 | protected |
|
75 | 88 | def validate |
|
76 | 89 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
77 | 90 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 |
|
78 | 91 | end |
|
79 | 92 | end |
@@ -1,82 +1,86 | |||
|
1 | 1 | <h2><%= l(:label_calendar) %></h2> |
|
2 | 2 | |
|
3 | 3 | <% form_tag do %> |
|
4 | 4 | <table width="100%"> |
|
5 | 5 | <tr> |
|
6 | 6 | <td align="left" style="width:15%"> |
|
7 | 7 | <%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")), |
|
8 | {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids }}, | |
|
9 | {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids)} | |
|
8 | {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }}, | |
|
9 | {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])} | |
|
10 | 10 | %> |
|
11 | 11 | </td> |
|
12 | 12 | <td align="center" style="width:55%"> |
|
13 | 13 | <%= select_month(@month, :prefix => "month", :discard_type => true) %> |
|
14 | 14 | <%= select_year(@year, :prefix => "year", :discard_type => true) %> |
|
15 | 15 | <%= submit_tag l(:button_submit), :class => "button-small" %> |
|
16 | 16 | </td> |
|
17 | 17 | <td align="left" style="width:15%"> |
|
18 | 18 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> |
|
19 | 19 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display:none;"> |
|
20 | 20 | <p><strong><%=l(:label_tracker_plural)%></strong></p> |
|
21 | 21 | <% @trackers.each do |tracker| %> |
|
22 | 22 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> |
|
23 | 23 | <%= tracker.name %><br /> |
|
24 | 24 | <% end %> |
|
25 | <% if @project.children.any? %> | |
|
26 | <p><strong><%=l(:label_subproject_plural)%></strong></p> | |
|
27 | <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %> | |
|
28 | <% end %> | |
|
25 | 29 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> |
|
26 | 30 | </div> |
|
27 | 31 | </td> |
|
28 | 32 | <td align="right" style="width:15%"> |
|
29 | 33 | <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'), |
|
30 | {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids }}, | |
|
31 | {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids)} | |
|
34 | {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }}, | |
|
35 | {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])} | |
|
32 | 36 | %> |
|
33 | 37 | </td> |
|
34 | 38 | </tr> |
|
35 | 39 | </table> |
|
36 | 40 | <% end %> |
|
37 | 41 | |
|
38 | 42 | <table class="list with-cells"> |
|
39 | 43 | <thead> |
|
40 | 44 | <tr> |
|
41 | 45 | <th></th> |
|
42 | 46 | <% 1.upto(7) do |d| %> |
|
43 | 47 | <th style="width:14%"><%= day_name(d) %></th> |
|
44 | 48 | <% end %> |
|
45 | 49 | </tr> |
|
46 | 50 | </thead> |
|
47 | 51 | <tbody> |
|
48 | 52 | <tr style="height:100px"> |
|
49 | 53 | <% day = @date_from |
|
50 | 54 | while day <= @date_to |
|
51 | 55 | if day.cwday == 1 %> |
|
52 | 56 | <th><%= day.cweek %></th> |
|
53 | 57 | <% end %> |
|
54 | 58 | <td valign="top" class="<%= day.month==@month ? "even" : "odd" %>" style="width:14%; <%= Date.today == day ? 'background:#FDFED0;' : '' %>"> |
|
55 | 59 | <p class="textright"><%= day==Date.today ? "<b>#{day.day}</b>" : day.day %></p> |
|
56 | 60 | <% ((@ending_issues_by_days[day] || []) + (@starting_issues_by_days[day] || [])).uniq.each do |i| %> |
|
57 | 61 | <div class="tooltip"> |
|
58 | 62 | <%= if day == i.start_date and day == i.due_date |
|
59 | 63 | image_tag('arrow_bw.png') |
|
60 | 64 | elsif day == i.start_date |
|
61 | 65 | image_tag('arrow_from.png') |
|
62 | 66 | elsif day == i.due_date |
|
63 | 67 | image_tag('arrow_to.png') |
|
64 | 68 | end %> |
|
65 | 69 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i } %>: <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> |
|
66 | 70 | <span class="tip"> |
|
67 | 71 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> |
|
68 | 72 | </span> |
|
69 | 73 | </div> |
|
70 | 74 | <% end %> |
|
71 | 75 | </td> |
|
72 | 76 | <%= '</tr><tr style="height:100px">' if day.cwday >= 7 and day!=@date_to %> |
|
73 | 77 | <% |
|
74 | 78 | day = day + 1 |
|
75 | 79 | end %> |
|
76 | 80 | </tr> |
|
77 | 81 | </tbody> |
|
78 | 82 | </table> |
|
79 | 83 | |
|
80 | 84 | <%= image_tag 'arrow_from.png' %> <%= l(:text_tip_task_begin_day) %><br /> |
|
81 | 85 | <%= image_tag 'arrow_to.png' %> <%= l(:text_tip_task_end_day) %><br /> |
|
82 | 86 | <%= image_tag 'arrow_bw.png' %> <%= l(:text_tip_task_begin_end_day) %><br /> No newline at end of file |
@@ -1,223 +1,227 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= l(:label_export_to) %> |
|
3 | <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :output => 'pdf'}, :class => 'icon icon-pdf' %> | |
|
3 | <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :output => 'pdf'}, :class => 'icon icon-pdf' %> | |
|
4 | 4 | </div> |
|
5 | 5 | |
|
6 | 6 | <h2><%= l(:label_gantt) %></h2> |
|
7 | 7 | |
|
8 | 8 | <% form_tag do %> |
|
9 | 9 | <table width="100%"> |
|
10 | 10 | <tr> |
|
11 | 11 | <td align="left"> |
|
12 | 12 | <input type="text" name="months" size="2" value="<%= @months %>" /> |
|
13 | 13 | <%= l(:label_months_from) %> |
|
14 | 14 | <%= select_month(@month_from, :prefix => "month", :discard_type => true) %> |
|
15 | 15 | <%= select_year(@year_from, :prefix => "year", :discard_type => true) %> |
|
16 | 16 | <%= hidden_field_tag 'zoom', @zoom %> |
|
17 | 17 | <%= submit_tag l(:button_submit), :class => "button-small" %> |
|
18 | 18 | </td> |
|
19 | 19 | <td> |
|
20 | 20 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> |
|
21 | 21 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display: none;"> |
|
22 | 22 | <p><strong><%=l(:label_tracker_plural)%></strong></p> |
|
23 | 23 | <% @trackers.each do |tracker| %> |
|
24 | 24 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> |
|
25 | 25 | <%= tracker.name %><br /> |
|
26 | 26 | <% end %> |
|
27 | <% if @project.children.any? %> | |
|
28 | <p><strong><%=l(:label_subproject_plural)%></strong></p> | |
|
29 | <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %> | |
|
30 | <% end %> | |
|
27 | 31 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> |
|
28 | 32 | </div> |
|
29 | 33 | </td> |
|
30 | 34 | <td align="right"> |
|
31 | 35 | <%= if @zoom < 4 |
|
32 | link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids} | |
|
36 | 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]} | |
|
33 | 37 | else |
|
34 | 38 | image_tag 'zoom_in_g.png' |
|
35 | 39 | end %> |
|
36 | 40 | <%= if @zoom > 1 |
|
37 | link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids} | |
|
41 | 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]} | |
|
38 | 42 | else |
|
39 | 43 | image_tag 'zoom_out_g.png' |
|
40 | 44 | end %> |
|
41 | 45 | </td> |
|
42 | 46 | </tr> |
|
43 | 47 | </table> |
|
44 | 48 | <% end %> |
|
45 | 49 | |
|
46 | 50 | <% zoom = 1 |
|
47 | 51 | @zoom.times { zoom = zoom * 2 } |
|
48 | 52 | |
|
49 | 53 | subject_width = 260 |
|
50 | 54 | header_heigth = 18 |
|
51 | 55 | |
|
52 | 56 | headers_height = header_heigth |
|
53 | 57 | show_weeks = false |
|
54 | 58 | show_days = false |
|
55 | 59 | |
|
56 | 60 | if @zoom >1 |
|
57 | 61 | show_weeks = true |
|
58 | 62 | headers_height = 2*header_heigth |
|
59 | 63 | if @zoom > 2 |
|
60 | 64 | show_days = true |
|
61 | 65 | headers_height = 3*header_heigth |
|
62 | 66 | end |
|
63 | 67 | end |
|
64 | 68 | |
|
65 | 69 | g_width = (@date_to - @date_from + 1)*zoom |
|
66 | 70 | g_height = [(20 * @issues.length + 6)+150, 206].max |
|
67 | 71 | t_height = g_height + headers_height |
|
68 | 72 | %> |
|
69 | 73 | |
|
70 | 74 | <table width="100%" style="border:0; border-collapse: collapse;"> |
|
71 | 75 | <tr> |
|
72 | 76 | <td style="width:260px;"> |
|
73 | 77 | |
|
74 | 78 | <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;"> |
|
75 | 79 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div> |
|
76 | 80 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div> |
|
77 | 81 | <% |
|
78 | 82 | # |
|
79 | 83 | # Tasks subjects |
|
80 | 84 | # |
|
81 | 85 | top = headers_height + 8 |
|
82 | 86 | @issues.each do |i| %> |
|
83 | 87 | <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"> |
|
84 | 88 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i }, :title => "#{i.subject}" %>: |
|
85 | 89 | <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> |
|
86 | 90 | </div> |
|
87 | 91 | <% top = top + 20 |
|
88 | 92 | end %> |
|
89 | 93 | </div> |
|
90 | 94 | </td> |
|
91 | 95 | <td> |
|
92 | 96 | |
|
93 | 97 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;"> |
|
94 | 98 | <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div> |
|
95 | 99 | <% |
|
96 | 100 | # |
|
97 | 101 | # Months headers |
|
98 | 102 | # |
|
99 | 103 | month_f = @date_from |
|
100 | 104 | left = 0 |
|
101 | 105 | height = (show_weeks ? header_heigth : header_heigth + g_height) |
|
102 | 106 | @months.times do |
|
103 | 107 | width = ((month_f >> 1) - month_f) * zoom - 1 |
|
104 | 108 | %> |
|
105 | 109 | <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
106 | <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months }, :title => "#{month_name(month_f.month)} #{month_f.year}"%> | |
|
110 | <%= 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}"%> | |
|
107 | 111 | </div> |
|
108 | 112 | <% |
|
109 | 113 | left = left + width + 1 |
|
110 | 114 | month_f = month_f >> 1 |
|
111 | 115 | end %> |
|
112 | 116 | |
|
113 | 117 | <% |
|
114 | 118 | # |
|
115 | 119 | # Weeks headers |
|
116 | 120 | # |
|
117 | 121 | if show_weeks |
|
118 | 122 | left = 0 |
|
119 | 123 | height = (show_days ? header_heigth-1 : header_heigth-1 + g_height) |
|
120 | 124 | if @date_from.cwday == 1 |
|
121 | 125 | # @date_from is monday |
|
122 | 126 | week_f = @date_from |
|
123 | 127 | else |
|
124 | 128 | # find next monday after @date_from |
|
125 | 129 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
126 | 130 | width = (7 - @date_from.cwday + 1) * zoom-1 |
|
127 | 131 | %> |
|
128 | 132 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div> |
|
129 | 133 | <% |
|
130 | 134 | left = left + width+1 |
|
131 | 135 | end %> |
|
132 | 136 | <% |
|
133 | 137 | while week_f <= @date_to |
|
134 | 138 | width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1 |
|
135 | 139 | %> |
|
136 | 140 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
137 | 141 | <small><%= week_f.cweek if width >= 16 %></small> |
|
138 | 142 | </div> |
|
139 | 143 | <% |
|
140 | 144 | left = left + width+1 |
|
141 | 145 | week_f = week_f+7 |
|
142 | 146 | end |
|
143 | 147 | end %> |
|
144 | 148 | |
|
145 | 149 | <% |
|
146 | 150 | # |
|
147 | 151 | # Days headers |
|
148 | 152 | # |
|
149 | 153 | if show_days |
|
150 | 154 | left = 0 |
|
151 | 155 | height = g_height + header_heigth - 1 |
|
152 | 156 | wday = @date_from.cwday |
|
153 | 157 | (@date_to - @date_from + 1).to_i.times do |
|
154 | 158 | width = zoom - 1 |
|
155 | 159 | %> |
|
156 | 160 | <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"> |
|
157 | 161 | <%= day_name(wday)[0,1] %> |
|
158 | 162 | </div> |
|
159 | 163 | <% |
|
160 | 164 | left = left + width+1 |
|
161 | 165 | wday = wday + 1 |
|
162 | 166 | wday = 1 if wday > 7 |
|
163 | 167 | end |
|
164 | 168 | end %> |
|
165 | 169 | |
|
166 | 170 | <% |
|
167 | 171 | # |
|
168 | 172 | # Today red line |
|
169 | 173 | # |
|
170 | 174 | if Date.today >= @date_from and Date.today <= @date_to %> |
|
171 | 175 | <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> |
|
172 | 176 | <% end %> |
|
173 | 177 | |
|
174 | 178 | <% |
|
175 | 179 | # |
|
176 | 180 | # Tasks |
|
177 | 181 | # |
|
178 | 182 | top = headers_height + 10 |
|
179 | 183 | @issues.each do |i| %> |
|
180 | 184 | <% |
|
181 | 185 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) |
|
182 | 186 | i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) |
|
183 | 187 | |
|
184 | 188 | i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor |
|
185 | 189 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) |
|
186 | 190 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) |
|
187 | 191 | |
|
188 | 192 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today |
|
189 | 193 | |
|
190 | 194 | i_left = ((i_start_date - @date_from)*zoom).floor |
|
191 | 195 | i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders) |
|
192 | 196 | d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width |
|
193 | 197 | l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width |
|
194 | 198 | %> |
|
195 | 199 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div> |
|
196 | 200 | <% if l_width > 0 %> |
|
197 | 201 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div> |
|
198 | 202 | <% end %> |
|
199 | 203 | <% if d_width > 0 %> |
|
200 | 204 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div> |
|
201 | 205 | <% end %> |
|
202 | 206 | <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task"> |
|
203 | 207 | <%= i.status.name %> |
|
204 | 208 | <%= (i.done_ratio).to_i %>% |
|
205 | 209 | </div> |
|
206 | 210 | <% # === tooltip === %> |
|
207 | 211 | <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;"> |
|
208 | 212 | <span class="tip"> |
|
209 | 213 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> |
|
210 | 214 | </span></div> |
|
211 | 215 | <% top = top + 20 |
|
212 | 216 | end %> |
|
213 | 217 | </div> |
|
214 | 218 | </td> |
|
215 | 219 | </tr> |
|
216 | 220 | </table> |
|
217 | 221 | |
|
218 | 222 | <table width="100%"> |
|
219 | 223 | <tr> |
|
220 | <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 %></td> | |
|
221 | <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 %></td> | |
|
224 | <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> | |
|
225 | <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> | |
|
222 | 226 | </tr> |
|
223 | 227 | </table> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now