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