@@ -1,660 +1,668 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'csv' |
|
18 | require 'csv' | |
19 |
|
19 | |||
20 | class ProjectsController < ApplicationController |
|
20 | class ProjectsController < ApplicationController | |
21 | layout 'base' |
|
21 | layout 'base' | |
22 | before_filter :find_project, :except => [ :index, :list, :add ] |
|
22 | before_filter :find_project, :except => [ :index, :list, :add ] | |
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
23 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] | |
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
24 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] | |
25 | accept_key_auth :activity, :calendar |
|
25 | accept_key_auth :activity, :calendar | |
26 |
|
26 | |||
27 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] |
|
27 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] | |
28 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] |
|
28 | cache_sweeper :issue_sweeper, :only => [ :add_issue ] | |
29 | cache_sweeper :version_sweeper, :only => [ :add_version ] |
|
29 | cache_sweeper :version_sweeper, :only => [ :add_version ] | |
30 |
|
30 | |||
31 | helper :sort |
|
31 | helper :sort | |
32 | include SortHelper |
|
32 | include SortHelper | |
33 | helper :custom_fields |
|
33 | helper :custom_fields | |
34 | include CustomFieldsHelper |
|
34 | include CustomFieldsHelper | |
35 | helper :ifpdf |
|
35 | helper :ifpdf | |
36 | include IfpdfHelper |
|
36 | include IfpdfHelper | |
37 | helper :issues |
|
37 | helper :issues | |
38 | helper IssuesHelper |
|
38 | helper IssuesHelper | |
39 | helper :queries |
|
39 | helper :queries | |
40 | include QueriesHelper |
|
40 | include QueriesHelper | |
41 | helper :repositories |
|
41 | helper :repositories | |
42 | include RepositoriesHelper |
|
42 | include RepositoriesHelper | |
43 | include ProjectsHelper |
|
43 | include ProjectsHelper | |
44 |
|
44 | |||
45 | def index |
|
45 | def index | |
46 | list |
|
46 | list | |
47 | render :action => 'list' unless request.xhr? |
|
47 | render :action => 'list' unless request.xhr? | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | # Lists visible projects |
|
50 | # Lists visible projects | |
51 | def list |
|
51 | def list | |
52 | projects = Project.find :all, |
|
52 | projects = Project.find :all, | |
53 | :conditions => Project.visible_by(logged_in_user), |
|
53 | :conditions => Project.visible_by(logged_in_user), | |
54 | :include => :parent |
|
54 | :include => :parent | |
55 | @project_tree = projects.group_by {|p| p.parent || p} |
|
55 | @project_tree = projects.group_by {|p| p.parent || p} | |
56 | @project_tree.each_key {|p| @project_tree[p] -= [p]} |
|
56 | @project_tree.each_key {|p| @project_tree[p] -= [p]} | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | # Add a new project |
|
59 | # Add a new project | |
60 | def add |
|
60 | def add | |
61 | @custom_fields = IssueCustomField.find(:all) |
|
61 | @custom_fields = IssueCustomField.find(:all) | |
62 | @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}") |
|
62 | @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}") | |
63 | @project = Project.new(params[:project]) |
|
63 | @project = Project.new(params[:project]) | |
64 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
64 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules | |
65 | if request.get? |
|
65 | if request.get? | |
66 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
66 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
67 | else |
|
67 | else | |
68 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
68 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
69 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } |
|
69 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } | |
70 | @project.custom_values = @custom_values |
|
70 | @project.custom_values = @custom_values | |
71 | if @project.save |
|
71 | if @project.save | |
72 | @project.enabled_module_names = params[:enabled_modules] |
|
72 | @project.enabled_module_names = params[:enabled_modules] | |
73 | flash[:notice] = l(:notice_successful_create) |
|
73 | flash[:notice] = l(:notice_successful_create) | |
74 | redirect_to :controller => 'admin', :action => 'projects' |
|
74 | redirect_to :controller => 'admin', :action => 'projects' | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | # Show @project |
|
79 | # Show @project | |
80 | def show |
|
80 | def show | |
81 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
81 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
82 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
82 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} | |
83 | @subprojects = @project.active_children |
|
83 | @subprojects = @project.active_children | |
84 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
84 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
85 | @trackers = Tracker.find(:all, :order => 'position') |
|
85 | @trackers = Tracker.find(:all, :order => 'position') | |
86 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) |
|
86 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) | |
87 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
87 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
88 | @total_hours = @project.time_entries.sum(:hours) |
|
88 | @total_hours = @project.time_entries.sum(:hours) | |
89 | @key = User.current.rss_key |
|
89 | @key = User.current.rss_key | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def settings |
|
92 | def settings | |
93 | @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id]) |
|
93 | @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id]) | |
94 | @custom_fields = IssueCustomField.find(:all) |
|
94 | @custom_fields = IssueCustomField.find(:all) | |
95 | @issue_category ||= IssueCategory.new |
|
95 | @issue_category ||= IssueCategory.new | |
96 | @member ||= @project.members.new |
|
96 | @member ||= @project.members.new | |
97 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
97 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
98 | @repository ||= @project.repository |
|
98 | @repository ||= @project.repository | |
99 | @wiki ||= @project.wiki |
|
99 | @wiki ||= @project.wiki | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | # Edit @project |
|
102 | # Edit @project | |
103 | def edit |
|
103 | def edit | |
104 | if request.post? |
|
104 | if request.post? | |
105 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
105 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
106 | if params[:custom_fields] |
|
106 | if params[:custom_fields] | |
107 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
107 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
108 | @project.custom_values = @custom_values |
|
108 | @project.custom_values = @custom_values | |
109 | end |
|
109 | end | |
110 | @project.attributes = params[:project] |
|
110 | @project.attributes = params[:project] | |
111 | if @project.save |
|
111 | if @project.save | |
112 | flash[:notice] = l(:notice_successful_update) |
|
112 | flash[:notice] = l(:notice_successful_update) | |
113 | redirect_to :action => 'settings', :id => @project |
|
113 | redirect_to :action => 'settings', :id => @project | |
114 | else |
|
114 | else | |
115 | settings |
|
115 | settings | |
116 | render :action => 'settings' |
|
116 | render :action => 'settings' | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def modules |
|
121 | def modules | |
122 | @project.enabled_module_names = params[:enabled_modules] |
|
122 | @project.enabled_module_names = params[:enabled_modules] | |
123 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
123 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def archive |
|
126 | def archive | |
127 | @project.archive if request.post? && @project.active? |
|
127 | @project.archive if request.post? && @project.active? | |
128 | redirect_to :controller => 'admin', :action => 'projects' |
|
128 | redirect_to :controller => 'admin', :action => 'projects' | |
129 | end |
|
129 | end | |
130 |
|
130 | |||
131 | def unarchive |
|
131 | def unarchive | |
132 | @project.unarchive if request.post? && !@project.active? |
|
132 | @project.unarchive if request.post? && !@project.active? | |
133 | redirect_to :controller => 'admin', :action => 'projects' |
|
133 | redirect_to :controller => 'admin', :action => 'projects' | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | # Delete @project |
|
136 | # Delete @project | |
137 | def destroy |
|
137 | def destroy | |
138 | @project_to_destroy = @project |
|
138 | @project_to_destroy = @project | |
139 | if request.post? and params[:confirm] |
|
139 | if request.post? and params[:confirm] | |
140 | @project_to_destroy.destroy |
|
140 | @project_to_destroy.destroy | |
141 | redirect_to :controller => 'admin', :action => 'projects' |
|
141 | redirect_to :controller => 'admin', :action => 'projects' | |
142 | end |
|
142 | end | |
143 | # hide project in layout |
|
143 | # hide project in layout | |
144 | @project = nil |
|
144 | @project = nil | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | # Add a new issue category to @project |
|
147 | # Add a new issue category to @project | |
148 | def add_issue_category |
|
148 | def add_issue_category | |
149 | @category = @project.issue_categories.build(params[:category]) |
|
149 | @category = @project.issue_categories.build(params[:category]) | |
150 | if request.post? and @category.save |
|
150 | if request.post? and @category.save | |
151 | respond_to do |format| |
|
151 | respond_to do |format| | |
152 | format.html do |
|
152 | format.html do | |
153 | flash[:notice] = l(:notice_successful_create) |
|
153 | flash[:notice] = l(:notice_successful_create) | |
154 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
154 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
155 | end |
|
155 | end | |
156 | format.js do |
|
156 | format.js do | |
157 | # IE doesn't support the replace_html rjs method for select box options |
|
157 | # IE doesn't support the replace_html rjs method for select box options | |
158 | render(:update) {|page| page.replace "issue_category_id", |
|
158 | render(:update) {|page| page.replace "issue_category_id", | |
159 | 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]') |
|
159 | 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]') | |
160 | } |
|
160 | } | |
161 | end |
|
161 | end | |
162 | end |
|
162 | end | |
163 | end |
|
163 | end | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | # Add a new version to @project |
|
166 | # Add a new version to @project | |
167 | def add_version |
|
167 | def add_version | |
168 | @version = @project.versions.build(params[:version]) |
|
168 | @version = @project.versions.build(params[:version]) | |
169 | if request.post? and @version.save |
|
169 | if request.post? and @version.save | |
170 | flash[:notice] = l(:notice_successful_create) |
|
170 | flash[:notice] = l(:notice_successful_create) | |
171 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
171 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | # Add a new document to @project |
|
175 | # Add a new document to @project | |
176 | def add_document |
|
176 | def add_document | |
177 | @categories = Enumeration::get_values('DCAT') |
|
177 | @categories = Enumeration::get_values('DCAT') | |
178 | @document = @project.documents.build(params[:document]) |
|
178 | @document = @project.documents.build(params[:document]) | |
179 | if request.post? and @document.save |
|
179 | if request.post? and @document.save | |
180 | # Save the attachments |
|
180 | # Save the attachments | |
181 | params[:attachments].each { |a| |
|
181 | params[:attachments].each { |a| | |
182 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
182 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
183 | } if params[:attachments] and params[:attachments].is_a? Array |
|
183 | } if params[:attachments] and params[:attachments].is_a? Array | |
184 | flash[:notice] = l(:notice_successful_create) |
|
184 | flash[:notice] = l(:notice_successful_create) | |
185 | Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added') |
|
185 | Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added') | |
186 | redirect_to :action => 'list_documents', :id => @project |
|
186 | redirect_to :action => 'list_documents', :id => @project | |
187 | end |
|
187 | end | |
188 | end |
|
188 | end | |
189 |
|
189 | |||
190 | # Show documents list of @project |
|
190 | # Show documents list of @project | |
191 | def list_documents |
|
191 | def list_documents | |
192 | @documents = @project.documents.find :all, :include => :category |
|
192 | @documents = @project.documents.find :all, :include => :category | |
193 | end |
|
193 | end | |
194 |
|
194 | |||
195 | # Add a new issue to @project |
|
195 | # Add a new issue to @project | |
196 | def add_issue |
|
196 | def add_issue | |
197 | @tracker = Tracker.find(params[:tracker_id]) |
|
197 | @tracker = Tracker.find(params[:tracker_id]) | |
198 | @priorities = Enumeration::get_values('IPRI') |
|
198 | @priorities = Enumeration::get_values('IPRI') | |
199 |
|
199 | |||
200 | default_status = IssueStatus.default |
|
200 | default_status = IssueStatus.default | |
201 | unless default_status |
|
201 | unless default_status | |
202 | flash.now[:error] = 'No default issue status defined. Please check your configuration.' |
|
202 | flash.now[:error] = 'No default issue status defined. Please check your configuration.' | |
203 | render :nothing => true, :layout => true |
|
203 | render :nothing => true, :layout => true | |
204 | return |
|
204 | return | |
205 | end |
|
205 | end | |
206 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
206 | @issue = Issue.new(:project => @project, :tracker => @tracker) | |
207 | @issue.status = default_status |
|
207 | @issue.status = default_status | |
208 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user |
|
208 | @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user | |
209 | if request.get? |
|
209 | if request.get? | |
210 | @issue.start_date = Date.today |
|
210 | @issue.start_date = Date.today | |
211 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
211 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
212 | else |
|
212 | else | |
213 | @issue.attributes = params[:issue] |
|
213 | @issue.attributes = params[:issue] | |
214 |
|
214 | |||
215 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) |
|
215 | requested_status = IssueStatus.find_by_id(params[:issue][:status_id]) | |
216 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status |
|
216 | @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status | |
217 |
|
217 | |||
218 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
218 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
219 | # Multiple file upload |
|
219 | # Multiple file upload | |
220 | @attachments = [] |
|
220 | @attachments = [] | |
221 | params[:attachments].each { |a| |
|
221 | params[:attachments].each { |a| | |
222 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
222 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
223 | } if params[:attachments] and params[:attachments].is_a? Array |
|
223 | } if params[:attachments] and params[:attachments].is_a? Array | |
224 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } |
|
224 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) } | |
225 | @issue.custom_values = @custom_values |
|
225 | @issue.custom_values = @custom_values | |
226 | if @issue.save |
|
226 | if @issue.save | |
227 | @attachments.each(&:save) |
|
227 | @attachments.each(&:save) | |
228 | flash[:notice] = l(:notice_successful_create) |
|
228 | flash[:notice] = l(:notice_successful_create) | |
229 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') |
|
229 | Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') | |
230 | redirect_to :action => 'list_issues', :id => @project |
|
230 | redirect_to :action => 'list_issues', :id => @project | |
231 | end |
|
231 | end | |
232 | end |
|
232 | end | |
233 | end |
|
233 | end | |
234 |
|
234 | |||
235 | # Show filtered/sorted issues list of @project |
|
235 | # Show filtered/sorted issues list of @project | |
236 | def list_issues |
|
236 | def list_issues | |
237 | sort_init "#{Issue.table_name}.id", "desc" |
|
237 | sort_init "#{Issue.table_name}.id", "desc" | |
238 | sort_update |
|
238 | sort_update | |
239 |
|
239 | |||
240 | retrieve_query |
|
240 | retrieve_query | |
241 |
|
241 | |||
242 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
242 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
243 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
243 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
244 | @results_per_page = params[:per_page].to_i |
|
244 | @results_per_page = params[:per_page].to_i | |
245 | session[:results_per_page] = @results_per_page |
|
245 | session[:results_per_page] = @results_per_page | |
246 | else |
|
246 | else | |
247 | @results_per_page = session[:results_per_page] || 25 |
|
247 | @results_per_page = session[:results_per_page] || 25 | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | if @query.valid? |
|
250 | if @query.valid? | |
251 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
251 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
252 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
252 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
253 | @issues = Issue.find :all, :order => sort_clause, |
|
253 | @issues = Issue.find :all, :order => sort_clause, | |
254 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], |
|
254 | :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ], | |
255 | :conditions => @query.statement, |
|
255 | :conditions => @query.statement, | |
256 | :limit => @issue_pages.items_per_page, |
|
256 | :limit => @issue_pages.items_per_page, | |
257 | :offset => @issue_pages.current.offset |
|
257 | :offset => @issue_pages.current.offset | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | render :layout => false if request.xhr? |
|
260 | render :layout => false if request.xhr? | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | # Export filtered/sorted issues list to CSV |
|
263 | # Export filtered/sorted issues list to CSV | |
264 | def export_issues_csv |
|
264 | def export_issues_csv | |
265 | sort_init "#{Issue.table_name}.id", "desc" |
|
265 | sort_init "#{Issue.table_name}.id", "desc" | |
266 | sort_update |
|
266 | sort_update | |
267 |
|
267 | |||
268 | retrieve_query |
|
268 | retrieve_query | |
269 | render :action => 'list_issues' and return unless @query.valid? |
|
269 | render :action => 'list_issues' and return unless @query.valid? | |
270 |
|
270 | |||
271 | @issues = Issue.find :all, :order => sort_clause, |
|
271 | @issues = Issue.find :all, :order => sort_clause, | |
272 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], |
|
272 | :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ], | |
273 | :conditions => @query.statement, |
|
273 | :conditions => @query.statement, | |
274 | :limit => Setting.issues_export_limit.to_i |
|
274 | :limit => Setting.issues_export_limit.to_i | |
275 |
|
275 | |||
276 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
276 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
277 | export = StringIO.new |
|
277 | export = StringIO.new | |
278 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
278 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
279 | # csv header fields |
|
279 | # csv header fields | |
280 | headers = [ "#", l(:field_status), |
|
280 | headers = [ "#", l(:field_status), | |
281 | l(:field_project), |
|
281 | l(:field_project), | |
282 | l(:field_tracker), |
|
282 | l(:field_tracker), | |
283 | l(:field_priority), |
|
283 | l(:field_priority), | |
284 | l(:field_subject), |
|
284 | l(:field_subject), | |
285 | l(:field_assigned_to), |
|
285 | l(:field_assigned_to), | |
286 | l(:field_author), |
|
286 | l(:field_author), | |
287 | l(:field_start_date), |
|
287 | l(:field_start_date), | |
288 | l(:field_due_date), |
|
288 | l(:field_due_date), | |
289 | l(:field_done_ratio), |
|
289 | l(:field_done_ratio), | |
290 | l(:field_created_on), |
|
290 | l(:field_created_on), | |
291 | l(:field_updated_on) |
|
291 | l(:field_updated_on) | |
292 | ] |
|
292 | ] | |
293 | for custom_field in @project.all_custom_fields |
|
293 | for custom_field in @project.all_custom_fields | |
294 | headers << custom_field.name |
|
294 | headers << custom_field.name | |
295 | end |
|
295 | end | |
296 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
296 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
297 | # csv lines |
|
297 | # csv lines | |
298 | @issues.each do |issue| |
|
298 | @issues.each do |issue| | |
299 | fields = [issue.id, issue.status.name, |
|
299 | fields = [issue.id, issue.status.name, | |
300 | issue.project.name, |
|
300 | issue.project.name, | |
301 | issue.tracker.name, |
|
301 | issue.tracker.name, | |
302 | issue.priority.name, |
|
302 | issue.priority.name, | |
303 | issue.subject, |
|
303 | issue.subject, | |
304 | (issue.assigned_to ? issue.assigned_to.name : ""), |
|
304 | (issue.assigned_to ? issue.assigned_to.name : ""), | |
305 | issue.author.name, |
|
305 | issue.author.name, | |
306 | issue.start_date ? l_date(issue.start_date) : nil, |
|
306 | issue.start_date ? l_date(issue.start_date) : nil, | |
307 | issue.due_date ? l_date(issue.due_date) : nil, |
|
307 | issue.due_date ? l_date(issue.due_date) : nil, | |
308 | issue.done_ratio, |
|
308 | issue.done_ratio, | |
309 | l_datetime(issue.created_on), |
|
309 | l_datetime(issue.created_on), | |
310 | l_datetime(issue.updated_on) |
|
310 | l_datetime(issue.updated_on) | |
311 | ] |
|
311 | ] | |
312 | for custom_field in @project.all_custom_fields |
|
312 | for custom_field in @project.all_custom_fields | |
313 | fields << (show_value issue.custom_value_for(custom_field)) |
|
313 | fields << (show_value issue.custom_value_for(custom_field)) | |
314 | end |
|
314 | end | |
315 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
315 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } | |
316 | end |
|
316 | end | |
317 | end |
|
317 | end | |
318 | export.rewind |
|
318 | export.rewind | |
319 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
319 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | # Export filtered/sorted issues to PDF |
|
322 | # Export filtered/sorted issues to PDF | |
323 | def export_issues_pdf |
|
323 | def export_issues_pdf | |
324 | sort_init "#{Issue.table_name}.id", "desc" |
|
324 | sort_init "#{Issue.table_name}.id", "desc" | |
325 | sort_update |
|
325 | sort_update | |
326 |
|
326 | |||
327 | retrieve_query |
|
327 | retrieve_query | |
328 | render :action => 'list_issues' and return unless @query.valid? |
|
328 | render :action => 'list_issues' and return unless @query.valid? | |
329 |
|
329 | |||
330 | @issues = Issue.find :all, :order => sort_clause, |
|
330 | @issues = Issue.find :all, :order => sort_clause, | |
331 | :include => [ :author, :status, :tracker, :priority, :project ], |
|
331 | :include => [ :author, :status, :tracker, :priority, :project ], | |
332 | :conditions => @query.statement, |
|
332 | :conditions => @query.statement, | |
333 | :limit => Setting.issues_export_limit.to_i |
|
333 | :limit => Setting.issues_export_limit.to_i | |
334 |
|
334 | |||
335 | @options_for_rfpdf ||= {} |
|
335 | @options_for_rfpdf ||= {} | |
336 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
336 | @options_for_rfpdf[:file_name] = "export.pdf" | |
337 | render :layout => false |
|
337 | render :layout => false | |
338 | end |
|
338 | end | |
339 |
|
339 | |||
340 | # Bulk edit issues |
|
340 | # Bulk edit issues | |
341 | def bulk_edit_issues |
|
341 | def bulk_edit_issues | |
342 | if request.post? |
|
342 | if request.post? | |
343 | priority = Enumeration.find_by_id(params[:priority_id]) |
|
343 | priority = Enumeration.find_by_id(params[:priority_id]) | |
344 | assigned_to = User.find_by_id(params[:assigned_to_id]) |
|
344 | assigned_to = User.find_by_id(params[:assigned_to_id]) | |
345 | category = @project.issue_categories.find_by_id(params[:category_id]) |
|
345 | category = @project.issue_categories.find_by_id(params[:category_id]) | |
346 | fixed_version = @project.versions.find_by_id(params[:fixed_version_id]) |
|
346 | fixed_version = @project.versions.find_by_id(params[:fixed_version_id]) | |
347 | issues = @project.issues.find_all_by_id(params[:issue_ids]) |
|
347 | issues = @project.issues.find_all_by_id(params[:issue_ids]) | |
348 | unsaved_issue_ids = [] |
|
348 | unsaved_issue_ids = [] | |
349 | issues.each do |issue| |
|
349 | issues.each do |issue| | |
350 | journal = issue.init_journal(User.current, params[:notes]) |
|
350 | journal = issue.init_journal(User.current, params[:notes]) | |
351 | issue.priority = priority if priority |
|
351 | issue.priority = priority if priority | |
352 | issue.assigned_to = assigned_to if assigned_to |
|
352 | issue.assigned_to = assigned_to if assigned_to | |
353 | issue.category = category if category |
|
353 | issue.category = category if category | |
354 | issue.fixed_version = fixed_version if fixed_version |
|
354 | issue.fixed_version = fixed_version if fixed_version | |
355 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
355 | issue.start_date = params[:start_date] unless params[:start_date].blank? | |
356 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
356 | issue.due_date = params[:due_date] unless params[:due_date].blank? | |
357 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
357 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? | |
358 | if issue.save |
|
358 | if issue.save | |
359 | # Send notification for each issue (if changed) |
|
359 | # Send notification for each issue (if changed) | |
360 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') |
|
360 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') | |
361 | else |
|
361 | else | |
362 | unsaved_issue_ids << issue.id |
|
362 | unsaved_issue_ids << issue.id | |
363 | end |
|
363 | end | |
364 | end |
|
364 | end | |
365 | if unsaved_issue_ids.empty? |
|
365 | if unsaved_issue_ids.empty? | |
366 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
366 | flash[:notice] = l(:notice_successful_update) unless issues.empty? | |
367 | else |
|
367 | else | |
368 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
368 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) | |
369 | end |
|
369 | end | |
370 | redirect_to :action => 'list_issues', :id => @project |
|
370 | redirect_to :action => 'list_issues', :id => @project | |
371 | return |
|
371 | return | |
372 | end |
|
372 | end | |
373 | render :update do |page| |
|
373 | render :update do |page| | |
374 | page.hide 'query_form' |
|
374 | page.hide 'query_form' | |
375 | page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form' |
|
375 | page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form' | |
376 | end |
|
376 | end | |
377 | end |
|
377 | end | |
378 |
|
378 | |||
379 | def move_issues |
|
379 | def move_issues | |
380 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
380 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
381 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
381 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
382 | @projects = [] |
|
382 | @projects = [] | |
383 | # find projects to which the user is allowed to move the issue |
|
383 | # find projects to which the user is allowed to move the issue | |
384 | User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')} |
|
384 | User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')} | |
385 | # issue can be moved to any tracker |
|
385 | # issue can be moved to any tracker | |
386 | @trackers = Tracker.find(:all) |
|
386 | @trackers = Tracker.find(:all) | |
387 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
387 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
388 | new_project = Project.find_by_id(params[:new_project_id]) |
|
388 | new_project = Project.find_by_id(params[:new_project_id]) | |
389 | new_tracker = Tracker.find_by_id(params[:new_tracker_id]) |
|
389 | new_tracker = Tracker.find_by_id(params[:new_tracker_id]) | |
390 | @issues.each do |i| |
|
390 | @issues.each do |i| | |
391 | if new_project && i.project_id != new_project.id |
|
391 | if new_project && i.project_id != new_project.id | |
392 | # issue is moved to another project |
|
392 | # issue is moved to another project | |
393 | i.category = nil |
|
393 | i.category = nil | |
394 | i.fixed_version = nil |
|
394 | i.fixed_version = nil | |
395 | # delete issue relations |
|
395 | # delete issue relations | |
396 | i.relations_from.clear |
|
396 | i.relations_from.clear | |
397 | i.relations_to.clear |
|
397 | i.relations_to.clear | |
398 | i.project = new_project |
|
398 | i.project = new_project | |
399 | end |
|
399 | end | |
400 | if new_tracker |
|
400 | if new_tracker | |
401 | i.tracker = new_tracker |
|
401 | i.tracker = new_tracker | |
402 | end |
|
402 | end | |
403 | i.save |
|
403 | i.save | |
404 | end |
|
404 | end | |
405 | flash[:notice] = l(:notice_successful_update) |
|
405 | flash[:notice] = l(:notice_successful_update) | |
406 | redirect_to :action => 'list_issues', :id => @project |
|
406 | redirect_to :action => 'list_issues', :id => @project | |
407 | end |
|
407 | end | |
408 | end |
|
408 | end | |
409 |
|
409 | |||
410 | # Add a news to @project |
|
410 | # Add a news to @project | |
411 | def add_news |
|
411 | def add_news | |
412 | @news = News.new(:project => @project) |
|
412 | @news = News.new(:project => @project) | |
413 | if request.post? |
|
413 | if request.post? | |
414 | @news.attributes = params[:news] |
|
414 | @news.attributes = params[:news] | |
415 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
415 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
416 | if @news.save |
|
416 | if @news.save | |
417 | flash[:notice] = l(:notice_successful_create) |
|
417 | flash[:notice] = l(:notice_successful_create) | |
418 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
418 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') | |
419 | redirect_to :action => 'list_news', :id => @project |
|
419 | redirect_to :action => 'list_news', :id => @project | |
420 | end |
|
420 | end | |
421 | end |
|
421 | end | |
422 | end |
|
422 | end | |
423 |
|
423 | |||
424 | # Show news list of @project |
|
424 | # Show news list of @project | |
425 | def list_news |
|
425 | def list_news | |
426 | @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
426 | @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" | |
427 |
|
427 | |||
428 | respond_to do |format| |
|
428 | respond_to do |format| | |
429 | format.html { render :layout => false if request.xhr? } |
|
429 | format.html { render :layout => false if request.xhr? } | |
430 | format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") } |
|
430 | format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") } | |
431 | end |
|
431 | end | |
432 | end |
|
432 | end | |
433 |
|
433 | |||
434 | def add_file |
|
434 | def add_file | |
435 | if request.post? |
|
435 | if request.post? | |
436 | @version = @project.versions.find_by_id(params[:version_id]) |
|
436 | @version = @project.versions.find_by_id(params[:version_id]) | |
437 | # Save the attachments |
|
437 | # Save the attachments | |
438 | @attachments = [] |
|
438 | @attachments = [] | |
439 | params[:attachments].each { |file| |
|
439 | params[:attachments].each { |file| | |
440 | next unless file.size > 0 |
|
440 | next unless file.size > 0 | |
441 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
441 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) | |
442 | @attachments << a unless a.new_record? |
|
442 | @attachments << a unless a.new_record? | |
443 | } if params[:attachments] and params[:attachments].is_a? Array |
|
443 | } if params[:attachments] and params[:attachments].is_a? Array | |
444 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added') |
|
444 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added') | |
445 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
445 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
446 | end |
|
446 | end | |
447 | @versions = @project.versions.sort |
|
447 | @versions = @project.versions.sort | |
448 | end |
|
448 | end | |
449 |
|
449 | |||
450 | def list_files |
|
450 | def list_files | |
451 | @versions = @project.versions.sort |
|
451 | @versions = @project.versions.sort | |
452 | end |
|
452 | end | |
453 |
|
453 | |||
454 | # Show changelog for @project |
|
454 | # Show changelog for @project | |
455 | def changelog |
|
455 | def changelog | |
456 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
456 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
457 | retrieve_selected_tracker_ids(@trackers) |
|
457 | retrieve_selected_tracker_ids(@trackers) | |
458 | @versions = @project.versions.sort |
|
458 | @versions = @project.versions.sort | |
459 | end |
|
459 | end | |
460 |
|
460 | |||
461 | def roadmap |
|
461 | def roadmap | |
462 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
462 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') | |
463 | retrieve_selected_tracker_ids(@trackers) |
|
463 | retrieve_selected_tracker_ids(@trackers) | |
464 | @versions = @project.versions.sort |
|
464 | @versions = @project.versions.sort | |
465 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
465 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] | |
466 | end |
|
466 | end | |
467 |
|
467 | |||
468 | def activity |
|
468 | def activity | |
469 | if params[:year] and params[:year].to_i > 1900 |
|
469 | if params[:year] and params[:year].to_i > 1900 | |
470 | @year = params[:year].to_i |
|
470 | @year = params[:year].to_i | |
471 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
471 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
472 | @month = params[:month].to_i |
|
472 | @month = params[:month].to_i | |
473 | end |
|
473 | end | |
474 | end |
|
474 | end | |
475 | @year ||= Date.today.year |
|
475 | @year ||= Date.today.year | |
476 | @month ||= Date.today.month |
|
476 | @month ||= Date.today.month | |
477 |
|
477 | |||
478 | case params[:format] |
|
478 | case params[:format] | |
479 | when 'atom' |
|
479 | when 'atom' | |
480 | # 30 last days |
|
480 | # 30 last days | |
481 | @date_from = Date.today - 30 |
|
481 | @date_from = Date.today - 30 | |
482 | @date_to = Date.today + 1 |
|
482 | @date_to = Date.today + 1 | |
483 | else |
|
483 | else | |
484 | # current month |
|
484 | # current month | |
485 | @date_from = Date.civil(@year, @month, 1) |
|
485 | @date_from = Date.civil(@year, @month, 1) | |
486 | @date_to = @date_from >> 1 |
|
486 | @date_to = @date_from >> 1 | |
487 | end |
|
487 | end | |
488 |
|
488 | |||
489 | @event_types = %w(issues news files documents wiki_pages changesets) |
|
489 | @event_types = %w(issues news files documents wiki_pages changesets) | |
490 | @event_types.delete('wiki_pages') unless @project.wiki |
|
490 | @event_types.delete('wiki_pages') unless @project.wiki | |
491 | @event_types.delete('changesets') unless @project.repository |
|
491 | @event_types.delete('changesets') unless @project.repository | |
492 | # only show what the user is allowed to view |
|
492 | # only show what the user is allowed to view | |
493 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} |
|
493 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} | |
494 |
|
494 | |||
495 | @scope = @event_types.select {|t| params["show_#{t}"]} |
|
495 | @scope = @event_types.select {|t| params["show_#{t}"]} | |
496 | # default events if none is specified in parameters |
|
496 | # default events if none is specified in parameters | |
497 | @scope = (@event_types - %w(wiki_pages))if @scope.empty? |
|
497 | @scope = (@event_types - %w(wiki_pages))if @scope.empty? | |
498 |
|
498 | |||
499 | @events = [] |
|
499 | @events = [] | |
500 |
|
500 | |||
501 | if @scope.include?('issues') |
|
501 | if @scope.include?('issues') | |
502 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) |
|
502 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) | |
503 | end |
|
503 | end | |
504 |
|
504 | |||
505 | if @scope.include?('news') |
|
505 | if @scope.include?('news') | |
506 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) |
|
506 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) | |
507 | end |
|
507 | end | |
508 |
|
508 | |||
509 | if @scope.include?('files') |
|
509 | if @scope.include?('files') | |
510 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
510 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
511 | end |
|
511 | end | |
512 |
|
512 | |||
513 | if @scope.include?('documents') |
|
513 | if @scope.include?('documents') | |
514 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) |
|
514 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) | |
515 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
515 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
516 | end |
|
516 | end | |
517 |
|
517 | |||
518 | if @scope.include?('wiki_pages') |
|
518 | if @scope.include?('wiki_pages') | |
519 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
519 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
520 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
520 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + | |
521 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
521 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + | |
522 | "#{WikiContent.versioned_table_name}.id" |
|
522 | "#{WikiContent.versioned_table_name}.id" | |
523 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
523 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
524 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
524 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
525 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
525 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
526 | @project.id, @date_from, @date_to] |
|
526 | @project.id, @date_from, @date_to] | |
527 |
|
527 | |||
528 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) |
|
528 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) | |
529 | end |
|
529 | end | |
530 |
|
530 | |||
531 | if @scope.include?('changesets') |
|
531 | if @scope.include?('changesets') | |
532 | @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]) |
|
532 | @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]) | |
533 | end |
|
533 | end | |
534 |
|
534 | |||
535 | @events_by_day = @events.group_by(&:event_date) |
|
535 | @events_by_day = @events.group_by(&:event_date) | |
536 |
|
536 | |||
537 | respond_to do |format| |
|
537 | respond_to do |format| | |
538 | format.html { render :layout => false if request.xhr? } |
|
538 | format.html { render :layout => false if request.xhr? } | |
539 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } |
|
539 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } | |
540 | end |
|
540 | end | |
541 | end |
|
541 | end | |
542 |
|
542 | |||
543 | def calendar |
|
543 | def calendar | |
544 | @trackers = Tracker.find(:all, :order => 'position') |
|
544 | @trackers = Tracker.find(:all, :order => 'position') | |
545 | retrieve_selected_tracker_ids(@trackers) |
|
545 | retrieve_selected_tracker_ids(@trackers) | |
546 |
|
546 | |||
547 | if params[:year] and params[:year].to_i > 1900 |
|
547 | if params[:year] and params[:year].to_i > 1900 | |
548 | @year = params[:year].to_i |
|
548 | @year = params[:year].to_i | |
549 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
549 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
550 | @month = params[:month].to_i |
|
550 | @month = params[:month].to_i | |
551 | end |
|
551 | end | |
552 | end |
|
552 | end | |
553 | @year ||= Date.today.year |
|
553 | @year ||= Date.today.year | |
554 | @month ||= Date.today.month |
|
554 | @month ||= Date.today.month | |
555 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
555 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
556 |
|
556 | |||
557 | events = [] |
|
557 | events = [] | |
558 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
558 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
559 | events += Issue.find(:all, |
|
559 | events += Issue.find(:all, | |
560 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
560 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
561 | :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] |
|
561 | :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] | |
562 | ) unless @selected_tracker_ids.empty? |
|
562 | ) unless @selected_tracker_ids.empty? | |
563 | end |
|
563 | end | |
564 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
564 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
565 | @calendar.events = events |
|
565 | @calendar.events = events | |
566 |
|
566 | |||
567 | render :layout => false if request.xhr? |
|
567 | render :layout => false if request.xhr? | |
568 | end |
|
568 | end | |
569 |
|
569 | |||
570 | def gantt |
|
570 | def gantt | |
571 | @trackers = Tracker.find(:all, :order => 'position') |
|
571 | @trackers = Tracker.find(:all, :order => 'position') | |
572 | retrieve_selected_tracker_ids(@trackers) |
|
572 | retrieve_selected_tracker_ids(@trackers) | |
573 |
|
573 | |||
574 | if params[:year] and params[:year].to_i >0 |
|
574 | if params[:year] and params[:year].to_i >0 | |
575 | @year_from = params[:year].to_i |
|
575 | @year_from = params[:year].to_i | |
576 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
576 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
577 | @month_from = params[:month].to_i |
|
577 | @month_from = params[:month].to_i | |
578 | else |
|
578 | else | |
579 | @month_from = 1 |
|
579 | @month_from = 1 | |
580 | end |
|
580 | end | |
581 | else |
|
581 | else | |
582 |
@month_from ||= |
|
582 | @month_from ||= Date.today.month | |
583 |
@year_from ||= |
|
583 | @year_from ||= Date.today.year | |
584 | end |
|
584 | end | |
585 |
|
585 | |||
586 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
586 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i | |
587 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
587 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 | |
|
588 | months = (params[:months] || User.current.pref[:gantt_months]).to_i | |||
|
589 | @months = (months > 0 && months < 25) ? months : 6 | |||
|
590 | ||||
|
591 | # Save gantt paramters as user preference (zoom and months count) | |||
|
592 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) | |||
|
593 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months | |||
|
594 | User.current.preference.save | |||
|
595 | end | |||
588 |
|
596 | |||
589 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
597 | @date_from = Date.civil(@year_from, @month_from, 1) | |
590 | @date_to = (@date_from >> @months) - 1 |
|
598 | @date_to = (@date_from >> @months) - 1 | |
591 |
|
599 | |||
592 | @events = [] |
|
600 | @events = [] | |
593 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
601 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
594 | @events += Issue.find(:all, |
|
602 | @events += Issue.find(:all, | |
595 | :order => "start_date, due_date", |
|
603 | :order => "start_date, due_date", | |
596 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
604 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
597 | :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] |
|
605 | :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] | |
598 | ) unless @selected_tracker_ids.empty? |
|
606 | ) unless @selected_tracker_ids.empty? | |
599 | end |
|
607 | end | |
600 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
608 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
601 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
609 | @events.sort! {|x,y| x.start_date <=> y.start_date } | |
602 |
|
610 | |||
603 | if params[:format]=='pdf' |
|
611 | if params[:format]=='pdf' | |
604 | @options_for_rfpdf ||= {} |
|
612 | @options_for_rfpdf ||= {} | |
605 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
613 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" | |
606 | render :template => "projects/gantt.rfpdf", :layout => false |
|
614 | render :template => "projects/gantt.rfpdf", :layout => false | |
607 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
615 | elsif params[:format]=='png' && respond_to?('gantt_image') | |
608 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
616 | image = gantt_image(@events, @date_from, @months, @zoom) | |
609 | image.format = 'PNG' |
|
617 | image.format = 'PNG' | |
610 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
618 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") | |
611 | else |
|
619 | else | |
612 | render :template => "projects/gantt.rhtml" |
|
620 | render :template => "projects/gantt.rhtml" | |
613 | end |
|
621 | end | |
614 | end |
|
622 | end | |
615 |
|
623 | |||
616 | private |
|
624 | private | |
617 | # Find project of id params[:id] |
|
625 | # Find project of id params[:id] | |
618 | # if not found, redirect to project list |
|
626 | # if not found, redirect to project list | |
619 | # Used as a before_filter |
|
627 | # Used as a before_filter | |
620 | def find_project |
|
628 | def find_project | |
621 | @project = Project.find(params[:id]) |
|
629 | @project = Project.find(params[:id]) | |
622 | rescue ActiveRecord::RecordNotFound |
|
630 | rescue ActiveRecord::RecordNotFound | |
623 | render_404 |
|
631 | render_404 | |
624 | end |
|
632 | end | |
625 |
|
633 | |||
626 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
634 | def retrieve_selected_tracker_ids(selectable_trackers) | |
627 | if ids = params[:tracker_ids] |
|
635 | if ids = params[:tracker_ids] | |
628 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
636 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
629 | else |
|
637 | else | |
630 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
638 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
631 | end |
|
639 | end | |
632 | end |
|
640 | end | |
633 |
|
641 | |||
634 | # Retrieve query from session or build a new query |
|
642 | # Retrieve query from session or build a new query | |
635 | def retrieve_query |
|
643 | def retrieve_query | |
636 | if params[:query_id] |
|
644 | if params[:query_id] | |
637 | @query = @project.queries.find(params[:query_id]) |
|
645 | @query = @project.queries.find(params[:query_id]) | |
638 | @query.executed_by = logged_in_user |
|
646 | @query.executed_by = logged_in_user | |
639 | session[:query] = @query |
|
647 | session[:query] = @query | |
640 | else |
|
648 | else | |
641 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id |
|
649 | if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id | |
642 | # Give it a name, required to be valid |
|
650 | # Give it a name, required to be valid | |
643 | @query = Query.new(:name => "_", :executed_by => logged_in_user) |
|
651 | @query = Query.new(:name => "_", :executed_by => logged_in_user) | |
644 | @query.project = @project |
|
652 | @query.project = @project | |
645 | if params[:fields] and params[:fields].is_a? Array |
|
653 | if params[:fields] and params[:fields].is_a? Array | |
646 | params[:fields].each do |field| |
|
654 | params[:fields].each do |field| | |
647 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
655 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
648 | end |
|
656 | end | |
649 | else |
|
657 | else | |
650 | @query.available_filters.keys.each do |field| |
|
658 | @query.available_filters.keys.each do |field| | |
651 | @query.add_short_filter(field, params[field]) if params[field] |
|
659 | @query.add_short_filter(field, params[field]) if params[field] | |
652 | end |
|
660 | end | |
653 | end |
|
661 | end | |
654 | session[:query] = @query |
|
662 | session[:query] = @query | |
655 | else |
|
663 | else | |
656 | @query = session[:query] |
|
664 | @query = session[:query] | |
657 | end |
|
665 | end | |
658 | end |
|
666 | end | |
659 | end |
|
667 | end | |
660 | end |
|
668 | end |
General Comments 0
You need to be logged in to leave comments.
Login now