##// END OF EJS Templates
Versions can now be created with no date....
Jean-Philippe Lang -
r533:d34ea9a56986
parent child
Show More
@@ -0,0 +1,9
1 class AllowNullVersionEffectiveDate < ActiveRecord::Migration
2 def self.up
3 change_column :versions, :effective_date, :date, :default => nil
4 end
5
6 def self.down
7 raise IrreversibleMigration
8 end
9 end
@@ -1,672 +1,662
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'csv'
18 require 'csv'
19
19
20 class ProjectsController < ApplicationController
20 class ProjectsController < ApplicationController
21 layout 'base'
21 layout 'base'
22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
24
24
25 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
25 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
26
26
27 helper :sort
27 helper :sort
28 include SortHelper
28 include SortHelper
29 helper :custom_fields
29 helper :custom_fields
30 include CustomFieldsHelper
30 include CustomFieldsHelper
31 helper :ifpdf
31 helper :ifpdf
32 include IfpdfHelper
32 include IfpdfHelper
33 helper IssuesHelper
33 helper IssuesHelper
34 helper :queries
34 helper :queries
35 include QueriesHelper
35 include QueriesHelper
36
36
37 def index
37 def index
38 list
38 list
39 render :action => 'list' unless request.xhr?
39 render :action => 'list' unless request.xhr?
40 end
40 end
41
41
42 # Lists public projects
42 # Lists public projects
43 def list
43 def list
44 sort_init "#{Project.table_name}.name", "asc"
44 sort_init "#{Project.table_name}.name", "asc"
45 sort_update
45 sort_update
46 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
46 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
47 @project_pages = Paginator.new self, @project_count,
47 @project_pages = Paginator.new self, @project_count,
48 15,
48 15,
49 params['page']
49 params['page']
50 @projects = Project.find :all, :order => sort_clause,
50 @projects = Project.find :all, :order => sort_clause,
51 :conditions => Project.visible_by(logged_in_user),
51 :conditions => Project.visible_by(logged_in_user),
52 :include => :parent,
52 :include => :parent,
53 :limit => @project_pages.items_per_page,
53 :limit => @project_pages.items_per_page,
54 :offset => @project_pages.current.offset
54 :offset => @project_pages.current.offset
55
55
56 render :action => "list", :layout => false if request.xhr?
56 render :action => "list", :layout => false if request.xhr?
57 end
57 end
58
58
59 # Add a new project
59 # Add a new project
60 def add
60 def add
61 @custom_fields = IssueCustomField.find(:all)
61 @custom_fields = IssueCustomField.find(:all)
62 @root_projects = Project.find(:all, :conditions => "parent_id is null")
62 @root_projects = Project.find(:all, :conditions => "parent_id is null")
63 @project = Project.new(params[:project])
63 @project = Project.new(params[:project])
64 if request.get?
64 if request.get?
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
66 else
66 else
67 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
68 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
68 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
69 @project.custom_values = @custom_values
69 @project.custom_values = @custom_values
70 if params[:repository_enabled] && params[:repository_enabled] == "1"
70 if params[:repository_enabled] && params[:repository_enabled] == "1"
71 @project.repository = Repository.new
71 @project.repository = Repository.new
72 @project.repository.attributes = params[:repository]
72 @project.repository.attributes = params[:repository]
73 end
73 end
74 if "1" == params[:wiki_enabled]
74 if "1" == params[:wiki_enabled]
75 @project.wiki = Wiki.new
75 @project.wiki = Wiki.new
76 @project.wiki.attributes = params[:wiki]
76 @project.wiki.attributes = params[:wiki]
77 end
77 end
78 if @project.save
78 if @project.save
79 flash[:notice] = l(:notice_successful_create)
79 flash[:notice] = l(:notice_successful_create)
80 redirect_to :controller => 'admin', :action => 'projects'
80 redirect_to :controller => 'admin', :action => 'projects'
81 end
81 end
82 end
82 end
83 end
83 end
84
84
85 # Show @project
85 # Show @project
86 def show
86 def show
87 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
87 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
88 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
89 @subprojects = @project.children if @project.children.size > 0
89 @subprojects = @project.children if @project.children.size > 0
90 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
90 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
91 @trackers = Tracker.find(:all, :order => 'position')
91 @trackers = Tracker.find(:all, :order => 'position')
92 @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])
92 @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])
93 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
93 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
94 end
94 end
95
95
96 def settings
96 def settings
97 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
97 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
98 @custom_fields = IssueCustomField.find(:all)
98 @custom_fields = IssueCustomField.find(:all)
99 @issue_category ||= IssueCategory.new
99 @issue_category ||= IssueCategory.new
100 @member ||= @project.members.new
100 @member ||= @project.members.new
101 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
101 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
102 end
102 end
103
103
104 # Edit @project
104 # Edit @project
105 def edit
105 def edit
106 if request.post?
106 if request.post?
107 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
107 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
108 if params[:custom_fields]
108 if params[:custom_fields]
109 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
109 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
110 @project.custom_values = @custom_values
110 @project.custom_values = @custom_values
111 end
111 end
112 if params[:repository_enabled]
112 if params[:repository_enabled]
113 case params[:repository_enabled]
113 case params[:repository_enabled]
114 when "0"
114 when "0"
115 @project.repository = nil
115 @project.repository = nil
116 when "1"
116 when "1"
117 @project.repository ||= Repository.new
117 @project.repository ||= Repository.new
118 @project.repository.update_attributes params[:repository]
118 @project.repository.update_attributes params[:repository]
119 end
119 end
120 end
120 end
121 if params[:wiki_enabled]
121 if params[:wiki_enabled]
122 case params[:wiki_enabled]
122 case params[:wiki_enabled]
123 when "0"
123 when "0"
124 @project.wiki.destroy if @project.wiki
124 @project.wiki.destroy if @project.wiki
125 when "1"
125 when "1"
126 @project.wiki ||= Wiki.new
126 @project.wiki ||= Wiki.new
127 @project.wiki.update_attributes params[:wiki]
127 @project.wiki.update_attributes params[:wiki]
128 end
128 end
129 end
129 end
130 @project.attributes = params[:project]
130 @project.attributes = params[:project]
131 if @project.save
131 if @project.save
132 flash[:notice] = l(:notice_successful_update)
132 flash[:notice] = l(:notice_successful_update)
133 redirect_to :action => 'settings', :id => @project
133 redirect_to :action => 'settings', :id => @project
134 else
134 else
135 settings
135 settings
136 render :action => 'settings'
136 render :action => 'settings'
137 end
137 end
138 end
138 end
139 end
139 end
140
140
141 # Delete @project
141 # Delete @project
142 def destroy
142 def destroy
143 if request.post? and params[:confirm]
143 if request.post? and params[:confirm]
144 @project.destroy
144 @project.destroy
145 redirect_to :controller => 'admin', :action => 'projects'
145 redirect_to :controller => 'admin', :action => 'projects'
146 end
146 end
147 end
147 end
148
148
149 # Add a new issue category to @project
149 # Add a new issue category to @project
150 def add_issue_category
150 def add_issue_category
151 if request.post?
151 if request.post?
152 @issue_category = @project.issue_categories.build(params[:issue_category])
152 @issue_category = @project.issue_categories.build(params[:issue_category])
153 if @issue_category.save
153 if @issue_category.save
154 flash[:notice] = l(:notice_successful_create)
154 flash[:notice] = l(:notice_successful_create)
155 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 redirect_to :action => 'settings', :tab => 'categories', :id => @project
156 else
156 else
157 settings
157 settings
158 render :action => 'settings'
158 render :action => 'settings'
159 end
159 end
160 end
160 end
161 end
161 end
162
162
163 # Add a new version to @project
163 # Add a new version to @project
164 def add_version
164 def add_version
165 @version = @project.versions.build(params[:version])
165 @version = @project.versions.build(params[:version])
166 if request.post? and @version.save
166 if request.post? and @version.save
167 flash[:notice] = l(:notice_successful_create)
167 flash[:notice] = l(:notice_successful_create)
168 redirect_to :action => 'settings', :tab => 'versions', :id => @project
168 redirect_to :action => 'settings', :tab => 'versions', :id => @project
169 end
169 end
170 end
170 end
171
171
172 # Add a new member to @project
172 # Add a new member to @project
173 def add_member
173 def add_member
174 @member = @project.members.build(params[:member])
174 @member = @project.members.build(params[:member])
175 if request.post? && @member.save
175 if request.post? && @member.save
176 respond_to do |format|
176 respond_to do |format|
177 format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
177 format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
178 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} }
178 format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} }
179 end
179 end
180 else
180 else
181 settings
181 settings
182 render :action => 'settings'
182 render :action => 'settings'
183 end
183 end
184 end
184 end
185
185
186 # Show members list of @project
186 # Show members list of @project
187 def list_members
187 def list_members
188 @members = @project.members.find(:all)
188 @members = @project.members.find(:all)
189 end
189 end
190
190
191 # Add a new document to @project
191 # Add a new document to @project
192 def add_document
192 def add_document
193 @categories = Enumeration::get_values('DCAT')
193 @categories = Enumeration::get_values('DCAT')
194 @document = @project.documents.build(params[:document])
194 @document = @project.documents.build(params[:document])
195 if request.post? and @document.save
195 if request.post? and @document.save
196 # Save the attachments
196 # Save the attachments
197 params[:attachments].each { |a|
197 params[:attachments].each { |a|
198 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
198 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
199 } if params[:attachments] and params[:attachments].is_a? Array
199 } if params[:attachments] and params[:attachments].is_a? Array
200 flash[:notice] = l(:notice_successful_create)
200 flash[:notice] = l(:notice_successful_create)
201 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
201 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
202 redirect_to :action => 'list_documents', :id => @project
202 redirect_to :action => 'list_documents', :id => @project
203 end
203 end
204 end
204 end
205
205
206 # Show documents list of @project
206 # Show documents list of @project
207 def list_documents
207 def list_documents
208 @documents = @project.documents.find :all, :include => :category
208 @documents = @project.documents.find :all, :include => :category
209 end
209 end
210
210
211 # Add a new issue to @project
211 # Add a new issue to @project
212 def add_issue
212 def add_issue
213 @tracker = Tracker.find(params[:tracker_id])
213 @tracker = Tracker.find(params[:tracker_id])
214 @priorities = Enumeration::get_values('IPRI')
214 @priorities = Enumeration::get_values('IPRI')
215
215
216 default_status = IssueStatus.default
216 default_status = IssueStatus.default
217 @issue = Issue.new(:project => @project, :tracker => @tracker)
217 @issue = Issue.new(:project => @project, :tracker => @tracker)
218 @issue.status = default_status
218 @issue.status = default_status
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
220 if request.get?
220 if request.get?
221 @issue.start_date = Date.today
221 @issue.start_date = Date.today
222 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
222 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
223 else
223 else
224 @issue.attributes = params[:issue]
224 @issue.attributes = params[:issue]
225
225
226 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
226 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
227 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
227 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
228
228
229 @issue.author_id = self.logged_in_user.id if self.logged_in_user
229 @issue.author_id = self.logged_in_user.id if self.logged_in_user
230 # Multiple file upload
230 # Multiple file upload
231 @attachments = []
231 @attachments = []
232 params[:attachments].each { |a|
232 params[:attachments].each { |a|
233 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
233 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
234 } if params[:attachments] and params[:attachments].is_a? Array
234 } if params[:attachments] and params[:attachments].is_a? Array
235 @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]) }
235 @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]) }
236 @issue.custom_values = @custom_values
236 @issue.custom_values = @custom_values
237 if @issue.save
237 if @issue.save
238 @attachments.each(&:save)
238 @attachments.each(&:save)
239 flash[:notice] = l(:notice_successful_create)
239 flash[:notice] = l(:notice_successful_create)
240 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
240 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
241 redirect_to :action => 'list_issues', :id => @project
241 redirect_to :action => 'list_issues', :id => @project
242 end
242 end
243 end
243 end
244 end
244 end
245
245
246 # Show filtered/sorted issues list of @project
246 # Show filtered/sorted issues list of @project
247 def list_issues
247 def list_issues
248 sort_init "#{Issue.table_name}.id", "desc"
248 sort_init "#{Issue.table_name}.id", "desc"
249 sort_update
249 sort_update
250
250
251 retrieve_query
251 retrieve_query
252
252
253 @results_per_page_options = [ 15, 25, 50, 100 ]
253 @results_per_page_options = [ 15, 25, 50, 100 ]
254 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
254 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
255 @results_per_page = params[:per_page].to_i
255 @results_per_page = params[:per_page].to_i
256 session[:results_per_page] = @results_per_page
256 session[:results_per_page] = @results_per_page
257 else
257 else
258 @results_per_page = session[:results_per_page] || 25
258 @results_per_page = session[:results_per_page] || 25
259 end
259 end
260
260
261 if @query.valid?
261 if @query.valid?
262 @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
262 @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
263 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
263 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
264 @issues = Issue.find :all, :order => sort_clause,
264 @issues = Issue.find :all, :order => sort_clause,
265 :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
265 :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
266 :conditions => @query.statement,
266 :conditions => @query.statement,
267 :limit => @issue_pages.items_per_page,
267 :limit => @issue_pages.items_per_page,
268 :offset => @issue_pages.current.offset
268 :offset => @issue_pages.current.offset
269 end
269 end
270 @trackers = Tracker.find :all, :order => 'position'
270 @trackers = Tracker.find :all, :order => 'position'
271 render :layout => false if request.xhr?
271 render :layout => false if request.xhr?
272 end
272 end
273
273
274 # Export filtered/sorted issues list to CSV
274 # Export filtered/sorted issues list to CSV
275 def export_issues_csv
275 def export_issues_csv
276 sort_init "#{Issue.table_name}.id", "desc"
276 sort_init "#{Issue.table_name}.id", "desc"
277 sort_update
277 sort_update
278
278
279 retrieve_query
279 retrieve_query
280 render :action => 'list_issues' and return unless @query.valid?
280 render :action => 'list_issues' and return unless @query.valid?
281
281
282 @issues = Issue.find :all, :order => sort_clause,
282 @issues = Issue.find :all, :order => sort_clause,
283 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
283 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
284 :conditions => @query.statement,
284 :conditions => @query.statement,
285 :limit => Setting.issues_export_limit
285 :limit => Setting.issues_export_limit
286
286
287 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
287 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
288 export = StringIO.new
288 export = StringIO.new
289 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
289 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
290 # csv header fields
290 # csv header fields
291 headers = [ "#", l(:field_status),
291 headers = [ "#", l(:field_status),
292 l(:field_project),
292 l(:field_project),
293 l(:field_tracker),
293 l(:field_tracker),
294 l(:field_priority),
294 l(:field_priority),
295 l(:field_subject),
295 l(:field_subject),
296 l(:field_assigned_to),
296 l(:field_assigned_to),
297 l(:field_author),
297 l(:field_author),
298 l(:field_start_date),
298 l(:field_start_date),
299 l(:field_due_date),
299 l(:field_due_date),
300 l(:field_done_ratio),
300 l(:field_done_ratio),
301 l(:field_created_on),
301 l(:field_created_on),
302 l(:field_updated_on)
302 l(:field_updated_on)
303 ]
303 ]
304 for custom_field in @project.all_custom_fields
304 for custom_field in @project.all_custom_fields
305 headers << custom_field.name
305 headers << custom_field.name
306 end
306 end
307 csv << headers.collect {|c| ic.iconv(c) }
307 csv << headers.collect {|c| ic.iconv(c) }
308 # csv lines
308 # csv lines
309 @issues.each do |issue|
309 @issues.each do |issue|
310 fields = [issue.id, issue.status.name,
310 fields = [issue.id, issue.status.name,
311 issue.project.name,
311 issue.project.name,
312 issue.tracker.name,
312 issue.tracker.name,
313 issue.priority.name,
313 issue.priority.name,
314 issue.subject,
314 issue.subject,
315 (issue.assigned_to ? issue.assigned_to.name : ""),
315 (issue.assigned_to ? issue.assigned_to.name : ""),
316 issue.author.name,
316 issue.author.name,
317 issue.start_date ? l_date(issue.start_date) : nil,
317 issue.start_date ? l_date(issue.start_date) : nil,
318 issue.due_date ? l_date(issue.due_date) : nil,
318 issue.due_date ? l_date(issue.due_date) : nil,
319 issue.done_ratio,
319 issue.done_ratio,
320 l_datetime(issue.created_on),
320 l_datetime(issue.created_on),
321 l_datetime(issue.updated_on)
321 l_datetime(issue.updated_on)
322 ]
322 ]
323 for custom_field in @project.all_custom_fields
323 for custom_field in @project.all_custom_fields
324 fields << (show_value issue.custom_value_for(custom_field))
324 fields << (show_value issue.custom_value_for(custom_field))
325 end
325 end
326 csv << fields.collect {|c| ic.iconv(c.to_s) }
326 csv << fields.collect {|c| ic.iconv(c.to_s) }
327 end
327 end
328 end
328 end
329 export.rewind
329 export.rewind
330 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
330 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
331 end
331 end
332
332
333 # Export filtered/sorted issues to PDF
333 # Export filtered/sorted issues to PDF
334 def export_issues_pdf
334 def export_issues_pdf
335 sort_init "#{Issue.table_name}.id", "desc"
335 sort_init "#{Issue.table_name}.id", "desc"
336 sort_update
336 sort_update
337
337
338 retrieve_query
338 retrieve_query
339 render :action => 'list_issues' and return unless @query.valid?
339 render :action => 'list_issues' and return unless @query.valid?
340
340
341 @issues = Issue.find :all, :order => sort_clause,
341 @issues = Issue.find :all, :order => sort_clause,
342 :include => [ :author, :status, :tracker, :priority, :project, :custom_values ],
342 :include => [ :author, :status, :tracker, :priority, :project, :custom_values ],
343 :conditions => @query.statement,
343 :conditions => @query.statement,
344 :limit => Setting.issues_export_limit
344 :limit => Setting.issues_export_limit
345
345
346 @options_for_rfpdf ||= {}
346 @options_for_rfpdf ||= {}
347 @options_for_rfpdf[:file_name] = "export.pdf"
347 @options_for_rfpdf[:file_name] = "export.pdf"
348 render :layout => false
348 render :layout => false
349 end
349 end
350
350
351 def move_issues
351 def move_issues
352 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
352 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
353 redirect_to :action => 'list_issues', :id => @project and return unless @issues
353 redirect_to :action => 'list_issues', :id => @project and return unless @issues
354 @projects = []
354 @projects = []
355 # find projects to which the user is allowed to move the issue
355 # find projects to which the user is allowed to move the issue
356 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
356 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
357 # issue can be moved to any tracker
357 # issue can be moved to any tracker
358 @trackers = Tracker.find(:all)
358 @trackers = Tracker.find(:all)
359 if request.post? and params[:new_project_id] and params[:new_tracker_id]
359 if request.post? and params[:new_project_id] and params[:new_tracker_id]
360 new_project = Project.find(params[:new_project_id])
360 new_project = Project.find(params[:new_project_id])
361 new_tracker = Tracker.find(params[:new_tracker_id])
361 new_tracker = Tracker.find(params[:new_tracker_id])
362 @issues.each { |i|
362 @issues.each { |i|
363 # project dependent properties
363 # project dependent properties
364 unless i.project_id == new_project.id
364 unless i.project_id == new_project.id
365 i.category = nil
365 i.category = nil
366 i.fixed_version = nil
366 i.fixed_version = nil
367 # delete issue relations
367 # delete issue relations
368 i.relations_from.clear
368 i.relations_from.clear
369 i.relations_to.clear
369 i.relations_to.clear
370 end
370 end
371 # move the issue
371 # move the issue
372 i.project = new_project
372 i.project = new_project
373 i.tracker = new_tracker
373 i.tracker = new_tracker
374 i.save
374 i.save
375 }
375 }
376 flash[:notice] = l(:notice_successful_update)
376 flash[:notice] = l(:notice_successful_update)
377 redirect_to :action => 'list_issues', :id => @project
377 redirect_to :action => 'list_issues', :id => @project
378 end
378 end
379 end
379 end
380
380
381 def add_query
381 def add_query
382 @query = Query.new(params[:query])
382 @query = Query.new(params[:query])
383 @query.project = @project
383 @query.project = @project
384 @query.user = logged_in_user
384 @query.user = logged_in_user
385
385
386 params[:fields].each do |field|
386 params[:fields].each do |field|
387 @query.add_filter(field, params[:operators][field], params[:values][field])
387 @query.add_filter(field, params[:operators][field], params[:values][field])
388 end if params[:fields]
388 end if params[:fields]
389
389
390 if request.post? and @query.save
390 if request.post? and @query.save
391 flash[:notice] = l(:notice_successful_create)
391 flash[:notice] = l(:notice_successful_create)
392 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
392 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
393 end
393 end
394 render :layout => false if request.xhr?
394 render :layout => false if request.xhr?
395 end
395 end
396
396
397 # Add a news to @project
397 # Add a news to @project
398 def add_news
398 def add_news
399 @news = News.new(:project => @project)
399 @news = News.new(:project => @project)
400 if request.post?
400 if request.post?
401 @news.attributes = params[:news]
401 @news.attributes = params[:news]
402 @news.author_id = self.logged_in_user.id if self.logged_in_user
402 @news.author_id = self.logged_in_user.id if self.logged_in_user
403 if @news.save
403 if @news.save
404 flash[:notice] = l(:notice_successful_create)
404 flash[:notice] = l(:notice_successful_create)
405 redirect_to :action => 'list_news', :id => @project
405 redirect_to :action => 'list_news', :id => @project
406 end
406 end
407 end
407 end
408 end
408 end
409
409
410 # Show news list of @project
410 # Show news list of @project
411 def list_news
411 def list_news
412 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
412 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
413 render :action => "list_news", :layout => false if request.xhr?
413 render :action => "list_news", :layout => false if request.xhr?
414 end
414 end
415
415
416 def add_file
416 def add_file
417 if request.post?
417 if request.post?
418 @version = @project.versions.find_by_id(params[:version_id])
418 @version = @project.versions.find_by_id(params[:version_id])
419 # Save the attachments
419 # Save the attachments
420 @attachments = []
420 @attachments = []
421 params[:attachments].each { |file|
421 params[:attachments].each { |file|
422 next unless file.size > 0
422 next unless file.size > 0
423 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
423 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
424 @attachments << a unless a.new_record?
424 @attachments << a unless a.new_record?
425 } if params[:attachments] and params[:attachments].is_a? Array
425 } if params[:attachments] and params[:attachments].is_a? Array
426 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
426 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
427 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
427 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
428 end
428 end
429 @versions = @project.versions
429 @versions = @project.versions.sort
430 end
430 end
431
431
432 def list_files
432 def list_files
433 @versions = @project.versions
433 @versions = @project.versions.sort
434 end
434 end
435
435
436 # Show changelog for @project
436 # Show changelog for @project
437 def changelog
437 def changelog
438 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
438 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
439 retrieve_selected_tracker_ids(@trackers)
439 retrieve_selected_tracker_ids(@trackers)
440
440 @versions = @project.versions.sort
441 @fixed_issues = @project.issues.find(:all,
442 :include => [ :fixed_version, :status, :tracker ],
443 :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],
444 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
445 ) unless @selected_tracker_ids.empty?
446 @fixed_issues ||= []
447 end
441 end
448
442
449 def roadmap
443 def roadmap
450 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
444 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
451 retrieve_selected_tracker_ids(@trackers)
445 retrieve_selected_tracker_ids(@trackers)
452 conditions = ("1" == params[:completed] ? nil : [ "#{Version.table_name}.effective_date > ?", Date.today])
446 conditions = ("1" == params[:completed] ? nil : [ "#{Version.table_name}.effective_date > ? OR #{Version.table_name}.effective_date IS NULL", Date.today])
453
447 @versions = @project.versions.find(:all, :conditions => conditions).sort
454 @versions = @project.versions.find(:all,
455 :conditions => conditions,
456 :order => "#{Version.table_name}.effective_date ASC"
457 )
458 end
448 end
459
449
460 def activity
450 def activity
461 if params[:year] and params[:year].to_i > 1900
451 if params[:year] and params[:year].to_i > 1900
462 @year = params[:year].to_i
452 @year = params[:year].to_i
463 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
453 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
464 @month = params[:month].to_i
454 @month = params[:month].to_i
465 end
455 end
466 end
456 end
467 @year ||= Date.today.year
457 @year ||= Date.today.year
468 @month ||= Date.today.month
458 @month ||= Date.today.month
469
459
470 @date_from = Date.civil(@year, @month, 1)
460 @date_from = Date.civil(@year, @month, 1)
471 @date_to = @date_from >> 1
461 @date_to = @date_from >> 1
472
462
473 @events_by_day = {}
463 @events_by_day = {}
474
464
475 unless params[:show_issues] == "0"
465 unless params[:show_issues] == "0"
476 @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
466 @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
477 @events_by_day[i.created_on.to_date] ||= []
467 @events_by_day[i.created_on.to_date] ||= []
478 @events_by_day[i.created_on.to_date] << i
468 @events_by_day[i.created_on.to_date] << i
479 }
469 }
480 @show_issues = 1
470 @show_issues = 1
481 end
471 end
482
472
483 unless params[:show_news] == "0"
473 unless params[:show_news] == "0"
484 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
474 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
485 @events_by_day[i.created_on.to_date] ||= []
475 @events_by_day[i.created_on.to_date] ||= []
486 @events_by_day[i.created_on.to_date] << i
476 @events_by_day[i.created_on.to_date] << i
487 }
477 }
488 @show_news = 1
478 @show_news = 1
489 end
479 end
490
480
491 unless params[:show_files] == "0"
481 unless params[:show_files] == "0"
492 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|
482 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|
493 @events_by_day[i.created_on.to_date] ||= []
483 @events_by_day[i.created_on.to_date] ||= []
494 @events_by_day[i.created_on.to_date] << i
484 @events_by_day[i.created_on.to_date] << i
495 }
485 }
496 @show_files = 1
486 @show_files = 1
497 end
487 end
498
488
499 unless params[:show_documents] == "0"
489 unless params[:show_documents] == "0"
500 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
490 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
501 @events_by_day[i.created_on.to_date] ||= []
491 @events_by_day[i.created_on.to_date] ||= []
502 @events_by_day[i.created_on.to_date] << i
492 @events_by_day[i.created_on.to_date] << i
503 }
493 }
504 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|
494 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|
505 @events_by_day[i.created_on.to_date] ||= []
495 @events_by_day[i.created_on.to_date] ||= []
506 @events_by_day[i.created_on.to_date] << i
496 @events_by_day[i.created_on.to_date] << i
507 }
497 }
508 @show_documents = 1
498 @show_documents = 1
509 end
499 end
510
500
511 unless @project.wiki.nil? || params[:show_wiki_edits] == "0"
501 unless @project.wiki.nil? || params[:show_wiki_edits] == "0"
512 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
502 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
513 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
503 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
514 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
504 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
515 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
505 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
516 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
506 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
517 @project.id, @date_from, @date_to]
507 @project.id, @date_from, @date_to]
518
508
519 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
509 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
520 # We provide this alias so all events can be treated in the same manner
510 # We provide this alias so all events can be treated in the same manner
521 def i.created_on
511 def i.created_on
522 self.updated_on
512 self.updated_on
523 end
513 end
524
514
525 @events_by_day[i.created_on.to_date] ||= []
515 @events_by_day[i.created_on.to_date] ||= []
526 @events_by_day[i.created_on.to_date] << i
516 @events_by_day[i.created_on.to_date] << i
527 }
517 }
528 @show_wiki_edits = 1
518 @show_wiki_edits = 1
529 end
519 end
530
520
531 unless @project.repository.nil? || params[:show_changesets] == "0"
521 unless @project.repository.nil? || params[:show_changesets] == "0"
532 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
522 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
533 def i.created_on
523 def i.created_on
534 self.committed_on
524 self.committed_on
535 end
525 end
536 @events_by_day[i.created_on.to_date] ||= []
526 @events_by_day[i.created_on.to_date] ||= []
537 @events_by_day[i.created_on.to_date] << i
527 @events_by_day[i.created_on.to_date] << i
538 }
528 }
539 @show_changesets = 1
529 @show_changesets = 1
540 end
530 end
541
531
542 render :layout => false if request.xhr?
532 render :layout => false if request.xhr?
543 end
533 end
544
534
545 def calendar
535 def calendar
546 @trackers = Tracker.find(:all, :order => 'position')
536 @trackers = Tracker.find(:all, :order => 'position')
547 retrieve_selected_tracker_ids(@trackers)
537 retrieve_selected_tracker_ids(@trackers)
548
538
549 if params[:year] and params[:year].to_i > 1900
539 if params[:year] and params[:year].to_i > 1900
550 @year = params[:year].to_i
540 @year = params[:year].to_i
551 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
541 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
552 @month = params[:month].to_i
542 @month = params[:month].to_i
553 end
543 end
554 end
544 end
555 @year ||= Date.today.year
545 @year ||= Date.today.year
556 @month ||= Date.today.month
546 @month ||= Date.today.month
557
547
558 @date_from = Date.civil(@year, @month, 1)
548 @date_from = Date.civil(@year, @month, 1)
559 @date_to = (@date_from >> 1)-1
549 @date_to = (@date_from >> 1)-1
560 # start on monday
550 # start on monday
561 @date_from = @date_from - (@date_from.cwday-1)
551 @date_from = @date_from - (@date_from.cwday-1)
562 # finish on sunday
552 # finish on sunday
563 @date_to = @date_to + (7-@date_to.cwday)
553 @date_to = @date_to + (7-@date_to.cwday)
564
554
565 @events = []
555 @events = []
566 @project.issues_with_subprojects(params[:with_subprojects]) do
556 @project.issues_with_subprojects(params[:with_subprojects]) do
567 @events += Issue.find(:all,
557 @events += Issue.find(:all,
568 :include => [:tracker, :status, :assigned_to, :priority, :project],
558 :include => [:tracker, :status, :assigned_to, :priority, :project],
569 :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]
559 :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]
570 ) unless @selected_tracker_ids.empty?
560 ) unless @selected_tracker_ids.empty?
571 end
561 end
572 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
562 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
573
563
574 @ending_events_by_days = @events.group_by {|event| event.due_date}
564 @ending_events_by_days = @events.group_by {|event| event.due_date}
575 @starting_events_by_days = @events.group_by {|event| event.start_date}
565 @starting_events_by_days = @events.group_by {|event| event.start_date}
576
566
577 render :layout => false if request.xhr?
567 render :layout => false if request.xhr?
578 end
568 end
579
569
580 def gantt
570 def gantt
581 @trackers = Tracker.find(:all, :order => 'position')
571 @trackers = Tracker.find(:all, :order => 'position')
582 retrieve_selected_tracker_ids(@trackers)
572 retrieve_selected_tracker_ids(@trackers)
583
573
584 if params[:year] and params[:year].to_i >0
574 if params[:year] and params[:year].to_i >0
585 @year_from = params[:year].to_i
575 @year_from = params[:year].to_i
586 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
576 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
587 @month_from = params[:month].to_i
577 @month_from = params[:month].to_i
588 else
578 else
589 @month_from = 1
579 @month_from = 1
590 end
580 end
591 else
581 else
592 @month_from ||= (Date.today << 1).month
582 @month_from ||= (Date.today << 1).month
593 @year_from ||= (Date.today << 1).year
583 @year_from ||= (Date.today << 1).year
594 end
584 end
595
585
596 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
586 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
597 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
587 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
598
588
599 @date_from = Date.civil(@year_from, @month_from, 1)
589 @date_from = Date.civil(@year_from, @month_from, 1)
600 @date_to = (@date_from >> @months) - 1
590 @date_to = (@date_from >> @months) - 1
601
591
602 @events = []
592 @events = []
603 @project.issues_with_subprojects(params[:with_subprojects]) do
593 @project.issues_with_subprojects(params[:with_subprojects]) do
604 @events += Issue.find(:all,
594 @events += Issue.find(:all,
605 :order => "start_date, due_date",
595 :order => "start_date, due_date",
606 :include => [:tracker, :status, :assigned_to, :priority, :project],
596 :include => [:tracker, :status, :assigned_to, :priority, :project],
607 :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]
597 :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]
608 ) unless @selected_tracker_ids.empty?
598 ) unless @selected_tracker_ids.empty?
609 end
599 end
610 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
600 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
611 @events.sort! {|x,y| x.start_date <=> y.start_date }
601 @events.sort! {|x,y| x.start_date <=> y.start_date }
612
602
613 if params[:output]=='pdf'
603 if params[:output]=='pdf'
614 @options_for_rfpdf ||= {}
604 @options_for_rfpdf ||= {}
615 @options_for_rfpdf[:file_name] = "gantt.pdf"
605 @options_for_rfpdf[:file_name] = "gantt.pdf"
616 render :template => "projects/gantt.rfpdf", :layout => false
606 render :template => "projects/gantt.rfpdf", :layout => false
617 else
607 else
618 render :template => "projects/gantt.rhtml"
608 render :template => "projects/gantt.rhtml"
619 end
609 end
620 end
610 end
621
611
622 def feeds
612 def feeds
623 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
613 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
624 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
614 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
625 end
615 end
626
616
627 private
617 private
628 # Find project of id params[:id]
618 # Find project of id params[:id]
629 # if not found, redirect to project list
619 # if not found, redirect to project list
630 # Used as a before_filter
620 # Used as a before_filter
631 def find_project
621 def find_project
632 @project = Project.find(params[:id])
622 @project = Project.find(params[:id])
633 @html_title = @project.name
623 @html_title = @project.name
634 rescue ActiveRecord::RecordNotFound
624 rescue ActiveRecord::RecordNotFound
635 render_404
625 render_404
636 end
626 end
637
627
638 def retrieve_selected_tracker_ids(selectable_trackers)
628 def retrieve_selected_tracker_ids(selectable_trackers)
639 if ids = params[:tracker_ids]
629 if ids = params[:tracker_ids]
640 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
630 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
641 else
631 else
642 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
632 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
643 end
633 end
644 end
634 end
645
635
646 # Retrieve query from session or build a new query
636 # Retrieve query from session or build a new query
647 def retrieve_query
637 def retrieve_query
648 if params[:query_id]
638 if params[:query_id]
649 @query = @project.queries.find(params[:query_id])
639 @query = @project.queries.find(params[:query_id])
650 @query.executed_by = logged_in_user
640 @query.executed_by = logged_in_user
651 session[:query] = @query
641 session[:query] = @query
652 else
642 else
653 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
643 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
654 # Give it a name, required to be valid
644 # Give it a name, required to be valid
655 @query = Query.new(:name => "_", :executed_by => logged_in_user)
645 @query = Query.new(:name => "_", :executed_by => logged_in_user)
656 @query.project = @project
646 @query.project = @project
657 if params[:fields] and params[:fields].is_a? Array
647 if params[:fields] and params[:fields].is_a? Array
658 params[:fields].each do |field|
648 params[:fields].each do |field|
659 @query.add_filter(field, params[:operators][field], params[:values][field])
649 @query.add_filter(field, params[:operators][field], params[:values][field])
660 end
650 end
661 else
651 else
662 @query.available_filters.keys.each do |field|
652 @query.available_filters.keys.each do |field|
663 @query.add_short_filter(field, params[field]) if params[field]
653 @query.add_short_filter(field, params[field]) if params[field]
664 end
654 end
665 end
655 end
666 session[:query] = @query
656 session[:query] = @query
667 else
657 else
668 @query = session[:query]
658 @query = session[:query]
669 end
659 end
670 end
660 end
671 end
661 end
672 end
662 end
@@ -1,234 +1,234
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Query < ActiveRecord::Base
18 class Query < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 belongs_to :user
20 belongs_to :user
21 serialize :filters
21 serialize :filters
22
22
23 attr_protected :project, :user
23 attr_protected :project, :user
24 attr_accessor :executed_by
24 attr_accessor :executed_by
25
25
26 validates_presence_of :name, :on => :save
26 validates_presence_of :name, :on => :save
27
27
28 @@operators = { "=" => :label_equals,
28 @@operators = { "=" => :label_equals,
29 "!" => :label_not_equals,
29 "!" => :label_not_equals,
30 "o" => :label_open_issues,
30 "o" => :label_open_issues,
31 "c" => :label_closed_issues,
31 "c" => :label_closed_issues,
32 "!*" => :label_none,
32 "!*" => :label_none,
33 "*" => :label_all,
33 "*" => :label_all,
34 "<t+" => :label_in_less_than,
34 "<t+" => :label_in_less_than,
35 ">t+" => :label_in_more_than,
35 ">t+" => :label_in_more_than,
36 "t+" => :label_in,
36 "t+" => :label_in,
37 "t" => :label_today,
37 "t" => :label_today,
38 ">t-" => :label_less_than_ago,
38 ">t-" => :label_less_than_ago,
39 "<t-" => :label_more_than_ago,
39 "<t-" => :label_more_than_ago,
40 "t-" => :label_ago,
40 "t-" => :label_ago,
41 "~" => :label_contains,
41 "~" => :label_contains,
42 "!~" => :label_not_contains }
42 "!~" => :label_not_contains }
43
43
44 cattr_reader :operators
44 cattr_reader :operators
45
45
46 @@operators_by_filter_type = { :list => [ "=", "!" ],
46 @@operators_by_filter_type = { :list => [ "=", "!" ],
47 :list_status => [ "o", "=", "!", "c", "*" ],
47 :list_status => [ "o", "=", "!", "c", "*" ],
48 :list_optional => [ "=", "!", "!*", "*" ],
48 :list_optional => [ "=", "!", "!*", "*" ],
49 :list_one_or_more => [ "*", "=" ],
49 :list_one_or_more => [ "*", "=" ],
50 :date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ],
50 :date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ],
51 :date_past => [ ">t-", "<t-", "t-", "t" ],
51 :date_past => [ ">t-", "<t-", "t-", "t" ],
52 :string => [ "=", "~", "!", "!~" ],
52 :string => [ "=", "~", "!", "!~" ],
53 :text => [ "~", "!~" ] }
53 :text => [ "~", "!~" ] }
54
54
55 cattr_reader :operators_by_filter_type
55 cattr_reader :operators_by_filter_type
56
56
57 def initialize(attributes = nil)
57 def initialize(attributes = nil)
58 super attributes
58 super attributes
59 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
59 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
60 self.is_public = true
60 self.is_public = true
61 end
61 end
62
62
63 def executed_by=(user)
63 def executed_by=(user)
64 @executed_by = user
64 @executed_by = user
65 set_language_if_valid(user.language) if user
65 set_language_if_valid(user.language) if user
66 end
66 end
67
67
68 def validate
68 def validate
69 filters.each_key do |field|
69 filters.each_key do |field|
70 errors.add label_for(field), :activerecord_error_blank unless
70 errors.add label_for(field), :activerecord_error_blank unless
71 # filter requires one or more values
71 # filter requires one or more values
72 (values_for(field) and !values_for(field).first.empty?) or
72 (values_for(field) and !values_for(field).first.empty?) or
73 # filter doesn't require any value
73 # filter doesn't require any value
74 ["o", "c", "!*", "*", "t"].include? operator_for(field)
74 ["o", "c", "!*", "*", "t"].include? operator_for(field)
75 end if filters
75 end if filters
76 end
76 end
77
77
78 def available_filters
78 def available_filters
79 return @available_filters if @available_filters
79 return @available_filters if @available_filters
80 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
80 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
81 "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
81 "tracker_id" => { :type => :list, :order => 2, :values => Tracker.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
82 "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
82 "priority_id" => { :type => :list, :order => 3, :values => Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect{|s| [s.name, s.id.to_s] } },
83 "subject" => { :type => :text, :order => 8 },
83 "subject" => { :type => :text, :order => 8 },
84 "created_on" => { :type => :date_past, :order => 9 },
84 "created_on" => { :type => :date_past, :order => 9 },
85 "updated_on" => { :type => :date_past, :order => 10 },
85 "updated_on" => { :type => :date_past, :order => 10 },
86 "start_date" => { :type => :date, :order => 11 },
86 "start_date" => { :type => :date, :order => 11 },
87 "due_date" => { :type => :date, :order => 12 } }
87 "due_date" => { :type => :date, :order => 12 } }
88 unless project.nil?
88 unless project.nil?
89 # project specific filters
89 # project specific filters
90 user_values = []
90 user_values = []
91 user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
91 user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
92 user_values += @project.users.collect{|s| [s.name, s.id.to_s] }
92 user_values += @project.users.collect{|s| [s.name, s.id.to_s] }
93
93
94 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values }
94 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values }
95 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values }
95 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values }
96 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
96 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
97 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.collect{|s| [s.name, s.id.to_s] } }
97 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
98 unless @project.children.empty?
98 unless @project.children.empty?
99 @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.children.collect{|s| [s.name, s.id.to_s] } }
99 @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.children.collect{|s| [s.name, s.id.to_s] } }
100 end
100 end
101 @project.all_custom_fields.select(&:is_filter?).each do |field|
101 @project.all_custom_fields.select(&:is_filter?).each do |field|
102 case field.field_format
102 case field.field_format
103 when "string", "int"
103 when "string", "int"
104 options = { :type => :string, :order => 20 }
104 options = { :type => :string, :order => 20 }
105 when "text"
105 when "text"
106 options = { :type => :text, :order => 20 }
106 options = { :type => :text, :order => 20 }
107 when "list"
107 when "list"
108 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
108 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
109 when "date"
109 when "date"
110 options = { :type => :date, :order => 20 }
110 options = { :type => :date, :order => 20 }
111 when "bool"
111 when "bool"
112 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
112 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
113 end
113 end
114 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
114 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
115 end
115 end
116 # remove category filter if no category defined
116 # remove category filter if no category defined
117 @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
117 @available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
118 end
118 end
119 @available_filters
119 @available_filters
120 end
120 end
121
121
122 def add_filter(field, operator, values)
122 def add_filter(field, operator, values)
123 # values must be an array
123 # values must be an array
124 return unless values and values.is_a? Array # and !values.first.empty?
124 return unless values and values.is_a? Array # and !values.first.empty?
125 # check if field is defined as an available filter
125 # check if field is defined as an available filter
126 if available_filters.has_key? field
126 if available_filters.has_key? field
127 filter_options = available_filters[field]
127 filter_options = available_filters[field]
128 # check if operator is allowed for that filter
128 # check if operator is allowed for that filter
129 #if @@operators_by_filter_type[filter_options[:type]].include? operator
129 #if @@operators_by_filter_type[filter_options[:type]].include? operator
130 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
130 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
131 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
131 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
132 #end
132 #end
133 filters[field] = {:operator => operator, :values => values }
133 filters[field] = {:operator => operator, :values => values }
134 end
134 end
135 end
135 end
136
136
137 def add_short_filter(field, expression)
137 def add_short_filter(field, expression)
138 return unless expression
138 return unless expression
139 parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
139 parms = expression.scan(/^(o|c|\!|\*)?(.*)$/).first
140 add_filter field, (parms[0] || "="), [parms[1] || ""]
140 add_filter field, (parms[0] || "="), [parms[1] || ""]
141 end
141 end
142
142
143 def has_filter?(field)
143 def has_filter?(field)
144 filters and filters[field]
144 filters and filters[field]
145 end
145 end
146
146
147 def operator_for(field)
147 def operator_for(field)
148 has_filter?(field) ? filters[field][:operator] : nil
148 has_filter?(field) ? filters[field][:operator] : nil
149 end
149 end
150
150
151 def values_for(field)
151 def values_for(field)
152 has_filter?(field) ? filters[field][:values] : nil
152 has_filter?(field) ? filters[field][:values] : nil
153 end
153 end
154
154
155 def label_for(field)
155 def label_for(field)
156 label = @available_filters[field][:name] if @available_filters.has_key?(field)
156 label = @available_filters[field][:name] if @available_filters.has_key?(field)
157 label ||= field.gsub(/\_id$/, "")
157 label ||= field.gsub(/\_id$/, "")
158 end
158 end
159
159
160 def statement
160 def statement
161 sql = "1=1"
161 sql = "1=1"
162 if has_filter?("subproject_id")
162 if has_filter?("subproject_id")
163 subproject_ids = []
163 subproject_ids = []
164 if operator_for("subproject_id") == "="
164 if operator_for("subproject_id") == "="
165 subproject_ids = values_for("subproject_id").each(&:to_i)
165 subproject_ids = values_for("subproject_id").each(&:to_i)
166 else
166 else
167 subproject_ids = project.children.collect{|p| p.id}
167 subproject_ids = project.children.collect{|p| p.id}
168 end
168 end
169 sql << " AND #{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
169 sql << " AND #{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
170 else
170 else
171 sql << " AND #{Issue.table_name}.project_id=%d" % project.id if project
171 sql << " AND #{Issue.table_name}.project_id=%d" % project.id if project
172 end
172 end
173 filters.each_key do |field|
173 filters.each_key do |field|
174 next if field == "subproject_id"
174 next if field == "subproject_id"
175 v = values_for(field).clone
175 v = values_for(field).clone
176 next unless v and !v.empty?
176 next unless v and !v.empty?
177
177
178 sql = sql + " AND " unless sql.empty?
178 sql = sql + " AND " unless sql.empty?
179 sql << "("
179 sql << "("
180
180
181 if field =~ /^cf_(\d+)$/
181 if field =~ /^cf_(\d+)$/
182 # custom field
182 # custom field
183 db_table = CustomValue.table_name
183 db_table = CustomValue.table_name
184 db_field = "value"
184 db_field = "value"
185 sql << "#{db_table}.custom_field_id = #{$1} AND "
185 sql << "#{db_table}.custom_field_id = #{$1} AND "
186 else
186 else
187 # regular field
187 # regular field
188 db_table = Issue.table_name
188 db_table = Issue.table_name
189 db_field = field
189 db_field = field
190 end
190 end
191
191
192 # "me" value subsitution
192 # "me" value subsitution
193 if %w(assigned_to_id author_id).include?(field)
193 if %w(assigned_to_id author_id).include?(field)
194 v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
194 v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
195 end
195 end
196
196
197 case operator_for field
197 case operator_for field
198 when "="
198 when "="
199 sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
199 sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
200 when "!"
200 when "!"
201 sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
201 sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
202 when "!*"
202 when "!*"
203 sql = sql + "#{db_table}.#{db_field} IS NULL"
203 sql = sql + "#{db_table}.#{db_field} IS NULL"
204 when "*"
204 when "*"
205 sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
205 sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
206 when "o"
206 when "o"
207 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
207 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
208 when "c"
208 when "c"
209 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
209 sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
210 when ">t-"
210 when ">t-"
211 sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
211 sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
212 when "<t-"
212 when "<t-"
213 sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
213 sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
214 when "t-"
214 when "t-"
215 sql = sql + "#{db_table}.#{db_field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
215 sql = sql + "#{db_table}.#{db_field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
216 when ">t+"
216 when ">t+"
217 sql = sql + "#{db_table}.#{db_field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
217 sql = sql + "#{db_table}.#{db_field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
218 when "<t+"
218 when "<t+"
219 sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
219 sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
220 when "t+"
220 when "t+"
221 sql = sql + "#{db_table}.#{db_field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
221 sql = sql + "#{db_table}.#{db_field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
222 when "t"
222 when "t"
223 sql = sql + "#{db_table}.#{db_field} = '%s'" % connection.quoted_date(Date.today)
223 sql = sql + "#{db_table}.#{db_field} = '%s'" % connection.quoted_date(Date.today)
224 when "~"
224 when "~"
225 sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
225 sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
226 when "!~"
226 when "!~"
227 sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
227 sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
228 end
228 end
229 sql << ")"
229 sql << ")"
230
230
231 end if filters and valid?
231 end if filters and valid?
232 sql
232 sql
233 end
233 end
234 end
234 end
@@ -1,44 +1,54
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Version < ActiveRecord::Base
18 class Version < ActiveRecord::Base
19 before_destroy :check_integrity
19 before_destroy :check_integrity
20 belongs_to :project
20 belongs_to :project
21 has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
21 has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
22 has_many :attachments, :as => :container, :dependent => :destroy
22 has_many :attachments, :as => :container, :dependent => :destroy
23
23
24 validates_presence_of :name
24 validates_presence_of :name
25 validates_uniqueness_of :name, :scope => [:project_id]
25 validates_uniqueness_of :name, :scope => [:project_id]
26 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date
26 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date, :allow_nil => true
27
27
28 def start_date
28 def start_date
29 effective_date
29 effective_date
30 end
30 end
31
31
32 def due_date
32 def due_date
33 effective_date
33 effective_date
34 end
34 end
35
35
36 def completed?
36 def completed?
37 effective_date && effective_date <= Date.today
37 effective_date && effective_date <= Date.today
38 end
38 end
39
39
40 # Versions are sorted by effective_date
41 # Those with no effective_date are at the end, sorted by name
42 def <=>(version)
43 if self.effective_date
44 version.effective_date ? (self.effective_date <=> version.effective_date) : -1
45 else
46 version.effective_date ? 1 : (self.name <=> version.name)
47 end
48 end
49
40 private
50 private
41 def check_integrity
51 def check_integrity
42 raise "Can't delete version" if self.fixed_issues.find(:first)
52 raise "Can't delete version" if self.fixed_issues.find(:first)
43 end
53 end
44 end
54 end
@@ -1,27 +1,36
1 <h2><%=l(:label_change_log)%></h2>
1 <h2><%=l(:label_change_log)%></h2>
2
2
3 <div class="rightbox" style="width:140px;">
3 <div class="rightbox" style="width:140px;">
4 <% form_tag do %>
4 <% form_tag do %>
5 <p><strong><%=l(:label_tracker_plural)%></strong><br />
5 <p><strong><%=l(:label_tracker_plural)%></strong><br />
6 <% @trackers.each do |tracker| %>
6 <% @trackers.each do |tracker| %>
7 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
7 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
8 <%= tracker.name %><br />
8 <%= tracker.name %><br />
9 <% end %></p>
9 <% end %></p>
10 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
10 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
11 <% end %>
11 <% end %>
12 </div>
12 </div>
13
13
14 <% if @fixed_issues.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
14 <% if @versions.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
15
15
16 <% ver_id = nil
16 <% @versions.each do |version| %>
17 @fixed_issues.each do |issue| %>
17 <a name="<%= version.name %>"><h3 class="icon22 icon22-package"><%= version.name %></h3></a>
18 <% unless ver_id == issue.fixed_version_id %>
18 <% if version.completed? %>
19 <% if ver_id %></ul><% end %>
19 <p><%= format_date(version.effective_date) %></p>
20 <h3 class="icon22 icon22-package"><%= issue.fixed_version.name %></h3>
20 <% elsif version.effective_date %>
21 <p><%= format_date(issue.fixed_version.effective_date) %><br />
21 <p><strong><%=l(:label_roadmap_due_in)%> <%= distance_of_time_in_words Time.now, version.effective_date %> (<%= format_date(version.effective_date) %>)</strong></p>
22 <%=h issue.fixed_version.description %></p>
22 <% end %>
23 <p><%=h version.description %></p>
24 <% issues = version.fixed_issues.find(:all,
25 :include => [:status, :tracker],
26 :conditions => ["#{IssueStatus.table_name}.is_closed=? AND #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", true],
27 :order => "#{Tracker.table_name}.position")
28 %>
29 <% if !issues.empty? %>
23 <ul>
30 <ul>
24 <% ver_id = issue.fixed_version_id
31 <% issues.each do |issue| %>
25 end %>
32 <li><%= link_to_issue(issue) %>: <%=h issue.subject %></li>
26 <li><%= link_to_issue issue %>: <%=h issue.subject %></li>
33 <% end %>
34 </ul>
35 <% end %>
27 <% end %>
36 <% end %>
@@ -1,61 +1,61
1 <h2><%=l(:label_roadmap)%></h2>
1 <h2><%=l(:label_roadmap)%></h2>
2
2
3 <div class="rightbox">
3 <div class="rightbox">
4 <% form_tag do %>
4 <% form_tag do %>
5 <p><strong><%=l(:label_tracker_plural)%></strong><br />
5 <p><strong><%=l(:label_tracker_plural)%></strong><br />
6 <% @trackers.each do |tracker| %>
6 <% @trackers.each do |tracker| %>
7 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
7 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
8 <%= tracker.name %><br />
8 <%= tracker.name %><br />
9 <% end %></p>
9 <% end %></p>
10 <p class="small"><label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label></p>
10 <p class="small"><label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label></p>
11 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
11 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
12 <% end %>
12 <% end %>
13 </div>
13 </div>
14
14
15 <% if @versions.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
15 <% if @versions.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
16
16
17 <% @versions.each do |version| %>
17 <% @versions.each do |version| %>
18 <a name="<%= version.name %>"><h3 class="icon22 icon22-package"><%= version.name %></h3></a>
18 <a name="<%= version.name %>"><h3 class="icon22 icon22-package"><%= version.name %></h3></a>
19 <% if version.completed? %>
19 <% if version.completed? %>
20 <p><%= format_date(version.effective_date) %></p>
20 <p><%= format_date(version.effective_date) %></p>
21 <% else %>
21 <% elsif version.effective_date %>
22 <p><strong><%=l(:label_roadmap_due_in)%> <%= distance_of_time_in_words Time.now, version.effective_date %> (<%= format_date(version.effective_date) %>)</strong></p>
22 <p><strong><%=l(:label_roadmap_due_in)%> <%= distance_of_time_in_words Time.now, version.effective_date %> (<%= format_date(version.effective_date) %>)</strong></p>
23 <% end %>
23 <% end %>
24 <p><%=h version.description %></p>
24 <p><%=h version.description %></p>
25 <% issues = version.fixed_issues.find(:all,
25 <% issues = version.fixed_issues.find(:all,
26 :include => [:status, :tracker],
26 :include => [:status, :tracker],
27 :conditions => ["tracker_id in (#{@selected_tracker_ids.join(',')})"],
27 :conditions => ["tracker_id in (#{@selected_tracker_ids.join(',')})"],
28 :order => "#{Tracker.table_name}.position")
28 :order => "#{Tracker.table_name}.position")
29
29
30 total = issues.size
30 total = issues.size
31 complete = issues.inject(0) {|c,i| i.status.is_closed? ? c + 1 : c }
31 complete = issues.inject(0) {|c,i| i.status.is_closed? ? c + 1 : c }
32 percentComplete = total == 0 ? 100 : (100 / total * complete).floor
32 percentComplete = total == 0 ? 100 : (100 / total * complete).floor
33 percentIncomplete = 100 - percentComplete
33 percentIncomplete = 100 - percentComplete
34 %>
34 %>
35 <table class="progress">
35 <table class="progress">
36 <tr>
36 <tr>
37 <% if percentComplete > 0 %>
37 <% if percentComplete > 0 %>
38 <td class="closed" style="width: <%= percentComplete %>%"></td>
38 <td class="closed" style="width: <%= percentComplete %>%"></td>
39 <% end; if percentIncomplete > 0 %>
39 <% end; if percentIncomplete > 0 %>
40 <td class="open" style="width: <%= percentIncomplete %>%"></td>
40 <td class="open" style="width: <%= percentIncomplete %>%"></td>
41 <% end %>
41 <% end %>
42 </tr>
42 </tr>
43 </table>
43 </table>
44 <em><%= link_to(complete, :controller => 'projects', :action => 'list_issues', :id => @project, :status_id => 'c', :fixed_version_id => version, :set_filter => 1) %> <%= lwr(:label_closed_issues, complete) %> (<%= percentComplete %>%) &#160;
44 <em><%= link_to(complete, :controller => 'projects', :action => 'list_issues', :id => @project, :status_id => 'c', :fixed_version_id => version, :set_filter => 1) %> <%= lwr(:label_closed_issues, complete) %> (<%= percentComplete %>%) &#160;
45 <%= link_to((total - complete), :controller => 'projects', :action => 'list_issues', :id => @project, :status_id => 'o', :fixed_version_id => version, :set_filter => 1) %> <%= lwr(:label_open_issues, total - complete)%> (<%= percentIncomplete %>%)</em>
45 <%= link_to((total - complete), :controller => 'projects', :action => 'list_issues', :id => @project, :status_id => 'o', :fixed_version_id => version, :set_filter => 1) %> <%= lwr(:label_open_issues, total - complete)%> (<%= percentIncomplete %>%)</em>
46 <br />
46 <br />
47 <br />
47 <br />
48 <ul>
48 <ul>
49 <% if total == 0 %>
49 <% if total == 0 %>
50 <li><%=l(:label_roadmap_no_issues)%></li>
50 <li><%=l(:label_roadmap_no_issues)%></li>
51 <% else %>
51 <% else %>
52 <% issues.each do |issue| %>
52 <% issues.each do |issue| %>
53 <li>
53 <li>
54 <%= link = link_to_issue(issue)
54 <%= link = link_to_issue(issue)
55 issue.status.is_closed? ? content_tag("del", link) : link %>: <%=h issue.subject %>
55 issue.status.is_closed? ? content_tag("del", link) : link %>: <%=h issue.subject %>
56 <%= content_tag "em", "(#{l(:label_closed_issues)})" if issue.status.is_closed? %>
56 <%= content_tag "em", "(#{l(:label_closed_issues)})" if issue.status.is_closed? %>
57 </li>
57 </li>
58 <% end %>
58 <% end %>
59 <% end %>
59 <% end %>
60 </ul>
60 </ul>
61 <% end %>
61 <% end %>
@@ -1,85 +1,85
1 <h2><%=l(:label_settings)%></h2>
1 <h2><%=l(:label_settings)%></h2>
2
2
3 <div class="tabs">
3 <div class="tabs">
4 <ul>
4 <ul>
5 <li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li>
5 <li><%= link_to l(:label_information_plural), {}, :id=> "tab-info", :onclick => "showTab('info'); this.blur(); return false;" %></li>
6 <li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li>
6 <li><%= link_to l(:label_member_plural), {}, :id=> "tab-members", :onclick => "showTab('members'); this.blur(); return false;" %></li>
7 <li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li>
7 <li><%= link_to l(:label_version_plural), {}, :id=> "tab-versions", :onclick => "showTab('versions'); this.blur(); return false;" %></li>
8 <li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li>
8 <li><%= link_to l(:label_issue_category_plural), {}, :id=> "tab-categories", :onclick => "showTab('categories'); this.blur(); return false;" %></li>
9 <li><%= link_to l(:label_board_plural), {}, :id=> "tab-boards", :onclick => "showTab('boards'); this.blur(); return false;" %></li>
9 <li><%= link_to l(:label_board_plural), {}, :id=> "tab-boards", :onclick => "showTab('boards'); this.blur(); return false;" %></li>
10 </ul>
10 </ul>
11 </div>
11 </div>
12
12
13 <div id="tab-content-info" class="tab-content">
13 <div id="tab-content-info" class="tab-content">
14 <% if authorize_for('projects', 'edit') %>
14 <% if authorize_for('projects', 'edit') %>
15 <% labelled_tabular_form_for :project, @project, :url => { :action => "edit", :id => @project } do |f| %>
15 <% labelled_tabular_form_for :project, @project, :url => { :action => "edit", :id => @project } do |f| %>
16 <%= render :partial => 'form', :locals => { :f => f } %>
16 <%= render :partial => 'form', :locals => { :f => f } %>
17 <%= submit_tag l(:button_save) %>
17 <%= submit_tag l(:button_save) %>
18 <% end %>
18 <% end %>
19 <% end %>
19 <% end %>
20 </div>
20 </div>
21
21
22 <div id="tab-content-members" class="tab-content" style="display:none;">
22 <div id="tab-content-members" class="tab-content" style="display:none;">
23 <%= render :partial => 'members' %>
23 <%= render :partial => 'members' %>
24 </div>
24 </div>
25
25
26 <div id="tab-content-versions" class="tab-content" style="display:none;">
26 <div id="tab-content-versions" class="tab-content" style="display:none;">
27 <table class="list">
27 <table class="list">
28 <thead><th><%= l(:label_version) %></th><th><%= l(:field_effective_date) %></th><th><%= l(:field_description) %></th><th style="width:15%"></th><th style="width:15%"></th></thead>
28 <thead><th><%= l(:label_version) %></th><th><%= l(:field_effective_date) %></th><th><%= l(:field_description) %></th><th style="width:15%"></th><th style="width:15%"></th></thead>
29 <tbody>
29 <tbody>
30 <% for version in @project.versions %>
30 <% for version in @project.versions.sort %>
31 <tr class="<%= cycle 'odd', 'even' %>">
31 <tr class="<%= cycle 'odd', 'even' %>">
32 <td><%=h version.name %></td>
32 <td><%=h version.name %></td>
33 <td align="center"><%= format_date(version.effective_date) %></td>
33 <td align="center"><%= format_date(version.effective_date) %></td>
34 <td><%=h version.description %></td>
34 <td><%=h version.description %></td>
35 <td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></small></td>
35 <td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></small></td>
36 <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td>
36 <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td>
37 </td>
37 </td>
38 </tr>
38 </tr>
39 <% end; reset_cycle %>
39 <% end; reset_cycle %>
40 </tbody>
40 </tbody>
41 </table>
41 </table>
42 &nbsp;
42 &nbsp;
43 <p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p>
43 <p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p>
44 </div>
44 </div>
45
45
46 <div id="tab-content-categories" class="tab-content" style="display:none;">
46 <div id="tab-content-categories" class="tab-content" style="display:none;">
47 <table class="list">
47 <table class="list">
48 <thead><th><%= l(:label_issue_category) %></th><th style="width:15%"></th></thead>
48 <thead><th><%= l(:label_issue_category) %></th><th style="width:15%"></th></thead>
49 <tbody>
49 <tbody>
50 <% for @category in @project.issue_categories %>
50 <% for @category in @project.issue_categories %>
51 <% unless @category.new_record? %>
51 <% unless @category.new_record? %>
52 <tr class="<%= cycle 'odd', 'even' %>">
52 <tr class="<%= cycle 'odd', 'even' %>">
53 <td>
53 <td>
54 <% form_tag({:controller => 'issue_categories', :action => 'edit', :id => @category}) do %>
54 <% form_tag({:controller => 'issue_categories', :action => 'edit', :id => @category}) do %>
55 <%= text_field 'category', 'name', :size => 25 %>
55 <%= text_field 'category', 'name', :size => 25 %>
56 <% if authorize_for('issue_categories', 'edit') %>
56 <% if authorize_for('issue_categories', 'edit') %>
57 <%= submit_tag l(:button_save), :class => "button-small" %>
57 <%= submit_tag l(:button_save), :class => "button-small" %>
58 <% end %>
58 <% end %>
59 <% end %>
59 <% end %>
60 </td>
60 </td>
61 <td align="center">
61 <td align="center">
62 <small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => @category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small>
62 <small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => @category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small>
63 </td>
63 </td>
64 </tr>
64 </tr>
65 <% end %>
65 <% end %>
66 <% end %>
66 <% end %>
67 </tbody>
67 </tbody>
68 </table>
68 </table>
69 &nbsp;
69 &nbsp;
70 <% if authorize_for('projects', 'add_issue_category') %>
70 <% if authorize_for('projects', 'add_issue_category') %>
71 <% form_tag({:action => 'add_issue_category', :tab => 'categories', :id => @project}) do %>
71 <% form_tag({:action => 'add_issue_category', :tab => 'categories', :id => @project}) do %>
72 <p><label for="issue_category_name"><%=l(:label_issue_category_new)%></label><br />
72 <p><label for="issue_category_name"><%=l(:label_issue_category_new)%></label><br />
73 <%= error_messages_for 'issue_category' %>
73 <%= error_messages_for 'issue_category' %>
74 <%= text_field 'issue_category', 'name', :size => 25 %>
74 <%= text_field 'issue_category', 'name', :size => 25 %>
75 <%= submit_tag l(:button_add) %></p>
75 <%= submit_tag l(:button_add) %></p>
76 <% end %>
76 <% end %>
77 <% end %>
77 <% end %>
78 </div>
78 </div>
79
79
80 <div id="tab-content-boards" class="tab-content" style="display:none;">
80 <div id="tab-content-boards" class="tab-content" style="display:none;">
81 <%= render :partial => 'boards' %>
81 <%= render :partial => 'boards' %>
82 </div>
82 </div>
83
83
84 <%= tab = params[:tab] ? h(params[:tab]) : 'info'
84 <%= tab = params[:tab] ? h(params[:tab]) : 'info'
85 javascript_tag "showTab('#{tab}');" %> No newline at end of file
85 javascript_tag "showTab('#{tab}');" %>
@@ -1,16 +1,16
1 <%= error_messages_for 'version' %>
1 <%= error_messages_for 'version' %>
2
2
3 <div class="box">
3 <div class="box">
4 <!--[form:version]-->
4 <!--[form:version]-->
5 <p><%= f.text_field :name, :size => 20, :required => true %></p>
5 <p><%= f.text_field :name, :size => 20, :required => true %></p>
6 <p><%= f.text_field :description, :size => 60 %></p>
6 <p><%= f.text_field :description, :size => 60 %></p>
7 <p><%= f.text_field :effective_date, :size => 10, :required => true %><%= calendar_for('version_effective_date') %></p>
7 <p><%= f.text_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
8 <!--[eoform:version]-->
8 <!--[eoform:version]-->
9 </div>
9 </div>
10
10
11 <% content_for :header_tags do %>
11 <% content_for :header_tags do %>
12 <%= javascript_include_tag 'calendar/calendar' %>
12 <%= javascript_include_tag 'calendar/calendar' %>
13 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
13 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
14 <%= javascript_include_tag 'calendar/calendar-setup' %>
14 <%= javascript_include_tag 'calendar/calendar-setup' %>
15 <%= stylesheet_link_tag 'calendar' %>
15 <%= stylesheet_link_tag 'calendar' %>
16 <% end %> No newline at end of file
16 <% end %>
@@ -1,17 +1,26
1 ---
1 ---
2 versions_001:
2 versions_001:
3 created_on: 2006-07-19 21:00:07 +02:00
3 created_on: 2006-07-19 21:00:07 +02:00
4 name: "0.1"
4 name: "0.1"
5 project_id: 1
5 project_id: 1
6 updated_on: 2006-07-19 21:00:07 +02:00
6 updated_on: 2006-07-19 21:00:07 +02:00
7 id: 1
7 id: 1
8 description: Beta
8 description: Beta
9 effective_date: 2006-07-01
9 effective_date: 2006-07-01
10 versions_002:
10 versions_002:
11 created_on: 2006-07-19 21:00:33 +02:00
11 created_on: 2006-07-19 21:00:33 +02:00
12 name: "1.0"
12 name: "1.0"
13 project_id: 1
13 project_id: 1
14 updated_on: 2006-07-19 21:00:33 +02:00
14 updated_on: 2006-07-19 21:00:33 +02:00
15 id: 2
15 id: 2
16 description: Stable release
16 description: Stable release
17 effective_date: 2006-07-19
17 effective_date: 2006-07-19
18 versions_003:
19 created_on: 2006-07-19 21:00:33 +02:00
20 name: "2.0"
21 project_id: 1
22 updated_on: 2006-07-19 21:00:33 +02:00
23 id: 3
24 description: Future version
25 effective_date:
26 No newline at end of file
@@ -1,128 +1,128
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :permissions
25 fixtures :projects, :permissions
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 end
31 end
32
32
33 def test_index
33 def test_index
34 get :index
34 get :index
35 assert_response :success
35 assert_response :success
36 assert_template 'list'
36 assert_template 'list'
37 end
37 end
38
38
39 def test_list
39 def test_list
40 get :list
40 get :list
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:projects)
43 assert_not_nil assigns(:projects)
44 end
44 end
45
45
46 def test_show
46 def test_show
47 get :show, :id => 1
47 get :show, :id => 1
48 assert_response :success
48 assert_response :success
49 assert_template 'show'
49 assert_template 'show'
50 assert_not_nil assigns(:project)
50 assert_not_nil assigns(:project)
51 end
51 end
52
52
53 def test_list_members
53 def test_list_members
54 get :list_members, :id => 1
54 get :list_members, :id => 1
55 assert_response :success
55 assert_response :success
56 assert_template 'list_members'
56 assert_template 'list_members'
57 assert_not_nil assigns(:members)
57 assert_not_nil assigns(:members)
58 end
58 end
59
59
60 def test_list_documents
60 def test_list_documents
61 get :list_documents, :id => 1
61 get :list_documents, :id => 1
62 assert_response :success
62 assert_response :success
63 assert_template 'list_documents'
63 assert_template 'list_documents'
64 assert_not_nil assigns(:documents)
64 assert_not_nil assigns(:documents)
65 end
65 end
66
66
67 def test_list_issues
67 def test_list_issues
68 get :list_issues, :id => 1
68 get :list_issues, :id => 1
69 assert_response :success
69 assert_response :success
70 assert_template 'list_issues'
70 assert_template 'list_issues'
71 assert_not_nil assigns(:issues)
71 assert_not_nil assigns(:issues)
72 end
72 end
73
73
74 def test_list_issues_with_filter
74 def test_list_issues_with_filter
75 get :list_issues, :id => 1, :set_filter => 1
75 get :list_issues, :id => 1, :set_filter => 1
76 assert_response :success
76 assert_response :success
77 assert_template 'list_issues'
77 assert_template 'list_issues'
78 assert_not_nil assigns(:issues)
78 assert_not_nil assigns(:issues)
79 end
79 end
80
80
81 def test_list_issues_reset_filter
81 def test_list_issues_reset_filter
82 post :list_issues, :id => 1
82 post :list_issues, :id => 1
83 assert_response :success
83 assert_response :success
84 assert_template 'list_issues'
84 assert_template 'list_issues'
85 assert_not_nil assigns(:issues)
85 assert_not_nil assigns(:issues)
86 end
86 end
87
87
88 def test_export_issues_csv
88 def test_export_issues_csv
89 get :export_issues_csv, :id => 1
89 get :export_issues_csv, :id => 1
90 assert_response :success
90 assert_response :success
91 assert_not_nil assigns(:issues)
91 assert_not_nil assigns(:issues)
92 end
92 end
93
93
94 def test_list_news
94 def test_list_news
95 get :list_news, :id => 1
95 get :list_news, :id => 1
96 assert_response :success
96 assert_response :success
97 assert_template 'list_news'
97 assert_template 'list_news'
98 assert_not_nil assigns(:news)
98 assert_not_nil assigns(:news)
99 end
99 end
100
100
101 def test_list_files
101 def test_list_files
102 get :list_files, :id => 1
102 get :list_files, :id => 1
103 assert_response :success
103 assert_response :success
104 assert_template 'list_files'
104 assert_template 'list_files'
105 assert_not_nil assigns(:versions)
105 assert_not_nil assigns(:versions)
106 end
106 end
107
107
108 def test_changelog
108 def test_changelog
109 get :changelog, :id => 1
109 get :changelog, :id => 1
110 assert_response :success
110 assert_response :success
111 assert_template 'changelog'
111 assert_template 'changelog'
112 assert_not_nil assigns(:fixed_issues)
112 assert_not_nil assigns(:versions)
113 end
113 end
114
114
115 def test_roadmap
115 def test_roadmap
116 get :roadmap, :id => 1
116 get :roadmap, :id => 1
117 assert_response :success
117 assert_response :success
118 assert_template 'roadmap'
118 assert_template 'roadmap'
119 assert_not_nil assigns(:versions)
119 assert_not_nil assigns(:versions)
120 end
120 end
121
121
122 def test_activity
122 def test_activity
123 get :activity, :id => 1
123 get :activity, :id => 1
124 assert_response :success
124 assert_response :success
125 assert_template 'activity'
125 assert_template 'activity'
126 assert_not_nil assigns(:events_by_day)
126 assert_not_nil assigns(:events_by_day)
127 end
127 end
128 end
128 end
General Comments 0
You need to be logged in to leave comments. Login now