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