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