The requested changes are too big and content was truncated. Show full diff
@@ -1,439 +1,439 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 IssuesController < ApplicationController |
|
18 | class IssuesController < ApplicationController | |
19 | menu_item :new_issue, :only => [:new, :create] |
|
19 | menu_item :new_issue, :only => [:new, :create] | |
20 | default_search_scope :issues |
|
20 | default_search_scope :issues | |
21 |
|
21 | |||
22 | before_filter :find_issue, :only => [:show, :edit, :update] |
|
22 | before_filter :find_issue, :only => [:show, :edit, :update] | |
23 | before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] |
|
23 | before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] | |
24 | before_filter :find_project, :only => [:new, :create, :update_form] |
|
24 | before_filter :find_project, :only => [:new, :create, :update_form] | |
25 | before_filter :authorize, :except => [:index] |
|
25 | before_filter :authorize, :except => [:index] | |
26 | before_filter :find_optional_project, :only => [:index] |
|
26 | before_filter :find_optional_project, :only => [:index] | |
27 | before_filter :check_for_default_issue_status, :only => [:new, :create] |
|
27 | before_filter :check_for_default_issue_status, :only => [:new, :create] | |
28 | before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form] |
|
28 | before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form] | |
29 | accept_rss_auth :index, :show |
|
29 | accept_rss_auth :index, :show | |
30 | accept_api_auth :index, :show, :create, :update, :destroy |
|
30 | accept_api_auth :index, :show, :create, :update, :destroy | |
31 |
|
31 | |||
32 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
32 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
33 |
|
33 | |||
34 | helper :journals |
|
34 | helper :journals | |
35 | helper :projects |
|
35 | helper :projects | |
36 | include ProjectsHelper |
|
36 | include ProjectsHelper | |
37 | helper :custom_fields |
|
37 | helper :custom_fields | |
38 | include CustomFieldsHelper |
|
38 | include CustomFieldsHelper | |
39 | helper :issue_relations |
|
39 | helper :issue_relations | |
40 | include IssueRelationsHelper |
|
40 | include IssueRelationsHelper | |
41 | helper :watchers |
|
41 | helper :watchers | |
42 | include WatchersHelper |
|
42 | include WatchersHelper | |
43 | helper :attachments |
|
43 | helper :attachments | |
44 | include AttachmentsHelper |
|
44 | include AttachmentsHelper | |
45 | helper :queries |
|
45 | helper :queries | |
46 | include QueriesHelper |
|
46 | include QueriesHelper | |
47 | helper :repositories |
|
47 | helper :repositories | |
48 | include RepositoriesHelper |
|
48 | include RepositoriesHelper | |
49 | helper :sort |
|
49 | helper :sort | |
50 | include SortHelper |
|
50 | include SortHelper | |
51 | include IssuesHelper |
|
51 | include IssuesHelper | |
52 | helper :timelog |
|
52 | helper :timelog | |
53 | include Redmine::Export::PDF |
|
53 | include Redmine::Export::PDF | |
54 |
|
54 | |||
55 | def index |
|
55 | def index | |
56 | retrieve_query |
|
56 | retrieve_query | |
57 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
57 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
58 | sort_update(@query.sortable_columns) |
|
58 | sort_update(@query.sortable_columns) | |
59 | @query.sort_criteria = sort_criteria.to_a |
|
59 | @query.sort_criteria = sort_criteria.to_a | |
60 |
|
60 | |||
61 | if @query.valid? |
|
61 | if @query.valid? | |
62 | case params[:format] |
|
62 | case params[:format] | |
63 | when 'csv', 'pdf' |
|
63 | when 'csv', 'pdf' | |
64 | @limit = Setting.issues_export_limit.to_i |
|
64 | @limit = Setting.issues_export_limit.to_i | |
65 | when 'atom' |
|
65 | when 'atom' | |
66 | @limit = Setting.feeds_limit.to_i |
|
66 | @limit = Setting.feeds_limit.to_i | |
67 | when 'xml', 'json' |
|
67 | when 'xml', 'json' | |
68 | @offset, @limit = api_offset_and_limit |
|
68 | @offset, @limit = api_offset_and_limit | |
69 | else |
|
69 | else | |
70 | @limit = per_page_option |
|
70 | @limit = per_page_option | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | @issue_count = @query.issue_count |
|
73 | @issue_count = @query.issue_count | |
74 | @issue_pages = Paginator.new @issue_count, @limit, params['page'] |
|
74 | @issue_pages = Paginator.new @issue_count, @limit, params['page'] | |
75 | @offset ||= @issue_pages.offset |
|
75 | @offset ||= @issue_pages.offset | |
76 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
76 | @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], | |
77 | :order => sort_clause, |
|
77 | :order => sort_clause, | |
78 | :offset => @offset, |
|
78 | :offset => @offset, | |
79 | :limit => @limit) |
|
79 | :limit => @limit) | |
80 | @issue_count_by_group = @query.issue_count_by_group |
|
80 | @issue_count_by_group = @query.issue_count_by_group | |
81 |
|
81 | |||
82 | respond_to do |format| |
|
82 | respond_to do |format| | |
83 | format.html { render :template => 'issues/index', :layout => !request.xhr? } |
|
83 | format.html { render :template => 'issues/index', :layout => !request.xhr? } | |
84 | format.api { |
|
84 | format.api { | |
85 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') |
|
85 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') | |
86 | } |
|
86 | } | |
87 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
87 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } | |
88 |
format.csv { send_data( |
|
88 | format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') } | |
89 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
|
89 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } | |
90 | end |
|
90 | end | |
91 | else |
|
91 | else | |
92 | respond_to do |format| |
|
92 | respond_to do |format| | |
93 | format.html { render(:template => 'issues/index', :layout => !request.xhr?) } |
|
93 | format.html { render(:template => 'issues/index', :layout => !request.xhr?) } | |
94 | format.any(:atom, :csv, :pdf) { render(:nothing => true) } |
|
94 | format.any(:atom, :csv, :pdf) { render(:nothing => true) } | |
95 | format.api { render_validation_errors(@query) } |
|
95 | format.api { render_validation_errors(@query) } | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 | rescue ActiveRecord::RecordNotFound |
|
98 | rescue ActiveRecord::RecordNotFound | |
99 | render_404 |
|
99 | render_404 | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def show |
|
102 | def show | |
103 | @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all |
|
103 | @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all | |
104 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
104 | @journals.each_with_index {|j,i| j.indice = i+1} | |
105 | @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) |
|
105 | @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) | |
106 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
106 | @journals.reverse! if User.current.wants_comments_in_reverse_order? | |
107 |
|
107 | |||
108 | @changesets = @issue.changesets.visible.all |
|
108 | @changesets = @issue.changesets.visible.all | |
109 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
109 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? | |
110 |
|
110 | |||
111 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
111 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } | |
112 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
112 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
113 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
113 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
114 | @priorities = IssuePriority.active |
|
114 | @priorities = IssuePriority.active | |
115 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
115 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | |
116 | respond_to do |format| |
|
116 | respond_to do |format| | |
117 | format.html { |
|
117 | format.html { | |
118 | retrieve_previous_and_next_issue_ids |
|
118 | retrieve_previous_and_next_issue_ids | |
119 | render :template => 'issues/show' |
|
119 | render :template => 'issues/show' | |
120 | } |
|
120 | } | |
121 | format.api |
|
121 | format.api | |
122 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } |
|
122 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } | |
123 | format.pdf { |
|
123 | format.pdf { | |
124 | pdf = issue_to_pdf(@issue, :journals => @journals) |
|
124 | pdf = issue_to_pdf(@issue, :journals => @journals) | |
125 | send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") |
|
125 | send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") | |
126 | } |
|
126 | } | |
127 | end |
|
127 | end | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | # Add a new issue |
|
130 | # Add a new issue | |
131 | # The new issue will be created from an existing one if copy_from parameter is given |
|
131 | # The new issue will be created from an existing one if copy_from parameter is given | |
132 | def new |
|
132 | def new | |
133 | respond_to do |format| |
|
133 | respond_to do |format| | |
134 | format.html { render :action => 'new', :layout => !request.xhr? } |
|
134 | format.html { render :action => 'new', :layout => !request.xhr? } | |
135 | end |
|
135 | end | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def create |
|
138 | def create | |
139 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
139 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) | |
140 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
140 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) | |
141 | if @issue.save |
|
141 | if @issue.save | |
142 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
142 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) | |
143 | respond_to do |format| |
|
143 | respond_to do |format| | |
144 | format.html { |
|
144 | format.html { | |
145 | render_attachment_warning_if_needed(@issue) |
|
145 | render_attachment_warning_if_needed(@issue) | |
146 | flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) |
|
146 | flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) | |
147 | if params[:continue] |
|
147 | if params[:continue] | |
148 | attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} |
|
148 | attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} | |
149 | redirect_to new_project_issue_path(@issue.project, :issue => attrs) |
|
149 | redirect_to new_project_issue_path(@issue.project, :issue => attrs) | |
150 | else |
|
150 | else | |
151 | redirect_to issue_path(@issue) |
|
151 | redirect_to issue_path(@issue) | |
152 | end |
|
152 | end | |
153 | } |
|
153 | } | |
154 | format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } |
|
154 | format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } | |
155 | end |
|
155 | end | |
156 | return |
|
156 | return | |
157 | else |
|
157 | else | |
158 | respond_to do |format| |
|
158 | respond_to do |format| | |
159 | format.html { render :action => 'new' } |
|
159 | format.html { render :action => 'new' } | |
160 | format.api { render_validation_errors(@issue) } |
|
160 | format.api { render_validation_errors(@issue) } | |
161 | end |
|
161 | end | |
162 | end |
|
162 | end | |
163 | end |
|
163 | end | |
164 |
|
164 | |||
165 | def edit |
|
165 | def edit | |
166 | return unless update_issue_from_params |
|
166 | return unless update_issue_from_params | |
167 |
|
167 | |||
168 | respond_to do |format| |
|
168 | respond_to do |format| | |
169 | format.html { } |
|
169 | format.html { } | |
170 | format.xml { } |
|
170 | format.xml { } | |
171 | end |
|
171 | end | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | def update |
|
174 | def update | |
175 | return unless update_issue_from_params |
|
175 | return unless update_issue_from_params | |
176 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
176 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) | |
177 | saved = false |
|
177 | saved = false | |
178 | begin |
|
178 | begin | |
179 | saved = @issue.save_issue_with_child_records(params, @time_entry) |
|
179 | saved = @issue.save_issue_with_child_records(params, @time_entry) | |
180 | rescue ActiveRecord::StaleObjectError |
|
180 | rescue ActiveRecord::StaleObjectError | |
181 | @conflict = true |
|
181 | @conflict = true | |
182 | if params[:last_journal_id] |
|
182 | if params[:last_journal_id] | |
183 | @conflict_journals = @issue.journals_after(params[:last_journal_id]).all |
|
183 | @conflict_journals = @issue.journals_after(params[:last_journal_id]).all | |
184 | @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) |
|
184 | @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) | |
185 | end |
|
185 | end | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 | if saved |
|
188 | if saved | |
189 | render_attachment_warning_if_needed(@issue) |
|
189 | render_attachment_warning_if_needed(@issue) | |
190 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
190 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? | |
191 |
|
191 | |||
192 | respond_to do |format| |
|
192 | respond_to do |format| | |
193 | format.html { redirect_back_or_default issue_path(@issue) } |
|
193 | format.html { redirect_back_or_default issue_path(@issue) } | |
194 | format.api { render_api_ok } |
|
194 | format.api { render_api_ok } | |
195 | end |
|
195 | end | |
196 | else |
|
196 | else | |
197 | respond_to do |format| |
|
197 | respond_to do |format| | |
198 | format.html { render :action => 'edit' } |
|
198 | format.html { render :action => 'edit' } | |
199 | format.api { render_validation_errors(@issue) } |
|
199 | format.api { render_validation_errors(@issue) } | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 | end |
|
202 | end | |
203 |
|
203 | |||
204 | # Updates the issue form when changing the project, status or tracker |
|
204 | # Updates the issue form when changing the project, status or tracker | |
205 | # on issue creation/update |
|
205 | # on issue creation/update | |
206 | def update_form |
|
206 | def update_form | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | # Bulk edit/copy a set of issues |
|
209 | # Bulk edit/copy a set of issues | |
210 | def bulk_edit |
|
210 | def bulk_edit | |
211 | @issues.sort! |
|
211 | @issues.sort! | |
212 | @copy = params[:copy].present? |
|
212 | @copy = params[:copy].present? | |
213 | @notes = params[:notes] |
|
213 | @notes = params[:notes] | |
214 |
|
214 | |||
215 | if User.current.allowed_to?(:move_issues, @projects) |
|
215 | if User.current.allowed_to?(:move_issues, @projects) | |
216 | @allowed_projects = Issue.allowed_target_projects_on_move |
|
216 | @allowed_projects = Issue.allowed_target_projects_on_move | |
217 | if params[:issue] |
|
217 | if params[:issue] | |
218 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} |
|
218 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} | |
219 | if @target_project |
|
219 | if @target_project | |
220 | target_projects = [@target_project] |
|
220 | target_projects = [@target_project] | |
221 | end |
|
221 | end | |
222 | end |
|
222 | end | |
223 | end |
|
223 | end | |
224 | target_projects ||= @projects |
|
224 | target_projects ||= @projects | |
225 |
|
225 | |||
226 | if @copy |
|
226 | if @copy | |
227 | @available_statuses = [IssueStatus.default] |
|
227 | @available_statuses = [IssueStatus.default] | |
228 | else |
|
228 | else | |
229 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) |
|
229 | @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | |
230 | end |
|
230 | end | |
231 | @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) |
|
231 | @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) | |
232 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
232 | @assignables = target_projects.map(&:assignable_users).reduce(:&) | |
233 | @trackers = target_projects.map(&:trackers).reduce(:&) |
|
233 | @trackers = target_projects.map(&:trackers).reduce(:&) | |
234 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
234 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) | |
235 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) |
|
235 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) | |
236 | if @copy |
|
236 | if @copy | |
237 | @attachments_present = @issues.detect {|i| i.attachments.any?}.present? |
|
237 | @attachments_present = @issues.detect {|i| i.attachments.any?}.present? | |
238 | @subtasks_present = @issues.detect {|i| !i.leaf?}.present? |
|
238 | @subtasks_present = @issues.detect {|i| !i.leaf?}.present? | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) |
|
241 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) | |
242 | render :layout => false if request.xhr? |
|
242 | render :layout => false if request.xhr? | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | def bulk_update |
|
245 | def bulk_update | |
246 | @issues.sort! |
|
246 | @issues.sort! | |
247 | @copy = params[:copy].present? |
|
247 | @copy = params[:copy].present? | |
248 | attributes = parse_params_for_bulk_issue_attributes(params) |
|
248 | attributes = parse_params_for_bulk_issue_attributes(params) | |
249 |
|
249 | |||
250 | unsaved_issue_ids = [] |
|
250 | unsaved_issue_ids = [] | |
251 | moved_issues = [] |
|
251 | moved_issues = [] | |
252 |
|
252 | |||
253 | if @copy && params[:copy_subtasks].present? |
|
253 | if @copy && params[:copy_subtasks].present? | |
254 | # Descendant issues will be copied with the parent task |
|
254 | # Descendant issues will be copied with the parent task | |
255 | # Don't copy them twice |
|
255 | # Don't copy them twice | |
256 | @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} |
|
256 | @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | @issues.each do |issue| |
|
259 | @issues.each do |issue| | |
260 | issue.reload |
|
260 | issue.reload | |
261 | if @copy |
|
261 | if @copy | |
262 | issue = issue.copy({}, |
|
262 | issue = issue.copy({}, | |
263 | :attachments => params[:copy_attachments].present?, |
|
263 | :attachments => params[:copy_attachments].present?, | |
264 | :subtasks => params[:copy_subtasks].present? |
|
264 | :subtasks => params[:copy_subtasks].present? | |
265 | ) |
|
265 | ) | |
266 | end |
|
266 | end | |
267 | journal = issue.init_journal(User.current, params[:notes]) |
|
267 | journal = issue.init_journal(User.current, params[:notes]) | |
268 | issue.safe_attributes = attributes |
|
268 | issue.safe_attributes = attributes | |
269 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
269 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) | |
270 | if issue.save |
|
270 | if issue.save | |
271 | moved_issues << issue |
|
271 | moved_issues << issue | |
272 | else |
|
272 | else | |
273 | # Keep unsaved issue ids to display them in flash error |
|
273 | # Keep unsaved issue ids to display them in flash error | |
274 | unsaved_issue_ids << issue.id |
|
274 | unsaved_issue_ids << issue.id | |
275 | end |
|
275 | end | |
276 | end |
|
276 | end | |
277 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) |
|
277 | set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) | |
278 |
|
278 | |||
279 | if params[:follow] |
|
279 | if params[:follow] | |
280 | if @issues.size == 1 && moved_issues.size == 1 |
|
280 | if @issues.size == 1 && moved_issues.size == 1 | |
281 | redirect_to issue_path(moved_issues.first) |
|
281 | redirect_to issue_path(moved_issues.first) | |
282 | elsif moved_issues.map(&:project).uniq.size == 1 |
|
282 | elsif moved_issues.map(&:project).uniq.size == 1 | |
283 | redirect_to project_issues_path(moved_issues.map(&:project).first) |
|
283 | redirect_to project_issues_path(moved_issues.map(&:project).first) | |
284 | end |
|
284 | end | |
285 | else |
|
285 | else | |
286 | redirect_back_or_default _project_issues_path(@project) |
|
286 | redirect_back_or_default _project_issues_path(@project) | |
287 | end |
|
287 | end | |
288 | end |
|
288 | end | |
289 |
|
289 | |||
290 | def destroy |
|
290 | def destroy | |
291 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
|
291 | @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f | |
292 | if @hours > 0 |
|
292 | if @hours > 0 | |
293 | case params[:todo] |
|
293 | case params[:todo] | |
294 | when 'destroy' |
|
294 | when 'destroy' | |
295 | # nothing to do |
|
295 | # nothing to do | |
296 | when 'nullify' |
|
296 | when 'nullify' | |
297 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) |
|
297 | TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) | |
298 | when 'reassign' |
|
298 | when 'reassign' | |
299 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
299 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) | |
300 | if reassign_to.nil? |
|
300 | if reassign_to.nil? | |
301 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
301 | flash.now[:error] = l(:error_issue_not_found_in_project) | |
302 | return |
|
302 | return | |
303 | else |
|
303 | else | |
304 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) |
|
304 | TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) | |
305 | end |
|
305 | end | |
306 | else |
|
306 | else | |
307 | # display the destroy form if it's a user request |
|
307 | # display the destroy form if it's a user request | |
308 | return unless api_request? |
|
308 | return unless api_request? | |
309 | end |
|
309 | end | |
310 | end |
|
310 | end | |
311 | @issues.each do |issue| |
|
311 | @issues.each do |issue| | |
312 | begin |
|
312 | begin | |
313 | issue.reload.destroy |
|
313 | issue.reload.destroy | |
314 | rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists |
|
314 | rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists | |
315 | # nothing to do, issue was already deleted (eg. by a parent) |
|
315 | # nothing to do, issue was already deleted (eg. by a parent) | |
316 | end |
|
316 | end | |
317 | end |
|
317 | end | |
318 | respond_to do |format| |
|
318 | respond_to do |format| | |
319 | format.html { redirect_back_or_default _project_issues_path(@project) } |
|
319 | format.html { redirect_back_or_default _project_issues_path(@project) } | |
320 | format.api { render_api_ok } |
|
320 | format.api { render_api_ok } | |
321 | end |
|
321 | end | |
322 | end |
|
322 | end | |
323 |
|
323 | |||
324 | private |
|
324 | private | |
325 |
|
325 | |||
326 | def find_project |
|
326 | def find_project | |
327 | project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) |
|
327 | project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) | |
328 | @project = Project.find(project_id) |
|
328 | @project = Project.find(project_id) | |
329 | rescue ActiveRecord::RecordNotFound |
|
329 | rescue ActiveRecord::RecordNotFound | |
330 | render_404 |
|
330 | render_404 | |
331 | end |
|
331 | end | |
332 |
|
332 | |||
333 | def retrieve_previous_and_next_issue_ids |
|
333 | def retrieve_previous_and_next_issue_ids | |
334 | retrieve_query_from_session |
|
334 | retrieve_query_from_session | |
335 | if @query |
|
335 | if @query | |
336 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
336 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) | |
337 | sort_update(@query.sortable_columns, 'issues_index_sort') |
|
337 | sort_update(@query.sortable_columns, 'issues_index_sort') | |
338 | limit = 500 |
|
338 | limit = 500 | |
339 | issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) |
|
339 | issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) | |
340 | if (idx = issue_ids.index(@issue.id)) && idx < limit |
|
340 | if (idx = issue_ids.index(@issue.id)) && idx < limit | |
341 | if issue_ids.size < 500 |
|
341 | if issue_ids.size < 500 | |
342 | @issue_position = idx + 1 |
|
342 | @issue_position = idx + 1 | |
343 | @issue_count = issue_ids.size |
|
343 | @issue_count = issue_ids.size | |
344 | end |
|
344 | end | |
345 | @prev_issue_id = issue_ids[idx - 1] if idx > 0 |
|
345 | @prev_issue_id = issue_ids[idx - 1] if idx > 0 | |
346 | @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) |
|
346 | @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) | |
347 | end |
|
347 | end | |
348 | end |
|
348 | end | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | # Used by #edit and #update to set some common instance variables |
|
351 | # Used by #edit and #update to set some common instance variables | |
352 | # from the params |
|
352 | # from the params | |
353 | # TODO: Refactor, not everything in here is needed by #edit |
|
353 | # TODO: Refactor, not everything in here is needed by #edit | |
354 | def update_issue_from_params |
|
354 | def update_issue_from_params | |
355 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
355 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
356 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
356 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | |
357 | @time_entry.attributes = params[:time_entry] |
|
357 | @time_entry.attributes = params[:time_entry] | |
358 |
|
358 | |||
359 | @issue.init_journal(User.current) |
|
359 | @issue.init_journal(User.current) | |
360 |
|
360 | |||
361 | issue_attributes = params[:issue] |
|
361 | issue_attributes = params[:issue] | |
362 | if issue_attributes && params[:conflict_resolution] |
|
362 | if issue_attributes && params[:conflict_resolution] | |
363 | case params[:conflict_resolution] |
|
363 | case params[:conflict_resolution] | |
364 | when 'overwrite' |
|
364 | when 'overwrite' | |
365 | issue_attributes = issue_attributes.dup |
|
365 | issue_attributes = issue_attributes.dup | |
366 | issue_attributes.delete(:lock_version) |
|
366 | issue_attributes.delete(:lock_version) | |
367 | when 'add_notes' |
|
367 | when 'add_notes' | |
368 | issue_attributes = issue_attributes.slice(:notes) |
|
368 | issue_attributes = issue_attributes.slice(:notes) | |
369 | when 'cancel' |
|
369 | when 'cancel' | |
370 | redirect_to issue_path(@issue) |
|
370 | redirect_to issue_path(@issue) | |
371 | return false |
|
371 | return false | |
372 | end |
|
372 | end | |
373 | end |
|
373 | end | |
374 | @issue.safe_attributes = issue_attributes |
|
374 | @issue.safe_attributes = issue_attributes | |
375 | @priorities = IssuePriority.active |
|
375 | @priorities = IssuePriority.active | |
376 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
376 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |
377 | true |
|
377 | true | |
378 | end |
|
378 | end | |
379 |
|
379 | |||
380 | # TODO: Refactor, lots of extra code in here |
|
380 | # TODO: Refactor, lots of extra code in here | |
381 | # TODO: Changing tracker on an existing issue should not trigger this |
|
381 | # TODO: Changing tracker on an existing issue should not trigger this | |
382 | def build_new_issue_from_params |
|
382 | def build_new_issue_from_params | |
383 | if params[:id].blank? |
|
383 | if params[:id].blank? | |
384 | @issue = Issue.new |
|
384 | @issue = Issue.new | |
385 | if params[:copy_from] |
|
385 | if params[:copy_from] | |
386 | begin |
|
386 | begin | |
387 | @copy_from = Issue.visible.find(params[:copy_from]) |
|
387 | @copy_from = Issue.visible.find(params[:copy_from]) | |
388 | @copy_attachments = params[:copy_attachments].present? || request.get? |
|
388 | @copy_attachments = params[:copy_attachments].present? || request.get? | |
389 | @copy_subtasks = params[:copy_subtasks].present? || request.get? |
|
389 | @copy_subtasks = params[:copy_subtasks].present? || request.get? | |
390 | @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks) |
|
390 | @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks) | |
391 | rescue ActiveRecord::RecordNotFound |
|
391 | rescue ActiveRecord::RecordNotFound | |
392 | render_404 |
|
392 | render_404 | |
393 | return |
|
393 | return | |
394 | end |
|
394 | end | |
395 | end |
|
395 | end | |
396 | @issue.project = @project |
|
396 | @issue.project = @project | |
397 | else |
|
397 | else | |
398 | @issue = @project.issues.visible.find(params[:id]) |
|
398 | @issue = @project.issues.visible.find(params[:id]) | |
399 | end |
|
399 | end | |
400 |
|
400 | |||
401 | @issue.project = @project |
|
401 | @issue.project = @project | |
402 | @issue.author ||= User.current |
|
402 | @issue.author ||= User.current | |
403 | # Tracker must be set before custom field values |
|
403 | # Tracker must be set before custom field values | |
404 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) |
|
404 | @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first) | |
405 | if @issue.tracker.nil? |
|
405 | if @issue.tracker.nil? | |
406 | render_error l(:error_no_tracker_in_project) |
|
406 | render_error l(:error_no_tracker_in_project) | |
407 | return false |
|
407 | return false | |
408 | end |
|
408 | end | |
409 | @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? |
|
409 | @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? | |
410 | @issue.safe_attributes = params[:issue] |
|
410 | @issue.safe_attributes = params[:issue] | |
411 |
|
411 | |||
412 | @priorities = IssuePriority.active |
|
412 | @priorities = IssuePriority.active | |
413 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) |
|
413 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true) | |
414 | @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq |
|
414 | @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq | |
415 | end |
|
415 | end | |
416 |
|
416 | |||
417 | def check_for_default_issue_status |
|
417 | def check_for_default_issue_status | |
418 | if IssueStatus.default.nil? |
|
418 | if IssueStatus.default.nil? | |
419 | render_error l(:error_no_default_issue_status) |
|
419 | render_error l(:error_no_default_issue_status) | |
420 | return false |
|
420 | return false | |
421 | end |
|
421 | end | |
422 | end |
|
422 | end | |
423 |
|
423 | |||
424 | def parse_params_for_bulk_issue_attributes(params) |
|
424 | def parse_params_for_bulk_issue_attributes(params) | |
425 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} |
|
425 | attributes = (params[:issue] || {}).reject {|k,v| v.blank?} | |
426 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
426 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | |
427 | if custom = attributes[:custom_field_values] |
|
427 | if custom = attributes[:custom_field_values] | |
428 | custom.reject! {|k,v| v.blank?} |
|
428 | custom.reject! {|k,v| v.blank?} | |
429 | custom.keys.each do |k| |
|
429 | custom.keys.each do |k| | |
430 | if custom[k].is_a?(Array) |
|
430 | if custom[k].is_a?(Array) | |
431 | custom[k] << '' if custom[k].delete('__none__') |
|
431 | custom[k] << '' if custom[k].delete('__none__') | |
432 | else |
|
432 | else | |
433 | custom[k] = '' if custom[k] == '__none__' |
|
433 | custom[k] = '' if custom[k] == '__none__' | |
434 | end |
|
434 | end | |
435 | end |
|
435 | end | |
436 | end |
|
436 | end | |
437 | attributes |
|
437 | attributes | |
438 | end |
|
438 | end | |
439 | end |
|
439 | end |
@@ -1,314 +1,314 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 TimelogController < ApplicationController |
|
18 | class TimelogController < ApplicationController | |
19 | menu_item :issues |
|
19 | menu_item :issues | |
20 |
|
20 | |||
21 | before_filter :find_project_for_new_time_entry, :only => [:create] |
|
21 | before_filter :find_project_for_new_time_entry, :only => [:create] | |
22 | before_filter :find_time_entry, :only => [:show, :edit, :update] |
|
22 | before_filter :find_time_entry, :only => [:show, :edit, :update] | |
23 | before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] |
|
23 | before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] | |
24 | before_filter :authorize, :except => [:new, :index, :report] |
|
24 | before_filter :authorize, :except => [:new, :index, :report] | |
25 |
|
25 | |||
26 | before_filter :find_optional_project, :only => [:index, :report] |
|
26 | before_filter :find_optional_project, :only => [:index, :report] | |
27 | before_filter :find_optional_project_for_new_time_entry, :only => [:new] |
|
27 | before_filter :find_optional_project_for_new_time_entry, :only => [:new] | |
28 | before_filter :authorize_global, :only => [:new, :index, :report] |
|
28 | before_filter :authorize_global, :only => [:new, :index, :report] | |
29 |
|
29 | |||
30 | accept_rss_auth :index |
|
30 | accept_rss_auth :index | |
31 | accept_api_auth :index, :show, :create, :update, :destroy |
|
31 | accept_api_auth :index, :show, :create, :update, :destroy | |
32 |
|
32 | |||
33 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
33 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
34 |
|
34 | |||
35 | helper :sort |
|
35 | helper :sort | |
36 | include SortHelper |
|
36 | include SortHelper | |
37 | helper :issues |
|
37 | helper :issues | |
38 | include TimelogHelper |
|
38 | include TimelogHelper | |
39 | helper :custom_fields |
|
39 | helper :custom_fields | |
40 | include CustomFieldsHelper |
|
40 | include CustomFieldsHelper | |
41 | helper :queries |
|
41 | helper :queries | |
42 | include QueriesHelper |
|
42 | include QueriesHelper | |
43 |
|
43 | |||
44 | def index |
|
44 | def index | |
45 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') |
|
45 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') | |
46 | scope = time_entry_scope |
|
46 | scope = time_entry_scope | |
47 |
|
47 | |||
48 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) |
|
48 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) | |
49 | sort_update(@query.sortable_columns) |
|
49 | sort_update(@query.sortable_columns) | |
50 |
|
50 | |||
51 | respond_to do |format| |
|
51 | respond_to do |format| | |
52 | format.html { |
|
52 | format.html { | |
53 | # Paginate results |
|
53 | # Paginate results | |
54 | @entry_count = scope.count |
|
54 | @entry_count = scope.count | |
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] |
|
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] | |
56 | @entries = scope.all( |
|
56 | @entries = scope.all( | |
57 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
57 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
58 | :order => sort_clause, |
|
58 | :order => sort_clause, | |
59 | :limit => @entry_pages.per_page, |
|
59 | :limit => @entry_pages.per_page, | |
60 | :offset => @entry_pages.offset |
|
60 | :offset => @entry_pages.offset | |
61 | ) |
|
61 | ) | |
62 | @total_hours = scope.sum(:hours).to_f |
|
62 | @total_hours = scope.sum(:hours).to_f | |
63 |
|
63 | |||
64 | render :layout => !request.xhr? |
|
64 | render :layout => !request.xhr? | |
65 | } |
|
65 | } | |
66 | format.api { |
|
66 | format.api { | |
67 | @entry_count = scope.count |
|
67 | @entry_count = scope.count | |
68 | @offset, @limit = api_offset_and_limit |
|
68 | @offset, @limit = api_offset_and_limit | |
69 | @entries = scope.all( |
|
69 | @entries = scope.all( | |
70 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
70 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
71 | :order => sort_clause, |
|
71 | :order => sort_clause, | |
72 | :limit => @limit, |
|
72 | :limit => @limit, | |
73 | :offset => @offset |
|
73 | :offset => @offset | |
74 | ) |
|
74 | ) | |
75 | } |
|
75 | } | |
76 | format.atom { |
|
76 | format.atom { | |
77 | entries = scope.all( |
|
77 | entries = scope.all( | |
78 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
78 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
79 | :order => "#{TimeEntry.table_name}.created_on DESC", |
|
79 | :order => "#{TimeEntry.table_name}.created_on DESC", | |
80 | :limit => Setting.feeds_limit.to_i |
|
80 | :limit => Setting.feeds_limit.to_i | |
81 | ) |
|
81 | ) | |
82 | render_feed(entries, :title => l(:label_spent_time)) |
|
82 | render_feed(entries, :title => l(:label_spent_time)) | |
83 | } |
|
83 | } | |
84 | format.csv { |
|
84 | format.csv { | |
85 | # Export all entries |
|
85 | # Export all entries | |
86 | @entries = scope.all( |
|
86 | @entries = scope.all( | |
87 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], |
|
87 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], | |
88 | :order => sort_clause |
|
88 | :order => sort_clause | |
89 | ) |
|
89 | ) | |
90 |
send_data( |
|
90 | send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') | |
91 | } |
|
91 | } | |
92 | end |
|
92 | end | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def report |
|
95 | def report | |
96 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') |
|
96 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') | |
97 | scope = time_entry_scope |
|
97 | scope = time_entry_scope | |
98 |
|
98 | |||
99 | @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope) |
|
99 | @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope) | |
100 |
|
100 | |||
101 | respond_to do |format| |
|
101 | respond_to do |format| | |
102 | format.html { render :layout => !request.xhr? } |
|
102 | format.html { render :layout => !request.xhr? } | |
103 | format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } |
|
103 | format.csv { send_data(report_to_csv(@report), :type => 'text/csv; header=present', :filename => 'timelog.csv') } | |
104 | end |
|
104 | end | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def show |
|
107 | def show | |
108 | respond_to do |format| |
|
108 | respond_to do |format| | |
109 | # TODO: Implement html response |
|
109 | # TODO: Implement html response | |
110 | format.html { render :nothing => true, :status => 406 } |
|
110 | format.html { render :nothing => true, :status => 406 } | |
111 | format.api |
|
111 | format.api | |
112 | end |
|
112 | end | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def new |
|
115 | def new | |
116 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
116 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
117 | @time_entry.safe_attributes = params[:time_entry] |
|
117 | @time_entry.safe_attributes = params[:time_entry] | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def create |
|
120 | def create | |
121 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
121 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) | |
122 | @time_entry.safe_attributes = params[:time_entry] |
|
122 | @time_entry.safe_attributes = params[:time_entry] | |
123 |
|
123 | |||
124 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
124 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
125 |
|
125 | |||
126 | if @time_entry.save |
|
126 | if @time_entry.save | |
127 | respond_to do |format| |
|
127 | respond_to do |format| | |
128 | format.html { |
|
128 | format.html { | |
129 | flash[:notice] = l(:notice_successful_create) |
|
129 | flash[:notice] = l(:notice_successful_create) | |
130 | if params[:continue] |
|
130 | if params[:continue] | |
131 | if params[:project_id] |
|
131 | if params[:project_id] | |
132 | options = { |
|
132 | options = { | |
133 | :time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id}, |
|
133 | :time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id}, | |
134 | :back_url => params[:back_url] |
|
134 | :back_url => params[:back_url] | |
135 | } |
|
135 | } | |
136 | if @time_entry.issue |
|
136 | if @time_entry.issue | |
137 | redirect_to new_project_issue_time_entry_path(@time_entry.project, @time_entry.issue, options) |
|
137 | redirect_to new_project_issue_time_entry_path(@time_entry.project, @time_entry.issue, options) | |
138 | else |
|
138 | else | |
139 | redirect_to new_project_time_entry_path(@time_entry.project, options) |
|
139 | redirect_to new_project_time_entry_path(@time_entry.project, options) | |
140 | end |
|
140 | end | |
141 | else |
|
141 | else | |
142 | options = { |
|
142 | options = { | |
143 | :time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id}, |
|
143 | :time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id}, | |
144 | :back_url => params[:back_url] |
|
144 | :back_url => params[:back_url] | |
145 | } |
|
145 | } | |
146 | redirect_to new_time_entry_path(options) |
|
146 | redirect_to new_time_entry_path(options) | |
147 | end |
|
147 | end | |
148 | else |
|
148 | else | |
149 | redirect_back_or_default project_time_entries_path(@time_entry.project) |
|
149 | redirect_back_or_default project_time_entries_path(@time_entry.project) | |
150 | end |
|
150 | end | |
151 | } |
|
151 | } | |
152 | format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } |
|
152 | format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } | |
153 | end |
|
153 | end | |
154 | else |
|
154 | else | |
155 | respond_to do |format| |
|
155 | respond_to do |format| | |
156 | format.html { render :action => 'new' } |
|
156 | format.html { render :action => 'new' } | |
157 | format.api { render_validation_errors(@time_entry) } |
|
157 | format.api { render_validation_errors(@time_entry) } | |
158 | end |
|
158 | end | |
159 | end |
|
159 | end | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | def edit |
|
162 | def edit | |
163 | @time_entry.safe_attributes = params[:time_entry] |
|
163 | @time_entry.safe_attributes = params[:time_entry] | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def update |
|
166 | def update | |
167 | @time_entry.safe_attributes = params[:time_entry] |
|
167 | @time_entry.safe_attributes = params[:time_entry] | |
168 |
|
168 | |||
169 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
|
169 | call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) | |
170 |
|
170 | |||
171 | if @time_entry.save |
|
171 | if @time_entry.save | |
172 | respond_to do |format| |
|
172 | respond_to do |format| | |
173 | format.html { |
|
173 | format.html { | |
174 | flash[:notice] = l(:notice_successful_update) |
|
174 | flash[:notice] = l(:notice_successful_update) | |
175 | redirect_back_or_default project_time_entries_path(@time_entry.project) |
|
175 | redirect_back_or_default project_time_entries_path(@time_entry.project) | |
176 | } |
|
176 | } | |
177 | format.api { render_api_ok } |
|
177 | format.api { render_api_ok } | |
178 | end |
|
178 | end | |
179 | else |
|
179 | else | |
180 | respond_to do |format| |
|
180 | respond_to do |format| | |
181 | format.html { render :action => 'edit' } |
|
181 | format.html { render :action => 'edit' } | |
182 | format.api { render_validation_errors(@time_entry) } |
|
182 | format.api { render_validation_errors(@time_entry) } | |
183 | end |
|
183 | end | |
184 | end |
|
184 | end | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def bulk_edit |
|
187 | def bulk_edit | |
188 | @available_activities = TimeEntryActivity.shared.active |
|
188 | @available_activities = TimeEntryActivity.shared.active | |
189 | @custom_fields = TimeEntry.first.available_custom_fields |
|
189 | @custom_fields = TimeEntry.first.available_custom_fields | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | def bulk_update |
|
192 | def bulk_update | |
193 | attributes = parse_params_for_bulk_time_entry_attributes(params) |
|
193 | attributes = parse_params_for_bulk_time_entry_attributes(params) | |
194 |
|
194 | |||
195 | unsaved_time_entry_ids = [] |
|
195 | unsaved_time_entry_ids = [] | |
196 | @time_entries.each do |time_entry| |
|
196 | @time_entries.each do |time_entry| | |
197 | time_entry.reload |
|
197 | time_entry.reload | |
198 | time_entry.safe_attributes = attributes |
|
198 | time_entry.safe_attributes = attributes | |
199 | call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry }) |
|
199 | call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry }) | |
200 | unless time_entry.save |
|
200 | unless time_entry.save | |
201 | # Keep unsaved time_entry ids to display them in flash error |
|
201 | # Keep unsaved time_entry ids to display them in flash error | |
202 | unsaved_time_entry_ids << time_entry.id |
|
202 | unsaved_time_entry_ids << time_entry.id | |
203 | end |
|
203 | end | |
204 | end |
|
204 | end | |
205 | set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids) |
|
205 | set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids) | |
206 | redirect_back_or_default project_time_entries_path(@projects.first) |
|
206 | redirect_back_or_default project_time_entries_path(@projects.first) | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | def destroy |
|
209 | def destroy | |
210 | destroyed = TimeEntry.transaction do |
|
210 | destroyed = TimeEntry.transaction do | |
211 | @time_entries.each do |t| |
|
211 | @time_entries.each do |t| | |
212 | unless t.destroy && t.destroyed? |
|
212 | unless t.destroy && t.destroyed? | |
213 | raise ActiveRecord::Rollback |
|
213 | raise ActiveRecord::Rollback | |
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | respond_to do |format| |
|
218 | respond_to do |format| | |
219 | format.html { |
|
219 | format.html { | |
220 | if destroyed |
|
220 | if destroyed | |
221 | flash[:notice] = l(:notice_successful_delete) |
|
221 | flash[:notice] = l(:notice_successful_delete) | |
222 | else |
|
222 | else | |
223 | flash[:error] = l(:notice_unable_delete_time_entry) |
|
223 | flash[:error] = l(:notice_unable_delete_time_entry) | |
224 | end |
|
224 | end | |
225 | redirect_back_or_default project_time_entries_path(@projects.first) |
|
225 | redirect_back_or_default project_time_entries_path(@projects.first) | |
226 | } |
|
226 | } | |
227 | format.api { |
|
227 | format.api { | |
228 | if destroyed |
|
228 | if destroyed | |
229 | render_api_ok |
|
229 | render_api_ok | |
230 | else |
|
230 | else | |
231 | render_validation_errors(@time_entries) |
|
231 | render_validation_errors(@time_entries) | |
232 | end |
|
232 | end | |
233 | } |
|
233 | } | |
234 | end |
|
234 | end | |
235 | end |
|
235 | end | |
236 |
|
236 | |||
237 | private |
|
237 | private | |
238 | def find_time_entry |
|
238 | def find_time_entry | |
239 | @time_entry = TimeEntry.find(params[:id]) |
|
239 | @time_entry = TimeEntry.find(params[:id]) | |
240 | unless @time_entry.editable_by?(User.current) |
|
240 | unless @time_entry.editable_by?(User.current) | |
241 | render_403 |
|
241 | render_403 | |
242 | return false |
|
242 | return false | |
243 | end |
|
243 | end | |
244 | @project = @time_entry.project |
|
244 | @project = @time_entry.project | |
245 | rescue ActiveRecord::RecordNotFound |
|
245 | rescue ActiveRecord::RecordNotFound | |
246 | render_404 |
|
246 | render_404 | |
247 | end |
|
247 | end | |
248 |
|
248 | |||
249 | def find_time_entries |
|
249 | def find_time_entries | |
250 | @time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids]) |
|
250 | @time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids]) | |
251 | raise ActiveRecord::RecordNotFound if @time_entries.empty? |
|
251 | raise ActiveRecord::RecordNotFound if @time_entries.empty? | |
252 | @projects = @time_entries.collect(&:project).compact.uniq |
|
252 | @projects = @time_entries.collect(&:project).compact.uniq | |
253 | @project = @projects.first if @projects.size == 1 |
|
253 | @project = @projects.first if @projects.size == 1 | |
254 | rescue ActiveRecord::RecordNotFound |
|
254 | rescue ActiveRecord::RecordNotFound | |
255 | render_404 |
|
255 | render_404 | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids) |
|
258 | def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids) | |
259 | if unsaved_time_entry_ids.empty? |
|
259 | if unsaved_time_entry_ids.empty? | |
260 | flash[:notice] = l(:notice_successful_update) unless time_entries.empty? |
|
260 | flash[:notice] = l(:notice_successful_update) unless time_entries.empty? | |
261 | else |
|
261 | else | |
262 | flash[:error] = l(:notice_failed_to_save_time_entries, |
|
262 | flash[:error] = l(:notice_failed_to_save_time_entries, | |
263 | :count => unsaved_time_entry_ids.size, |
|
263 | :count => unsaved_time_entry_ids.size, | |
264 | :total => time_entries.size, |
|
264 | :total => time_entries.size, | |
265 | :ids => '#' + unsaved_time_entry_ids.join(', #')) |
|
265 | :ids => '#' + unsaved_time_entry_ids.join(', #')) | |
266 | end |
|
266 | end | |
267 | end |
|
267 | end | |
268 |
|
268 | |||
269 | def find_optional_project_for_new_time_entry |
|
269 | def find_optional_project_for_new_time_entry | |
270 | if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present? |
|
270 | if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present? | |
271 | @project = Project.find(project_id) |
|
271 | @project = Project.find(project_id) | |
272 | end |
|
272 | end | |
273 | if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present? |
|
273 | if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present? | |
274 | @issue = Issue.find(issue_id) |
|
274 | @issue = Issue.find(issue_id) | |
275 | @project ||= @issue.project |
|
275 | @project ||= @issue.project | |
276 | end |
|
276 | end | |
277 | rescue ActiveRecord::RecordNotFound |
|
277 | rescue ActiveRecord::RecordNotFound | |
278 | render_404 |
|
278 | render_404 | |
279 | end |
|
279 | end | |
280 |
|
280 | |||
281 | def find_project_for_new_time_entry |
|
281 | def find_project_for_new_time_entry | |
282 | find_optional_project_for_new_time_entry |
|
282 | find_optional_project_for_new_time_entry | |
283 | if @project.nil? |
|
283 | if @project.nil? | |
284 | render_404 |
|
284 | render_404 | |
285 | end |
|
285 | end | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | def find_optional_project |
|
288 | def find_optional_project | |
289 | if !params[:issue_id].blank? |
|
289 | if !params[:issue_id].blank? | |
290 | @issue = Issue.find(params[:issue_id]) |
|
290 | @issue = Issue.find(params[:issue_id]) | |
291 | @project = @issue.project |
|
291 | @project = @issue.project | |
292 | elsif !params[:project_id].blank? |
|
292 | elsif !params[:project_id].blank? | |
293 | @project = Project.find(params[:project_id]) |
|
293 | @project = Project.find(params[:project_id]) | |
294 | end |
|
294 | end | |
295 | end |
|
295 | end | |
296 |
|
296 | |||
297 | # Returns the TimeEntry scope for index and report actions |
|
297 | # Returns the TimeEntry scope for index and report actions | |
298 | def time_entry_scope |
|
298 | def time_entry_scope | |
299 | scope = TimeEntry.visible.where(@query.statement) |
|
299 | scope = TimeEntry.visible.where(@query.statement) | |
300 | if @issue |
|
300 | if @issue | |
301 | scope = scope.on_issue(@issue) |
|
301 | scope = scope.on_issue(@issue) | |
302 | elsif @project |
|
302 | elsif @project | |
303 | scope = scope.on_project(@project, Setting.display_subprojects_issues?) |
|
303 | scope = scope.on_project(@project, Setting.display_subprojects_issues?) | |
304 | end |
|
304 | end | |
305 | scope |
|
305 | scope | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def parse_params_for_bulk_time_entry_attributes(params) |
|
308 | def parse_params_for_bulk_time_entry_attributes(params) | |
309 | attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?} |
|
309 | attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?} | |
310 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} |
|
310 | attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} | |
311 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] |
|
311 | attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] | |
312 | attributes |
|
312 | attributes | |
313 | end |
|
313 | end | |
314 | end |
|
314 | end |
@@ -1,393 +1,373 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module IssuesHelper |
|
20 | module IssuesHelper | |
21 | include ApplicationHelper |
|
21 | include ApplicationHelper | |
22 |
|
22 | |||
23 | def issue_list(issues, &block) |
|
23 | def issue_list(issues, &block) | |
24 | ancestors = [] |
|
24 | ancestors = [] | |
25 | issues.each do |issue| |
|
25 | issues.each do |issue| | |
26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
|
26 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) | |
27 | ancestors.pop |
|
27 | ancestors.pop | |
28 | end |
|
28 | end | |
29 | yield issue, ancestors.size |
|
29 | yield issue, ancestors.size | |
30 | ancestors << issue unless issue.leaf? |
|
30 | ancestors << issue unless issue.leaf? | |
31 | end |
|
31 | end | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | # Renders a HTML/CSS tooltip |
|
34 | # Renders a HTML/CSS tooltip | |
35 | # |
|
35 | # | |
36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
|
36 | # To use, a trigger div is needed. This is a div with the class of "tooltip" | |
37 | # that contains this method wrapped in a span with the class of "tip" |
|
37 | # that contains this method wrapped in a span with the class of "tip" | |
38 | # |
|
38 | # | |
39 | # <div class="tooltip"><%= link_to_issue(issue) %> |
|
39 | # <div class="tooltip"><%= link_to_issue(issue) %> | |
40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
|
40 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> | |
41 | # </div> |
|
41 | # </div> | |
42 | # |
|
42 | # | |
43 | def render_issue_tooltip(issue) |
|
43 | def render_issue_tooltip(issue) | |
44 | @cached_label_status ||= l(:field_status) |
|
44 | @cached_label_status ||= l(:field_status) | |
45 | @cached_label_start_date ||= l(:field_start_date) |
|
45 | @cached_label_start_date ||= l(:field_start_date) | |
46 | @cached_label_due_date ||= l(:field_due_date) |
|
46 | @cached_label_due_date ||= l(:field_due_date) | |
47 | @cached_label_assigned_to ||= l(:field_assigned_to) |
|
47 | @cached_label_assigned_to ||= l(:field_assigned_to) | |
48 | @cached_label_priority ||= l(:field_priority) |
|
48 | @cached_label_priority ||= l(:field_priority) | |
49 | @cached_label_project ||= l(:field_project) |
|
49 | @cached_label_project ||= l(:field_project) | |
50 |
|
50 | |||
51 | link_to_issue(issue) + "<br /><br />".html_safe + |
|
51 | link_to_issue(issue) + "<br /><br />".html_safe + | |
52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + |
|
52 | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe + | |
53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + |
|
53 | "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe + | |
54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + |
|
54 | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe + | |
55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + |
|
55 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe + | |
56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + |
|
56 | "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe + | |
57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe |
|
57 | "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def issue_heading(issue) |
|
60 | def issue_heading(issue) | |
61 | h("#{issue.tracker} ##{issue.id}") |
|
61 | h("#{issue.tracker} ##{issue.id}") | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def render_issue_subject_with_tree(issue) |
|
64 | def render_issue_subject_with_tree(issue) | |
65 | s = '' |
|
65 | s = '' | |
66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all |
|
66 | ancestors = issue.root? ? [] : issue.ancestors.visible.all | |
67 | ancestors.each do |ancestor| |
|
67 | ancestors.each do |ancestor| | |
68 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) |
|
68 | s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id))) | |
69 | end |
|
69 | end | |
70 | s << '<div>' |
|
70 | s << '<div>' | |
71 | subject = h(issue.subject) |
|
71 | subject = h(issue.subject) | |
72 | if issue.is_private? |
|
72 | if issue.is_private? | |
73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject |
|
73 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject | |
74 | end |
|
74 | end | |
75 | s << content_tag('h3', subject) |
|
75 | s << content_tag('h3', subject) | |
76 | s << '</div>' * (ancestors.size + 1) |
|
76 | s << '</div>' * (ancestors.size + 1) | |
77 | s.html_safe |
|
77 | s.html_safe | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def render_descendants_tree(issue) |
|
80 | def render_descendants_tree(issue) | |
81 | s = '<form><table class="list issues">' |
|
81 | s = '<form><table class="list issues">' | |
82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
|
82 | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| | |
83 | css = "issue issue-#{child.id} hascontextmenu" |
|
83 | css = "issue issue-#{child.id} hascontextmenu" | |
84 | css << " idnt idnt-#{level}" if level > 0 |
|
84 | css << " idnt idnt-#{level}" if level > 0 | |
85 | s << content_tag('tr', |
|
85 | s << content_tag('tr', | |
86 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + |
|
86 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') + | |
87 | content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + |
|
87 | content_tag('td', link_to_issue(child, :truncate => 60, :project => (issue.project_id != child.project_id)), :class => 'subject') + | |
88 | content_tag('td', h(child.status)) + |
|
88 | content_tag('td', h(child.status)) + | |
89 | content_tag('td', link_to_user(child.assigned_to)) + |
|
89 | content_tag('td', link_to_user(child.assigned_to)) + | |
90 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), |
|
90 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')), | |
91 | :class => css) |
|
91 | :class => css) | |
92 | end |
|
92 | end | |
93 | s << '</table></form>' |
|
93 | s << '</table></form>' | |
94 | s.html_safe |
|
94 | s.html_safe | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | # Returns a link for adding a new subtask to the given issue |
|
97 | # Returns a link for adding a new subtask to the given issue | |
98 | def link_to_new_subtask(issue) |
|
98 | def link_to_new_subtask(issue) | |
99 | attrs = { |
|
99 | attrs = { | |
100 | :tracker_id => issue.tracker, |
|
100 | :tracker_id => issue.tracker, | |
101 | :parent_issue_id => issue |
|
101 | :parent_issue_id => issue | |
102 | } |
|
102 | } | |
103 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) |
|
103 | link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | class IssueFieldsRows |
|
106 | class IssueFieldsRows | |
107 | include ActionView::Helpers::TagHelper |
|
107 | include ActionView::Helpers::TagHelper | |
108 |
|
108 | |||
109 | def initialize |
|
109 | def initialize | |
110 | @left = [] |
|
110 | @left = [] | |
111 | @right = [] |
|
111 | @right = [] | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
114 | def left(*args) |
|
114 | def left(*args) | |
115 | args.any? ? @left << cells(*args) : @left |
|
115 | args.any? ? @left << cells(*args) : @left | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def right(*args) |
|
118 | def right(*args) | |
119 | args.any? ? @right << cells(*args) : @right |
|
119 | args.any? ? @right << cells(*args) : @right | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def size |
|
122 | def size | |
123 | @left.size > @right.size ? @left.size : @right.size |
|
123 | @left.size > @right.size ? @left.size : @right.size | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def to_html |
|
126 | def to_html | |
127 | html = ''.html_safe |
|
127 | html = ''.html_safe | |
128 | blank = content_tag('th', '') + content_tag('td', '') |
|
128 | blank = content_tag('th', '') + content_tag('td', '') | |
129 | size.times do |i| |
|
129 | size.times do |i| | |
130 | left = @left[i] || blank |
|
130 | left = @left[i] || blank | |
131 | right = @right[i] || blank |
|
131 | right = @right[i] || blank | |
132 | html << content_tag('tr', left + right) |
|
132 | html << content_tag('tr', left + right) | |
133 | end |
|
133 | end | |
134 | html |
|
134 | html | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def cells(label, text, options={}) |
|
137 | def cells(label, text, options={}) | |
138 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) |
|
138 | content_tag('th', "#{label}:", options) + content_tag('td', text, options) | |
139 | end |
|
139 | end | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | def issue_fields_rows |
|
142 | def issue_fields_rows | |
143 | r = IssueFieldsRows.new |
|
143 | r = IssueFieldsRows.new | |
144 | yield r |
|
144 | yield r | |
145 | r.to_html |
|
145 | r.to_html | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def render_custom_fields_rows(issue) |
|
148 | def render_custom_fields_rows(issue) | |
149 | return if issue.custom_field_values.empty? |
|
149 | return if issue.custom_field_values.empty? | |
150 | ordered_values = [] |
|
150 | ordered_values = [] | |
151 | half = (issue.custom_field_values.size / 2.0).ceil |
|
151 | half = (issue.custom_field_values.size / 2.0).ceil | |
152 | half.times do |i| |
|
152 | half.times do |i| | |
153 | ordered_values << issue.custom_field_values[i] |
|
153 | ordered_values << issue.custom_field_values[i] | |
154 | ordered_values << issue.custom_field_values[i + half] |
|
154 | ordered_values << issue.custom_field_values[i + half] | |
155 | end |
|
155 | end | |
156 | s = "<tr>\n" |
|
156 | s = "<tr>\n" | |
157 | n = 0 |
|
157 | n = 0 | |
158 | ordered_values.compact.each do |value| |
|
158 | ordered_values.compact.each do |value| | |
159 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
|
159 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 | |
160 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" |
|
160 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n" | |
161 | n += 1 |
|
161 | n += 1 | |
162 | end |
|
162 | end | |
163 | s << "</tr>\n" |
|
163 | s << "</tr>\n" | |
164 | s.html_safe |
|
164 | s.html_safe | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def issues_destroy_confirmation_message(issues) |
|
167 | def issues_destroy_confirmation_message(issues) | |
168 | issues = [issues] unless issues.is_a?(Array) |
|
168 | issues = [issues] unless issues.is_a?(Array) | |
169 | message = l(:text_issues_destroy_confirmation) |
|
169 | message = l(:text_issues_destroy_confirmation) | |
170 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} |
|
170 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} | |
171 | if descendant_count > 0 |
|
171 | if descendant_count > 0 | |
172 | issues.each do |issue| |
|
172 | issues.each do |issue| | |
173 | next if issue.root? |
|
173 | next if issue.root? | |
174 | issues.each do |other_issue| |
|
174 | issues.each do |other_issue| | |
175 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
|
175 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) | |
176 | end |
|
176 | end | |
177 | end |
|
177 | end | |
178 | if descendant_count > 0 |
|
178 | if descendant_count > 0 | |
179 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
|
179 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 | message |
|
182 | message | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def sidebar_queries |
|
185 | def sidebar_queries | |
186 | unless @sidebar_queries |
|
186 | unless @sidebar_queries | |
187 | @sidebar_queries = IssueQuery.visible.all( |
|
187 | @sidebar_queries = IssueQuery.visible.all( | |
188 | :order => "#{Query.table_name}.name ASC", |
|
188 | :order => "#{Query.table_name}.name ASC", | |
189 | # Project specific queries and global queries |
|
189 | # Project specific queries and global queries | |
190 | :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) |
|
190 | :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) | |
191 | ) |
|
191 | ) | |
192 | end |
|
192 | end | |
193 | @sidebar_queries |
|
193 | @sidebar_queries | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def query_links(title, queries) |
|
196 | def query_links(title, queries) | |
197 | # links to #index on issues/show |
|
197 | # links to #index on issues/show | |
198 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params |
|
198 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params | |
199 |
|
199 | |||
200 | content_tag('h3', h(title)) + |
|
200 | content_tag('h3', h(title)) + | |
201 | queries.collect {|query| |
|
201 | queries.collect {|query| | |
202 | css = 'query' |
|
202 | css = 'query' | |
203 | css << ' selected' if query == @query |
|
203 | css << ' selected' if query == @query | |
204 | link_to(h(query.name), url_params.merge(:query_id => query), :class => css) |
|
204 | link_to(h(query.name), url_params.merge(:query_id => query), :class => css) | |
205 | }.join('<br />').html_safe |
|
205 | }.join('<br />').html_safe | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | def render_sidebar_queries |
|
208 | def render_sidebar_queries | |
209 | out = ''.html_safe |
|
209 | out = ''.html_safe | |
210 | queries = sidebar_queries.select {|q| !q.is_public?} |
|
210 | queries = sidebar_queries.select {|q| !q.is_public?} | |
211 | out << query_links(l(:label_my_queries), queries) if queries.any? |
|
211 | out << query_links(l(:label_my_queries), queries) if queries.any? | |
212 | queries = sidebar_queries.select {|q| q.is_public?} |
|
212 | queries = sidebar_queries.select {|q| q.is_public?} | |
213 | out << query_links(l(:label_query_plural), queries) if queries.any? |
|
213 | out << query_links(l(:label_query_plural), queries) if queries.any? | |
214 | out |
|
214 | out | |
215 | end |
|
215 | end | |
216 |
|
216 | |||
217 | # Returns the textual representation of a journal details |
|
217 | # Returns the textual representation of a journal details | |
218 | # as an array of strings |
|
218 | # as an array of strings | |
219 | def details_to_strings(details, no_html=false, options={}) |
|
219 | def details_to_strings(details, no_html=false, options={}) | |
220 | options[:only_path] = (options[:only_path] == false ? false : true) |
|
220 | options[:only_path] = (options[:only_path] == false ? false : true) | |
221 | strings = [] |
|
221 | strings = [] | |
222 | values_by_field = {} |
|
222 | values_by_field = {} | |
223 | details.each do |detail| |
|
223 | details.each do |detail| | |
224 | if detail.property == 'cf' |
|
224 | if detail.property == 'cf' | |
225 | field_id = detail.prop_key |
|
225 | field_id = detail.prop_key | |
226 | field = CustomField.find_by_id(field_id) |
|
226 | field = CustomField.find_by_id(field_id) | |
227 | if field && field.multiple? |
|
227 | if field && field.multiple? | |
228 | values_by_field[field_id] ||= {:added => [], :deleted => []} |
|
228 | values_by_field[field_id] ||= {:added => [], :deleted => []} | |
229 | if detail.old_value |
|
229 | if detail.old_value | |
230 | values_by_field[field_id][:deleted] << detail.old_value |
|
230 | values_by_field[field_id][:deleted] << detail.old_value | |
231 | end |
|
231 | end | |
232 | if detail.value |
|
232 | if detail.value | |
233 | values_by_field[field_id][:added] << detail.value |
|
233 | values_by_field[field_id][:added] << detail.value | |
234 | end |
|
234 | end | |
235 | next |
|
235 | next | |
236 | end |
|
236 | end | |
237 | end |
|
237 | end | |
238 | strings << show_detail(detail, no_html, options) |
|
238 | strings << show_detail(detail, no_html, options) | |
239 | end |
|
239 | end | |
240 | values_by_field.each do |field_id, changes| |
|
240 | values_by_field.each do |field_id, changes| | |
241 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) |
|
241 | detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) | |
242 | if changes[:added].any? |
|
242 | if changes[:added].any? | |
243 | detail.value = changes[:added] |
|
243 | detail.value = changes[:added] | |
244 | strings << show_detail(detail, no_html, options) |
|
244 | strings << show_detail(detail, no_html, options) | |
245 | elsif changes[:deleted].any? |
|
245 | elsif changes[:deleted].any? | |
246 | detail.old_value = changes[:deleted] |
|
246 | detail.old_value = changes[:deleted] | |
247 | strings << show_detail(detail, no_html, options) |
|
247 | strings << show_detail(detail, no_html, options) | |
248 | end |
|
248 | end | |
249 | end |
|
249 | end | |
250 | strings |
|
250 | strings | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
253 | # Returns the textual representation of a single journal detail |
|
253 | # Returns the textual representation of a single journal detail | |
254 | def show_detail(detail, no_html=false, options={}) |
|
254 | def show_detail(detail, no_html=false, options={}) | |
255 | multiple = false |
|
255 | multiple = false | |
256 | case detail.property |
|
256 | case detail.property | |
257 | when 'attr' |
|
257 | when 'attr' | |
258 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
|
258 | field = detail.prop_key.to_s.gsub(/\_id$/, "") | |
259 | label = l(("field_" + field).to_sym) |
|
259 | label = l(("field_" + field).to_sym) | |
260 | case detail.prop_key |
|
260 | case detail.prop_key | |
261 | when 'due_date', 'start_date' |
|
261 | when 'due_date', 'start_date' | |
262 | value = format_date(detail.value.to_date) if detail.value |
|
262 | value = format_date(detail.value.to_date) if detail.value | |
263 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
|
263 | old_value = format_date(detail.old_value.to_date) if detail.old_value | |
264 |
|
264 | |||
265 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', |
|
265 | when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id', | |
266 | 'priority_id', 'category_id', 'fixed_version_id' |
|
266 | 'priority_id', 'category_id', 'fixed_version_id' | |
267 | value = find_name_by_reflection(field, detail.value) |
|
267 | value = find_name_by_reflection(field, detail.value) | |
268 | old_value = find_name_by_reflection(field, detail.old_value) |
|
268 | old_value = find_name_by_reflection(field, detail.old_value) | |
269 |
|
269 | |||
270 | when 'estimated_hours' |
|
270 | when 'estimated_hours' | |
271 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
|
271 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? | |
272 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
|
272 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? | |
273 |
|
273 | |||
274 | when 'parent_id' |
|
274 | when 'parent_id' | |
275 | label = l(:field_parent_issue) |
|
275 | label = l(:field_parent_issue) | |
276 | value = "##{detail.value}" unless detail.value.blank? |
|
276 | value = "##{detail.value}" unless detail.value.blank? | |
277 | old_value = "##{detail.old_value}" unless detail.old_value.blank? |
|
277 | old_value = "##{detail.old_value}" unless detail.old_value.blank? | |
278 |
|
278 | |||
279 | when 'is_private' |
|
279 | when 'is_private' | |
280 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
|
280 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? | |
281 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
|
281 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? | |
282 | end |
|
282 | end | |
283 | when 'cf' |
|
283 | when 'cf' | |
284 | custom_field = CustomField.find_by_id(detail.prop_key) |
|
284 | custom_field = CustomField.find_by_id(detail.prop_key) | |
285 | if custom_field |
|
285 | if custom_field | |
286 | multiple = custom_field.multiple? |
|
286 | multiple = custom_field.multiple? | |
287 | label = custom_field.name |
|
287 | label = custom_field.name | |
288 | value = format_value(detail.value, custom_field.field_format) if detail.value |
|
288 | value = format_value(detail.value, custom_field.field_format) if detail.value | |
289 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
|
289 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value | |
290 | end |
|
290 | end | |
291 | when 'attachment' |
|
291 | when 'attachment' | |
292 | label = l(:label_attachment) |
|
292 | label = l(:label_attachment) | |
293 | end |
|
293 | end | |
294 | call_hook(:helper_issues_show_detail_after_setting, |
|
294 | call_hook(:helper_issues_show_detail_after_setting, | |
295 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) |
|
295 | {:detail => detail, :label => label, :value => value, :old_value => old_value }) | |
296 |
|
296 | |||
297 | label ||= detail.prop_key |
|
297 | label ||= detail.prop_key | |
298 | value ||= detail.value |
|
298 | value ||= detail.value | |
299 | old_value ||= detail.old_value |
|
299 | old_value ||= detail.old_value | |
300 |
|
300 | |||
301 | unless no_html |
|
301 | unless no_html | |
302 | label = content_tag('strong', label) |
|
302 | label = content_tag('strong', label) | |
303 | old_value = content_tag("i", h(old_value)) if detail.old_value |
|
303 | old_value = content_tag("i", h(old_value)) if detail.old_value | |
304 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? |
|
304 | old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? | |
305 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
|
305 | if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) | |
306 | # Link to the attachment if it has not been removed |
|
306 | # Link to the attachment if it has not been removed | |
307 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
|
307 | value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) | |
308 | if options[:only_path] != false && atta.is_text? |
|
308 | if options[:only_path] != false && atta.is_text? | |
309 | value += link_to( |
|
309 | value += link_to( | |
310 | image_tag('magnifier.png'), |
|
310 | image_tag('magnifier.png'), | |
311 | :controller => 'attachments', :action => 'show', |
|
311 | :controller => 'attachments', :action => 'show', | |
312 | :id => atta, :filename => atta.filename |
|
312 | :id => atta, :filename => atta.filename | |
313 | ) |
|
313 | ) | |
314 | end |
|
314 | end | |
315 | else |
|
315 | else | |
316 | value = content_tag("i", h(value)) if value |
|
316 | value = content_tag("i", h(value)) if value | |
317 | end |
|
317 | end | |
318 | end |
|
318 | end | |
319 |
|
319 | |||
320 | if detail.property == 'attr' && detail.prop_key == 'description' |
|
320 | if detail.property == 'attr' && detail.prop_key == 'description' | |
321 | s = l(:text_journal_changed_no_detail, :label => label) |
|
321 | s = l(:text_journal_changed_no_detail, :label => label) | |
322 | unless no_html |
|
322 | unless no_html | |
323 | diff_link = link_to 'diff', |
|
323 | diff_link = link_to 'diff', | |
324 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, |
|
324 | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, | |
325 | :detail_id => detail.id, :only_path => options[:only_path]}, |
|
325 | :detail_id => detail.id, :only_path => options[:only_path]}, | |
326 | :title => l(:label_view_diff) |
|
326 | :title => l(:label_view_diff) | |
327 | s << " (#{ diff_link })" |
|
327 | s << " (#{ diff_link })" | |
328 | end |
|
328 | end | |
329 | s.html_safe |
|
329 | s.html_safe | |
330 | elsif detail.value.present? |
|
330 | elsif detail.value.present? | |
331 | case detail.property |
|
331 | case detail.property | |
332 | when 'attr', 'cf' |
|
332 | when 'attr', 'cf' | |
333 | if detail.old_value.present? |
|
333 | if detail.old_value.present? | |
334 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe |
|
334 | l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe | |
335 | elsif multiple |
|
335 | elsif multiple | |
336 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
336 | l(:text_journal_added, :label => label, :value => value).html_safe | |
337 | else |
|
337 | else | |
338 | l(:text_journal_set_to, :label => label, :value => value).html_safe |
|
338 | l(:text_journal_set_to, :label => label, :value => value).html_safe | |
339 | end |
|
339 | end | |
340 | when 'attachment' |
|
340 | when 'attachment' | |
341 | l(:text_journal_added, :label => label, :value => value).html_safe |
|
341 | l(:text_journal_added, :label => label, :value => value).html_safe | |
342 | end |
|
342 | end | |
343 | else |
|
343 | else | |
344 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
|
344 | l(:text_journal_deleted, :label => label, :old => old_value).html_safe | |
345 | end |
|
345 | end | |
346 | end |
|
346 | end | |
347 |
|
347 | |||
348 | # Find the name of an associated record stored in the field attribute |
|
348 | # Find the name of an associated record stored in the field attribute | |
349 | def find_name_by_reflection(field, id) |
|
349 | def find_name_by_reflection(field, id) | |
350 | unless id.present? |
|
350 | unless id.present? | |
351 | return nil |
|
351 | return nil | |
352 | end |
|
352 | end | |
353 | association = Issue.reflect_on_association(field.to_sym) |
|
353 | association = Issue.reflect_on_association(field.to_sym) | |
354 | if association |
|
354 | if association | |
355 | record = association.class_name.constantize.find_by_id(id) |
|
355 | record = association.class_name.constantize.find_by_id(id) | |
356 | return record.name if record |
|
356 | return record.name if record | |
357 | end |
|
357 | end | |
358 | end |
|
358 | end | |
359 |
|
359 | |||
360 | # Renders issue children recursively |
|
360 | # Renders issue children recursively | |
361 | def render_api_issue_children(issue, api) |
|
361 | def render_api_issue_children(issue, api) | |
362 | return if issue.leaf? |
|
362 | return if issue.leaf? | |
363 | api.array :children do |
|
363 | api.array :children do | |
364 | issue.children.each do |child| |
|
364 | issue.children.each do |child| | |
365 | api.issue(:id => child.id) do |
|
365 | api.issue(:id => child.id) do | |
366 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
|
366 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? | |
367 | api.subject child.subject |
|
367 | api.subject child.subject | |
368 | render_api_issue_children(child, api) |
|
368 | render_api_issue_children(child, api) | |
369 | end |
|
369 | end | |
370 | end |
|
370 | end | |
371 | end |
|
371 | end | |
372 | end |
|
372 | end | |
373 |
|
||||
374 | def issues_to_csv(issues, project, query, options={}) |
|
|||
375 | encoding = l(:general_csv_encoding) |
|
|||
376 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) |
|
|||
377 | if options[:description] |
|
|||
378 | if description = query.available_columns.detect {|q| q.name == :description} |
|
|||
379 | columns << description |
|
|||
380 | end |
|
|||
381 | end |
|
|||
382 |
|
||||
383 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
|||
384 | # csv header fields |
|
|||
385 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } |
|
|||
386 | # csv lines |
|
|||
387 | issues.each do |issue| |
|
|||
388 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, issue), encoding) } |
|
|||
389 | end |
|
|||
390 | end |
|
|||
391 | export |
|
|||
392 | end |
|
|||
393 | end |
|
373 | end |
@@ -1,166 +1,186 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module QueriesHelper |
|
20 | module QueriesHelper | |
21 | def filters_options_for_select(query) |
|
21 | def filters_options_for_select(query) | |
22 | options_for_select(filters_options(query)) |
|
22 | options_for_select(filters_options(query)) | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | def filters_options(query) |
|
25 | def filters_options(query) | |
26 | options = [[]] |
|
26 | options = [[]] | |
27 | options += query.available_filters.map do |field, field_options| |
|
27 | options += query.available_filters.map do |field, field_options| | |
28 | [field_options[:name], field] |
|
28 | [field_options[:name], field] | |
29 | end |
|
29 | end | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def available_block_columns_tags(query) |
|
32 | def available_block_columns_tags(query) | |
33 | tags = ''.html_safe |
|
33 | tags = ''.html_safe | |
34 | query.available_block_columns.each do |column| |
|
34 | query.available_block_columns.each do |column| | |
35 | tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline') |
|
35 | tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline') | |
36 | end |
|
36 | end | |
37 | tags |
|
37 | tags | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def column_header(column) |
|
40 | def column_header(column) | |
41 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, |
|
41 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, | |
42 | :default_order => column.default_order) : |
|
42 | :default_order => column.default_order) : | |
43 | content_tag('th', h(column.caption)) |
|
43 | content_tag('th', h(column.caption)) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def column_content(column, issue) |
|
46 | def column_content(column, issue) | |
47 | value = column.value(issue) |
|
47 | value = column.value(issue) | |
48 | if value.is_a?(Array) |
|
48 | if value.is_a?(Array) | |
49 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe |
|
49 | value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe | |
50 | else |
|
50 | else | |
51 | column_value(column, issue, value) |
|
51 | column_value(column, issue, value) | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def column_value(column, issue, value) |
|
55 | def column_value(column, issue, value) | |
56 | case value.class.name |
|
56 | case value.class.name | |
57 | when 'String' |
|
57 | when 'String' | |
58 | if column.name == :subject |
|
58 | if column.name == :subject | |
59 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) |
|
59 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) | |
60 | elsif column.name == :description |
|
60 | elsif column.name == :description | |
61 | issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' |
|
61 | issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : '' | |
62 | else |
|
62 | else | |
63 | h(value) |
|
63 | h(value) | |
64 | end |
|
64 | end | |
65 | when 'Time' |
|
65 | when 'Time' | |
66 | format_time(value) |
|
66 | format_time(value) | |
67 | when 'Date' |
|
67 | when 'Date' | |
68 | format_date(value) |
|
68 | format_date(value) | |
69 | when 'Fixnum' |
|
69 | when 'Fixnum' | |
70 | if column.name == :id |
|
70 | if column.name == :id | |
71 | link_to value, issue_path(issue) |
|
71 | link_to value, issue_path(issue) | |
72 | elsif column.name == :done_ratio |
|
72 | elsif column.name == :done_ratio | |
73 | progress_bar(value, :width => '80px') |
|
73 | progress_bar(value, :width => '80px') | |
74 | else |
|
74 | else | |
75 | value.to_s |
|
75 | value.to_s | |
76 | end |
|
76 | end | |
77 | when 'Float' |
|
77 | when 'Float' | |
78 | sprintf "%.2f", value |
|
78 | sprintf "%.2f", value | |
79 | when 'User' |
|
79 | when 'User' | |
80 | link_to_user value |
|
80 | link_to_user value | |
81 | when 'Project' |
|
81 | when 'Project' | |
82 | link_to_project value |
|
82 | link_to_project value | |
83 | when 'Version' |
|
83 | when 'Version' | |
84 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) |
|
84 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) | |
85 | when 'TrueClass' |
|
85 | when 'TrueClass' | |
86 | l(:general_text_Yes) |
|
86 | l(:general_text_Yes) | |
87 | when 'FalseClass' |
|
87 | when 'FalseClass' | |
88 | l(:general_text_No) |
|
88 | l(:general_text_No) | |
89 | when 'Issue' |
|
89 | when 'Issue' | |
90 | value.visible? ? link_to_issue(value) : "##{value.id}" |
|
90 | value.visible? ? link_to_issue(value) : "##{value.id}" | |
91 | when 'IssueRelation' |
|
91 | when 'IssueRelation' | |
92 | other = value.other_issue(issue) |
|
92 | other = value.other_issue(issue) | |
93 | content_tag('span', |
|
93 | content_tag('span', | |
94 | (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, |
|
94 | (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe, | |
95 | :class => value.css_classes_for(issue)) |
|
95 | :class => value.css_classes_for(issue)) | |
96 | else |
|
96 | else | |
97 | h(value) |
|
97 | h(value) | |
98 | end |
|
98 | end | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | def csv_content(column, issue) |
|
101 | def csv_content(column, issue) | |
102 | value = column.value(issue) |
|
102 | value = column.value(issue) | |
103 | if value.is_a?(Array) |
|
103 | if value.is_a?(Array) | |
104 | value.collect {|v| csv_value(column, issue, v)}.compact.join(', ') |
|
104 | value.collect {|v| csv_value(column, issue, v)}.compact.join(', ') | |
105 | else |
|
105 | else | |
106 | csv_value(column, issue, value) |
|
106 | csv_value(column, issue, value) | |
107 | end |
|
107 | end | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def csv_value(column, issue, value) |
|
110 | def csv_value(column, issue, value) | |
111 | case value.class.name |
|
111 | case value.class.name | |
112 | when 'Time' |
|
112 | when 'Time' | |
113 | format_time(value) |
|
113 | format_time(value) | |
114 | when 'Date' |
|
114 | when 'Date' | |
115 | format_date(value) |
|
115 | format_date(value) | |
116 | when 'Float' |
|
116 | when 'Float' | |
117 | sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) |
|
117 | sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) | |
118 | when 'IssueRelation' |
|
118 | when 'IssueRelation' | |
119 | other = value.other_issue(issue) |
|
119 | other = value.other_issue(issue) | |
120 | l(value.label_for(issue)) + " ##{other.id}" |
|
120 | l(value.label_for(issue)) + " ##{other.id}" | |
121 | else |
|
121 | else | |
122 | value.to_s |
|
122 | value.to_s | |
123 | end |
|
123 | end | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
|
126 | def query_to_csv(items, query, options={}) | |||
|
127 | encoding = l(:general_csv_encoding) | |||
|
128 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) | |||
|
129 | query.available_block_columns.each do |column| | |||
|
130 | if options[column.name].present? | |||
|
131 | columns << column | |||
|
132 | end | |||
|
133 | end | |||
|
134 | ||||
|
135 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |||
|
136 | # csv header fields | |||
|
137 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } | |||
|
138 | # csv lines | |||
|
139 | items.each do |item| | |||
|
140 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) } | |||
|
141 | end | |||
|
142 | end | |||
|
143 | export | |||
|
144 | end | |||
|
145 | ||||
126 | # Retrieve query from session or build a new query |
|
146 | # Retrieve query from session or build a new query | |
127 | def retrieve_query |
|
147 | def retrieve_query | |
128 | if !params[:query_id].blank? |
|
148 | if !params[:query_id].blank? | |
129 | cond = "project_id IS NULL" |
|
149 | cond = "project_id IS NULL" | |
130 | cond << " OR project_id = #{@project.id}" if @project |
|
150 | cond << " OR project_id = #{@project.id}" if @project | |
131 | @query = IssueQuery.find(params[:query_id], :conditions => cond) |
|
151 | @query = IssueQuery.find(params[:query_id], :conditions => cond) | |
132 | raise ::Unauthorized unless @query.visible? |
|
152 | raise ::Unauthorized unless @query.visible? | |
133 | @query.project = @project |
|
153 | @query.project = @project | |
134 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
154 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
135 | sort_clear |
|
155 | sort_clear | |
136 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
156 | elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
137 | # Give it a name, required to be valid |
|
157 | # Give it a name, required to be valid | |
138 | @query = IssueQuery.new(:name => "_") |
|
158 | @query = IssueQuery.new(:name => "_") | |
139 | @query.project = @project |
|
159 | @query.project = @project | |
140 | @query.build_from_params(params) |
|
160 | @query.build_from_params(params) | |
141 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
161 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
142 | else |
|
162 | else | |
143 | # retrieve from session |
|
163 | # retrieve from session | |
144 | @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] |
|
164 | @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id] | |
145 | @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
165 | @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
146 | @query.project = @project |
|
166 | @query.project = @project | |
147 | end |
|
167 | end | |
148 | end |
|
168 | end | |
149 |
|
169 | |||
150 | def retrieve_query_from_session |
|
170 | def retrieve_query_from_session | |
151 | if session[:query] |
|
171 | if session[:query] | |
152 | if session[:query][:id] |
|
172 | if session[:query][:id] | |
153 | @query = IssueQuery.find_by_id(session[:query][:id]) |
|
173 | @query = IssueQuery.find_by_id(session[:query][:id]) | |
154 | return unless @query |
|
174 | return unless @query | |
155 | else |
|
175 | else | |
156 | @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
176 | @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
157 | end |
|
177 | end | |
158 | if session[:query].has_key?(:project_id) |
|
178 | if session[:query].has_key?(:project_id) | |
159 | @query.project_id = session[:query][:project_id] |
|
179 | @query.project_id = session[:query][:project_id] | |
160 | else |
|
180 | else | |
161 | @query.project = @project |
|
181 | @query.project = @project | |
162 | end |
|
182 | end | |
163 | @query |
|
183 | @query | |
164 | end |
|
184 | end | |
165 | end |
|
185 | end | |
166 | end |
|
186 | end |
@@ -1,169 +1,154 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module TimelogHelper |
|
20 | module TimelogHelper | |
21 | include ApplicationHelper |
|
21 | include ApplicationHelper | |
22 |
|
22 | |||
23 | def render_timelog_breadcrumb |
|
23 | def render_timelog_breadcrumb | |
24 | links = [] |
|
24 | links = [] | |
25 | links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil}) |
|
25 | links << link_to(l(:label_project_all), {:project_id => nil, :issue_id => nil}) | |
26 | links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project |
|
26 | links << link_to(h(@project), {:project_id => @project, :issue_id => nil}) if @project | |
27 | if @issue |
|
27 | if @issue | |
28 | if @issue.visible? |
|
28 | if @issue.visible? | |
29 | links << link_to_issue(@issue, :subject => false) |
|
29 | links << link_to_issue(@issue, :subject => false) | |
30 | else |
|
30 | else | |
31 | links << "##{@issue.id}" |
|
31 | links << "##{@issue.id}" | |
32 | end |
|
32 | end | |
33 | end |
|
33 | end | |
34 | breadcrumb links |
|
34 | breadcrumb links | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | # Returns a collection of activities for a select field. time_entry |
|
37 | # Returns a collection of activities for a select field. time_entry | |
38 | # is optional and will be used to check if the selected TimeEntryActivity |
|
38 | # is optional and will be used to check if the selected TimeEntryActivity | |
39 | # is active. |
|
39 | # is active. | |
40 | def activity_collection_for_select_options(time_entry=nil, project=nil) |
|
40 | def activity_collection_for_select_options(time_entry=nil, project=nil) | |
41 | project ||= @project |
|
41 | project ||= @project | |
42 | if project.nil? |
|
42 | if project.nil? | |
43 | activities = TimeEntryActivity.shared.active |
|
43 | activities = TimeEntryActivity.shared.active | |
44 | else |
|
44 | else | |
45 | activities = project.activities |
|
45 | activities = project.activities | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | collection = [] |
|
48 | collection = [] | |
49 | if time_entry && time_entry.activity && !time_entry.activity.active? |
|
49 | if time_entry && time_entry.activity && !time_entry.activity.active? | |
50 | collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] |
|
50 | collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] | |
51 | else |
|
51 | else | |
52 | collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default) |
|
52 | collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default) | |
53 | end |
|
53 | end | |
54 | activities.each { |a| collection << [a.name, a.id] } |
|
54 | activities.each { |a| collection << [a.name, a.id] } | |
55 | collection |
|
55 | collection | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def select_hours(data, criteria, value) |
|
58 | def select_hours(data, criteria, value) | |
59 | if value.to_s.empty? |
|
59 | if value.to_s.empty? | |
60 | data.select {|row| row[criteria].blank? } |
|
60 | data.select {|row| row[criteria].blank? } | |
61 | else |
|
61 | else | |
62 | data.select {|row| row[criteria].to_s == value.to_s} |
|
62 | data.select {|row| row[criteria].to_s == value.to_s} | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def sum_hours(data) |
|
66 | def sum_hours(data) | |
67 | sum = 0 |
|
67 | sum = 0 | |
68 | data.each do |row| |
|
68 | data.each do |row| | |
69 | sum += row['hours'].to_f |
|
69 | sum += row['hours'].to_f | |
70 | end |
|
70 | end | |
71 | sum |
|
71 | sum | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def options_for_period_select(value) |
|
74 | def options_for_period_select(value) | |
75 | options_for_select([[l(:label_all_time), 'all'], |
|
75 | options_for_select([[l(:label_all_time), 'all'], | |
76 | [l(:label_today), 'today'], |
|
76 | [l(:label_today), 'today'], | |
77 | [l(:label_yesterday), 'yesterday'], |
|
77 | [l(:label_yesterday), 'yesterday'], | |
78 | [l(:label_this_week), 'current_week'], |
|
78 | [l(:label_this_week), 'current_week'], | |
79 | [l(:label_last_week), 'last_week'], |
|
79 | [l(:label_last_week), 'last_week'], | |
80 | [l(:label_last_n_weeks, 2), 'last_2_weeks'], |
|
80 | [l(:label_last_n_weeks, 2), 'last_2_weeks'], | |
81 | [l(:label_last_n_days, 7), '7_days'], |
|
81 | [l(:label_last_n_days, 7), '7_days'], | |
82 | [l(:label_this_month), 'current_month'], |
|
82 | [l(:label_this_month), 'current_month'], | |
83 | [l(:label_last_month), 'last_month'], |
|
83 | [l(:label_last_month), 'last_month'], | |
84 | [l(:label_last_n_days, 30), '30_days'], |
|
84 | [l(:label_last_n_days, 30), '30_days'], | |
85 | [l(:label_this_year), 'current_year']], |
|
85 | [l(:label_this_year), 'current_year']], | |
86 | value) |
|
86 | value) | |
87 | end |
|
87 | end | |
88 |
|
88 | |||
89 | def entries_to_csv(entries, query, options={}) |
|
|||
90 | encoding = l(:general_csv_encoding) |
|
|||
91 | columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns) |
|
|||
92 |
|
||||
93 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
|||
94 | # csv header fields |
|
|||
95 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) } |
|
|||
96 | # csv lines |
|
|||
97 | entries.each do |entry| |
|
|||
98 | csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, entry), encoding) } |
|
|||
99 | end |
|
|||
100 | end |
|
|||
101 | export |
|
|||
102 | end |
|
|||
103 |
|
||||
104 | def format_criteria_value(criteria_options, value) |
|
89 | def format_criteria_value(criteria_options, value) | |
105 | if value.blank? |
|
90 | if value.blank? | |
106 | "[#{l(:label_none)}]" |
|
91 | "[#{l(:label_none)}]" | |
107 | elsif k = criteria_options[:klass] |
|
92 | elsif k = criteria_options[:klass] | |
108 | obj = k.find_by_id(value.to_i) |
|
93 | obj = k.find_by_id(value.to_i) | |
109 | if obj.is_a?(Issue) |
|
94 | if obj.is_a?(Issue) | |
110 | obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}" |
|
95 | obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}" | |
111 | else |
|
96 | else | |
112 | obj |
|
97 | obj | |
113 | end |
|
98 | end | |
114 | else |
|
99 | else | |
115 | format_value(value, criteria_options[:format]) |
|
100 | format_value(value, criteria_options[:format]) | |
116 | end |
|
101 | end | |
117 | end |
|
102 | end | |
118 |
|
103 | |||
119 | def report_to_csv(report) |
|
104 | def report_to_csv(report) | |
120 | decimal_separator = l(:general_csv_decimal_separator) |
|
105 | decimal_separator = l(:general_csv_decimal_separator) | |
121 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
106 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |
122 | # Column headers |
|
107 | # Column headers | |
123 | headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) } |
|
108 | headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) } | |
124 | headers += report.periods |
|
109 | headers += report.periods | |
125 | headers << l(:label_total) |
|
110 | headers << l(:label_total) | |
126 | csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( |
|
111 | csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( | |
127 | c.to_s, |
|
112 | c.to_s, | |
128 | l(:general_csv_encoding) ) } |
|
113 | l(:general_csv_encoding) ) } | |
129 | # Content |
|
114 | # Content | |
130 | report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours) |
|
115 | report_criteria_to_csv(csv, report.available_criteria, report.columns, report.criteria, report.periods, report.hours) | |
131 | # Total row |
|
116 | # Total row | |
132 | str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding)) |
|
117 | str_total = Redmine::CodesetUtil.from_utf8(l(:label_total), l(:general_csv_encoding)) | |
133 | row = [ str_total ] + [''] * (report.criteria.size - 1) |
|
118 | row = [ str_total ] + [''] * (report.criteria.size - 1) | |
134 | total = 0 |
|
119 | total = 0 | |
135 | report.periods.each do |period| |
|
120 | report.periods.each do |period| | |
136 | sum = sum_hours(select_hours(report.hours, report.columns, period.to_s)) |
|
121 | sum = sum_hours(select_hours(report.hours, report.columns, period.to_s)) | |
137 | total += sum |
|
122 | total += sum | |
138 | row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') |
|
123 | row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') | |
139 | end |
|
124 | end | |
140 | row << ("%.2f" % total).gsub('.',decimal_separator) |
|
125 | row << ("%.2f" % total).gsub('.',decimal_separator) | |
141 | csv << row |
|
126 | csv << row | |
142 | end |
|
127 | end | |
143 | export |
|
128 | export | |
144 | end |
|
129 | end | |
145 |
|
130 | |||
146 | def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0) |
|
131 | def report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours, level=0) | |
147 | decimal_separator = l(:general_csv_decimal_separator) |
|
132 | decimal_separator = l(:general_csv_decimal_separator) | |
148 | hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value| |
|
133 | hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value| | |
149 | hours_for_value = select_hours(hours, criteria[level], value) |
|
134 | hours_for_value = select_hours(hours, criteria[level], value) | |
150 | next if hours_for_value.empty? |
|
135 | next if hours_for_value.empty? | |
151 | row = [''] * level |
|
136 | row = [''] * level | |
152 | row << Redmine::CodesetUtil.from_utf8( |
|
137 | row << Redmine::CodesetUtil.from_utf8( | |
153 | format_criteria_value(available_criteria[criteria[level]], value).to_s, |
|
138 | format_criteria_value(available_criteria[criteria[level]], value).to_s, | |
154 | l(:general_csv_encoding) ) |
|
139 | l(:general_csv_encoding) ) | |
155 | row += [''] * (criteria.length - level - 1) |
|
140 | row += [''] * (criteria.length - level - 1) | |
156 | total = 0 |
|
141 | total = 0 | |
157 | periods.each do |period| |
|
142 | periods.each do |period| | |
158 | sum = sum_hours(select_hours(hours_for_value, columns, period.to_s)) |
|
143 | sum = sum_hours(select_hours(hours_for_value, columns, period.to_s)) | |
159 | total += sum |
|
144 | total += sum | |
160 | row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') |
|
145 | row << (sum > 0 ? ("%.2f" % sum).gsub('.',decimal_separator) : '') | |
161 | end |
|
146 | end | |
162 | row << ("%.2f" % total).gsub('.',decimal_separator) |
|
147 | row << ("%.2f" % total).gsub('.',decimal_separator) | |
163 | csv << row |
|
148 | csv << row | |
164 | if criteria.length > level + 1 |
|
149 | if criteria.length > level + 1 | |
165 | report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1) |
|
150 | report_criteria_to_csv(csv, available_criteria, columns, criteria, periods, hours_for_value, level + 1) | |
166 | end |
|
151 | end | |
167 | end |
|
152 | end | |
168 | end |
|
153 | end | |
169 | end |
|
154 | end |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now