##// END OF EJS Templates
Make the project files list sortable (#997)....
Jean-Philippe Lang -
r1315:fe74ab8c0644
parent child
Show More
@@ -1,428 +1,431
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :overview
20 menu_item :overview
21 menu_item :activity, :only => :activity
21 menu_item :activity, :only => :activity
22 menu_item :roadmap, :only => :roadmap
22 menu_item :roadmap, :only => :roadmap
23 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :files, :only => [:list_files, :add_file]
24 menu_item :settings, :only => :settings
24 menu_item :settings, :only => :settings
25 menu_item :issues, :only => [:changelog]
25 menu_item :issues, :only => [:changelog]
26
26
27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 before_filter :find_optional_project, :only => :activity
28 before_filter :find_optional_project, :only => :activity
29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 accept_key_auth :activity, :calendar
31 accept_key_auth :activity, :calendar
32
32
33 helper :sort
33 helper :sort
34 include SortHelper
34 include SortHelper
35 helper :custom_fields
35 helper :custom_fields
36 include CustomFieldsHelper
36 include CustomFieldsHelper
37 helper :ifpdf
37 helper :ifpdf
38 include IfpdfHelper
38 include IfpdfHelper
39 helper :issues
39 helper :issues
40 helper IssuesHelper
40 helper IssuesHelper
41 helper :queries
41 helper :queries
42 include QueriesHelper
42 include QueriesHelper
43 helper :repositories
43 helper :repositories
44 include RepositoriesHelper
44 include RepositoriesHelper
45 include ProjectsHelper
45 include ProjectsHelper
46
46
47 def index
47 def index
48 list
48 list
49 render :action => 'list' unless request.xhr?
49 render :action => 'list' unless request.xhr?
50 end
50 end
51
51
52 # Lists visible projects
52 # Lists visible projects
53 def list
53 def list
54 projects = Project.find :all,
54 projects = Project.find :all,
55 :conditions => Project.visible_by(User.current),
55 :conditions => Project.visible_by(User.current),
56 :include => :parent
56 :include => :parent
57 @project_tree = projects.group_by {|p| p.parent || p}
57 @project_tree = projects.group_by {|p| p.parent || p}
58 @project_tree.each_key {|p| @project_tree[p] -= [p]}
58 @project_tree.each_key {|p| @project_tree[p] -= [p]}
59 end
59 end
60
60
61 # Add a new project
61 # Add a new project
62 def add
62 def add
63 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
63 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
64 @trackers = Tracker.all
64 @trackers = Tracker.all
65 @root_projects = Project.find(:all,
65 @root_projects = Project.find(:all,
66 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
66 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
67 :order => 'name')
67 :order => 'name')
68 @project = Project.new(params[:project])
68 @project = Project.new(params[:project])
69 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
69 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
70 if request.get?
70 if request.get?
71 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
71 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
72 @project.trackers = Tracker.all
72 @project.trackers = Tracker.all
73 @project.is_public = Setting.default_projects_public?
73 @project.is_public = Setting.default_projects_public?
74 else
74 else
75 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
75 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
76 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
76 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
77 @project.custom_values = @custom_values
77 @project.custom_values = @custom_values
78 if @project.save
78 if @project.save
79 @project.enabled_module_names = params[:enabled_modules]
79 @project.enabled_module_names = params[:enabled_modules]
80 flash[:notice] = l(:notice_successful_create)
80 flash[:notice] = l(:notice_successful_create)
81 redirect_to :controller => 'admin', :action => 'projects'
81 redirect_to :controller => 'admin', :action => 'projects'
82 end
82 end
83 end
83 end
84 end
84 end
85
85
86 # Show @project
86 # Show @project
87 def show
87 def show
88 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
88 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
89 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
89 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
90 @subprojects = @project.active_children
90 @subprojects = @project.active_children
91 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
91 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
92 @trackers = @project.rolled_up_trackers
92 @trackers = @project.rolled_up_trackers
93
93
94 cond = @project.project_condition(Setting.display_subprojects_issues?)
94 cond = @project.project_condition(Setting.display_subprojects_issues?)
95 Issue.visible_by(User.current) do
95 Issue.visible_by(User.current) do
96 @open_issues_by_tracker = Issue.count(:group => :tracker,
96 @open_issues_by_tracker = Issue.count(:group => :tracker,
97 :include => [:project, :status, :tracker],
97 :include => [:project, :status, :tracker],
98 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
98 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
99 @total_issues_by_tracker = Issue.count(:group => :tracker,
99 @total_issues_by_tracker = Issue.count(:group => :tracker,
100 :include => [:project, :status, :tracker],
100 :include => [:project, :status, :tracker],
101 :conditions => cond)
101 :conditions => cond)
102 end
102 end
103 TimeEntry.visible_by(User.current) do
103 TimeEntry.visible_by(User.current) do
104 @total_hours = TimeEntry.sum(:hours,
104 @total_hours = TimeEntry.sum(:hours,
105 :include => :project,
105 :include => :project,
106 :conditions => cond).to_f
106 :conditions => cond).to_f
107 end
107 end
108 @key = User.current.rss_key
108 @key = User.current.rss_key
109 end
109 end
110
110
111 def settings
111 def settings
112 @root_projects = Project.find(:all,
112 @root_projects = Project.find(:all,
113 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
113 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
114 :order => 'name')
114 :order => 'name')
115 @custom_fields = IssueCustomField.find(:all)
115 @custom_fields = IssueCustomField.find(:all)
116 @issue_category ||= IssueCategory.new
116 @issue_category ||= IssueCategory.new
117 @member ||= @project.members.new
117 @member ||= @project.members.new
118 @trackers = Tracker.all
118 @trackers = Tracker.all
119 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
119 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
120 @repository ||= @project.repository
120 @repository ||= @project.repository
121 @wiki ||= @project.wiki
121 @wiki ||= @project.wiki
122 end
122 end
123
123
124 # Edit @project
124 # Edit @project
125 def edit
125 def edit
126 if request.post?
126 if request.post?
127 if params[:custom_fields]
127 if params[:custom_fields]
128 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
128 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
129 @project.custom_values = @custom_values
129 @project.custom_values = @custom_values
130 end
130 end
131 @project.attributes = params[:project]
131 @project.attributes = params[:project]
132 if @project.save
132 if @project.save
133 flash[:notice] = l(:notice_successful_update)
133 flash[:notice] = l(:notice_successful_update)
134 redirect_to :action => 'settings', :id => @project
134 redirect_to :action => 'settings', :id => @project
135 else
135 else
136 settings
136 settings
137 render :action => 'settings'
137 render :action => 'settings'
138 end
138 end
139 end
139 end
140 end
140 end
141
141
142 def modules
142 def modules
143 @project.enabled_module_names = params[:enabled_modules]
143 @project.enabled_module_names = params[:enabled_modules]
144 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
144 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
145 end
145 end
146
146
147 def archive
147 def archive
148 @project.archive if request.post? && @project.active?
148 @project.archive if request.post? && @project.active?
149 redirect_to :controller => 'admin', :action => 'projects'
149 redirect_to :controller => 'admin', :action => 'projects'
150 end
150 end
151
151
152 def unarchive
152 def unarchive
153 @project.unarchive if request.post? && !@project.active?
153 @project.unarchive if request.post? && !@project.active?
154 redirect_to :controller => 'admin', :action => 'projects'
154 redirect_to :controller => 'admin', :action => 'projects'
155 end
155 end
156
156
157 # Delete @project
157 # Delete @project
158 def destroy
158 def destroy
159 @project_to_destroy = @project
159 @project_to_destroy = @project
160 if request.post? and params[:confirm]
160 if request.post? and params[:confirm]
161 @project_to_destroy.destroy
161 @project_to_destroy.destroy
162 redirect_to :controller => 'admin', :action => 'projects'
162 redirect_to :controller => 'admin', :action => 'projects'
163 end
163 end
164 # hide project in layout
164 # hide project in layout
165 @project = nil
165 @project = nil
166 end
166 end
167
167
168 # Add a new issue category to @project
168 # Add a new issue category to @project
169 def add_issue_category
169 def add_issue_category
170 @category = @project.issue_categories.build(params[:category])
170 @category = @project.issue_categories.build(params[:category])
171 if request.post? and @category.save
171 if request.post? and @category.save
172 respond_to do |format|
172 respond_to do |format|
173 format.html do
173 format.html do
174 flash[:notice] = l(:notice_successful_create)
174 flash[:notice] = l(:notice_successful_create)
175 redirect_to :action => 'settings', :tab => 'categories', :id => @project
175 redirect_to :action => 'settings', :tab => 'categories', :id => @project
176 end
176 end
177 format.js do
177 format.js do
178 # IE doesn't support the replace_html rjs method for select box options
178 # IE doesn't support the replace_html rjs method for select box options
179 render(:update) {|page| page.replace "issue_category_id",
179 render(:update) {|page| page.replace "issue_category_id",
180 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
180 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
181 }
181 }
182 end
182 end
183 end
183 end
184 end
184 end
185 end
185 end
186
186
187 # Add a new version to @project
187 # Add a new version to @project
188 def add_version
188 def add_version
189 @version = @project.versions.build(params[:version])
189 @version = @project.versions.build(params[:version])
190 if request.post? and @version.save
190 if request.post? and @version.save
191 flash[:notice] = l(:notice_successful_create)
191 flash[:notice] = l(:notice_successful_create)
192 redirect_to :action => 'settings', :tab => 'versions', :id => @project
192 redirect_to :action => 'settings', :tab => 'versions', :id => @project
193 end
193 end
194 end
194 end
195
195
196 def add_file
196 def add_file
197 if request.post?
197 if request.post?
198 @version = @project.versions.find_by_id(params[:version_id])
198 @version = @project.versions.find_by_id(params[:version_id])
199 attachments = attach_files(@version, params[:attachments])
199 attachments = attach_files(@version, params[:attachments])
200 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
200 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
201 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
201 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
202 end
202 end
203 @versions = @project.versions.sort
203 @versions = @project.versions.sort
204 end
204 end
205
205
206 def list_files
206 def list_files
207 @versions = @project.versions.sort.reverse
207 sort_init "#{Attachment.table_name}.filename", "asc"
208 sort_update
209 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
210 render :layout => !request.xhr?
208 end
211 end
209
212
210 # Show changelog for @project
213 # Show changelog for @project
211 def changelog
214 def changelog
212 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
215 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
213 retrieve_selected_tracker_ids(@trackers)
216 retrieve_selected_tracker_ids(@trackers)
214 @versions = @project.versions.sort
217 @versions = @project.versions.sort
215 end
218 end
216
219
217 def roadmap
220 def roadmap
218 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
221 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
219 retrieve_selected_tracker_ids(@trackers)
222 retrieve_selected_tracker_ids(@trackers)
220 @versions = @project.versions.sort
223 @versions = @project.versions.sort
221 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
224 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
222 end
225 end
223
226
224 def activity
227 def activity
225 @days = Setting.activity_days_default.to_i
228 @days = Setting.activity_days_default.to_i
226
229
227 if params[:from]
230 if params[:from]
228 begin; @date_to = params[:from].to_date; rescue; end
231 begin; @date_to = params[:from].to_date; rescue; end
229 end
232 end
230
233
231 @date_to ||= Date.today + 1
234 @date_to ||= Date.today + 1
232 @date_from = @date_to - @days
235 @date_from = @date_to - @days
233
236
234 @event_types = %w(issues news files documents changesets wiki_pages messages)
237 @event_types = %w(issues news files documents changesets wiki_pages messages)
235 if @project
238 if @project
236 @event_types.delete('wiki_pages') unless @project.wiki
239 @event_types.delete('wiki_pages') unless @project.wiki
237 @event_types.delete('changesets') unless @project.repository
240 @event_types.delete('changesets') unless @project.repository
238 @event_types.delete('messages') unless @project.boards.any?
241 @event_types.delete('messages') unless @project.boards.any?
239 # only show what the user is allowed to view
242 # only show what the user is allowed to view
240 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
243 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
241 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
244 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
242 end
245 end
243 @scope = @event_types.select {|t| params["show_#{t}"]}
246 @scope = @event_types.select {|t| params["show_#{t}"]}
244 # default events if none is specified in parameters
247 # default events if none is specified in parameters
245 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
248 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
246
249
247 @events = []
250 @events = []
248
251
249 if @scope.include?('issues')
252 if @scope.include?('issues')
250 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
253 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
251 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
254 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
252 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
255 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
253
256
254 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
257 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
255 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
258 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
256 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
259 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
257 end
260 end
258
261
259 if @scope.include?('news')
262 if @scope.include?('news')
260 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
263 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
261 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
264 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
262 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
265 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
263 end
266 end
264
267
265 if @scope.include?('files')
268 if @scope.include?('files')
266 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
269 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
267 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
270 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
268 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
271 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
269 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
272 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
270 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
273 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
271 :conditions => cond.conditions)
274 :conditions => cond.conditions)
272 end
275 end
273
276
274 if @scope.include?('documents')
277 if @scope.include?('documents')
275 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
278 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
276 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
279 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
277 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
280 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
278
281
279 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
282 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
280 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
283 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
281 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
284 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
282 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
285 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
283 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
286 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
284 :conditions => cond.conditions)
287 :conditions => cond.conditions)
285 end
288 end
286
289
287 if @scope.include?('wiki_pages')
290 if @scope.include?('wiki_pages')
288 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
291 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
289 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
292 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
290 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
293 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
291 "#{WikiContent.versioned_table_name}.id"
294 "#{WikiContent.versioned_table_name}.id"
292 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
295 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
293 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
296 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
294 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
297 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
295
298
296 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
299 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
297 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
300 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
298 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
301 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
299 end
302 end
300
303
301 if @scope.include?('changesets')
304 if @scope.include?('changesets')
302 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
305 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
303 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
306 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
304 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
307 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
305 end
308 end
306
309
307 if @scope.include?('messages')
310 if @scope.include?('messages')
308 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
311 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
309 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
312 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
310 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
313 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
311 end
314 end
312
315
313 @events_by_day = @events.group_by(&:event_date)
316 @events_by_day = @events.group_by(&:event_date)
314
317
315 respond_to do |format|
318 respond_to do |format|
316 format.html { render :layout => false if request.xhr? }
319 format.html { render :layout => false if request.xhr? }
317 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
320 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
318 end
321 end
319 end
322 end
320
323
321 def calendar
324 def calendar
322 @trackers = @project.rolled_up_trackers
325 @trackers = @project.rolled_up_trackers
323 retrieve_selected_tracker_ids(@trackers)
326 retrieve_selected_tracker_ids(@trackers)
324
327
325 if params[:year] and params[:year].to_i > 1900
328 if params[:year] and params[:year].to_i > 1900
326 @year = params[:year].to_i
329 @year = params[:year].to_i
327 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
330 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
328 @month = params[:month].to_i
331 @month = params[:month].to_i
329 end
332 end
330 end
333 end
331 @year ||= Date.today.year
334 @year ||= Date.today.year
332 @month ||= Date.today.month
335 @month ||= Date.today.month
333 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
336 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
334 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
337 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
335 events = []
338 events = []
336 @project.issues_with_subprojects(@with_subprojects) do
339 @project.issues_with_subprojects(@with_subprojects) do
337 events += Issue.find(:all,
340 events += Issue.find(:all,
338 :include => [:tracker, :status, :assigned_to, :priority, :project],
341 :include => [:tracker, :status, :assigned_to, :priority, :project],
339 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
342 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
340 ) unless @selected_tracker_ids.empty?
343 ) unless @selected_tracker_ids.empty?
341 end
344 end
342 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
345 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
343 @calendar.events = events
346 @calendar.events = events
344
347
345 render :layout => false if request.xhr?
348 render :layout => false if request.xhr?
346 end
349 end
347
350
348 def gantt
351 def gantt
349 @trackers = @project.rolled_up_trackers
352 @trackers = @project.rolled_up_trackers
350 retrieve_selected_tracker_ids(@trackers)
353 retrieve_selected_tracker_ids(@trackers)
351
354
352 if params[:year] and params[:year].to_i >0
355 if params[:year] and params[:year].to_i >0
353 @year_from = params[:year].to_i
356 @year_from = params[:year].to_i
354 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
357 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
355 @month_from = params[:month].to_i
358 @month_from = params[:month].to_i
356 else
359 else
357 @month_from = 1
360 @month_from = 1
358 end
361 end
359 else
362 else
360 @month_from ||= Date.today.month
363 @month_from ||= Date.today.month
361 @year_from ||= Date.today.year
364 @year_from ||= Date.today.year
362 end
365 end
363
366
364 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
367 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
365 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
368 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
366 months = (params[:months] || User.current.pref[:gantt_months]).to_i
369 months = (params[:months] || User.current.pref[:gantt_months]).to_i
367 @months = (months > 0 && months < 25) ? months : 6
370 @months = (months > 0 && months < 25) ? months : 6
368
371
369 # Save gantt paramters as user preference (zoom and months count)
372 # Save gantt paramters as user preference (zoom and months count)
370 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
373 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
371 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
374 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
372 User.current.preference.save
375 User.current.preference.save
373 end
376 end
374
377
375 @date_from = Date.civil(@year_from, @month_from, 1)
378 @date_from = Date.civil(@year_from, @month_from, 1)
376 @date_to = (@date_from >> @months) - 1
379 @date_to = (@date_from >> @months) - 1
377 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
380 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
378
381
379 @events = []
382 @events = []
380 @project.issues_with_subprojects(@with_subprojects) do
383 @project.issues_with_subprojects(@with_subprojects) do
381 @events += Issue.find(:all,
384 @events += Issue.find(:all,
382 :order => "start_date, due_date",
385 :order => "start_date, due_date",
383 :include => [:tracker, :status, :assigned_to, :priority, :project],
386 :include => [:tracker, :status, :assigned_to, :priority, :project],
384 :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]
387 :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]
385 ) unless @selected_tracker_ids.empty?
388 ) unless @selected_tracker_ids.empty?
386 end
389 end
387 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
390 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
388 @events.sort! {|x,y| x.start_date <=> y.start_date }
391 @events.sort! {|x,y| x.start_date <=> y.start_date }
389
392
390 if params[:format]=='pdf'
393 if params[:format]=='pdf'
391 @options_for_rfpdf ||= {}
394 @options_for_rfpdf ||= {}
392 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
395 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
393 render :template => "projects/gantt.rfpdf", :layout => false
396 render :template => "projects/gantt.rfpdf", :layout => false
394 elsif params[:format]=='png' && respond_to?('gantt_image')
397 elsif params[:format]=='png' && respond_to?('gantt_image')
395 image = gantt_image(@events, @date_from, @months, @zoom)
398 image = gantt_image(@events, @date_from, @months, @zoom)
396 image.format = 'PNG'
399 image.format = 'PNG'
397 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
400 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
398 else
401 else
399 render :template => "projects/gantt.rhtml"
402 render :template => "projects/gantt.rhtml"
400 end
403 end
401 end
404 end
402
405
403 private
406 private
404 # Find project of id params[:id]
407 # Find project of id params[:id]
405 # if not found, redirect to project list
408 # if not found, redirect to project list
406 # Used as a before_filter
409 # Used as a before_filter
407 def find_project
410 def find_project
408 @project = Project.find(params[:id])
411 @project = Project.find(params[:id])
409 rescue ActiveRecord::RecordNotFound
412 rescue ActiveRecord::RecordNotFound
410 render_404
413 render_404
411 end
414 end
412
415
413 def find_optional_project
416 def find_optional_project
414 return true unless params[:id]
417 return true unless params[:id]
415 @project = Project.find(params[:id])
418 @project = Project.find(params[:id])
416 authorize
419 authorize
417 rescue ActiveRecord::RecordNotFound
420 rescue ActiveRecord::RecordNotFound
418 render_404
421 render_404
419 end
422 end
420
423
421 def retrieve_selected_tracker_ids(selectable_trackers)
424 def retrieve_selected_tracker_ids(selectable_trackers)
422 if ids = params[:tracker_ids]
425 if ids = params[:tracker_ids]
423 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
426 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
424 else
427 else
425 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
428 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
426 end
429 end
427 end
430 end
428 end
431 end
@@ -1,45 +1,45
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %>
2 <%= link_to_if_authorized l(:label_attachment_new), {:controller => 'projects', :action => 'add_file', :id => @project}, :class => 'icon icon-add' %>
3 </div>
3 </div>
4
4
5 <h2><%=l(:label_attachment_plural)%></h2>
5 <h2><%=l(:label_attachment_plural)%></h2>
6
6
7 <% delete_allowed = authorize_for('versions', 'destroy_file') %>
7 <% delete_allowed = authorize_for('versions', 'destroy_file') %>
8
8
9 <table class="list">
9 <table class="list">
10 <thead><tr>
10 <thead><tr>
11 <th><%=l(:field_version)%></th>
11 <th><%=l(:field_version)%></th>
12 <th><%=l(:field_filename)%></th>
12 <%= sort_header_tag("#{Attachment.table_name}.filename", :caption => l(:field_filename)) %>
13 <th><%=l(:label_date)%></th>
13 <%= sort_header_tag("#{Attachment.table_name}.created_on", :caption => l(:label_date), :default_order => 'desc') %>
14 <th><%=l(:field_filesize)%></th>
14 <%= sort_header_tag("#{Attachment.table_name}.filesize", :caption => l(:field_filesize), :default_order => 'desc') %>
15 <th><%=l(:label_downloads_abbr)%></th>
15 <%= sort_header_tag("#{Attachment.table_name}.downloads", :caption => l(:label_downloads_abbr), :default_order => 'desc') %>
16 <th>MD5</th>
16 <th>MD5</th>
17 <% if delete_allowed %><th></th><% end %>
17 <% if delete_allowed %><th></th><% end %>
18 </tr></thead>
18 </tr></thead>
19 <tbody>
19 <tbody>
20 <% for version in @versions %>
20 <% for version in @versions %>
21 <% unless version.attachments.empty? %>
21 <% unless version.attachments.empty? %>
22 <tr><th colspan="7" align="left"><span class="icon icon-package"><b><%= version.name %></b></span></th></tr>
22 <tr><th colspan="7" align="left"><span class="icon icon-package"><b><%= version.name %></b></span></th></tr>
23 <% for file in version.attachments %>
23 <% for file in version.attachments %>
24 <tr class="<%= cycle("odd", "even") %>">
24 <tr class="<%= cycle("odd", "even") %>">
25 <td></td>
25 <td></td>
26 <td><%= link_to(file.filename, {:controller => 'versions', :action => 'download', :id => version, :attachment_id => file},
26 <td><%= link_to(file.filename, {:controller => 'versions', :action => 'download', :id => version, :attachment_id => file},
27 :title => file.description) %></td>
27 :title => file.description) %></td>
28 <td align="center"><%= format_time(file.created_on) %></td>
28 <td align="center"><%= format_time(file.created_on) %></td>
29 <td align="center"><%= number_to_human_size(file.filesize) %></td>
29 <td align="center"><%= number_to_human_size(file.filesize) %></td>
30 <td align="center"><%= file.downloads %></td>
30 <td align="center"><%= file.downloads %></td>
31 <td align="center"><small><%= file.digest %></small></td>
31 <td align="center"><small><%= file.digest %></small></td>
32 <% if delete_allowed %>
32 <% if delete_allowed %>
33 <td align="center">
33 <td align="center">
34 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'versions', :action => 'destroy_file', :id => version, :attachment_id => file}, :confirm => l(:text_are_you_sure), :method => :post %>
34 <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'versions', :action => 'destroy_file', :id => version, :attachment_id => file}, :confirm => l(:text_are_you_sure), :method => :post %>
35 </td>
35 </td>
36 <% end %>
36 <% end %>
37 </tr>
37 </tr>
38 <% end
38 <% end
39 reset_cycle %>
39 reset_cycle %>
40 <% end %>
40 <% end %>
41 <% end %>
41 <% end %>
42 </tbody>
42 </tbody>
43 </table>
43 </table>
44
44
45 <% html_title(l(:label_attachment_plural)) -%>
45 <% html_title(l(:label_attachment_plural)) -%>
General Comments 0
You need to be logged in to leave comments. Login now