##// END OF EJS Templates
Fixed: custom field selection is not saved when unchecking them all on project settings...
Jean-Philippe Lang -
r1069:d79c20c4f28f
parent child
Show More
@@ -1,485 +1,484
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 => [:bulk_edit_issues, :changelog, :move_issues]
25 menu_item :issues, :only => [:bulk_edit_issues, :changelog, :move_issues]
26
26
27 before_filter :find_project, :except => [ :index, :list, :add ]
27 before_filter :find_project, :except => [ :index, :list, :add ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
30 accept_key_auth :activity, :calendar
30 accept_key_auth :activity, :calendar
31
31
32 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
32 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
33 cache_sweeper :version_sweeper, :only => [ :add_version ]
33 cache_sweeper :version_sweeper, :only => [ :add_version ]
34
34
35 helper :sort
35 helper :sort
36 include SortHelper
36 include SortHelper
37 helper :custom_fields
37 helper :custom_fields
38 include CustomFieldsHelper
38 include CustomFieldsHelper
39 helper :ifpdf
39 helper :ifpdf
40 include IfpdfHelper
40 include IfpdfHelper
41 helper :issues
41 helper :issues
42 helper IssuesHelper
42 helper IssuesHelper
43 helper :queries
43 helper :queries
44 include QueriesHelper
44 include QueriesHelper
45 helper :repositories
45 helper :repositories
46 include RepositoriesHelper
46 include RepositoriesHelper
47 include ProjectsHelper
47 include ProjectsHelper
48
48
49 def index
49 def index
50 list
50 list
51 render :action => 'list' unless request.xhr?
51 render :action => 'list' unless request.xhr?
52 end
52 end
53
53
54 # Lists visible projects
54 # Lists visible projects
55 def list
55 def list
56 projects = Project.find :all,
56 projects = Project.find :all,
57 :conditions => Project.visible_by(User.current),
57 :conditions => Project.visible_by(User.current),
58 :include => :parent
58 :include => :parent
59 @project_tree = projects.group_by {|p| p.parent || p}
59 @project_tree = projects.group_by {|p| p.parent || p}
60 @project_tree.each_key {|p| @project_tree[p] -= [p]}
60 @project_tree.each_key {|p| @project_tree[p] -= [p]}
61 end
61 end
62
62
63 # Add a new project
63 # Add a new project
64 def add
64 def add
65 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
65 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
66 @trackers = Tracker.all
66 @trackers = Tracker.all
67 @root_projects = Project.find(:all,
67 @root_projects = Project.find(:all,
68 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
68 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
69 :order => 'name')
69 :order => 'name')
70 @project = Project.new(params[:project])
70 @project = Project.new(params[:project])
71 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
71 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
72 if request.get?
72 if request.get?
73 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
73 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
74 @project.trackers = Tracker.all
74 @project.trackers = Tracker.all
75 else
75 else
76 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
76 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
77 @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 @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)) }
78 @project.custom_values = @custom_values
78 @project.custom_values = @custom_values
79 if @project.save
79 if @project.save
80 @project.enabled_module_names = params[:enabled_modules]
80 @project.enabled_module_names = params[:enabled_modules]
81 flash[:notice] = l(:notice_successful_create)
81 flash[:notice] = l(:notice_successful_create)
82 redirect_to :controller => 'admin', :action => 'projects'
82 redirect_to :controller => 'admin', :action => 'projects'
83 end
83 end
84 end
84 end
85 end
85 end
86
86
87 # Show @project
87 # Show @project
88 def show
88 def show
89 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
89 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
90 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
90 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
91 @subprojects = @project.active_children
91 @subprojects = @project.active_children
92 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
92 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
93 @trackers = @project.trackers
93 @trackers = @project.trackers
94 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
94 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
95 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
95 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
96 @total_hours = @project.time_entries.sum(:hours)
96 @total_hours = @project.time_entries.sum(:hours)
97 @key = User.current.rss_key
97 @key = User.current.rss_key
98 end
98 end
99
99
100 def settings
100 def settings
101 @root_projects = Project.find(:all,
101 @root_projects = Project.find(:all,
102 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
102 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
103 :order => 'name')
103 :order => 'name')
104 @custom_fields = IssueCustomField.find(:all)
104 @custom_fields = IssueCustomField.find(:all)
105 @issue_category ||= IssueCategory.new
105 @issue_category ||= IssueCategory.new
106 @member ||= @project.members.new
106 @member ||= @project.members.new
107 @trackers = Tracker.all
107 @trackers = Tracker.all
108 @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) }
108 @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) }
109 @repository ||= @project.repository
109 @repository ||= @project.repository
110 @wiki ||= @project.wiki
110 @wiki ||= @project.wiki
111 end
111 end
112
112
113 # Edit @project
113 # Edit @project
114 def edit
114 def edit
115 if request.post?
115 if request.post?
116 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
117 if params[:custom_fields]
116 if params[:custom_fields]
118 @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]) }
117 @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]) }
119 @project.custom_values = @custom_values
118 @project.custom_values = @custom_values
120 end
119 end
121 @project.attributes = params[:project]
120 @project.attributes = params[:project]
122 if @project.save
121 if @project.save
123 flash[:notice] = l(:notice_successful_update)
122 flash[:notice] = l(:notice_successful_update)
124 redirect_to :action => 'settings', :id => @project
123 redirect_to :action => 'settings', :id => @project
125 else
124 else
126 settings
125 settings
127 render :action => 'settings'
126 render :action => 'settings'
128 end
127 end
129 end
128 end
130 end
129 end
131
130
132 def modules
131 def modules
133 @project.enabled_module_names = params[:enabled_modules]
132 @project.enabled_module_names = params[:enabled_modules]
134 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
133 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
135 end
134 end
136
135
137 def archive
136 def archive
138 @project.archive if request.post? && @project.active?
137 @project.archive if request.post? && @project.active?
139 redirect_to :controller => 'admin', :action => 'projects'
138 redirect_to :controller => 'admin', :action => 'projects'
140 end
139 end
141
140
142 def unarchive
141 def unarchive
143 @project.unarchive if request.post? && !@project.active?
142 @project.unarchive if request.post? && !@project.active?
144 redirect_to :controller => 'admin', :action => 'projects'
143 redirect_to :controller => 'admin', :action => 'projects'
145 end
144 end
146
145
147 # Delete @project
146 # Delete @project
148 def destroy
147 def destroy
149 @project_to_destroy = @project
148 @project_to_destroy = @project
150 if request.post? and params[:confirm]
149 if request.post? and params[:confirm]
151 @project_to_destroy.destroy
150 @project_to_destroy.destroy
152 redirect_to :controller => 'admin', :action => 'projects'
151 redirect_to :controller => 'admin', :action => 'projects'
153 end
152 end
154 # hide project in layout
153 # hide project in layout
155 @project = nil
154 @project = nil
156 end
155 end
157
156
158 # Add a new issue category to @project
157 # Add a new issue category to @project
159 def add_issue_category
158 def add_issue_category
160 @category = @project.issue_categories.build(params[:category])
159 @category = @project.issue_categories.build(params[:category])
161 if request.post? and @category.save
160 if request.post? and @category.save
162 respond_to do |format|
161 respond_to do |format|
163 format.html do
162 format.html do
164 flash[:notice] = l(:notice_successful_create)
163 flash[:notice] = l(:notice_successful_create)
165 redirect_to :action => 'settings', :tab => 'categories', :id => @project
164 redirect_to :action => 'settings', :tab => 'categories', :id => @project
166 end
165 end
167 format.js do
166 format.js do
168 # IE doesn't support the replace_html rjs method for select box options
167 # IE doesn't support the replace_html rjs method for select box options
169 render(:update) {|page| page.replace "issue_category_id",
168 render(:update) {|page| page.replace "issue_category_id",
170 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]')
169 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]')
171 }
170 }
172 end
171 end
173 end
172 end
174 end
173 end
175 end
174 end
176
175
177 # Add a new version to @project
176 # Add a new version to @project
178 def add_version
177 def add_version
179 @version = @project.versions.build(params[:version])
178 @version = @project.versions.build(params[:version])
180 if request.post? and @version.save
179 if request.post? and @version.save
181 flash[:notice] = l(:notice_successful_create)
180 flash[:notice] = l(:notice_successful_create)
182 redirect_to :action => 'settings', :tab => 'versions', :id => @project
181 redirect_to :action => 'settings', :tab => 'versions', :id => @project
183 end
182 end
184 end
183 end
185
184
186 # Bulk edit issues
185 # Bulk edit issues
187 def bulk_edit_issues
186 def bulk_edit_issues
188 if request.post?
187 if request.post?
189 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
188 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
190 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
189 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
191 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
190 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
192 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
191 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
193 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
192 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
194 issues = @project.issues.find_all_by_id(params[:issue_ids])
193 issues = @project.issues.find_all_by_id(params[:issue_ids])
195 unsaved_issue_ids = []
194 unsaved_issue_ids = []
196 issues.each do |issue|
195 issues.each do |issue|
197 journal = issue.init_journal(User.current, params[:notes])
196 journal = issue.init_journal(User.current, params[:notes])
198 issue.priority = priority if priority
197 issue.priority = priority if priority
199 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
198 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
200 issue.category = category if category
199 issue.category = category if category
201 issue.fixed_version = fixed_version if fixed_version
200 issue.fixed_version = fixed_version if fixed_version
202 issue.start_date = params[:start_date] unless params[:start_date].blank?
201 issue.start_date = params[:start_date] unless params[:start_date].blank?
203 issue.due_date = params[:due_date] unless params[:due_date].blank?
202 issue.due_date = params[:due_date] unless params[:due_date].blank?
204 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
203 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
205 # Don't save any change to the issue if the user is not authorized to apply the requested status
204 # Don't save any change to the issue if the user is not authorized to apply the requested status
206 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
205 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
207 # Send notification for each issue (if changed)
206 # Send notification for each issue (if changed)
208 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
207 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
209 else
208 else
210 # Keep unsaved issue ids to display them in flash error
209 # Keep unsaved issue ids to display them in flash error
211 unsaved_issue_ids << issue.id
210 unsaved_issue_ids << issue.id
212 end
211 end
213 end
212 end
214 if unsaved_issue_ids.empty?
213 if unsaved_issue_ids.empty?
215 flash[:notice] = l(:notice_successful_update) unless issues.empty?
214 flash[:notice] = l(:notice_successful_update) unless issues.empty?
216 else
215 else
217 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
216 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
218 end
217 end
219 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
218 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
220 return
219 return
221 end
220 end
222 # Find potential statuses the user could be allowed to switch issues to
221 # Find potential statuses the user could be allowed to switch issues to
223 @available_statuses = Workflow.find(:all, :include => :new_status,
222 @available_statuses = Workflow.find(:all, :include => :new_status,
224 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
223 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
225 render :update do |page|
224 render :update do |page|
226 page.hide 'query_form'
225 page.hide 'query_form'
227 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
226 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
228 end
227 end
229 end
228 end
230
229
231 def move_issues
230 def move_issues
232 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
231 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
233 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
232 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
234
233
235 @projects = []
234 @projects = []
236 # find projects to which the user is allowed to move the issue
235 # find projects to which the user is allowed to move the issue
237 if User.current.admin?
236 if User.current.admin?
238 # admin is allowed to move issues to any active (visible) project
237 # admin is allowed to move issues to any active (visible) project
239 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
238 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
240 else
239 else
241 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
240 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
242 end
241 end
243 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
242 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
244 @target_project ||= @project
243 @target_project ||= @project
245 @trackers = @target_project.trackers
244 @trackers = @target_project.trackers
246 if request.post?
245 if request.post?
247 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
246 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
248 unsaved_issue_ids = []
247 unsaved_issue_ids = []
249 @issues.each do |issue|
248 @issues.each do |issue|
250 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
249 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
251 end
250 end
252 if unsaved_issue_ids.empty?
251 if unsaved_issue_ids.empty?
253 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
252 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
254 else
253 else
255 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
254 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
256 end
255 end
257 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
256 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
258 return
257 return
259 end
258 end
260 render :layout => false if request.xhr?
259 render :layout => false if request.xhr?
261 end
260 end
262
261
263 # Add a news to @project
262 # Add a news to @project
264 def add_news
263 def add_news
265 @news = News.new(:project => @project, :author => User.current)
264 @news = News.new(:project => @project, :author => User.current)
266 if request.post?
265 if request.post?
267 @news.attributes = params[:news]
266 @news.attributes = params[:news]
268 if @news.save
267 if @news.save
269 flash[:notice] = l(:notice_successful_create)
268 flash[:notice] = l(:notice_successful_create)
270 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
269 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
271 redirect_to :controller => 'news', :action => 'index', :project_id => @project
270 redirect_to :controller => 'news', :action => 'index', :project_id => @project
272 end
271 end
273 end
272 end
274 end
273 end
275
274
276 def add_file
275 def add_file
277 if request.post?
276 if request.post?
278 @version = @project.versions.find_by_id(params[:version_id])
277 @version = @project.versions.find_by_id(params[:version_id])
279 attachments = attach_files(@version, params[:attachments])
278 attachments = attach_files(@version, params[:attachments])
280 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
279 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
281 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
280 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
282 end
281 end
283 @versions = @project.versions.sort
282 @versions = @project.versions.sort
284 end
283 end
285
284
286 def list_files
285 def list_files
287 @versions = @project.versions.sort
286 @versions = @project.versions.sort
288 end
287 end
289
288
290 # Show changelog for @project
289 # Show changelog for @project
291 def changelog
290 def changelog
292 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
291 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
293 retrieve_selected_tracker_ids(@trackers)
292 retrieve_selected_tracker_ids(@trackers)
294 @versions = @project.versions.sort
293 @versions = @project.versions.sort
295 end
294 end
296
295
297 def roadmap
296 def roadmap
298 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
297 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
299 retrieve_selected_tracker_ids(@trackers)
298 retrieve_selected_tracker_ids(@trackers)
300 @versions = @project.versions.sort
299 @versions = @project.versions.sort
301 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
300 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
302 end
301 end
303
302
304 def activity
303 def activity
305 if params[:year] and params[:year].to_i > 1900
304 if params[:year] and params[:year].to_i > 1900
306 @year = params[:year].to_i
305 @year = params[:year].to_i
307 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
306 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
308 @month = params[:month].to_i
307 @month = params[:month].to_i
309 end
308 end
310 end
309 end
311 @year ||= Date.today.year
310 @year ||= Date.today.year
312 @month ||= Date.today.month
311 @month ||= Date.today.month
313
312
314 case params[:format]
313 case params[:format]
315 when 'atom'
314 when 'atom'
316 # 30 last days
315 # 30 last days
317 @date_from = Date.today - 30
316 @date_from = Date.today - 30
318 @date_to = Date.today + 1
317 @date_to = Date.today + 1
319 else
318 else
320 # current month
319 # current month
321 @date_from = Date.civil(@year, @month, 1)
320 @date_from = Date.civil(@year, @month, 1)
322 @date_to = @date_from >> 1
321 @date_to = @date_from >> 1
323 end
322 end
324
323
325 @event_types = %w(issues news files documents changesets wiki_pages messages)
324 @event_types = %w(issues news files documents changesets wiki_pages messages)
326 @event_types.delete('wiki_pages') unless @project.wiki
325 @event_types.delete('wiki_pages') unless @project.wiki
327 @event_types.delete('changesets') unless @project.repository
326 @event_types.delete('changesets') unless @project.repository
328 @event_types.delete('messages') unless @project.boards.any?
327 @event_types.delete('messages') unless @project.boards.any?
329 # only show what the user is allowed to view
328 # only show what the user is allowed to view
330 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
329 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
331
330
332 @scope = @event_types.select {|t| params["show_#{t}"]}
331 @scope = @event_types.select {|t| params["show_#{t}"]}
333 # default events if none is specified in parameters
332 # default events if none is specified in parameters
334 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
333 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
335
334
336 @events = []
335 @events = []
337
336
338 if @scope.include?('issues')
337 if @scope.include?('issues')
339 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
338 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
340 @events += @project.issues_status_changes(@date_from, @date_to)
339 @events += @project.issues_status_changes(@date_from, @date_to)
341 end
340 end
342
341
343 if @scope.include?('news')
342 if @scope.include?('news')
344 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
343 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
345 end
344 end
346
345
347 if @scope.include?('files')
346 if @scope.include?('files')
348 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
347 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
349 end
348 end
350
349
351 if @scope.include?('documents')
350 if @scope.include?('documents')
352 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
351 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
353 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
352 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
354 end
353 end
355
354
356 if @scope.include?('wiki_pages')
355 if @scope.include?('wiki_pages')
357 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
356 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
358 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
357 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
359 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
358 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
360 "#{WikiContent.versioned_table_name}.id"
359 "#{WikiContent.versioned_table_name}.id"
361 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
360 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
362 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
361 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
363 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
362 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
364 @project.id, @date_from, @date_to]
363 @project.id, @date_from, @date_to]
365
364
366 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
365 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
367 end
366 end
368
367
369 if @scope.include?('changesets')
368 if @scope.include?('changesets')
370 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
369 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
371 end
370 end
372
371
373 if @scope.include?('messages')
372 if @scope.include?('messages')
374 @events += Message.find(:all,
373 @events += Message.find(:all,
375 :include => [:board, :author],
374 :include => [:board, :author],
376 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
375 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
377 end
376 end
378
377
379 @events_by_day = @events.group_by(&:event_date)
378 @events_by_day = @events.group_by(&:event_date)
380
379
381 respond_to do |format|
380 respond_to do |format|
382 format.html { render :layout => false if request.xhr? }
381 format.html { render :layout => false if request.xhr? }
383 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
382 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
384 end
383 end
385 end
384 end
386
385
387 def calendar
386 def calendar
388 @trackers = @project.rolled_up_trackers
387 @trackers = @project.rolled_up_trackers
389 retrieve_selected_tracker_ids(@trackers)
388 retrieve_selected_tracker_ids(@trackers)
390
389
391 if params[:year] and params[:year].to_i > 1900
390 if params[:year] and params[:year].to_i > 1900
392 @year = params[:year].to_i
391 @year = params[:year].to_i
393 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
392 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
394 @month = params[:month].to_i
393 @month = params[:month].to_i
395 end
394 end
396 end
395 end
397 @year ||= Date.today.year
396 @year ||= Date.today.year
398 @month ||= Date.today.month
397 @month ||= Date.today.month
399 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
398 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
400
399
401 events = []
400 events = []
402 @project.issues_with_subprojects(params[:with_subprojects]) do
401 @project.issues_with_subprojects(params[:with_subprojects]) do
403 events += Issue.find(:all,
402 events += Issue.find(:all,
404 :include => [:tracker, :status, :assigned_to, :priority, :project],
403 :include => [:tracker, :status, :assigned_to, :priority, :project],
405 :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]
404 :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]
406 ) unless @selected_tracker_ids.empty?
405 ) unless @selected_tracker_ids.empty?
407 end
406 end
408 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
407 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
409 @calendar.events = events
408 @calendar.events = events
410
409
411 render :layout => false if request.xhr?
410 render :layout => false if request.xhr?
412 end
411 end
413
412
414 def gantt
413 def gantt
415 @trackers = @project.rolled_up_trackers
414 @trackers = @project.rolled_up_trackers
416 retrieve_selected_tracker_ids(@trackers)
415 retrieve_selected_tracker_ids(@trackers)
417
416
418 if params[:year] and params[:year].to_i >0
417 if params[:year] and params[:year].to_i >0
419 @year_from = params[:year].to_i
418 @year_from = params[:year].to_i
420 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
419 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
421 @month_from = params[:month].to_i
420 @month_from = params[:month].to_i
422 else
421 else
423 @month_from = 1
422 @month_from = 1
424 end
423 end
425 else
424 else
426 @month_from ||= Date.today.month
425 @month_from ||= Date.today.month
427 @year_from ||= Date.today.year
426 @year_from ||= Date.today.year
428 end
427 end
429
428
430 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
429 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
431 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
430 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
432 months = (params[:months] || User.current.pref[:gantt_months]).to_i
431 months = (params[:months] || User.current.pref[:gantt_months]).to_i
433 @months = (months > 0 && months < 25) ? months : 6
432 @months = (months > 0 && months < 25) ? months : 6
434
433
435 # Save gantt paramters as user preference (zoom and months count)
434 # Save gantt paramters as user preference (zoom and months count)
436 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
435 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
437 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
436 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
438 User.current.preference.save
437 User.current.preference.save
439 end
438 end
440
439
441 @date_from = Date.civil(@year_from, @month_from, 1)
440 @date_from = Date.civil(@year_from, @month_from, 1)
442 @date_to = (@date_from >> @months) - 1
441 @date_to = (@date_from >> @months) - 1
443
442
444 @events = []
443 @events = []
445 @project.issues_with_subprojects(params[:with_subprojects]) do
444 @project.issues_with_subprojects(params[:with_subprojects]) do
446 @events += Issue.find(:all,
445 @events += Issue.find(:all,
447 :order => "start_date, due_date",
446 :order => "start_date, due_date",
448 :include => [:tracker, :status, :assigned_to, :priority, :project],
447 :include => [:tracker, :status, :assigned_to, :priority, :project],
449 :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]
448 :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]
450 ) unless @selected_tracker_ids.empty?
449 ) unless @selected_tracker_ids.empty?
451 end
450 end
452 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
451 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
453 @events.sort! {|x,y| x.start_date <=> y.start_date }
452 @events.sort! {|x,y| x.start_date <=> y.start_date }
454
453
455 if params[:format]=='pdf'
454 if params[:format]=='pdf'
456 @options_for_rfpdf ||= {}
455 @options_for_rfpdf ||= {}
457 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
456 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
458 render :template => "projects/gantt.rfpdf", :layout => false
457 render :template => "projects/gantt.rfpdf", :layout => false
459 elsif params[:format]=='png' && respond_to?('gantt_image')
458 elsif params[:format]=='png' && respond_to?('gantt_image')
460 image = gantt_image(@events, @date_from, @months, @zoom)
459 image = gantt_image(@events, @date_from, @months, @zoom)
461 image.format = 'PNG'
460 image.format = 'PNG'
462 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
461 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
463 else
462 else
464 render :template => "projects/gantt.rhtml"
463 render :template => "projects/gantt.rhtml"
465 end
464 end
466 end
465 end
467
466
468 private
467 private
469 # Find project of id params[:id]
468 # Find project of id params[:id]
470 # if not found, redirect to project list
469 # if not found, redirect to project list
471 # Used as a before_filter
470 # Used as a before_filter
472 def find_project
471 def find_project
473 @project = Project.find(params[:id])
472 @project = Project.find(params[:id])
474 rescue ActiveRecord::RecordNotFound
473 rescue ActiveRecord::RecordNotFound
475 render_404
474 render_404
476 end
475 end
477
476
478 def retrieve_selected_tracker_ids(selectable_trackers)
477 def retrieve_selected_tracker_ids(selectable_trackers)
479 if ids = params[:tracker_ids]
478 if ids = params[:tracker_ids]
480 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
479 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
481 else
480 else
482 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
481 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
483 end
482 end
484 end
483 end
485 end
484 end
@@ -1,52 +1,53
1 <%= error_messages_for 'project' %>
1 <%= error_messages_for 'project' %>
2
2
3 <div class="box">
3 <div class="box">
4 <!--[form:project]-->
4 <!--[form:project]-->
5 <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p>
5 <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p>
6
6
7 <% if User.current.admin? and !@root_projects.empty? %>
7 <% if User.current.admin? and !@root_projects.empty? %>
8 <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p>
8 <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p>
9 <% end %>
9 <% end %>
10
10
11 <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 5 %><em><%= l(:text_caracters_maximum, 255) %></em></p>
11 <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 5 %><em><%= l(:text_caracters_maximum, 255) %></em></p>
12 <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %><br /><em><%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %></em></p>
12 <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %><br /><em><%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %></em></p>
13 <p><%= f.text_field :homepage, :size => 40 %></p>
13 <p><%= f.text_field :homepage, :size => 40 %></p>
14 <p><%= f.check_box :is_public %></p>
14 <p><%= f.check_box :is_public %></p>
15 <%= wikitoolbar_for 'project_description' %>
15 <%= wikitoolbar_for 'project_description' %>
16
16
17 <% for @custom_value in @custom_values %>
17 <% for @custom_value in @custom_values %>
18 <p><%= custom_field_tag_with_label @custom_value %></p>
18 <p><%= custom_field_tag_with_label @custom_value %></p>
19 <% end %>
19 <% end %>
20 </div>
20 </div>
21
21
22 <% unless @trackers.empty? %>
22 <% unless @trackers.empty? %>
23 <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend>
23 <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend>
24 <% @trackers.each do |tracker| %>
24 <% @trackers.each do |tracker| %>
25 <label class="floating">
25 <label class="floating">
26 <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %>
26 <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %>
27 <%= tracker %>
27 <%= tracker %>
28 </label>
28 </label>
29 <% end %>
29 <% end %>
30 <%= hidden_field_tag 'project[tracker_ids][]', '' %>
30 <%= hidden_field_tag 'project[tracker_ids][]', '' %>
31 </fieldset>
31 </fieldset>
32 <% end %>
32 <% end %>
33
33
34 <% unless @custom_fields.empty? %>
34 <% unless @custom_fields.empty? %>
35 <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend>
35 <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend>
36 <% for custom_field in @custom_fields %>
36 <% for custom_field in @custom_fields %>
37 <label class="floating">
37 <label class="floating">
38 <%= check_box_tag "custom_field_ids[]", custom_field.id, ((@project.custom_fields.include? custom_field) or custom_field.is_for_all?), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %>
38 <%= check_box_tag 'project[custom_field_ids][]', custom_field.id, ((@project.custom_fields.include? custom_field) or custom_field.is_for_all?), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %>
39 <%= custom_field.name %>
39 <%= custom_field.name %>
40 </label>
40 </label>
41 <% end %>
41 <% end %>
42 <%= hidden_field_tag 'project[custom_field_ids][]', '' %>
42 </fieldset>
43 </fieldset>
43 <% end %>
44 <% end %>
44 <!--[eoform:project]-->
45 <!--[eoform:project]-->
45
46
46
47
47 <% content_for :header_tags do %>
48 <% content_for :header_tags do %>
48 <%= javascript_include_tag 'calendar/calendar' %>
49 <%= javascript_include_tag 'calendar/calendar' %>
49 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
50 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
50 <%= javascript_include_tag 'calendar/calendar-setup' %>
51 <%= javascript_include_tag 'calendar/calendar-setup' %>
51 <%= stylesheet_link_tag 'calendar' %>
52 <%= stylesheet_link_tag 'calendar' %>
52 <% end %>
53 <% end %>
@@ -1,239 +1,240
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, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 end
31 end
32
32
33 def test_index
33 def test_index
34 get :index
34 get :index
35 assert_response :success
35 assert_response :success
36 assert_template 'list'
36 assert_template 'list'
37 end
37 end
38
38
39 def test_list
39 def test_list
40 get :list
40 get :list
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:project_tree)
43 assert_not_nil assigns(:project_tree)
44 # Root project as hash key
44 # Root project as hash key
45 assert assigns(:project_tree).has_key?(Project.find(1))
45 assert assigns(:project_tree).has_key?(Project.find(1))
46 # Subproject in corresponding value
46 # Subproject in corresponding value
47 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
47 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
48 end
48 end
49
49
50 def test_show_by_id
50 def test_show_by_id
51 get :show, :id => 1
51 get :show, :id => 1
52 assert_response :success
52 assert_response :success
53 assert_template 'show'
53 assert_template 'show'
54 assert_not_nil assigns(:project)
54 assert_not_nil assigns(:project)
55 end
55 end
56
56
57 def test_show_by_identifier
57 def test_show_by_identifier
58 get :show, :id => 'ecookbook'
58 get :show, :id => 'ecookbook'
59 assert_response :success
59 assert_response :success
60 assert_template 'show'
60 assert_template 'show'
61 assert_not_nil assigns(:project)
61 assert_not_nil assigns(:project)
62 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
62 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
63 end
63 end
64
64
65 def test_settings
65 def test_settings
66 @request.session[:user_id] = 2 # manager
66 @request.session[:user_id] = 2 # manager
67 get :settings, :id => 1
67 get :settings, :id => 1
68 assert_response :success
68 assert_response :success
69 assert_template 'settings'
69 assert_template 'settings'
70 end
70 end
71
71
72 def test_edit
72 def test_edit
73 @request.session[:user_id] = 2 # manager
73 @request.session[:user_id] = 2 # manager
74 post :edit, :id => 1, :project => {:name => 'Test changed name'}
74 post :edit, :id => 1, :project => {:name => 'Test changed name',
75 :custom_field_ids => ['']}
75 assert_redirected_to 'projects/settings/ecookbook'
76 assert_redirected_to 'projects/settings/ecookbook'
76 project = Project.find(1)
77 project = Project.find(1)
77 assert_equal 'Test changed name', project.name
78 assert_equal 'Test changed name', project.name
78 end
79 end
79
80
80 def test_get_destroy
81 def test_get_destroy
81 @request.session[:user_id] = 1 # admin
82 @request.session[:user_id] = 1 # admin
82 get :destroy, :id => 1
83 get :destroy, :id => 1
83 assert_response :success
84 assert_response :success
84 assert_template 'destroy'
85 assert_template 'destroy'
85 assert_not_nil Project.find_by_id(1)
86 assert_not_nil Project.find_by_id(1)
86 end
87 end
87
88
88 def test_post_destroy
89 def test_post_destroy
89 @request.session[:user_id] = 1 # admin
90 @request.session[:user_id] = 1 # admin
90 post :destroy, :id => 1, :confirm => 1
91 post :destroy, :id => 1, :confirm => 1
91 assert_redirected_to 'admin/projects'
92 assert_redirected_to 'admin/projects'
92 assert_nil Project.find_by_id(1)
93 assert_nil Project.find_by_id(1)
93 end
94 end
94
95
95 def test_bulk_edit_issues
96 def test_bulk_edit_issues
96 @request.session[:user_id] = 2
97 @request.session[:user_id] = 2
97 # update issues priority
98 # update issues priority
98 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
99 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
99 assert_response 302
100 assert_response 302
100 # check that the issues were updated
101 # check that the issues were updated
101 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
102 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
102 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
103 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
103 end
104 end
104
105
105 def test_move_issues_to_another_project
106 def test_move_issues_to_another_project
106 @request.session[:user_id] = 1
107 @request.session[:user_id] = 1
107 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2
108 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2
108 assert_redirected_to 'projects/ecookbook/issues'
109 assert_redirected_to 'projects/ecookbook/issues'
109 assert_equal 2, Issue.find(1).project_id
110 assert_equal 2, Issue.find(1).project_id
110 assert_equal 2, Issue.find(2).project_id
111 assert_equal 2, Issue.find(2).project_id
111 end
112 end
112
113
113 def test_move_issues_to_another_tracker
114 def test_move_issues_to_another_tracker
114 @request.session[:user_id] = 1
115 @request.session[:user_id] = 1
115 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2
116 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2
116 assert_redirected_to 'projects/ecookbook/issues'
117 assert_redirected_to 'projects/ecookbook/issues'
117 assert_equal 2, Issue.find(1).tracker_id
118 assert_equal 2, Issue.find(1).tracker_id
118 assert_equal 2, Issue.find(2).tracker_id
119 assert_equal 2, Issue.find(2).tracker_id
119 end
120 end
120
121
121 def test_list_files
122 def test_list_files
122 get :list_files, :id => 1
123 get :list_files, :id => 1
123 assert_response :success
124 assert_response :success
124 assert_template 'list_files'
125 assert_template 'list_files'
125 assert_not_nil assigns(:versions)
126 assert_not_nil assigns(:versions)
126 end
127 end
127
128
128 def test_changelog
129 def test_changelog
129 get :changelog, :id => 1
130 get :changelog, :id => 1
130 assert_response :success
131 assert_response :success
131 assert_template 'changelog'
132 assert_template 'changelog'
132 assert_not_nil assigns(:versions)
133 assert_not_nil assigns(:versions)
133 end
134 end
134
135
135 def test_roadmap
136 def test_roadmap
136 get :roadmap, :id => 1
137 get :roadmap, :id => 1
137 assert_response :success
138 assert_response :success
138 assert_template 'roadmap'
139 assert_template 'roadmap'
139 assert_not_nil assigns(:versions)
140 assert_not_nil assigns(:versions)
140 # Version with no date set appears
141 # Version with no date set appears
141 assert assigns(:versions).include?(Version.find(3))
142 assert assigns(:versions).include?(Version.find(3))
142 # Completed version doesn't appear
143 # Completed version doesn't appear
143 assert !assigns(:versions).include?(Version.find(1))
144 assert !assigns(:versions).include?(Version.find(1))
144 end
145 end
145
146
146 def test_roadmap_with_completed_versions
147 def test_roadmap_with_completed_versions
147 get :roadmap, :id => 1, :completed => 1
148 get :roadmap, :id => 1, :completed => 1
148 assert_response :success
149 assert_response :success
149 assert_template 'roadmap'
150 assert_template 'roadmap'
150 assert_not_nil assigns(:versions)
151 assert_not_nil assigns(:versions)
151 # Version with no date set appears
152 # Version with no date set appears
152 assert assigns(:versions).include?(Version.find(3))
153 assert assigns(:versions).include?(Version.find(3))
153 # Completed version appears
154 # Completed version appears
154 assert assigns(:versions).include?(Version.find(1))
155 assert assigns(:versions).include?(Version.find(1))
155 end
156 end
156
157
157 def test_activity
158 def test_activity
158 get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month
159 get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month
159 assert_response :success
160 assert_response :success
160 assert_template 'activity'
161 assert_template 'activity'
161 assert_not_nil assigns(:events_by_day)
162 assert_not_nil assigns(:events_by_day)
162
163
163 assert_tag :tag => "h3",
164 assert_tag :tag => "h3",
164 :content => /#{2.days.ago.to_date.day}/,
165 :content => /#{2.days.ago.to_date.day}/,
165 :sibling => { :tag => "ul",
166 :sibling => { :tag => "ul",
166 :child => { :tag => "li",
167 :child => { :tag => "li",
167 :child => { :tag => "p",
168 :child => { :tag => "p",
168 :content => /(#{IssueStatus.find(2).name})/,
169 :content => /(#{IssueStatus.find(2).name})/,
169 }
170 }
170 }
171 }
171 }
172 }
172
173
173 get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month
174 get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month
174 assert_response :success
175 assert_response :success
175 assert_template 'activity'
176 assert_template 'activity'
176 assert_not_nil assigns(:events_by_day)
177 assert_not_nil assigns(:events_by_day)
177
178
178 assert_tag :tag => "h3",
179 assert_tag :tag => "h3",
179 :content => /#{3.day.ago.to_date.day}/,
180 :content => /#{3.day.ago.to_date.day}/,
180 :sibling => { :tag => "ul",
181 :sibling => { :tag => "ul",
181 :child => { :tag => "li",
182 :child => { :tag => "li",
182 :child => { :tag => "p",
183 :child => { :tag => "p",
183 :content => /#{Issue.find(1).subject}/,
184 :content => /#{Issue.find(1).subject}/,
184 }
185 }
185 }
186 }
186 }
187 }
187 end
188 end
188
189
189 def test_calendar
190 def test_calendar
190 get :calendar, :id => 1
191 get :calendar, :id => 1
191 assert_response :success
192 assert_response :success
192 assert_template 'calendar'
193 assert_template 'calendar'
193 assert_not_nil assigns(:calendar)
194 assert_not_nil assigns(:calendar)
194 end
195 end
195
196
196 def test_calendar_with_subprojects
197 def test_calendar_with_subprojects
197 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
198 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
198 assert_response :success
199 assert_response :success
199 assert_template 'calendar'
200 assert_template 'calendar'
200 assert_not_nil assigns(:calendar)
201 assert_not_nil assigns(:calendar)
201 end
202 end
202
203
203 def test_gantt
204 def test_gantt
204 get :gantt, :id => 1
205 get :gantt, :id => 1
205 assert_response :success
206 assert_response :success
206 assert_template 'gantt.rhtml'
207 assert_template 'gantt.rhtml'
207 assert_not_nil assigns(:events)
208 assert_not_nil assigns(:events)
208 end
209 end
209
210
210 def test_gantt_with_subprojects
211 def test_gantt_with_subprojects
211 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
212 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
212 assert_response :success
213 assert_response :success
213 assert_template 'gantt.rhtml'
214 assert_template 'gantt.rhtml'
214 assert_not_nil assigns(:events)
215 assert_not_nil assigns(:events)
215 end
216 end
216
217
217 def test_gantt_export_to_pdf
218 def test_gantt_export_to_pdf
218 get :gantt, :id => 1, :format => 'pdf'
219 get :gantt, :id => 1, :format => 'pdf'
219 assert_response :success
220 assert_response :success
220 assert_template 'gantt.rfpdf'
221 assert_template 'gantt.rfpdf'
221 assert_equal 'application/pdf', @response.content_type
222 assert_equal 'application/pdf', @response.content_type
222 assert_not_nil assigns(:events)
223 assert_not_nil assigns(:events)
223 end
224 end
224
225
225 def test_archive
226 def test_archive
226 @request.session[:user_id] = 1 # admin
227 @request.session[:user_id] = 1 # admin
227 post :archive, :id => 1
228 post :archive, :id => 1
228 assert_redirected_to 'admin/projects'
229 assert_redirected_to 'admin/projects'
229 assert !Project.find(1).active?
230 assert !Project.find(1).active?
230 end
231 end
231
232
232 def test_unarchive
233 def test_unarchive
233 @request.session[:user_id] = 1 # admin
234 @request.session[:user_id] = 1 # admin
234 Project.find(1).archive
235 Project.find(1).archive
235 post :unarchive, :id => 1
236 post :unarchive, :id => 1
236 assert_redirected_to 'admin/projects'
237 assert_redirected_to 'admin/projects'
237 assert Project.find(1).active?
238 assert Project.find(1).active?
238 end
239 end
239 end
240 end
General Comments 0
You need to be logged in to leave comments. Login now