##// END OF EJS Templates
Fixed: activity atom feed broken by r1701 (#1703)....
Jean-Philippe Lang -
r1710:6034067d8623
parent child
Show More
@@ -1,365 +1,365
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 # Lists visible projects
47 # Lists visible projects
48 def index
48 def index
49 projects = Project.find :all,
49 projects = Project.find :all,
50 :conditions => Project.visible_by(User.current),
50 :conditions => Project.visible_by(User.current),
51 :include => :parent
51 :include => :parent
52 respond_to do |format|
52 respond_to do |format|
53 format.html {
53 format.html {
54 @project_tree = projects.group_by {|p| p.parent || p}
54 @project_tree = projects.group_by {|p| p.parent || p}
55 @project_tree.keys.each {|p| @project_tree[p] -= [p]}
55 @project_tree.keys.each {|p| @project_tree[p] -= [p]}
56 }
56 }
57 format.atom {
57 format.atom {
58 render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
58 render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
59 :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
59 :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 }
60 }
61 end
61 end
62 end
62 end
63
63
64 # Add a new project
64 # Add a new project
65 def add
65 def add
66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 @trackers = Tracker.all
67 @trackers = Tracker.all
68 @root_projects = Project.find(:all,
68 @root_projects = Project.find(:all,
69 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
69 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
70 :order => 'name')
70 :order => 'name')
71 @project = Project.new(params[:project])
71 @project = Project.new(params[:project])
72 if request.get?
72 if request.get?
73 @project.trackers = Tracker.all
73 @project.trackers = Tracker.all
74 @project.is_public = Setting.default_projects_public?
74 @project.is_public = Setting.default_projects_public?
75 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
75 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
76 else
76 else
77 @project.enabled_module_names = params[:enabled_modules]
77 @project.enabled_module_names = params[:enabled_modules]
78 if @project.save
78 if @project.save
79 flash[:notice] = l(:notice_successful_create)
79 flash[:notice] = l(:notice_successful_create)
80 redirect_to :controller => 'admin', :action => 'projects'
80 redirect_to :controller => 'admin', :action => 'projects'
81 end
81 end
82 end
82 end
83 end
83 end
84
84
85 # Show @project
85 # Show @project
86 def show
86 def show
87 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
87 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
88 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
89 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
89 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
90 @trackers = @project.rolled_up_trackers
90 @trackers = @project.rolled_up_trackers
91
91
92 cond = @project.project_condition(Setting.display_subprojects_issues?)
92 cond = @project.project_condition(Setting.display_subprojects_issues?)
93 Issue.visible_by(User.current) do
93 Issue.visible_by(User.current) do
94 @open_issues_by_tracker = Issue.count(:group => :tracker,
94 @open_issues_by_tracker = Issue.count(:group => :tracker,
95 :include => [:project, :status, :tracker],
95 :include => [:project, :status, :tracker],
96 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
96 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
97 @total_issues_by_tracker = Issue.count(:group => :tracker,
97 @total_issues_by_tracker = Issue.count(:group => :tracker,
98 :include => [:project, :status, :tracker],
98 :include => [:project, :status, :tracker],
99 :conditions => cond)
99 :conditions => cond)
100 end
100 end
101 TimeEntry.visible_by(User.current) do
101 TimeEntry.visible_by(User.current) do
102 @total_hours = TimeEntry.sum(:hours,
102 @total_hours = TimeEntry.sum(:hours,
103 :include => :project,
103 :include => :project,
104 :conditions => cond).to_f
104 :conditions => cond).to_f
105 end
105 end
106 @key = User.current.rss_key
106 @key = User.current.rss_key
107 end
107 end
108
108
109 def settings
109 def settings
110 @root_projects = Project.find(:all,
110 @root_projects = Project.find(:all,
111 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
111 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
112 :order => 'name')
112 :order => 'name')
113 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
113 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
114 @issue_category ||= IssueCategory.new
114 @issue_category ||= IssueCategory.new
115 @member ||= @project.members.new
115 @member ||= @project.members.new
116 @trackers = Tracker.all
116 @trackers = Tracker.all
117 @repository ||= @project.repository
117 @repository ||= @project.repository
118 @wiki ||= @project.wiki
118 @wiki ||= @project.wiki
119 end
119 end
120
120
121 # Edit @project
121 # Edit @project
122 def edit
122 def edit
123 if request.post?
123 if request.post?
124 @project.attributes = params[:project]
124 @project.attributes = params[:project]
125 if @project.save
125 if @project.save
126 flash[:notice] = l(:notice_successful_update)
126 flash[:notice] = l(:notice_successful_update)
127 redirect_to :action => 'settings', :id => @project
127 redirect_to :action => 'settings', :id => @project
128 else
128 else
129 settings
129 settings
130 render :action => 'settings'
130 render :action => 'settings'
131 end
131 end
132 end
132 end
133 end
133 end
134
134
135 def modules
135 def modules
136 @project.enabled_module_names = params[:enabled_modules]
136 @project.enabled_module_names = params[:enabled_modules]
137 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
137 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
138 end
138 end
139
139
140 def archive
140 def archive
141 @project.archive if request.post? && @project.active?
141 @project.archive if request.post? && @project.active?
142 redirect_to :controller => 'admin', :action => 'projects'
142 redirect_to :controller => 'admin', :action => 'projects'
143 end
143 end
144
144
145 def unarchive
145 def unarchive
146 @project.unarchive if request.post? && !@project.active?
146 @project.unarchive if request.post? && !@project.active?
147 redirect_to :controller => 'admin', :action => 'projects'
147 redirect_to :controller => 'admin', :action => 'projects'
148 end
148 end
149
149
150 # Delete @project
150 # Delete @project
151 def destroy
151 def destroy
152 @project_to_destroy = @project
152 @project_to_destroy = @project
153 if request.post? and params[:confirm]
153 if request.post? and params[:confirm]
154 @project_to_destroy.destroy
154 @project_to_destroy.destroy
155 redirect_to :controller => 'admin', :action => 'projects'
155 redirect_to :controller => 'admin', :action => 'projects'
156 end
156 end
157 # hide project in layout
157 # hide project in layout
158 @project = nil
158 @project = nil
159 end
159 end
160
160
161 # Add a new issue category to @project
161 # Add a new issue category to @project
162 def add_issue_category
162 def add_issue_category
163 @category = @project.issue_categories.build(params[:category])
163 @category = @project.issue_categories.build(params[:category])
164 if request.post? and @category.save
164 if request.post? and @category.save
165 respond_to do |format|
165 respond_to do |format|
166 format.html do
166 format.html do
167 flash[:notice] = l(:notice_successful_create)
167 flash[:notice] = l(:notice_successful_create)
168 redirect_to :action => 'settings', :tab => 'categories', :id => @project
168 redirect_to :action => 'settings', :tab => 'categories', :id => @project
169 end
169 end
170 format.js do
170 format.js do
171 # IE doesn't support the replace_html rjs method for select box options
171 # IE doesn't support the replace_html rjs method for select box options
172 render(:update) {|page| page.replace "issue_category_id",
172 render(:update) {|page| page.replace "issue_category_id",
173 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]')
173 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]')
174 }
174 }
175 end
175 end
176 end
176 end
177 end
177 end
178 end
178 end
179
179
180 # Add a new version to @project
180 # Add a new version to @project
181 def add_version
181 def add_version
182 @version = @project.versions.build(params[:version])
182 @version = @project.versions.build(params[:version])
183 if request.post? and @version.save
183 if request.post? and @version.save
184 flash[:notice] = l(:notice_successful_create)
184 flash[:notice] = l(:notice_successful_create)
185 redirect_to :action => 'settings', :tab => 'versions', :id => @project
185 redirect_to :action => 'settings', :tab => 'versions', :id => @project
186 end
186 end
187 end
187 end
188
188
189 def add_file
189 def add_file
190 if request.post?
190 if request.post?
191 @version = @project.versions.find_by_id(params[:version_id])
191 @version = @project.versions.find_by_id(params[:version_id])
192 attachments = attach_files(@version, params[:attachments])
192 attachments = attach_files(@version, params[:attachments])
193 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
193 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
194 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
194 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
195 end
195 end
196 @versions = @project.versions.sort
196 @versions = @project.versions.sort
197 end
197 end
198
198
199 def list_files
199 def list_files
200 sort_init "#{Attachment.table_name}.filename", "asc"
200 sort_init "#{Attachment.table_name}.filename", "asc"
201 sort_update
201 sort_update
202 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
202 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
203 render :layout => !request.xhr?
203 render :layout => !request.xhr?
204 end
204 end
205
205
206 # Show changelog for @project
206 # Show changelog for @project
207 def changelog
207 def changelog
208 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
208 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
209 retrieve_selected_tracker_ids(@trackers)
209 retrieve_selected_tracker_ids(@trackers)
210 @versions = @project.versions.sort
210 @versions = @project.versions.sort
211 end
211 end
212
212
213 def roadmap
213 def roadmap
214 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
214 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
215 retrieve_selected_tracker_ids(@trackers)
215 retrieve_selected_tracker_ids(@trackers)
216 @versions = @project.versions.sort
216 @versions = @project.versions.sort
217 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
217 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
218 end
218 end
219
219
220 def activity
220 def activity
221 @days = Setting.activity_days_default.to_i
221 @days = Setting.activity_days_default.to_i
222
222
223 if params[:from]
223 if params[:from]
224 begin; @date_to = params[:from].to_date; rescue; end
224 begin; @date_to = params[:from].to_date; rescue; end
225 end
225 end
226
226
227 @date_to ||= Date.today + 1
227 @date_to ||= Date.today + 1
228 @date_from = @date_to - @days
228 @date_from = @date_to - @days
229 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
229 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
230
230
231 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
231 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
232 @activity.scope_select {|t| !params["show_#{t}"].nil?}
232 @activity.scope_select {|t| !params["show_#{t}"].nil?}
233 @activity.default_scope! if @activity.scope.empty?
233 @activity.default_scope! if @activity.scope.empty?
234
234
235 events = @activity.events(@date_from, @date_to)
235 events = @activity.events(@date_from, @date_to)
236
236
237 respond_to do |format|
237 respond_to do |format|
238 format.html {
238 format.html {
239 @events_by_day = events.group_by(&:event_date)
239 @events_by_day = events.group_by(&:event_date)
240 render :layout => false if request.xhr?
240 render :layout => false if request.xhr?
241 }
241 }
242 format.atom {
242 format.atom {
243 title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity)
243 title = (@activity.scope.size == 1) ? l("label_#{@activity.scope.first.singularize}_plural") : l(:label_activity)
244 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
244 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
245 }
245 }
246 end
246 end
247 end
247 end
248
248
249 def calendar
249 def calendar
250 @trackers = @project.rolled_up_trackers
250 @trackers = @project.rolled_up_trackers
251 retrieve_selected_tracker_ids(@trackers)
251 retrieve_selected_tracker_ids(@trackers)
252
252
253 if params[:year] and params[:year].to_i > 1900
253 if params[:year] and params[:year].to_i > 1900
254 @year = params[:year].to_i
254 @year = params[:year].to_i
255 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
255 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
256 @month = params[:month].to_i
256 @month = params[:month].to_i
257 end
257 end
258 end
258 end
259 @year ||= Date.today.year
259 @year ||= Date.today.year
260 @month ||= Date.today.month
260 @month ||= Date.today.month
261 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
261 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
262 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
262 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
263 events = []
263 events = []
264 @project.issues_with_subprojects(@with_subprojects) do
264 @project.issues_with_subprojects(@with_subprojects) do
265 events += Issue.find(:all,
265 events += Issue.find(:all,
266 :include => [:tracker, :status, :assigned_to, :priority, :project],
266 :include => [:tracker, :status, :assigned_to, :priority, :project],
267 :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]
267 :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]
268 ) unless @selected_tracker_ids.empty?
268 ) unless @selected_tracker_ids.empty?
269 events += Version.find(:all, :include => :project,
269 events += Version.find(:all, :include => :project,
270 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
270 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
271 end
271 end
272 @calendar.events = events
272 @calendar.events = events
273
273
274 render :layout => false if request.xhr?
274 render :layout => false if request.xhr?
275 end
275 end
276
276
277 def gantt
277 def gantt
278 @trackers = @project.rolled_up_trackers
278 @trackers = @project.rolled_up_trackers
279 retrieve_selected_tracker_ids(@trackers)
279 retrieve_selected_tracker_ids(@trackers)
280
280
281 if params[:year] and params[:year].to_i >0
281 if params[:year] and params[:year].to_i >0
282 @year_from = params[:year].to_i
282 @year_from = params[:year].to_i
283 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
283 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
284 @month_from = params[:month].to_i
284 @month_from = params[:month].to_i
285 else
285 else
286 @month_from = 1
286 @month_from = 1
287 end
287 end
288 else
288 else
289 @month_from ||= Date.today.month
289 @month_from ||= Date.today.month
290 @year_from ||= Date.today.year
290 @year_from ||= Date.today.year
291 end
291 end
292
292
293 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
293 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
294 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
294 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
295 months = (params[:months] || User.current.pref[:gantt_months]).to_i
295 months = (params[:months] || User.current.pref[:gantt_months]).to_i
296 @months = (months > 0 && months < 25) ? months : 6
296 @months = (months > 0 && months < 25) ? months : 6
297
297
298 # Save gantt paramters as user preference (zoom and months count)
298 # Save gantt paramters as user preference (zoom and months count)
299 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
299 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
300 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
300 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
301 User.current.preference.save
301 User.current.preference.save
302 end
302 end
303
303
304 @date_from = Date.civil(@year_from, @month_from, 1)
304 @date_from = Date.civil(@year_from, @month_from, 1)
305 @date_to = (@date_from >> @months) - 1
305 @date_to = (@date_from >> @months) - 1
306 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
306 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
307
307
308 @events = []
308 @events = []
309 @project.issues_with_subprojects(@with_subprojects) do
309 @project.issues_with_subprojects(@with_subprojects) do
310 # Issues that have start and due dates
310 # Issues that have start and due dates
311 @events += Issue.find(:all,
311 @events += Issue.find(:all,
312 :order => "start_date, due_date",
312 :order => "start_date, due_date",
313 :include => [:tracker, :status, :assigned_to, :priority, :project],
313 :include => [:tracker, :status, :assigned_to, :priority, :project],
314 :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]
314 :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]
315 ) unless @selected_tracker_ids.empty?
315 ) unless @selected_tracker_ids.empty?
316 # Issues that don't have a due date but that are assigned to a version with a date
316 # Issues that don't have a due date but that are assigned to a version with a date
317 @events += Issue.find(:all,
317 @events += Issue.find(:all,
318 :order => "start_date, effective_date",
318 :order => "start_date, effective_date",
319 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
319 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
320 :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]
320 :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]
321 ) unless @selected_tracker_ids.empty?
321 ) unless @selected_tracker_ids.empty?
322 @events += Version.find(:all, :include => :project,
322 @events += Version.find(:all, :include => :project,
323 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
323 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
324 end
324 end
325 @events.sort! {|x,y| x.start_date <=> y.start_date }
325 @events.sort! {|x,y| x.start_date <=> y.start_date }
326
326
327 if params[:format]=='pdf'
327 if params[:format]=='pdf'
328 @options_for_rfpdf ||= {}
328 @options_for_rfpdf ||= {}
329 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
329 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
330 render :template => "projects/gantt.rfpdf", :layout => false
330 render :template => "projects/gantt.rfpdf", :layout => false
331 elsif params[:format]=='png' && respond_to?('gantt_image')
331 elsif params[:format]=='png' && respond_to?('gantt_image')
332 image = gantt_image(@events, @date_from, @months, @zoom)
332 image = gantt_image(@events, @date_from, @months, @zoom)
333 image.format = 'PNG'
333 image.format = 'PNG'
334 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
334 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
335 else
335 else
336 render :template => "projects/gantt.rhtml"
336 render :template => "projects/gantt.rhtml"
337 end
337 end
338 end
338 end
339
339
340 private
340 private
341 # Find project of id params[:id]
341 # Find project of id params[:id]
342 # if not found, redirect to project list
342 # if not found, redirect to project list
343 # Used as a before_filter
343 # Used as a before_filter
344 def find_project
344 def find_project
345 @project = Project.find(params[:id])
345 @project = Project.find(params[:id])
346 rescue ActiveRecord::RecordNotFound
346 rescue ActiveRecord::RecordNotFound
347 render_404
347 render_404
348 end
348 end
349
349
350 def find_optional_project
350 def find_optional_project
351 return true unless params[:id]
351 return true unless params[:id]
352 @project = Project.find(params[:id])
352 @project = Project.find(params[:id])
353 authorize
353 authorize
354 rescue ActiveRecord::RecordNotFound
354 rescue ActiveRecord::RecordNotFound
355 render_404
355 render_404
356 end
356 end
357
357
358 def retrieve_selected_tracker_ids(selectable_trackers)
358 def retrieve_selected_tracker_ids(selectable_trackers)
359 if ids = params[:tracker_ids]
359 if ids = params[:tracker_ids]
360 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
360 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
361 else
361 else
362 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
362 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
363 end
363 end
364 end
364 end
365 end
365 end
@@ -1,313 +1,319
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 'index'
38 assert_template 'index'
39 assert_not_nil assigns(:project_tree)
39 assert_not_nil assigns(:project_tree)
40 # Root project as hash key
40 # Root project as hash key
41 assert assigns(:project_tree).keys.include?(Project.find(1))
41 assert assigns(:project_tree).keys.include?(Project.find(1))
42 # Subproject in corresponding value
42 # Subproject in corresponding value
43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
43 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
44 end
44 end
45
45
46 def test_index_atom
46 def test_index_atom
47 get :index, :format => 'atom'
47 get :index, :format => 'atom'
48 assert_response :success
48 assert_response :success
49 assert_template 'common/feed.atom.rxml'
49 assert_template 'common/feed.atom.rxml'
50 assert_select 'feed>title', :text => 'Redmine: Latest projects'
50 assert_select 'feed>title', :text => 'Redmine: Latest projects'
51 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
51 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
52 end
52 end
53
53
54 def test_show_by_id
54 def test_show_by_id
55 get :show, :id => 1
55 get :show, :id => 1
56 assert_response :success
56 assert_response :success
57 assert_template 'show'
57 assert_template 'show'
58 assert_not_nil assigns(:project)
58 assert_not_nil assigns(:project)
59 end
59 end
60
60
61 def test_show_by_identifier
61 def test_show_by_identifier
62 get :show, :id => 'ecookbook'
62 get :show, :id => 'ecookbook'
63 assert_response :success
63 assert_response :success
64 assert_template 'show'
64 assert_template 'show'
65 assert_not_nil assigns(:project)
65 assert_not_nil assigns(:project)
66 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
66 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
67 end
67 end
68
68
69 def test_private_subprojects_hidden
69 def test_private_subprojects_hidden
70 get :show, :id => 'ecookbook'
70 get :show, :id => 'ecookbook'
71 assert_response :success
71 assert_response :success
72 assert_template 'show'
72 assert_template 'show'
73 assert_no_tag :tag => 'a', :content => /Private child/
73 assert_no_tag :tag => 'a', :content => /Private child/
74 end
74 end
75
75
76 def test_private_subprojects_visible
76 def test_private_subprojects_visible
77 @request.session[:user_id] = 2 # manager who is a member of the private subproject
77 @request.session[:user_id] = 2 # manager who is a member of the private subproject
78 get :show, :id => 'ecookbook'
78 get :show, :id => 'ecookbook'
79 assert_response :success
79 assert_response :success
80 assert_template 'show'
80 assert_template 'show'
81 assert_tag :tag => 'a', :content => /Private child/
81 assert_tag :tag => 'a', :content => /Private child/
82 end
82 end
83
83
84 def test_settings
84 def test_settings
85 @request.session[:user_id] = 2 # manager
85 @request.session[:user_id] = 2 # manager
86 get :settings, :id => 1
86 get :settings, :id => 1
87 assert_response :success
87 assert_response :success
88 assert_template 'settings'
88 assert_template 'settings'
89 end
89 end
90
90
91 def test_edit
91 def test_edit
92 @request.session[:user_id] = 2 # manager
92 @request.session[:user_id] = 2 # manager
93 post :edit, :id => 1, :project => {:name => 'Test changed name',
93 post :edit, :id => 1, :project => {:name => 'Test changed name',
94 :issue_custom_field_ids => ['']}
94 :issue_custom_field_ids => ['']}
95 assert_redirected_to 'projects/settings/ecookbook'
95 assert_redirected_to 'projects/settings/ecookbook'
96 project = Project.find(1)
96 project = Project.find(1)
97 assert_equal 'Test changed name', project.name
97 assert_equal 'Test changed name', project.name
98 end
98 end
99
99
100 def test_get_destroy
100 def test_get_destroy
101 @request.session[:user_id] = 1 # admin
101 @request.session[:user_id] = 1 # admin
102 get :destroy, :id => 1
102 get :destroy, :id => 1
103 assert_response :success
103 assert_response :success
104 assert_template 'destroy'
104 assert_template 'destroy'
105 assert_not_nil Project.find_by_id(1)
105 assert_not_nil Project.find_by_id(1)
106 end
106 end
107
107
108 def test_post_destroy
108 def test_post_destroy
109 @request.session[:user_id] = 1 # admin
109 @request.session[:user_id] = 1 # admin
110 post :destroy, :id => 1, :confirm => 1
110 post :destroy, :id => 1, :confirm => 1
111 assert_redirected_to 'admin/projects'
111 assert_redirected_to 'admin/projects'
112 assert_nil Project.find_by_id(1)
112 assert_nil Project.find_by_id(1)
113 end
113 end
114
114
115 def test_list_files
115 def test_list_files
116 get :list_files, :id => 1
116 get :list_files, :id => 1
117 assert_response :success
117 assert_response :success
118 assert_template 'list_files'
118 assert_template 'list_files'
119 assert_not_nil assigns(:versions)
119 assert_not_nil assigns(:versions)
120 end
120 end
121
121
122 def test_changelog
122 def test_changelog
123 get :changelog, :id => 1
123 get :changelog, :id => 1
124 assert_response :success
124 assert_response :success
125 assert_template 'changelog'
125 assert_template 'changelog'
126 assert_not_nil assigns(:versions)
126 assert_not_nil assigns(:versions)
127 end
127 end
128
128
129 def test_roadmap
129 def test_roadmap
130 get :roadmap, :id => 1
130 get :roadmap, :id => 1
131 assert_response :success
131 assert_response :success
132 assert_template 'roadmap'
132 assert_template 'roadmap'
133 assert_not_nil assigns(:versions)
133 assert_not_nil assigns(:versions)
134 # Version with no date set appears
134 # Version with no date set appears
135 assert assigns(:versions).include?(Version.find(3))
135 assert assigns(:versions).include?(Version.find(3))
136 # Completed version doesn't appear
136 # Completed version doesn't appear
137 assert !assigns(:versions).include?(Version.find(1))
137 assert !assigns(:versions).include?(Version.find(1))
138 end
138 end
139
139
140 def test_roadmap_with_completed_versions
140 def test_roadmap_with_completed_versions
141 get :roadmap, :id => 1, :completed => 1
141 get :roadmap, :id => 1, :completed => 1
142 assert_response :success
142 assert_response :success
143 assert_template 'roadmap'
143 assert_template 'roadmap'
144 assert_not_nil assigns(:versions)
144 assert_not_nil assigns(:versions)
145 # Version with no date set appears
145 # Version with no date set appears
146 assert assigns(:versions).include?(Version.find(3))
146 assert assigns(:versions).include?(Version.find(3))
147 # Completed version appears
147 # Completed version appears
148 assert assigns(:versions).include?(Version.find(1))
148 assert assigns(:versions).include?(Version.find(1))
149 end
149 end
150
150
151 def test_project_activity
151 def test_project_activity
152 get :activity, :id => 1, :with_subprojects => 0
152 get :activity, :id => 1, :with_subprojects => 0
153 assert_response :success
153 assert_response :success
154 assert_template 'activity'
154 assert_template 'activity'
155 assert_not_nil assigns(:events_by_day)
155 assert_not_nil assigns(:events_by_day)
156
156
157 assert_tag :tag => "h3",
157 assert_tag :tag => "h3",
158 :content => /#{2.days.ago.to_date.day}/,
158 :content => /#{2.days.ago.to_date.day}/,
159 :sibling => { :tag => "dl",
159 :sibling => { :tag => "dl",
160 :child => { :tag => "dt",
160 :child => { :tag => "dt",
161 :attributes => { :class => /issue-edit/ },
161 :attributes => { :class => /issue-edit/ },
162 :child => { :tag => "a",
162 :child => { :tag => "a",
163 :content => /(#{IssueStatus.find(2).name})/,
163 :content => /(#{IssueStatus.find(2).name})/,
164 }
164 }
165 }
165 }
166 }
166 }
167 end
167 end
168
168
169 def test_previous_project_activity
169 def test_previous_project_activity
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_global_activity
187 def test_global_activity
188 get :activity
188 get :activity
189 assert_response :success
189 assert_response :success
190 assert_template 'activity'
190 assert_template 'activity'
191 assert_not_nil assigns(:events_by_day)
191 assert_not_nil assigns(:events_by_day)
192
192
193 assert_tag :tag => "h3",
193 assert_tag :tag => "h3",
194 :content => /#{5.day.ago.to_date.day}/,
194 :content => /#{5.day.ago.to_date.day}/,
195 :sibling => { :tag => "dl",
195 :sibling => { :tag => "dl",
196 :child => { :tag => "dt",
196 :child => { :tag => "dt",
197 :attributes => { :class => /issue/ },
197 :attributes => { :class => /issue/ },
198 :child => { :tag => "a",
198 :child => { :tag => "a",
199 :content => /#{Issue.find(5).subject}/,
199 :content => /#{Issue.find(5).subject}/,
200 }
200 }
201 }
201 }
202 }
202 }
203 end
203 end
204
204
205 def test_activity_atom_feed
206 get :activity, :format => 'atom'
207 assert_response :success
208 assert_template 'common/feed.atom.rxml'
209 end
210
205 def test_calendar
211 def test_calendar
206 get :calendar, :id => 1
212 get :calendar, :id => 1
207 assert_response :success
213 assert_response :success
208 assert_template 'calendar'
214 assert_template 'calendar'
209 assert_not_nil assigns(:calendar)
215 assert_not_nil assigns(:calendar)
210 end
216 end
211
217
212 def test_calendar_with_subprojects_should_not_show_private_subprojects
218 def test_calendar_with_subprojects_should_not_show_private_subprojects
213 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
219 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
214 assert_response :success
220 assert_response :success
215 assert_template 'calendar'
221 assert_template 'calendar'
216 assert_not_nil assigns(:calendar)
222 assert_not_nil assigns(:calendar)
217 assert_no_tag :tag => 'a', :content => /#6/
223 assert_no_tag :tag => 'a', :content => /#6/
218 end
224 end
219
225
220 def test_calendar_with_subprojects_should_show_private_subprojects
226 def test_calendar_with_subprojects_should_show_private_subprojects
221 @request.session[:user_id] = 2
227 @request.session[:user_id] = 2
222 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
228 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
223 assert_response :success
229 assert_response :success
224 assert_template 'calendar'
230 assert_template 'calendar'
225 assert_not_nil assigns(:calendar)
231 assert_not_nil assigns(:calendar)
226 assert_tag :tag => 'a', :content => /#6/
232 assert_tag :tag => 'a', :content => /#6/
227 end
233 end
228
234
229 def test_gantt
235 def test_gantt
230 get :gantt, :id => 1
236 get :gantt, :id => 1
231 assert_response :success
237 assert_response :success
232 assert_template 'gantt.rhtml'
238 assert_template 'gantt.rhtml'
233 events = assigns(:events)
239 events = assigns(:events)
234 assert_not_nil events
240 assert_not_nil events
235 # Issue with start and due dates
241 # Issue with start and due dates
236 i = Issue.find(1)
242 i = Issue.find(1)
237 assert_not_nil i.due_date
243 assert_not_nil i.due_date
238 assert events.include?(Issue.find(1))
244 assert events.include?(Issue.find(1))
239 # Issue with without due date but targeted to a version with date
245 # Issue with without due date but targeted to a version with date
240 i = Issue.find(2)
246 i = Issue.find(2)
241 assert_nil i.due_date
247 assert_nil i.due_date
242 assert events.include?(i)
248 assert events.include?(i)
243 end
249 end
244
250
245 def test_gantt_with_subprojects_should_not_show_private_subprojects
251 def test_gantt_with_subprojects_should_not_show_private_subprojects
246 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
252 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
247 assert_response :success
253 assert_response :success
248 assert_template 'gantt.rhtml'
254 assert_template 'gantt.rhtml'
249 assert_not_nil assigns(:events)
255 assert_not_nil assigns(:events)
250 assert_no_tag :tag => 'a', :content => /#6/
256 assert_no_tag :tag => 'a', :content => /#6/
251 end
257 end
252
258
253 def test_gantt_with_subprojects_should_show_private_subprojects
259 def test_gantt_with_subprojects_should_show_private_subprojects
254 @request.session[:user_id] = 2
260 @request.session[:user_id] = 2
255 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
261 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
256 assert_response :success
262 assert_response :success
257 assert_template 'gantt.rhtml'
263 assert_template 'gantt.rhtml'
258 assert_not_nil assigns(:events)
264 assert_not_nil assigns(:events)
259 assert_tag :tag => 'a', :content => /#6/
265 assert_tag :tag => 'a', :content => /#6/
260 end
266 end
261
267
262 def test_gantt_export_to_pdf
268 def test_gantt_export_to_pdf
263 get :gantt, :id => 1, :format => 'pdf'
269 get :gantt, :id => 1, :format => 'pdf'
264 assert_response :success
270 assert_response :success
265 assert_template 'gantt.rfpdf'
271 assert_template 'gantt.rfpdf'
266 assert_equal 'application/pdf', @response.content_type
272 assert_equal 'application/pdf', @response.content_type
267 assert_not_nil assigns(:events)
273 assert_not_nil assigns(:events)
268 end
274 end
269
275
270 def test_archive
276 def test_archive
271 @request.session[:user_id] = 1 # admin
277 @request.session[:user_id] = 1 # admin
272 post :archive, :id => 1
278 post :archive, :id => 1
273 assert_redirected_to 'admin/projects'
279 assert_redirected_to 'admin/projects'
274 assert !Project.find(1).active?
280 assert !Project.find(1).active?
275 end
281 end
276
282
277 def test_unarchive
283 def test_unarchive
278 @request.session[:user_id] = 1 # admin
284 @request.session[:user_id] = 1 # admin
279 Project.find(1).archive
285 Project.find(1).archive
280 post :unarchive, :id => 1
286 post :unarchive, :id => 1
281 assert_redirected_to 'admin/projects'
287 assert_redirected_to 'admin/projects'
282 assert Project.find(1).active?
288 assert Project.find(1).active?
283 end
289 end
284
290
285 def test_project_menu
291 def test_project_menu
286 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
292 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
287 Redmine::MenuManager.map :project_menu do |menu|
293 Redmine::MenuManager.map :project_menu do |menu|
288 menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo'
294 menu.push :foo, { :controller => 'projects', :action => 'show' }, :cation => 'Foo'
289 menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
295 menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
290 menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
296 menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
291 end
297 end
292
298
293 get :show, :id => 1
299 get :show, :id => 1
294 assert_tag :div, :attributes => { :id => 'main-menu' },
300 assert_tag :div, :attributes => { :id => 'main-menu' },
295 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } }
301 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Foo' } }
296
302
297 assert_tag :div, :attributes => { :id => 'main-menu' },
303 assert_tag :div, :attributes => { :id => 'main-menu' },
298 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' },
304 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'Bar' },
299 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } }
305 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' } } }
300
306
301 assert_tag :div, :attributes => { :id => 'main-menu' },
307 assert_tag :div, :attributes => { :id => 'main-menu' },
302 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' },
308 :descendant => { :tag => 'li', :child => { :tag => 'a', :content => 'ECOOKBOOK' },
303 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } }
309 :before => { :tag => 'li', :child => { :tag => 'a', :content => 'Activity' } } }
304
310
305 # Remove the menu items
311 # Remove the menu items
306 Redmine::MenuManager.map :project_menu do |menu|
312 Redmine::MenuManager.map :project_menu do |menu|
307 menu.delete :foo
313 menu.delete :foo
308 menu.delete :bar
314 menu.delete :bar
309 menu.delete :hello
315 menu.delete :hello
310 end
316 end
311 end
317 end
312 end
318 end
313 end
319 end
General Comments 0
You need to be logged in to leave comments. Login now