@@ -1,673 +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, :authorize, :except => [ :index, :list, :add ] |
|
22 | before_filter :find_project, :authorize, :except => [ :index, :list, :add ] | |
23 | before_filter :require_admin, :only => [ :add, :destroy ] |
|
23 | before_filter :require_admin, :only => [ :add, :destroy ] | |
24 |
|
24 | |||
25 | helper :sort |
|
25 | helper :sort | |
26 | include SortHelper |
|
26 | include SortHelper | |
27 | helper :custom_fields |
|
27 | helper :custom_fields | |
28 | include CustomFieldsHelper |
|
28 | include CustomFieldsHelper | |
29 | helper :ifpdf |
|
29 | helper :ifpdf | |
30 | include IfpdfHelper |
|
30 | include IfpdfHelper | |
31 | helper IssuesHelper |
|
31 | helper IssuesHelper | |
32 | helper :queries |
|
32 | helper :queries | |
33 | include QueriesHelper |
|
33 | include QueriesHelper | |
34 |
|
34 | |||
35 | def index |
|
35 | def index | |
36 | list |
|
36 | list | |
37 | render :action => 'list' unless request.xhr? |
|
37 | render :action => 'list' unless request.xhr? | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | # Lists public projects |
|
40 | # Lists public projects | |
41 | def list |
|
41 | def list | |
42 | sort_init 'name', 'asc' |
|
42 | sort_init 'name', 'asc' | |
43 | sort_update |
|
43 | sort_update | |
44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) |
|
44 | @project_count = Project.count(:all, :conditions => ["is_public=?", true]) | |
45 | @project_pages = Paginator.new self, @project_count, |
|
45 | @project_pages = Paginator.new self, @project_count, | |
46 | 15, |
|
46 | 15, | |
47 | params['page'] |
|
47 | params['page'] | |
48 | @projects = Project.find :all, :order => sort_clause, |
|
48 | @projects = Project.find :all, :order => sort_clause, | |
49 | :conditions => ["is_public=?", true], |
|
49 | :conditions => ["is_public=?", true], | |
50 | :limit => @project_pages.items_per_page, |
|
50 | :limit => @project_pages.items_per_page, | |
51 | :offset => @project_pages.current.offset |
|
51 | :offset => @project_pages.current.offset | |
52 |
|
52 | |||
53 | render :action => "list", :layout => false if request.xhr? |
|
53 | render :action => "list", :layout => false if request.xhr? | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | # Add a new project |
|
56 | # Add a new project | |
57 | def add |
|
57 | def add | |
58 | @custom_fields = IssueCustomField.find(:all) |
|
58 | @custom_fields = IssueCustomField.find(:all) | |
59 | @root_projects = Project.find(:all, :conditions => "parent_id is null") |
|
59 | @root_projects = Project.find(:all, :conditions => "parent_id is null") | |
60 | @project = Project.new(params[:project]) |
|
60 | @project = Project.new(params[:project]) | |
61 | if request.get? |
|
61 | if request.get? | |
62 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
62 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
63 | else |
|
63 | else | |
64 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
64 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
65 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
65 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
66 | @project.custom_values = @custom_values |
|
66 | @project.custom_values = @custom_values | |
67 | if params[:repository_enabled] && params[:repository_enabled] == "1" |
|
67 | if params[:repository_enabled] && params[:repository_enabled] == "1" | |
68 | @project.repository = Repository.new |
|
68 | @project.repository = Repository.new | |
69 | @project.repository.attributes = params[:repository] |
|
69 | @project.repository.attributes = params[:repository] | |
70 | end |
|
70 | end | |
71 | if "1" == params[:wiki_enabled] |
|
71 | if "1" == params[:wiki_enabled] | |
72 | @project.wiki = Wiki.new |
|
72 | @project.wiki = Wiki.new | |
73 | @project.wiki.attributes = params[:wiki] |
|
73 | @project.wiki.attributes = params[:wiki] | |
74 | end |
|
74 | end | |
75 | if @project.save |
|
75 | if @project.save | |
76 | flash[:notice] = l(:notice_successful_create) |
|
76 | flash[:notice] = l(:notice_successful_create) | |
77 | redirect_to :controller => 'admin', :action => 'projects' |
|
77 | redirect_to :controller => 'admin', :action => 'projects' | |
78 | end |
|
78 | end | |
79 | end |
|
79 | end | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | # Show @project |
|
82 | # Show @project | |
83 | def show |
|
83 | def show | |
84 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) |
|
84 | @custom_values = @project.custom_values.find(:all, :include => :custom_field) | |
85 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') |
|
85 | @members = @project.members.find(:all, :include => [:user, :role], :order => 'position') | |
86 | @subprojects = @project.children if @project.children.size > 0 |
|
86 | @subprojects = @project.children if @project.children.size > 0 | |
87 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
87 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") | |
88 | @trackers = Tracker.find(:all, :order => 'position') |
|
88 | @trackers = Tracker.find(:all, :order => 'position') | |
89 | @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]) |
|
89 | @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]) | |
90 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
90 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def settings |
|
93 | def settings | |
94 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) |
|
94 | @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id]) | |
95 | @custom_fields = IssueCustomField.find(:all) |
|
95 | @custom_fields = IssueCustomField.find(:all) | |
96 | @issue_category ||= IssueCategory.new |
|
96 | @issue_category ||= IssueCategory.new | |
97 | @member ||= @project.members.new |
|
97 | @member ||= @project.members.new | |
98 | @roles = Role.find(:all, :order => 'position') |
|
98 | @roles = Role.find(:all, :order => 'position') | |
99 | @users = User.find_active(:all) - @project.users |
|
99 | @users = User.find_active(:all) - @project.users | |
100 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
100 | @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | # Edit @project |
|
103 | # Edit @project | |
104 | def edit |
|
104 | def edit | |
105 | if request.post? |
|
105 | if request.post? | |
106 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
106 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
107 | if params[:custom_fields] |
|
107 | if params[:custom_fields] | |
108 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
108 | @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
109 | @project.custom_values = @custom_values |
|
109 | @project.custom_values = @custom_values | |
110 | end |
|
110 | end | |
111 | if params[:repository_enabled] |
|
111 | if params[:repository_enabled] | |
112 | case params[:repository_enabled] |
|
112 | case params[:repository_enabled] | |
113 | when "0" |
|
113 | when "0" | |
114 | @project.repository = nil |
|
114 | @project.repository = nil | |
115 | when "1" |
|
115 | when "1" | |
116 | @project.repository ||= Repository.new |
|
116 | @project.repository ||= Repository.new | |
117 | @project.repository.update_attributes params[:repository] |
|
117 | @project.repository.update_attributes params[:repository] | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 | if params[:wiki_enabled] |
|
120 | if params[:wiki_enabled] | |
121 | case params[:wiki_enabled] |
|
121 | case params[:wiki_enabled] | |
122 | when "0" |
|
122 | when "0" | |
123 | @project.wiki.destroy if @project.wiki |
|
123 | @project.wiki.destroy if @project.wiki | |
124 | when "1" |
|
124 | when "1" | |
125 | @project.wiki ||= Wiki.new |
|
125 | @project.wiki ||= Wiki.new | |
126 | @project.wiki.update_attributes params[:wiki] |
|
126 | @project.wiki.update_attributes params[:wiki] | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 | @project.attributes = params[:project] |
|
129 | @project.attributes = params[:project] | |
130 | if @project.save |
|
130 | if @project.save | |
131 | flash[:notice] = l(:notice_successful_update) |
|
131 | flash[:notice] = l(:notice_successful_update) | |
132 | redirect_to :action => 'settings', :id => @project |
|
132 | redirect_to :action => 'settings', :id => @project | |
133 | else |
|
133 | else | |
134 | settings |
|
134 | settings | |
135 | render :action => 'settings' |
|
135 | render :action => 'settings' | |
136 | end |
|
136 | end | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | # Delete @project |
|
140 | # Delete @project | |
141 | def destroy |
|
141 | def destroy | |
142 | if request.post? and params[:confirm] |
|
142 | if request.post? and params[:confirm] | |
143 | @project.destroy |
|
143 | @project.destroy | |
144 | redirect_to :controller => 'admin', :action => 'projects' |
|
144 | redirect_to :controller => 'admin', :action => 'projects' | |
145 | end |
|
145 | end | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | # Add a new issue category to @project |
|
148 | # Add a new issue category to @project | |
149 | def add_issue_category |
|
149 | def add_issue_category | |
150 | if request.post? |
|
150 | if request.post? | |
151 | @issue_category = @project.issue_categories.build(params[:issue_category]) |
|
151 | @issue_category = @project.issue_categories.build(params[:issue_category]) | |
152 | if @issue_category.save |
|
152 | if @issue_category.save | |
153 | flash[:notice] = l(:notice_successful_create) |
|
153 | flash[:notice] = l(:notice_successful_create) | |
154 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
154 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
155 | else |
|
155 | else | |
156 | settings |
|
156 | settings | |
157 | render :action => 'settings' |
|
157 | render :action => 'settings' | |
158 | end |
|
158 | end | |
159 | end |
|
159 | end | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | # Add a new version to @project |
|
162 | # Add a new version to @project | |
163 | def add_version |
|
163 | def add_version | |
164 | @version = @project.versions.build(params[:version]) |
|
164 | @version = @project.versions.build(params[:version]) | |
165 | if request.post? and @version.save |
|
165 | if request.post? and @version.save | |
166 | flash[:notice] = l(:notice_successful_create) |
|
166 | flash[:notice] = l(:notice_successful_create) | |
167 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
167 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
168 | end |
|
168 | end | |
169 | end |
|
169 | end | |
170 |
|
170 | |||
171 | # Add a new member to @project |
|
171 | # Add a new member to @project | |
172 | def add_member |
|
172 | def add_member | |
173 | @member = @project.members.build(params[:member]) |
|
173 | @member = @project.members.build(params[:member]) | |
174 | if request.post? |
|
174 | if request.post? | |
175 | if @member.save |
|
175 | if @member.save | |
176 | flash[:notice] = l(:notice_successful_create) |
|
176 | flash[:notice] = l(:notice_successful_create) | |
177 | redirect_to :action => 'settings', :tab => 'members', :id => @project |
|
177 | redirect_to :action => 'settings', :tab => 'members', :id => @project | |
178 | else |
|
178 | else | |
179 | settings |
|
179 | settings | |
180 | render :action => 'settings' |
|
180 | render :action => 'settings' | |
181 | end |
|
181 | end | |
182 | end |
|
182 | end | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | # Show members list of @project |
|
185 | # Show members list of @project | |
186 | def list_members |
|
186 | def list_members | |
187 | @members = @project.members.find(:all) |
|
187 | @members = @project.members.find(:all) | |
188 | end |
|
188 | end | |
189 |
|
189 | |||
190 | # Add a new document to @project |
|
190 | # Add a new document to @project | |
191 | def add_document |
|
191 | def add_document | |
192 | @categories = Enumeration::get_values('DCAT') |
|
192 | @categories = Enumeration::get_values('DCAT') | |
193 | @document = @project.documents.build(params[:document]) |
|
193 | @document = @project.documents.build(params[:document]) | |
194 | if request.post? and @document.save |
|
194 | if request.post? and @document.save | |
195 | # Save the attachments |
|
195 | # Save the attachments | |
196 | params[:attachments].each { |a| |
|
196 | params[:attachments].each { |a| | |
197 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 |
|
197 | Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0 | |
198 | } if params[:attachments] and params[:attachments].is_a? Array |
|
198 | } if params[:attachments] and params[:attachments].is_a? Array | |
199 | flash[:notice] = l(:notice_successful_create) |
|
199 | flash[:notice] = l(:notice_successful_create) | |
200 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
200 | Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
201 | redirect_to :action => 'list_documents', :id => @project |
|
201 | redirect_to :action => 'list_documents', :id => @project | |
202 | end |
|
202 | end | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | # Show documents list of @project |
|
205 | # Show documents list of @project | |
206 | def list_documents |
|
206 | def list_documents | |
207 | @documents = @project.documents.find :all, :include => :category |
|
207 | @documents = @project.documents.find :all, :include => :category | |
208 | end |
|
208 | end | |
209 |
|
209 | |||
210 | # Add a new issue to @project |
|
210 | # Add a new issue to @project | |
211 | def add_issue |
|
211 | def add_issue | |
212 | @tracker = Tracker.find(params[:tracker_id]) |
|
212 | @tracker = Tracker.find(params[:tracker_id]) | |
213 | @priorities = Enumeration::get_values('IPRI') |
|
213 | @priorities = Enumeration::get_values('IPRI') | |
214 | @issue = Issue.new(:project => @project, :tracker => @tracker) |
|
214 | @issue = Issue.new(:project => @project, :tracker => @tracker) | |
215 | if request.get? |
|
215 | if request.get? | |
216 | @issue.start_date = Date.today |
|
216 | @issue.start_date = Date.today | |
217 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } |
|
217 | @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } | |
218 | else |
|
218 | else | |
219 | @issue.attributes = params[:issue] |
|
219 | @issue.attributes = params[:issue] | |
220 | @issue.author_id = self.logged_in_user.id if self.logged_in_user |
|
220 | @issue.author_id = self.logged_in_user.id if self.logged_in_user | |
221 | # Multiple file upload |
|
221 | # Multiple file upload | |
222 | @attachments = [] |
|
222 | @attachments = [] | |
223 | params[:attachments].each { |a| |
|
223 | params[:attachments].each { |a| | |
224 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 |
|
224 | @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0 | |
225 | } if params[:attachments] and params[:attachments].is_a? Array |
|
225 | } if params[:attachments] and params[:attachments].is_a? Array | |
226 | @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]) } |
|
226 | @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]) } | |
227 | @issue.custom_values = @custom_values |
|
227 | @issue.custom_values = @custom_values | |
228 | if @issue.save |
|
228 | if @issue.save | |
229 | @attachments.each(&:save) |
|
229 | @attachments.each(&:save) | |
230 | flash[:notice] = l(:notice_successful_create) |
|
230 | flash[:notice] = l(:notice_successful_create) | |
231 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
231 | Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
232 | redirect_to :action => 'list_issues', :id => @project |
|
232 | redirect_to :action => 'list_issues', :id => @project | |
233 | end |
|
233 | end | |
234 | end |
|
234 | end | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | # Show filtered/sorted issues list of @project |
|
237 | # Show filtered/sorted issues list of @project | |
238 | def list_issues |
|
238 | def list_issues | |
239 | sort_init "#{Issue.table_name}.id", "desc" |
|
239 | sort_init "#{Issue.table_name}.id", "desc" | |
240 | sort_update |
|
240 | sort_update | |
241 |
|
241 | |||
242 | retrieve_query |
|
242 | retrieve_query | |
243 |
|
243 | |||
244 | @results_per_page_options = [ 15, 25, 50, 100 ] |
|
244 | @results_per_page_options = [ 15, 25, 50, 100 ] | |
245 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i |
|
245 | if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i | |
246 | @results_per_page = params[:per_page].to_i |
|
246 | @results_per_page = params[:per_page].to_i | |
247 | session[:results_per_page] = @results_per_page |
|
247 | session[:results_per_page] = @results_per_page | |
248 | else |
|
248 | else | |
249 | @results_per_page = session[:results_per_page] || 25 |
|
249 | @results_per_page = session[:results_per_page] || 25 | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | if @query.valid? |
|
252 | if @query.valid? | |
253 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) |
|
253 | @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement) | |
254 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] |
|
254 | @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page'] | |
255 | @issues = Issue.find :all, :order => sort_clause, |
|
255 | @issues = Issue.find :all, :order => sort_clause, | |
256 | :include => [ :author, :status, :tracker, :project, :priority ], |
|
256 | :include => [ :author, :status, :tracker, :project, :priority ], | |
257 | :conditions => @query.statement, |
|
257 | :conditions => @query.statement, | |
258 | :limit => @issue_pages.items_per_page, |
|
258 | :limit => @issue_pages.items_per_page, | |
259 | :offset => @issue_pages.current.offset |
|
259 | :offset => @issue_pages.current.offset | |
260 | end |
|
260 | end | |
261 | @trackers = Tracker.find :all, :order => 'position' |
|
261 | @trackers = Tracker.find :all, :order => 'position' | |
262 | render :layout => false if request.xhr? |
|
262 | render :layout => false if request.xhr? | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | # Export filtered/sorted issues list to CSV |
|
265 | # Export filtered/sorted issues list to CSV | |
266 | def export_issues_csv |
|
266 | def export_issues_csv | |
267 | sort_init "#{Issue.table_name}.id", "desc" |
|
267 | sort_init "#{Issue.table_name}.id", "desc" | |
268 | sort_update |
|
268 | sort_update | |
269 |
|
269 | |||
270 | retrieve_query |
|
270 | retrieve_query | |
271 | render :action => 'list_issues' and return unless @query.valid? |
|
271 | render :action => 'list_issues' and return unless @query.valid? | |
272 |
|
272 | |||
273 | @issues = Issue.find :all, :order => sort_clause, |
|
273 | @issues = Issue.find :all, :order => sort_clause, | |
274 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], |
|
274 | :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ], | |
275 | :conditions => @query.statement, |
|
275 | :conditions => @query.statement, | |
276 | :limit => Setting.issues_export_limit |
|
276 | :limit => Setting.issues_export_limit | |
277 |
|
277 | |||
278 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
278 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') | |
279 | export = StringIO.new |
|
279 | export = StringIO.new | |
280 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| |
|
280 | CSV::Writer.generate(export, l(:general_csv_separator)) do |csv| | |
281 | # csv header fields |
|
281 | # csv header fields | |
282 | headers = [ "#", l(:field_status), |
|
282 | headers = [ "#", l(:field_status), | |
283 | l(:field_tracker), |
|
283 | l(:field_tracker), | |
284 | l(:field_priority), |
|
284 | l(:field_priority), | |
285 | l(:field_subject), |
|
285 | l(:field_subject), | |
286 | l(:field_author), |
|
286 | l(:field_author), | |
287 | l(:field_start_date), |
|
287 | l(:field_start_date), | |
288 | l(:field_due_date), |
|
288 | l(:field_due_date), | |
289 | l(:field_done_ratio), |
|
289 | l(:field_done_ratio), | |
290 | l(:field_created_on), |
|
290 | l(:field_created_on), | |
291 | l(:field_updated_on) |
|
291 | l(:field_updated_on) | |
292 | ] |
|
292 | ] | |
293 | for custom_field in @project.all_custom_fields |
|
293 | for custom_field in @project.all_custom_fields | |
294 | headers << custom_field.name |
|
294 | headers << custom_field.name | |
295 | end |
|
295 | end | |
296 | csv << headers.collect {|c| ic.iconv(c) } |
|
296 | csv << headers.collect {|c| ic.iconv(c) } | |
297 | # csv lines |
|
297 | # csv lines | |
298 | @issues.each do |issue| |
|
298 | @issues.each do |issue| | |
299 | fields = [issue.id, issue.status.name, |
|
299 | fields = [issue.id, issue.status.name, | |
300 | issue.tracker.name, |
|
300 | issue.tracker.name, | |
301 | issue.priority.name, |
|
301 | issue.priority.name, | |
302 | issue.subject, |
|
302 | issue.subject, | |
303 | issue.author.display_name, |
|
303 | issue.author.display_name, | |
304 | issue.start_date ? l_date(issue.start_date) : nil, |
|
304 | issue.start_date ? l_date(issue.start_date) : nil, | |
305 | issue.due_date ? l_date(issue.due_date) : nil, |
|
305 | issue.due_date ? l_date(issue.due_date) : nil, | |
306 | issue.done_ratio, |
|
306 | issue.done_ratio, | |
307 | l_datetime(issue.created_on), |
|
307 | l_datetime(issue.created_on), | |
308 | l_datetime(issue.updated_on) |
|
308 | l_datetime(issue.updated_on) | |
309 | ] |
|
309 | ] | |
310 | for custom_field in @project.all_custom_fields |
|
310 | for custom_field in @project.all_custom_fields | |
311 | fields << (show_value issue.custom_value_for(custom_field)) |
|
311 | fields << (show_value issue.custom_value_for(custom_field)) | |
312 | end |
|
312 | end | |
313 | csv << fields.collect {|c| ic.iconv(c.to_s) } |
|
313 | csv << fields.collect {|c| ic.iconv(c.to_s) } | |
314 | end |
|
314 | end | |
315 | end |
|
315 | end | |
316 | export.rewind |
|
316 | export.rewind | |
317 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') |
|
317 | send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv') | |
318 | end |
|
318 | end | |
319 |
|
319 | |||
320 | # Export filtered/sorted issues to PDF |
|
320 | # Export filtered/sorted issues to PDF | |
321 | def export_issues_pdf |
|
321 | def export_issues_pdf | |
322 | sort_init "#{Issue.table_name}.id", "desc" |
|
322 | sort_init "#{Issue.table_name}.id", "desc" | |
323 | sort_update |
|
323 | sort_update | |
324 |
|
324 | |||
325 | retrieve_query |
|
325 | retrieve_query | |
326 | render :action => 'list_issues' and return unless @query.valid? |
|
326 | render :action => 'list_issues' and return unless @query.valid? | |
327 |
|
327 | |||
328 | @issues = Issue.find :all, :order => sort_clause, |
|
328 | @issues = Issue.find :all, :order => sort_clause, | |
329 | :include => [ :author, :status, :tracker, :priority ], |
|
329 | :include => [ :author, :status, :tracker, :priority ], | |
330 | :conditions => @query.statement, |
|
330 | :conditions => @query.statement, | |
331 | :limit => Setting.issues_export_limit |
|
331 | :limit => Setting.issues_export_limit | |
332 |
|
332 | |||
333 | @options_for_rfpdf ||= {} |
|
333 | @options_for_rfpdf ||= {} | |
334 | @options_for_rfpdf[:file_name] = "export.pdf" |
|
334 | @options_for_rfpdf[:file_name] = "export.pdf" | |
335 | render :layout => false |
|
335 | render :layout => false | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | def move_issues |
|
338 | def move_issues | |
339 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
339 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] | |
340 | redirect_to :action => 'list_issues', :id => @project and return unless @issues |
|
340 | redirect_to :action => 'list_issues', :id => @project and return unless @issues | |
341 | @projects = [] |
|
341 | @projects = [] | |
342 | # find projects to which the user is allowed to move the issue |
|
342 | # find projects to which the user is allowed to move the issue | |
343 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)} |
|
343 | @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)} | |
344 | # issue can be moved to any tracker |
|
344 | # issue can be moved to any tracker | |
345 | @trackers = Tracker.find(:all) |
|
345 | @trackers = Tracker.find(:all) | |
346 | if request.post? and params[:new_project_id] and params[:new_tracker_id] |
|
346 | if request.post? and params[:new_project_id] and params[:new_tracker_id] | |
347 | new_project = Project.find(params[:new_project_id]) |
|
347 | new_project = Project.find(params[:new_project_id]) | |
348 | new_tracker = Tracker.find(params[:new_tracker_id]) |
|
348 | new_tracker = Tracker.find(params[:new_tracker_id]) | |
349 | @issues.each { |i| |
|
349 | @issues.each { |i| | |
350 | # project dependent properties |
|
350 | # project dependent properties | |
351 | unless i.project_id == new_project.id |
|
351 | unless i.project_id == new_project.id | |
352 | i.category = nil |
|
352 | i.category = nil | |
353 | i.fixed_version = nil |
|
353 | i.fixed_version = nil | |
354 | end |
|
354 | end | |
355 | # move the issue |
|
355 | # move the issue | |
356 | i.project = new_project |
|
356 | i.project = new_project | |
357 | i.tracker = new_tracker |
|
357 | i.tracker = new_tracker | |
358 | i.save |
|
358 | i.save | |
359 | } |
|
359 | } | |
360 | flash[:notice] = l(:notice_successful_update) |
|
360 | flash[:notice] = l(:notice_successful_update) | |
361 | redirect_to :action => 'list_issues', :id => @project |
|
361 | redirect_to :action => 'list_issues', :id => @project | |
362 | end |
|
362 | end | |
363 | end |
|
363 | end | |
364 |
|
364 | |||
365 | def add_query |
|
365 | def add_query | |
366 | @query = Query.new(params[:query]) |
|
366 | @query = Query.new(params[:query]) | |
367 | @query.project = @project |
|
367 | @query.project = @project | |
368 | @query.user = logged_in_user |
|
368 | @query.user = logged_in_user | |
369 |
|
369 | |||
370 | params[:fields].each do |field| |
|
370 | params[:fields].each do |field| | |
371 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
371 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
372 | end if params[:fields] |
|
372 | end if params[:fields] | |
373 |
|
373 | |||
374 | if request.post? and @query.save |
|
374 | if request.post? and @query.save | |
375 | flash[:notice] = l(:notice_successful_create) |
|
375 | flash[:notice] = l(:notice_successful_create) | |
376 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project |
|
376 | redirect_to :controller => 'reports', :action => 'issue_report', :id => @project | |
377 | end |
|
377 | end | |
378 | render :layout => false if request.xhr? |
|
378 | render :layout => false if request.xhr? | |
379 | end |
|
379 | end | |
380 |
|
380 | |||
381 | # Add a news to @project |
|
381 | # Add a news to @project | |
382 | def add_news |
|
382 | def add_news | |
383 | @news = News.new(:project => @project) |
|
383 | @news = News.new(:project => @project) | |
384 | if request.post? |
|
384 | if request.post? | |
385 | @news.attributes = params[:news] |
|
385 | @news.attributes = params[:news] | |
386 | @news.author_id = self.logged_in_user.id if self.logged_in_user |
|
386 | @news.author_id = self.logged_in_user.id if self.logged_in_user | |
387 | if @news.save |
|
387 | if @news.save | |
388 | flash[:notice] = l(:notice_successful_create) |
|
388 | flash[:notice] = l(:notice_successful_create) | |
389 | redirect_to :action => 'list_news', :id => @project |
|
389 | redirect_to :action => 'list_news', :id => @project | |
390 | end |
|
390 | end | |
391 | end |
|
391 | end | |
392 | end |
|
392 | end | |
393 |
|
393 | |||
394 | # Show news list of @project |
|
394 | # Show news list of @project | |
395 | def list_news |
|
395 | def list_news | |
396 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" |
|
396 | @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC" | |
397 | render :action => "list_news", :layout => false if request.xhr? |
|
397 | render :action => "list_news", :layout => false if request.xhr? | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | def add_file |
|
400 | def add_file | |
401 | if request.post? |
|
401 | if request.post? | |
402 | @version = @project.versions.find_by_id(params[:version_id]) |
|
402 | @version = @project.versions.find_by_id(params[:version_id]) | |
403 | # Save the attachments |
|
403 | # Save the attachments | |
404 | @attachments = [] |
|
404 | @attachments = [] | |
405 | params[:attachments].each { |file| |
|
405 | params[:attachments].each { |file| | |
406 | next unless file.size > 0 |
|
406 | next unless file.size > 0 | |
407 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) |
|
407 | a = Attachment.create(:container => @version, :file => file, :author => logged_in_user) | |
408 | @attachments << a unless a.new_record? |
|
408 | @attachments << a unless a.new_record? | |
409 | } if params[:attachments] and params[:attachments].is_a? Array |
|
409 | } if params[:attachments] and params[:attachments].is_a? Array | |
410 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? |
|
410 | Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled? | |
411 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
411 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
412 | end |
|
412 | end | |
413 | @versions = @project.versions |
|
413 | @versions = @project.versions | |
414 | end |
|
414 | end | |
415 |
|
415 | |||
416 | def list_files |
|
416 | def list_files | |
417 | @versions = @project.versions |
|
417 | @versions = @project.versions | |
418 | end |
|
418 | end | |
419 |
|
419 | |||
420 | # Show changelog for @project |
|
420 | # Show changelog for @project | |
421 | def changelog |
|
421 | def changelog | |
422 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
422 | @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') | |
423 | retrieve_selected_tracker_ids(@trackers) |
|
423 | retrieve_selected_tracker_ids(@trackers) | |
424 |
|
424 | |||
425 | @fixed_issues = @project.issues.find(:all, |
|
425 | @fixed_issues = @project.issues.find(:all, | |
426 | :include => [ :fixed_version, :status, :tracker ], |
|
426 | :include => [ :fixed_version, :status, :tracker ], | |
427 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], |
|
427 | :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true], | |
428 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" |
|
428 | :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC" | |
429 | ) unless @selected_tracker_ids.empty? |
|
429 | ) unless @selected_tracker_ids.empty? | |
430 | @fixed_issues ||= [] |
|
430 | @fixed_issues ||= [] | |
431 | end |
|
431 | end | |
432 |
|
432 | |||
433 | def roadmap |
|
433 | def roadmap | |
434 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') |
|
434 | @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position') | |
435 | retrieve_selected_tracker_ids(@trackers) |
|
435 | retrieve_selected_tracker_ids(@trackers) | |
436 |
|
436 | |||
437 | @versions = @project.versions.find(:all, |
|
437 | @versions = @project.versions.find(:all, | |
438 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], |
|
438 | :conditions => [ "#{Version.table_name}.effective_date>?", Date.today], | |
439 | :order => "#{Version.table_name}.effective_date ASC" |
|
439 | :order => "#{Version.table_name}.effective_date ASC" | |
440 | ) |
|
440 | ) | |
441 | end |
|
441 | end | |
442 |
|
442 | |||
443 | def activity |
|
443 | def activity | |
444 | if params[:year] and params[:year].to_i > 1900 |
|
444 | if params[:year] and params[:year].to_i > 1900 | |
445 | @year = params[:year].to_i |
|
445 | @year = params[:year].to_i | |
446 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
446 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
447 | @month = params[:month].to_i |
|
447 | @month = params[:month].to_i | |
448 | end |
|
448 | end | |
449 | end |
|
449 | end | |
450 | @year ||= Date.today.year |
|
450 | @year ||= Date.today.year | |
451 | @month ||= Date.today.month |
|
451 | @month ||= Date.today.month | |
452 |
|
452 | |||
453 | @date_from = Date.civil(@year, @month, 1) |
|
453 | @date_from = Date.civil(@year, @month, 1) | |
454 | @date_to = (@date_from >> 1)-1 |
|
454 | @date_to = (@date_from >> 1)-1 | |
455 |
|
455 | |||
456 | @events_by_day = {} |
|
456 | @events_by_day = {} | |
457 |
|
457 | |||
458 | unless params[:show_issues] == "0" |
|
458 | unless params[:show_issues] == "0" | |
459 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
459 | @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
460 | @events_by_day[i.created_on.to_date] ||= [] |
|
460 | @events_by_day[i.created_on.to_date] ||= [] | |
461 | @events_by_day[i.created_on.to_date] << i |
|
461 | @events_by_day[i.created_on.to_date] << i | |
462 | } |
|
462 | } | |
463 | @show_issues = 1 |
|
463 | @show_issues = 1 | |
464 | end |
|
464 | end | |
465 |
|
465 | |||
466 | unless params[:show_news] == "0" |
|
466 | unless params[:show_news] == "0" | |
467 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| |
|
467 | @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i| | |
468 | @events_by_day[i.created_on.to_date] ||= [] |
|
468 | @events_by_day[i.created_on.to_date] ||= [] | |
469 | @events_by_day[i.created_on.to_date] << i |
|
469 | @events_by_day[i.created_on.to_date] << i | |
470 | } |
|
470 | } | |
471 | @show_news = 1 |
|
471 | @show_news = 1 | |
472 | end |
|
472 | end | |
473 |
|
473 | |||
474 | unless params[:show_files] == "0" |
|
474 | unless params[:show_files] == "0" | |
475 | 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| |
|
475 | 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| | |
476 | @events_by_day[i.created_on.to_date] ||= [] |
|
476 | @events_by_day[i.created_on.to_date] ||= [] | |
477 | @events_by_day[i.created_on.to_date] << i |
|
477 | @events_by_day[i.created_on.to_date] << i | |
478 | } |
|
478 | } | |
479 | @show_files = 1 |
|
479 | @show_files = 1 | |
480 | end |
|
480 | end | |
481 |
|
481 | |||
482 | unless params[:show_documents] == "0" |
|
482 | unless params[:show_documents] == "0" | |
483 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| |
|
483 | @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i| | |
484 | @events_by_day[i.created_on.to_date] ||= [] |
|
484 | @events_by_day[i.created_on.to_date] ||= [] | |
485 | @events_by_day[i.created_on.to_date] << i |
|
485 | @events_by_day[i.created_on.to_date] << i | |
486 | } |
|
486 | } | |
487 | 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| |
|
487 | 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| | |
488 | @events_by_day[i.created_on.to_date] ||= [] |
|
488 | @events_by_day[i.created_on.to_date] ||= [] | |
489 | @events_by_day[i.created_on.to_date] << i |
|
489 | @events_by_day[i.created_on.to_date] << i | |
490 | } |
|
490 | } | |
491 | @show_documents = 1 |
|
491 | @show_documents = 1 | |
492 | end |
|
492 | end | |
493 |
|
493 | |||
494 | unless params[:show_wiki_edits] == "0" |
|
494 | unless params[:show_wiki_edits] == "0" | |
495 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + |
|
495 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " + | |
496 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" |
|
496 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title" | |
497 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
497 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
498 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
498 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
499 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
499 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
500 | @project.id, @date_from, @date_to] |
|
500 | @project.id, @date_from, @date_to] | |
501 |
|
501 | |||
502 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| |
|
502 | WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i| | |
503 | # We provide this alias so all events can be treated in the same manner |
|
503 | # We provide this alias so all events can be treated in the same manner | |
504 | def i.created_on |
|
504 | def i.created_on | |
505 | self.updated_on |
|
505 | self.updated_on | |
506 | end |
|
506 | end | |
507 |
|
507 | |||
508 | @events_by_day[i.created_on.to_date] ||= [] |
|
508 | @events_by_day[i.created_on.to_date] ||= [] | |
509 | @events_by_day[i.created_on.to_date] << i |
|
509 | @events_by_day[i.created_on.to_date] << i | |
510 | } |
|
510 | } | |
511 | @show_wiki_edits = 1 |
|
511 | @show_wiki_edits = 1 | |
512 | end |
|
512 | end | |
513 |
|
513 | |||
514 | unless @project.repository.nil? || params[:show_changesets] == "0" |
|
514 | unless @project.repository.nil? || params[:show_changesets] == "0" | |
515 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| |
|
515 | @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i| | |
516 | def i.created_on |
|
516 | def i.created_on | |
517 | self.committed_on |
|
517 | self.committed_on | |
518 | end |
|
518 | end | |
519 | @events_by_day[i.created_on.to_date] ||= [] |
|
519 | @events_by_day[i.created_on.to_date] ||= [] | |
520 | @events_by_day[i.created_on.to_date] << i |
|
520 | @events_by_day[i.created_on.to_date] << i | |
521 | } |
|
521 | } | |
522 | @show_changesets = 1 |
|
522 | @show_changesets = 1 | |
523 | end |
|
523 | end | |
524 |
|
524 | |||
525 | render :layout => false if request.xhr? |
|
525 | render :layout => false if request.xhr? | |
526 | end |
|
526 | end | |
527 |
|
527 | |||
528 | def calendar |
|
528 | def calendar | |
529 | @trackers = Tracker.find(:all, :order => 'position') |
|
529 | @trackers = Tracker.find(:all, :order => 'position') | |
530 | retrieve_selected_tracker_ids(@trackers) |
|
530 | retrieve_selected_tracker_ids(@trackers) | |
531 |
|
531 | |||
532 | if params[:year] and params[:year].to_i > 1900 |
|
532 | if params[:year] and params[:year].to_i > 1900 | |
533 | @year = params[:year].to_i |
|
533 | @year = params[:year].to_i | |
534 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
534 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
535 | @month = params[:month].to_i |
|
535 | @month = params[:month].to_i | |
536 | end |
|
536 | end | |
537 | end |
|
537 | end | |
538 | @year ||= Date.today.year |
|
538 | @year ||= Date.today.year | |
539 | @month ||= Date.today.month |
|
539 | @month ||= Date.today.month | |
540 |
|
540 | |||
541 | @date_from = Date.civil(@year, @month, 1) |
|
541 | @date_from = Date.civil(@year, @month, 1) | |
542 | @date_to = (@date_from >> 1)-1 |
|
542 | @date_to = (@date_from >> 1)-1 | |
543 | # start on monday |
|
543 | # start on monday | |
544 | @date_from = @date_from - (@date_from.cwday-1) |
|
544 | @date_from = @date_from - (@date_from.cwday-1) | |
545 | # finish on sunday |
|
545 | # finish on sunday | |
546 | @date_to = @date_to + (7-@date_to.cwday) |
|
546 | @date_to = @date_to + (7-@date_to.cwday) | |
547 |
|
547 | |||
548 | @issues = @project.issues.find(:all, |
|
548 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
|
549 | @issues = Issue.find(:all, | |||
549 |
|
|
550 | :include => [:tracker, :status, :assigned_to, :priority], | |
550 |
|
|
551 | :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] | |
551 |
|
|
552 | ) unless @selected_tracker_ids.empty? | |
|
553 | end | |||
552 | @issues ||=[] |
|
554 | @issues ||=[] | |
553 |
|
555 | |||
554 | @ending_issues_by_days = @issues.group_by {|issue| issue.due_date} |
|
556 | @ending_issues_by_days = @issues.group_by {|issue| issue.due_date} | |
555 | @starting_issues_by_days = @issues.group_by {|issue| issue.start_date} |
|
557 | @starting_issues_by_days = @issues.group_by {|issue| issue.start_date} | |
556 |
|
558 | |||
557 | render :layout => false if request.xhr? |
|
559 | render :layout => false if request.xhr? | |
558 | end |
|
560 | end | |
559 |
|
561 | |||
560 | def gantt |
|
562 | def gantt | |
561 | @trackers = Tracker.find(:all, :order => 'position') |
|
563 | @trackers = Tracker.find(:all, :order => 'position') | |
562 | retrieve_selected_tracker_ids(@trackers) |
|
564 | retrieve_selected_tracker_ids(@trackers) | |
563 |
|
565 | |||
564 | if params[:year] and params[:year].to_i >0 |
|
566 | if params[:year] and params[:year].to_i >0 | |
565 | @year_from = params[:year].to_i |
|
567 | @year_from = params[:year].to_i | |
566 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
568 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
567 | @month_from = params[:month].to_i |
|
569 | @month_from = params[:month].to_i | |
568 | else |
|
570 | else | |
569 | @month_from = 1 |
|
571 | @month_from = 1 | |
570 | end |
|
572 | end | |
571 | else |
|
573 | else | |
572 | @month_from ||= (Date.today << 1).month |
|
574 | @month_from ||= (Date.today << 1).month | |
573 | @year_from ||= (Date.today << 1).year |
|
575 | @year_from ||= (Date.today << 1).year | |
574 | end |
|
576 | end | |
575 |
|
577 | |||
576 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 |
|
578 | @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2 | |
577 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 |
|
579 | @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6 | |
578 |
|
580 | |||
579 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
581 | @date_from = Date.civil(@year_from, @month_from, 1) | |
580 | @date_to = (@date_from >> @months) - 1 |
|
582 | @date_to = (@date_from >> @months) - 1 | |
581 |
|
583 | |||
582 | @issues = @project.issues.find(:all, |
|
584 | @project.issues_with_subprojects(params[:with_subprojects]) do | |
|
585 | @issues = Issue.find(:all, | |||
583 |
|
|
586 | :order => "start_date, due_date", | |
584 |
|
|
587 | :include => [:tracker, :status, :assigned_to, :priority], | |
585 |
|
|
588 | :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] | |
586 |
|
|
589 | ) unless @selected_tracker_ids.empty? | |
|
590 | end | |||
587 | @issues ||=[] |
|
591 | @issues ||=[] | |
588 |
|
592 | |||
589 | if params[:output]=='pdf' |
|
593 | if params[:output]=='pdf' | |
590 | @options_for_rfpdf ||= {} |
|
594 | @options_for_rfpdf ||= {} | |
591 | @options_for_rfpdf[:file_name] = "gantt.pdf" |
|
595 | @options_for_rfpdf[:file_name] = "gantt.pdf" | |
592 | render :template => "projects/gantt.rfpdf", :layout => false |
|
596 | render :template => "projects/gantt.rfpdf", :layout => false | |
593 | else |
|
597 | else | |
594 | render :template => "projects/gantt.rhtml" |
|
598 | render :template => "projects/gantt.rhtml" | |
595 | end |
|
599 | end | |
596 | end |
|
600 | end | |
597 |
|
601 | |||
598 | def search |
|
602 | def search | |
599 | @question = params[:q] || "" |
|
603 | @question = params[:q] || "" | |
600 | @question.strip! |
|
604 | @question.strip! | |
601 | @all_words = params[:all_words] || (params[:submit] ? false : true) |
|
605 | @all_words = params[:all_words] || (params[:submit] ? false : true) | |
602 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) |
|
606 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) ) | |
603 | # tokens must be at least 3 character long |
|
607 | # tokens must be at least 3 character long | |
604 | @tokens = @question.split.uniq.select {|w| w.length > 2 } |
|
608 | @tokens = @question.split.uniq.select {|w| w.length > 2 } | |
605 | if !@tokens.empty? |
|
609 | if !@tokens.empty? | |
606 | # no more than 5 tokens to search for |
|
610 | # no more than 5 tokens to search for | |
607 | @tokens.slice! 5..-1 if @tokens.size > 5 |
|
611 | @tokens.slice! 5..-1 if @tokens.size > 5 | |
608 | # strings used in sql like statement |
|
612 | # strings used in sql like statement | |
609 | like_tokens = @tokens.collect {|w| "%#{w}%"} |
|
613 | like_tokens = @tokens.collect {|w| "%#{w}%"} | |
610 | operator = @all_words ? " AND " : " OR " |
|
614 | operator = @all_words ? " AND " : " OR " | |
611 | limit = 10 |
|
615 | limit = 10 | |
612 | @results = [] |
|
616 | @results = [] | |
613 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' |
|
617 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' | |
614 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' |
|
618 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' | |
615 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' |
|
619 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' | |
616 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') |
|
620 | @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') | |
617 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') |
|
621 | @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets') | |
618 | @question = @tokens.join(" ") |
|
622 | @question = @tokens.join(" ") | |
619 | else |
|
623 | else | |
620 | @question = "" |
|
624 | @question = "" | |
621 | end |
|
625 | end | |
622 | end |
|
626 | end | |
623 |
|
627 | |||
624 | def feeds |
|
628 | def feeds | |
625 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] |
|
629 | @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)] | |
626 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user |
|
630 | @key = logged_in_user.get_or_create_rss_key.value if logged_in_user | |
627 | end |
|
631 | end | |
628 |
|
632 | |||
629 | private |
|
633 | private | |
630 | # Find project of id params[:id] |
|
634 | # Find project of id params[:id] | |
631 | # if not found, redirect to project list |
|
635 | # if not found, redirect to project list | |
632 | # Used as a before_filter |
|
636 | # Used as a before_filter | |
633 | def find_project |
|
637 | def find_project | |
634 | @project = Project.find(params[:id]) |
|
638 | @project = Project.find(params[:id]) | |
635 | @html_title = @project.name |
|
639 | @html_title = @project.name | |
636 | rescue ActiveRecord::RecordNotFound |
|
640 | rescue ActiveRecord::RecordNotFound | |
637 | render_404 |
|
641 | render_404 | |
638 | end |
|
642 | end | |
639 |
|
643 | |||
640 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
644 | def retrieve_selected_tracker_ids(selectable_trackers) | |
641 | if ids = params[:tracker_ids] |
|
645 | if ids = params[:tracker_ids] | |
642 | @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 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
643 | else |
|
647 | else | |
644 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
648 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
645 | end |
|
649 | end | |
646 | end |
|
650 | end | |
647 |
|
651 | |||
648 | # Retrieve query from session or build a new query |
|
652 | # Retrieve query from session or build a new query | |
649 | def retrieve_query |
|
653 | def retrieve_query | |
650 | if params[:query_id] |
|
654 | if params[:query_id] | |
651 | @query = @project.queries.find(params[:query_id]) |
|
655 | @query = @project.queries.find(params[:query_id]) | |
652 | session[:query] = @query |
|
656 | session[:query] = @query | |
653 | else |
|
657 | else | |
654 | 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 | |
655 | # Give it a name, required to be valid |
|
659 | # Give it a name, required to be valid | |
656 | @query = Query.new(:name => "_") |
|
660 | @query = Query.new(:name => "_") | |
657 | @query.project = @project |
|
661 | @query.project = @project | |
658 | if params[:fields] and params[:fields].is_a? Array |
|
662 | if params[:fields] and params[:fields].is_a? Array | |
659 | params[:fields].each do |field| |
|
663 | params[:fields].each do |field| | |
660 | @query.add_filter(field, params[:operators][field], params[:values][field]) |
|
664 | @query.add_filter(field, params[:operators][field], params[:values][field]) | |
661 | end |
|
665 | end | |
662 | else |
|
666 | else | |
663 | @query.available_filters.keys.each do |field| |
|
667 | @query.available_filters.keys.each do |field| | |
664 | @query.add_short_filter(field, params[field]) if params[field] |
|
668 | @query.add_short_filter(field, params[field]) if params[field] | |
665 | end |
|
669 | end | |
666 | end |
|
670 | end | |
667 | session[:query] = @query |
|
671 | session[:query] = @query | |
668 | else |
|
672 | else | |
669 | @query = session[:query] |
|
673 | @query = session[:query] | |
670 | end |
|
674 | end | |
671 | end |
|
675 | end | |
672 | end |
|
676 | end | |
673 | end |
|
677 | end |
@@ -1,79 +1,92 | |||||
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 Project < ActiveRecord::Base |
|
18 | class Project < ActiveRecord::Base | |
19 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" |
|
19 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" | |
20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" |
|
20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" | |
21 | has_many :users, :through => :members |
|
21 | has_many :users, :through => :members | |
22 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
22 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
23 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] |
|
23 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] | |
24 | has_many :time_entries, :dependent => :delete_all |
|
24 | has_many :time_entries, :dependent => :delete_all | |
25 | has_many :queries, :dependent => :delete_all |
|
25 | has_many :queries, :dependent => :delete_all | |
26 | has_many :documents, :dependent => :destroy |
|
26 | has_many :documents, :dependent => :destroy | |
27 | has_many :news, :dependent => :delete_all, :include => :author |
|
27 | has_many :news, :dependent => :delete_all, :include => :author | |
28 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" |
|
28 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" | |
29 | has_one :repository, :dependent => :destroy |
|
29 | has_one :repository, :dependent => :destroy | |
30 | has_one :wiki, :dependent => :destroy |
|
30 | has_one :wiki, :dependent => :destroy | |
31 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' |
|
31 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id' | |
32 | acts_as_tree :order => "name", :counter_cache => true |
|
32 | acts_as_tree :order => "name", :counter_cache => true | |
33 |
|
33 | |||
34 | validates_presence_of :name, :description, :identifier |
|
34 | validates_presence_of :name, :description, :identifier | |
35 | validates_uniqueness_of :name, :identifier |
|
35 | validates_uniqueness_of :name, :identifier | |
36 | validates_associated :custom_values, :on => :update |
|
36 | validates_associated :custom_values, :on => :update | |
37 | validates_associated :repository, :wiki |
|
37 | validates_associated :repository, :wiki | |
38 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
38 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i | |
39 | validates_length_of :identifier, :maximum => 12 |
|
39 | validates_length_of :identifier, :maximum => 12 | |
40 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ |
|
40 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ | |
41 |
|
41 | |||
42 | def identifier=(identifier) |
|
42 | def identifier=(identifier) | |
43 | super unless identifier_frozen? |
|
43 | super unless identifier_frozen? | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def identifier_frozen? |
|
46 | def identifier_frozen? | |
47 | errors[:identifier].nil? && !(new_record? || identifier.blank?) |
|
47 | errors[:identifier].nil? && !(new_record? || identifier.blank?) | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
|
50 | def issues_with_subprojects(include_subprojects=false) | |||
|
51 | conditions = nil | |||
|
52 | if include_subprojects && children.size > 0 | |||
|
53 | ids = [id] + children.collect {|c| c.id} | |||
|
54 | conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"] | |||
|
55 | else | |||
|
56 | conditions = ["#{Issue.table_name}.project_id = ?", id] | |||
|
57 | end | |||
|
58 | Issue.with_scope :find => { :conditions => conditions } do | |||
|
59 | yield | |||
|
60 | end | |||
|
61 | end | |||
|
62 | ||||
50 | # returns latest created projects |
|
63 | # returns latest created projects | |
51 | # non public projects will be returned only if user is a member of those |
|
64 | # non public projects will be returned only if user is a member of those | |
52 | def self.latest(user=nil, count=5) |
|
65 | def self.latest(user=nil, count=5) | |
53 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") |
|
66 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") | |
54 | end |
|
67 | end | |
55 |
|
68 | |||
56 | def self.visible_by(user=nil) |
|
69 | def self.visible_by(user=nil) | |
57 | if user && !user.memberships.empty? |
|
70 | if user && !user.memberships.empty? | |
58 | return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true] |
|
71 | return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true] | |
59 | else |
|
72 | else | |
60 | return ["#{Project.table_name}.is_public = ?", true] |
|
73 | return ["#{Project.table_name}.is_public = ?", true] | |
61 | end |
|
74 | end | |
62 | end |
|
75 | end | |
63 |
|
76 | |||
64 | # Returns an array of all custom fields enabled for project issues |
|
77 | # Returns an array of all custom fields enabled for project issues | |
65 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
78 | # (explictly associated custom fields and custom fields enabled for all projects) | |
66 | def custom_fields_for_issues(tracker) |
|
79 | def custom_fields_for_issues(tracker) | |
67 | all_custom_fields.select {|c| tracker.custom_fields.include? c } |
|
80 | all_custom_fields.select {|c| tracker.custom_fields.include? c } | |
68 | end |
|
81 | end | |
69 |
|
82 | |||
70 | def all_custom_fields |
|
83 | def all_custom_fields | |
71 | @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq |
|
84 | @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq | |
72 | end |
|
85 | end | |
73 |
|
86 | |||
74 | protected |
|
87 | protected | |
75 | def validate |
|
88 | def validate | |
76 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
89 | errors.add(parent_id, " must be a root project") if parent and parent.parent | |
77 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 |
|
90 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 | |
78 | end |
|
91 | end | |
79 | end |
|
92 | end |
@@ -1,82 +1,86 | |||||
1 | <h2><%= l(:label_calendar) %></h2> |
|
1 | <h2><%= l(:label_calendar) %></h2> | |
2 |
|
2 | |||
3 | <% form_tag do %> |
|
3 | <% form_tag do %> | |
4 | <table width="100%"> |
|
4 | <table width="100%"> | |
5 | <tr> |
|
5 | <tr> | |
6 | <td align="left" style="width:15%"> |
|
6 | <td align="left" style="width:15%"> | |
7 | <%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")), |
|
7 | <%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")), | |
8 | {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids }}, |
|
8 | {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }}, | |
9 | {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids)} |
|
9 | {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])} | |
10 | %> |
|
10 | %> | |
11 | </td> |
|
11 | </td> | |
12 | <td align="center" style="width:55%"> |
|
12 | <td align="center" style="width:55%"> | |
13 | <%= select_month(@month, :prefix => "month", :discard_type => true) %> |
|
13 | <%= select_month(@month, :prefix => "month", :discard_type => true) %> | |
14 | <%= select_year(@year, :prefix => "year", :discard_type => true) %> |
|
14 | <%= select_year(@year, :prefix => "year", :discard_type => true) %> | |
15 | <%= submit_tag l(:button_submit), :class => "button-small" %> |
|
15 | <%= submit_tag l(:button_submit), :class => "button-small" %> | |
16 | </td> |
|
16 | </td> | |
17 | <td align="left" style="width:15%"> |
|
17 | <td align="left" style="width:15%"> | |
18 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> |
|
18 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> | |
19 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display:none;"> |
|
19 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display:none;"> | |
20 | <p><strong><%=l(:label_tracker_plural)%></strong></p> |
|
20 | <p><strong><%=l(:label_tracker_plural)%></strong></p> | |
21 | <% @trackers.each do |tracker| %> |
|
21 | <% @trackers.each do |tracker| %> | |
22 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> |
|
22 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> | |
23 | <%= tracker.name %><br /> |
|
23 | <%= tracker.name %><br /> | |
24 | <% end %> |
|
24 | <% end %> | |
|
25 | <% if @project.children.any? %> | |||
|
26 | <p><strong><%=l(:label_subproject_plural)%></strong></p> | |||
|
27 | <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %> | |||
|
28 | <% end %> | |||
25 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> |
|
29 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> | |
26 | </div> |
|
30 | </div> | |
27 | </td> |
|
31 | </td> | |
28 | <td align="right" style="width:15%"> |
|
32 | <td align="right" style="width:15%"> | |
29 | <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'), |
|
33 | <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'), | |
30 | {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids }}, |
|
34 | {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }}, | |
31 | {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids)} |
|
35 | {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])} | |
32 | %> |
|
36 | %> | |
33 | </td> |
|
37 | </td> | |
34 | </tr> |
|
38 | </tr> | |
35 | </table> |
|
39 | </table> | |
36 | <% end %> |
|
40 | <% end %> | |
37 |
|
41 | |||
38 | <table class="list with-cells"> |
|
42 | <table class="list with-cells"> | |
39 | <thead> |
|
43 | <thead> | |
40 | <tr> |
|
44 | <tr> | |
41 | <th></th> |
|
45 | <th></th> | |
42 | <% 1.upto(7) do |d| %> |
|
46 | <% 1.upto(7) do |d| %> | |
43 | <th style="width:14%"><%= day_name(d) %></th> |
|
47 | <th style="width:14%"><%= day_name(d) %></th> | |
44 | <% end %> |
|
48 | <% end %> | |
45 | </tr> |
|
49 | </tr> | |
46 | </thead> |
|
50 | </thead> | |
47 | <tbody> |
|
51 | <tbody> | |
48 | <tr style="height:100px"> |
|
52 | <tr style="height:100px"> | |
49 | <% day = @date_from |
|
53 | <% day = @date_from | |
50 | while day <= @date_to |
|
54 | while day <= @date_to | |
51 | if day.cwday == 1 %> |
|
55 | if day.cwday == 1 %> | |
52 | <th><%= day.cweek %></th> |
|
56 | <th><%= day.cweek %></th> | |
53 | <% end %> |
|
57 | <% end %> | |
54 | <td valign="top" class="<%= day.month==@month ? "even" : "odd" %>" style="width:14%; <%= Date.today == day ? 'background:#FDFED0;' : '' %>"> |
|
58 | <td valign="top" class="<%= day.month==@month ? "even" : "odd" %>" style="width:14%; <%= Date.today == day ? 'background:#FDFED0;' : '' %>"> | |
55 | <p class="textright"><%= day==Date.today ? "<b>#{day.day}</b>" : day.day %></p> |
|
59 | <p class="textright"><%= day==Date.today ? "<b>#{day.day}</b>" : day.day %></p> | |
56 | <% ((@ending_issues_by_days[day] || []) + (@starting_issues_by_days[day] || [])).uniq.each do |i| %> |
|
60 | <% ((@ending_issues_by_days[day] || []) + (@starting_issues_by_days[day] || [])).uniq.each do |i| %> | |
57 | <div class="tooltip"> |
|
61 | <div class="tooltip"> | |
58 | <%= if day == i.start_date and day == i.due_date |
|
62 | <%= if day == i.start_date and day == i.due_date | |
59 | image_tag('arrow_bw.png') |
|
63 | image_tag('arrow_bw.png') | |
60 | elsif day == i.start_date |
|
64 | elsif day == i.start_date | |
61 | image_tag('arrow_from.png') |
|
65 | image_tag('arrow_from.png') | |
62 | elsif day == i.due_date |
|
66 | elsif day == i.due_date | |
63 | image_tag('arrow_to.png') |
|
67 | image_tag('arrow_to.png') | |
64 | end %> |
|
68 | end %> | |
65 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i } %>: <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> |
|
69 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i } %>: <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> | |
66 | <span class="tip"> |
|
70 | <span class="tip"> | |
67 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> |
|
71 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> | |
68 | </span> |
|
72 | </span> | |
69 | </div> |
|
73 | </div> | |
70 | <% end %> |
|
74 | <% end %> | |
71 | </td> |
|
75 | </td> | |
72 | <%= '</tr><tr style="height:100px">' if day.cwday >= 7 and day!=@date_to %> |
|
76 | <%= '</tr><tr style="height:100px">' if day.cwday >= 7 and day!=@date_to %> | |
73 | <% |
|
77 | <% | |
74 | day = day + 1 |
|
78 | day = day + 1 | |
75 | end %> |
|
79 | end %> | |
76 | </tr> |
|
80 | </tr> | |
77 | </tbody> |
|
81 | </tbody> | |
78 | </table> |
|
82 | </table> | |
79 |
|
83 | |||
80 | <%= image_tag 'arrow_from.png' %> <%= l(:text_tip_task_begin_day) %><br /> |
|
84 | <%= image_tag 'arrow_from.png' %> <%= l(:text_tip_task_begin_day) %><br /> | |
81 | <%= image_tag 'arrow_to.png' %> <%= l(:text_tip_task_end_day) %><br /> |
|
85 | <%= image_tag 'arrow_to.png' %> <%= l(:text_tip_task_end_day) %><br /> | |
82 | <%= image_tag 'arrow_bw.png' %> <%= l(:text_tip_task_begin_end_day) %><br /> No newline at end of file |
|
86 | <%= image_tag 'arrow_bw.png' %> <%= l(:text_tip_task_begin_end_day) %><br /> |
@@ -1,223 +1,227 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= l(:label_export_to) %> |
|
2 | <%= l(:label_export_to) %> | |
3 | <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :output => 'pdf'}, :class => 'icon icon-pdf' %> |
|
3 | <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :output => 'pdf'}, :class => 'icon icon-pdf' %> | |
4 | </div> |
|
4 | </div> | |
5 |
|
5 | |||
6 | <h2><%= l(:label_gantt) %></h2> |
|
6 | <h2><%= l(:label_gantt) %></h2> | |
7 |
|
7 | |||
8 | <% form_tag do %> |
|
8 | <% form_tag do %> | |
9 | <table width="100%"> |
|
9 | <table width="100%"> | |
10 | <tr> |
|
10 | <tr> | |
11 | <td align="left"> |
|
11 | <td align="left"> | |
12 | <input type="text" name="months" size="2" value="<%= @months %>" /> |
|
12 | <input type="text" name="months" size="2" value="<%= @months %>" /> | |
13 | <%= l(:label_months_from) %> |
|
13 | <%= l(:label_months_from) %> | |
14 | <%= select_month(@month_from, :prefix => "month", :discard_type => true) %> |
|
14 | <%= select_month(@month_from, :prefix => "month", :discard_type => true) %> | |
15 | <%= select_year(@year_from, :prefix => "year", :discard_type => true) %> |
|
15 | <%= select_year(@year_from, :prefix => "year", :discard_type => true) %> | |
16 | <%= hidden_field_tag 'zoom', @zoom %> |
|
16 | <%= hidden_field_tag 'zoom', @zoom %> | |
17 | <%= submit_tag l(:button_submit), :class => "button-small" %> |
|
17 | <%= submit_tag l(:button_submit), :class => "button-small" %> | |
18 | </td> |
|
18 | </td> | |
19 | <td> |
|
19 | <td> | |
20 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> |
|
20 | <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a> | |
21 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display: none;"> |
|
21 | <div id="trackerselect" class="rightbox overlay" style="width:140px; display: none;"> | |
22 | <p><strong><%=l(:label_tracker_plural)%></strong></p> |
|
22 | <p><strong><%=l(:label_tracker_plural)%></strong></p> | |
23 | <% @trackers.each do |tracker| %> |
|
23 | <% @trackers.each do |tracker| %> | |
24 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> |
|
24 | <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> | |
25 | <%= tracker.name %><br /> |
|
25 | <%= tracker.name %><br /> | |
26 | <% end %> |
|
26 | <% end %> | |
|
27 | <% if @project.children.any? %> | |||
|
28 | <p><strong><%=l(:label_subproject_plural)%></strong></p> | |||
|
29 | <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %> | |||
|
30 | <% end %> | |||
27 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> |
|
31 | <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p> | |
28 | </div> |
|
32 | </div> | |
29 | </td> |
|
33 | </td> | |
30 | <td align="right"> |
|
34 | <td align="right"> | |
31 | <%= if @zoom < 4 |
|
35 | <%= if @zoom < 4 | |
32 | link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids} |
|
36 | link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]} | |
33 | else |
|
37 | else | |
34 | image_tag 'zoom_in_g.png' |
|
38 | image_tag 'zoom_in_g.png' | |
35 | end %> |
|
39 | end %> | |
36 | <%= if @zoom > 1 |
|
40 | <%= if @zoom > 1 | |
37 | link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids} |
|
41 | link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]} | |
38 | else |
|
42 | else | |
39 | image_tag 'zoom_out_g.png' |
|
43 | image_tag 'zoom_out_g.png' | |
40 | end %> |
|
44 | end %> | |
41 | </td> |
|
45 | </td> | |
42 | </tr> |
|
46 | </tr> | |
43 | </table> |
|
47 | </table> | |
44 | <% end %> |
|
48 | <% end %> | |
45 |
|
49 | |||
46 | <% zoom = 1 |
|
50 | <% zoom = 1 | |
47 | @zoom.times { zoom = zoom * 2 } |
|
51 | @zoom.times { zoom = zoom * 2 } | |
48 |
|
52 | |||
49 | subject_width = 260 |
|
53 | subject_width = 260 | |
50 | header_heigth = 18 |
|
54 | header_heigth = 18 | |
51 |
|
55 | |||
52 | headers_height = header_heigth |
|
56 | headers_height = header_heigth | |
53 | show_weeks = false |
|
57 | show_weeks = false | |
54 | show_days = false |
|
58 | show_days = false | |
55 |
|
59 | |||
56 | if @zoom >1 |
|
60 | if @zoom >1 | |
57 | show_weeks = true |
|
61 | show_weeks = true | |
58 | headers_height = 2*header_heigth |
|
62 | headers_height = 2*header_heigth | |
59 | if @zoom > 2 |
|
63 | if @zoom > 2 | |
60 | show_days = true |
|
64 | show_days = true | |
61 | headers_height = 3*header_heigth |
|
65 | headers_height = 3*header_heigth | |
62 | end |
|
66 | end | |
63 | end |
|
67 | end | |
64 |
|
68 | |||
65 | g_width = (@date_to - @date_from + 1)*zoom |
|
69 | g_width = (@date_to - @date_from + 1)*zoom | |
66 | g_height = [(20 * @issues.length + 6)+150, 206].max |
|
70 | g_height = [(20 * @issues.length + 6)+150, 206].max | |
67 | t_height = g_height + headers_height |
|
71 | t_height = g_height + headers_height | |
68 | %> |
|
72 | %> | |
69 |
|
73 | |||
70 | <table width="100%" style="border:0; border-collapse: collapse;"> |
|
74 | <table width="100%" style="border:0; border-collapse: collapse;"> | |
71 | <tr> |
|
75 | <tr> | |
72 | <td style="width:260px;"> |
|
76 | <td style="width:260px;"> | |
73 |
|
77 | |||
74 | <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;"> |
|
78 | <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;"> | |
75 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div> |
|
79 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div> | |
76 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div> |
|
80 | <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div> | |
77 | <% |
|
81 | <% | |
78 | # |
|
82 | # | |
79 | # Tasks subjects |
|
83 | # Tasks subjects | |
80 | # |
|
84 | # | |
81 | top = headers_height + 8 |
|
85 | top = headers_height + 8 | |
82 | @issues.each do |i| %> |
|
86 | @issues.each do |i| %> | |
83 | <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"> |
|
87 | <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"> | |
84 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i }, :title => "#{i.subject}" %>: |
|
88 | <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i }, :title => "#{i.subject}" %>: | |
85 | <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> |
|
89 | <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small> | |
86 | </div> |
|
90 | </div> | |
87 | <% top = top + 20 |
|
91 | <% top = top + 20 | |
88 | end %> |
|
92 | end %> | |
89 | </div> |
|
93 | </div> | |
90 | </td> |
|
94 | </td> | |
91 | <td> |
|
95 | <td> | |
92 |
|
96 | |||
93 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;"> |
|
97 | <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;"> | |
94 | <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div> |
|
98 | <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div> | |
95 | <% |
|
99 | <% | |
96 | # |
|
100 | # | |
97 | # Months headers |
|
101 | # Months headers | |
98 | # |
|
102 | # | |
99 | month_f = @date_from |
|
103 | month_f = @date_from | |
100 | left = 0 |
|
104 | left = 0 | |
101 | height = (show_weeks ? header_heigth : header_heigth + g_height) |
|
105 | height = (show_weeks ? header_heigth : header_heigth + g_height) | |
102 | @months.times do |
|
106 | @months.times do | |
103 | width = ((month_f >> 1) - month_f) * zoom - 1 |
|
107 | width = ((month_f >> 1) - month_f) * zoom - 1 | |
104 | %> |
|
108 | %> | |
105 | <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
109 | <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> | |
106 | <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months }, :title => "#{month_name(month_f.month)} #{month_f.year}"%> |
|
110 | <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }, :title => "#{month_name(month_f.month)} #{month_f.year}"%> | |
107 | </div> |
|
111 | </div> | |
108 | <% |
|
112 | <% | |
109 | left = left + width + 1 |
|
113 | left = left + width + 1 | |
110 | month_f = month_f >> 1 |
|
114 | month_f = month_f >> 1 | |
111 | end %> |
|
115 | end %> | |
112 |
|
116 | |||
113 | <% |
|
117 | <% | |
114 | # |
|
118 | # | |
115 | # Weeks headers |
|
119 | # Weeks headers | |
116 | # |
|
120 | # | |
117 | if show_weeks |
|
121 | if show_weeks | |
118 | left = 0 |
|
122 | left = 0 | |
119 | height = (show_days ? header_heigth-1 : header_heigth-1 + g_height) |
|
123 | height = (show_days ? header_heigth-1 : header_heigth-1 + g_height) | |
120 | if @date_from.cwday == 1 |
|
124 | if @date_from.cwday == 1 | |
121 | # @date_from is monday |
|
125 | # @date_from is monday | |
122 | week_f = @date_from |
|
126 | week_f = @date_from | |
123 | else |
|
127 | else | |
124 | # find next monday after @date_from |
|
128 | # find next monday after @date_from | |
125 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
129 | week_f = @date_from + (7 - @date_from.cwday + 1) | |
126 | width = (7 - @date_from.cwday + 1) * zoom-1 |
|
130 | width = (7 - @date_from.cwday + 1) * zoom-1 | |
127 | %> |
|
131 | %> | |
128 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div> |
|
132 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div> | |
129 | <% |
|
133 | <% | |
130 | left = left + width+1 |
|
134 | left = left + width+1 | |
131 | end %> |
|
135 | end %> | |
132 | <% |
|
136 | <% | |
133 | while week_f <= @date_to |
|
137 | while week_f <= @date_to | |
134 | width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1 |
|
138 | width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1 | |
135 | %> |
|
139 | %> | |
136 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> |
|
140 | <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> | |
137 | <small><%= week_f.cweek if width >= 16 %></small> |
|
141 | <small><%= week_f.cweek if width >= 16 %></small> | |
138 | </div> |
|
142 | </div> | |
139 | <% |
|
143 | <% | |
140 | left = left + width+1 |
|
144 | left = left + width+1 | |
141 | week_f = week_f+7 |
|
145 | week_f = week_f+7 | |
142 | end |
|
146 | end | |
143 | end %> |
|
147 | end %> | |
144 |
|
148 | |||
145 | <% |
|
149 | <% | |
146 | # |
|
150 | # | |
147 | # Days headers |
|
151 | # Days headers | |
148 | # |
|
152 | # | |
149 | if show_days |
|
153 | if show_days | |
150 | left = 0 |
|
154 | left = 0 | |
151 | height = g_height + header_heigth - 1 |
|
155 | height = g_height + header_heigth - 1 | |
152 | wday = @date_from.cwday |
|
156 | wday = @date_from.cwday | |
153 | (@date_to - @date_from + 1).to_i.times do |
|
157 | (@date_to - @date_from + 1).to_i.times do | |
154 | width = zoom - 1 |
|
158 | width = zoom - 1 | |
155 | %> |
|
159 | %> | |
156 | <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr"> |
|
160 | <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr"> | |
157 | <%= day_name(wday)[0,1] %> |
|
161 | <%= day_name(wday)[0,1] %> | |
158 | </div> |
|
162 | </div> | |
159 | <% |
|
163 | <% | |
160 | left = left + width+1 |
|
164 | left = left + width+1 | |
161 | wday = wday + 1 |
|
165 | wday = wday + 1 | |
162 | wday = 1 if wday > 7 |
|
166 | wday = 1 if wday > 7 | |
163 | end |
|
167 | end | |
164 | end %> |
|
168 | end %> | |
165 |
|
169 | |||
166 | <% |
|
170 | <% | |
167 | # |
|
171 | # | |
168 | # Today red line |
|
172 | # Today red line | |
169 | # |
|
173 | # | |
170 | if Date.today >= @date_from and Date.today <= @date_to %> |
|
174 | if Date.today >= @date_from and Date.today <= @date_to %> | |
171 | <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;"> </div> |
|
175 | <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;"> </div> | |
172 | <% end %> |
|
176 | <% end %> | |
173 |
|
177 | |||
174 | <% |
|
178 | <% | |
175 | # |
|
179 | # | |
176 | # Tasks |
|
180 | # Tasks | |
177 | # |
|
181 | # | |
178 | top = headers_height + 10 |
|
182 | top = headers_height + 10 | |
179 | @issues.each do |i| %> |
|
183 | @issues.each do |i| %> | |
180 | <% |
|
184 | <% | |
181 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) |
|
185 | i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) | |
182 | i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) |
|
186 | i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) | |
183 |
|
187 | |||
184 | i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor |
|
188 | i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor | |
185 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) |
|
189 | i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) | |
186 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) |
|
190 | i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) | |
187 |
|
191 | |||
188 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today |
|
192 | i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today | |
189 |
|
193 | |||
190 | i_left = ((i_start_date - @date_from)*zoom).floor |
|
194 | i_left = ((i_start_date - @date_from)*zoom).floor | |
191 | i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders) |
|
195 | i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders) | |
192 | d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width |
|
196 | d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width | |
193 | l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width |
|
197 | l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width | |
194 | %> |
|
198 | %> | |
195 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div> |
|
199 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div> | |
196 | <% if l_width > 0 %> |
|
200 | <% if l_width > 0 %> | |
197 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div> |
|
201 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div> | |
198 | <% end %> |
|
202 | <% end %> | |
199 | <% if d_width > 0 %> |
|
203 | <% if d_width > 0 %> | |
200 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div> |
|
204 | <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div> | |
201 | <% end %> |
|
205 | <% end %> | |
202 | <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task"> |
|
206 | <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task"> | |
203 | <%= i.status.name %> |
|
207 | <%= i.status.name %> | |
204 | <%= (i.done_ratio).to_i %>% |
|
208 | <%= (i.done_ratio).to_i %>% | |
205 | </div> |
|
209 | </div> | |
206 | <% # === tooltip === %> |
|
210 | <% # === tooltip === %> | |
207 | <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;"> |
|
211 | <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;"> | |
208 | <span class="tip"> |
|
212 | <span class="tip"> | |
209 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> |
|
213 | <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> | |
210 | </span></div> |
|
214 | </span></div> | |
211 | <% top = top + 20 |
|
215 | <% top = top + 20 | |
212 | end %> |
|
216 | end %> | |
213 | </div> |
|
217 | </div> | |
214 | </td> |
|
218 | </td> | |
215 | </tr> |
|
219 | </tr> | |
216 | </table> |
|
220 | </table> | |
217 |
|
221 | |||
218 | <table width="100%"> |
|
222 | <table width="100%"> | |
219 | <tr> |
|
223 | <tr> | |
220 | <td align="left"><%= link_to ('« ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids %></td> |
|
224 | <td align="left"><%= link_to ('« ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td> | |
221 | <td align="right"><%= link_to (l(:label_next) + ' »'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids %></td> |
|
225 | <td align="right"><%= link_to (l(:label_next) + ' »'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td> | |
222 | </tr> |
|
226 | </tr> | |
223 | </table> No newline at end of file |
|
227 | </table> |
General Comments 0
You need to be logged in to leave comments.
Login now