##// END OF EJS Templates
Moves relations fetching from views to the controller and skip invalid relations (#7385)....
Jean-Philippe Lang -
r4621:b8dee485ca04
parent child
Show More
@@ -1,318 +1,319
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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, :move, :perform_move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
25 before_filter :find_project, :only => [:new, :create]
25 before_filter :find_project, :only => [:new, :create]
26 before_filter :authorize, :except => [:index]
26 before_filter :authorize, :except => [:index]
27 before_filter :find_optional_project, :only => [:index]
27 before_filter :find_optional_project, :only => [:index]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
30 accept_key_auth :index, :show, :create, :update, :destroy
30 accept_key_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 helper :gantt
53 helper :gantt
54 include Redmine::Export::PDF
54 include Redmine::Export::PDF
55
55
56 verify :method => [:post, :delete],
56 verify :method => [:post, :delete],
57 :only => :destroy,
57 :only => :destroy,
58 :render => { :nothing => true, :status => :method_not_allowed }
58 :render => { :nothing => true, :status => :method_not_allowed }
59
59
60 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
60 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
61 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
61 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
62 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
62 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
63
63
64 def index
64 def index
65 retrieve_query
65 retrieve_query
66 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
66 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
67 sort_update(@query.sortable_columns)
67 sort_update(@query.sortable_columns)
68
68
69 if @query.valid?
69 if @query.valid?
70 case params[:format]
70 case params[:format]
71 when 'csv', 'pdf'
71 when 'csv', 'pdf'
72 @limit = Setting.issues_export_limit.to_i
72 @limit = Setting.issues_export_limit.to_i
73 when 'atom'
73 when 'atom'
74 @limit = Setting.feeds_limit.to_i
74 @limit = Setting.feeds_limit.to_i
75 when 'xml', 'json'
75 when 'xml', 'json'
76 @offset, @limit = api_offset_and_limit
76 @offset, @limit = api_offset_and_limit
77 else
77 else
78 @limit = per_page_option
78 @limit = per_page_option
79 end
79 end
80
80
81 @issue_count = @query.issue_count
81 @issue_count = @query.issue_count
82 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
82 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
83 @offset ||= @issue_pages.current.offset
83 @offset ||= @issue_pages.current.offset
84 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
84 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
85 :order => sort_clause,
85 :order => sort_clause,
86 :offset => @offset,
86 :offset => @offset,
87 :limit => @limit)
87 :limit => @limit)
88 @issue_count_by_group = @query.issue_count_by_group
88 @issue_count_by_group = @query.issue_count_by_group
89
89
90 respond_to do |format|
90 respond_to do |format|
91 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
91 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
92 format.api
92 format.api
93 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
93 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
94 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
94 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
95 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
95 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
96 end
96 end
97 else
97 else
98 # Send html if the query is not valid
98 # Send html if the query is not valid
99 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
99 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
100 end
100 end
101 rescue ActiveRecord::RecordNotFound
101 rescue ActiveRecord::RecordNotFound
102 render_404
102 render_404
103 end
103 end
104
104
105 def show
105 def show
106 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
106 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
107 @journals.each_with_index {|j,i| j.indice = i+1}
107 @journals.each_with_index {|j,i| j.indice = i+1}
108 @journals.reverse! if User.current.wants_comments_in_reverse_order?
108 @journals.reverse! if User.current.wants_comments_in_reverse_order?
109 @changesets = @issue.changesets.visible.all
109 @changesets = @issue.changesets.visible.all
110 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
110 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
111 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
112 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
113 @priorities = IssuePriority.all
114 @priorities = IssuePriority.all
114 @time_entry = TimeEntry.new
115 @time_entry = TimeEntry.new
115 respond_to do |format|
116 respond_to do |format|
116 format.html { render :template => 'issues/show.rhtml' }
117 format.html { render :template => 'issues/show.rhtml' }
117 format.api
118 format.api
118 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
119 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
119 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
120 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
120 end
121 end
121 end
122 end
122
123
123 # Add a new issue
124 # Add a new issue
124 # The new issue will be created from an existing one if copy_from parameter is given
125 # The new issue will be created from an existing one if copy_from parameter is given
125 def new
126 def new
126 respond_to do |format|
127 respond_to do |format|
127 format.html { render :action => 'new', :layout => !request.xhr? }
128 format.html { render :action => 'new', :layout => !request.xhr? }
128 format.js { render :partial => 'attributes' }
129 format.js { render :partial => 'attributes' }
129 end
130 end
130 end
131 end
131
132
132 def create
133 def create
133 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
134 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
134 if @issue.save
135 if @issue.save
135 attachments = Attachment.attach_files(@issue, params[:attachments])
136 attachments = Attachment.attach_files(@issue, params[:attachments])
136 render_attachment_warning_if_needed(@issue)
137 render_attachment_warning_if_needed(@issue)
137 flash[:notice] = l(:notice_successful_create)
138 flash[:notice] = l(:notice_successful_create)
138 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
139 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
139 respond_to do |format|
140 respond_to do |format|
140 format.html {
141 format.html {
141 redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
142 redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
142 { :action => 'show', :id => @issue })
143 { :action => 'show', :id => @issue })
143 }
144 }
144 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
145 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
145 end
146 end
146 return
147 return
147 else
148 else
148 respond_to do |format|
149 respond_to do |format|
149 format.html { render :action => 'new' }
150 format.html { render :action => 'new' }
150 format.api { render_validation_errors(@issue) }
151 format.api { render_validation_errors(@issue) }
151 end
152 end
152 end
153 end
153 end
154 end
154
155
155 def edit
156 def edit
156 update_issue_from_params
157 update_issue_from_params
157
158
158 @journal = @issue.current_journal
159 @journal = @issue.current_journal
159
160
160 respond_to do |format|
161 respond_to do |format|
161 format.html { }
162 format.html { }
162 format.xml { }
163 format.xml { }
163 end
164 end
164 end
165 end
165
166
166 def update
167 def update
167 update_issue_from_params
168 update_issue_from_params
168
169
169 if @issue.save_issue_with_child_records(params, @time_entry)
170 if @issue.save_issue_with_child_records(params, @time_entry)
170 render_attachment_warning_if_needed(@issue)
171 render_attachment_warning_if_needed(@issue)
171 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
172 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
172
173
173 respond_to do |format|
174 respond_to do |format|
174 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
175 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
175 format.api { head :ok }
176 format.api { head :ok }
176 end
177 end
177 else
178 else
178 render_attachment_warning_if_needed(@issue)
179 render_attachment_warning_if_needed(@issue)
179 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
180 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
180 @journal = @issue.current_journal
181 @journal = @issue.current_journal
181
182
182 respond_to do |format|
183 respond_to do |format|
183 format.html { render :action => 'edit' }
184 format.html { render :action => 'edit' }
184 format.api { render_validation_errors(@issue) }
185 format.api { render_validation_errors(@issue) }
185 end
186 end
186 end
187 end
187 end
188 end
188
189
189 # Bulk edit a set of issues
190 # Bulk edit a set of issues
190 def bulk_edit
191 def bulk_edit
191 @issues.sort!
192 @issues.sort!
192 @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
193 @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
193 @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
194 @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
194 @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
195 @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
195 @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
196 @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
196 end
197 end
197
198
198 def bulk_update
199 def bulk_update
199 @issues.sort!
200 @issues.sort!
200 attributes = parse_params_for_bulk_issue_attributes(params)
201 attributes = parse_params_for_bulk_issue_attributes(params)
201
202
202 unsaved_issue_ids = []
203 unsaved_issue_ids = []
203 @issues.each do |issue|
204 @issues.each do |issue|
204 issue.reload
205 issue.reload
205 journal = issue.init_journal(User.current, params[:notes])
206 journal = issue.init_journal(User.current, params[:notes])
206 issue.safe_attributes = attributes
207 issue.safe_attributes = attributes
207 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
208 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
208 unless issue.save
209 unless issue.save
209 # Keep unsaved issue ids to display them in flash error
210 # Keep unsaved issue ids to display them in flash error
210 unsaved_issue_ids << issue.id
211 unsaved_issue_ids << issue.id
211 end
212 end
212 end
213 end
213 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
214 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
214 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
215 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
215 end
216 end
216
217
217 def destroy
218 def destroy
218 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
219 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
219 if @hours > 0
220 if @hours > 0
220 case params[:todo]
221 case params[:todo]
221 when 'destroy'
222 when 'destroy'
222 # nothing to do
223 # nothing to do
223 when 'nullify'
224 when 'nullify'
224 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
225 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
225 when 'reassign'
226 when 'reassign'
226 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
227 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
227 if reassign_to.nil?
228 if reassign_to.nil?
228 flash.now[:error] = l(:error_issue_not_found_in_project)
229 flash.now[:error] = l(:error_issue_not_found_in_project)
229 return
230 return
230 else
231 else
231 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
232 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
232 end
233 end
233 else
234 else
234 # display the destroy form if it's a user request
235 # display the destroy form if it's a user request
235 return unless api_request?
236 return unless api_request?
236 end
237 end
237 end
238 end
238 @issues.each(&:destroy)
239 @issues.each(&:destroy)
239 respond_to do |format|
240 respond_to do |format|
240 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
241 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
241 format.api { head :ok }
242 format.api { head :ok }
242 end
243 end
243 end
244 end
244
245
245 private
246 private
246 def find_issue
247 def find_issue
247 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
248 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
248 @project = @issue.project
249 @project = @issue.project
249 rescue ActiveRecord::RecordNotFound
250 rescue ActiveRecord::RecordNotFound
250 render_404
251 render_404
251 end
252 end
252
253
253 def find_project
254 def find_project
254 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
255 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
255 @project = Project.find(project_id)
256 @project = Project.find(project_id)
256 rescue ActiveRecord::RecordNotFound
257 rescue ActiveRecord::RecordNotFound
257 render_404
258 render_404
258 end
259 end
259
260
260 # Used by #edit and #update to set some common instance variables
261 # Used by #edit and #update to set some common instance variables
261 # from the params
262 # from the params
262 # TODO: Refactor, not everything in here is needed by #edit
263 # TODO: Refactor, not everything in here is needed by #edit
263 def update_issue_from_params
264 def update_issue_from_params
264 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
265 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
265 @priorities = IssuePriority.all
266 @priorities = IssuePriority.all
266 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
267 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
267 @time_entry = TimeEntry.new
268 @time_entry = TimeEntry.new
268 @time_entry.attributes = params[:time_entry]
269 @time_entry.attributes = params[:time_entry]
269
270
270 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
271 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
271 @issue.init_journal(User.current, @notes)
272 @issue.init_journal(User.current, @notes)
272 @issue.safe_attributes = params[:issue]
273 @issue.safe_attributes = params[:issue]
273 end
274 end
274
275
275 # TODO: Refactor, lots of extra code in here
276 # TODO: Refactor, lots of extra code in here
276 # TODO: Changing tracker on an existing issue should not trigger this
277 # TODO: Changing tracker on an existing issue should not trigger this
277 def build_new_issue_from_params
278 def build_new_issue_from_params
278 if params[:id].blank?
279 if params[:id].blank?
279 @issue = Issue.new
280 @issue = Issue.new
280 @issue.copy_from(params[:copy_from]) if params[:copy_from]
281 @issue.copy_from(params[:copy_from]) if params[:copy_from]
281 @issue.project = @project
282 @issue.project = @project
282 else
283 else
283 @issue = @project.issues.visible.find(params[:id])
284 @issue = @project.issues.visible.find(params[:id])
284 end
285 end
285
286
286 @issue.project = @project
287 @issue.project = @project
287 # Tracker must be set before custom field values
288 # Tracker must be set before custom field values
288 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
289 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
289 if @issue.tracker.nil?
290 if @issue.tracker.nil?
290 render_error l(:error_no_tracker_in_project)
291 render_error l(:error_no_tracker_in_project)
291 return false
292 return false
292 end
293 end
293 @issue.start_date ||= Date.today
294 @issue.start_date ||= Date.today
294 if params[:issue].is_a?(Hash)
295 if params[:issue].is_a?(Hash)
295 @issue.safe_attributes = params[:issue]
296 @issue.safe_attributes = params[:issue]
296 if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
297 if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
297 @issue.watcher_user_ids = params[:issue]['watcher_user_ids']
298 @issue.watcher_user_ids = params[:issue]['watcher_user_ids']
298 end
299 end
299 end
300 end
300 @issue.author = User.current
301 @issue.author = User.current
301 @priorities = IssuePriority.all
302 @priorities = IssuePriority.all
302 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
303 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
303 end
304 end
304
305
305 def check_for_default_issue_status
306 def check_for_default_issue_status
306 if IssueStatus.default.nil?
307 if IssueStatus.default.nil?
307 render_error l(:error_no_default_issue_status)
308 render_error l(:error_no_default_issue_status)
308 return false
309 return false
309 end
310 end
310 end
311 end
311
312
312 def parse_params_for_bulk_issue_attributes(params)
313 def parse_params_for_bulk_issue_attributes(params)
313 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
314 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
314 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
315 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
315 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
316 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
316 attributes
317 attributes
317 end
318 end
318 end
319 end
@@ -1,34 +1,34
1 <div class="contextual">
1 <div class="contextual">
2 <% if authorize_for('issue_relations', 'new') %>
2 <% if authorize_for('issue_relations', 'new') %>
3 <%= toggle_link l(:button_add), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>
3 <%= toggle_link l(:button_add), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>
4 <% end %>
4 <% end %>
5 </div>
5 </div>
6
6
7 <p><strong><%=l(:label_related_issues)%></strong></p>
7 <p><strong><%=l(:label_related_issues)%></strong></p>
8
8
9 <% if @issue.relations.any? %>
9 <% if @relations.present? %>
10 <table style="width:100%">
10 <table style="width:100%">
11 <% @issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation| %>
11 <% @relations.each do |relation| %>
12 <tr>
12 <tr>
13 <td><%= l(relation.label_for(@issue)) %> <%= "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)})" if relation.delay && relation.delay != 0 %>
13 <td><%= l(relation.label_for(@issue)) %> <%= "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)})" if relation.delay && relation.delay != 0 %>
14 <%= h(relation.other_issue(@issue).project) + ' - ' if Setting.cross_project_issue_relations? %>
14 <%= h(relation.other_issue(@issue).project) + ' - ' if Setting.cross_project_issue_relations? %>
15 <%= link_to_issue(relation.other_issue(@issue), :truncate => 60) %>
15 <%= link_to_issue(relation.other_issue(@issue), :truncate => 60) %>
16 </td>
16 </td>
17 <td><%= relation.other_issue(@issue).status.name %></td>
17 <td><%= relation.other_issue(@issue).status.name %></td>
18 <td><%= format_date(relation.other_issue(@issue).start_date) %></td>
18 <td><%= format_date(relation.other_issue(@issue).start_date) %></td>
19 <td><%= format_date(relation.other_issue(@issue).due_date) %></td>
19 <td><%= format_date(relation.other_issue(@issue).due_date) %></td>
20 <td><%= link_to_remote(image_tag('delete.png'), { :url => {:controller => 'issue_relations', :action => 'destroy', :issue_id => @issue, :id => relation},
20 <td><%= link_to_remote(image_tag('delete.png'), { :url => {:controller => 'issue_relations', :action => 'destroy', :issue_id => @issue, :id => relation},
21 :method => :post
21 :method => :post
22 }, :title => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %></td>
22 }, :title => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %></td>
23 </tr>
23 </tr>
24 <% end %>
24 <% end %>
25 </table>
25 </table>
26 <% end %>
26 <% end %>
27
27
28 <% remote_form_for(:relation, @relation,
28 <% remote_form_for(:relation, @relation,
29 :url => {:controller => 'issue_relations', :action => 'new', :issue_id => @issue},
29 :url => {:controller => 'issue_relations', :action => 'new', :issue_id => @issue},
30 :method => :post,
30 :method => :post,
31 :complete => "Form.Element.focus('relation_issue_to_id');",
31 :complete => "Form.Element.focus('relation_issue_to_id');",
32 :html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %>
32 :html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %>
33 <%= render :partial => 'issue_relations/form', :locals => {:f => f}%>
33 <%= render :partial => 'issue_relations/form', :locals => {:f => f}%>
34 <% end %>
34 <% end %>
@@ -1,61 +1,61
1 api.issue do
1 api.issue do
2 api.id @issue.id
2 api.id @issue.id
3 api.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil?
3 api.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil?
4 api.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil?
4 api.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil?
5 api.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil?
5 api.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil?
6 api.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil?
6 api.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil?
7 api.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil?
7 api.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil?
8 api.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil?
8 api.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil?
9 api.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil?
9 api.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil?
10 api.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil?
10 api.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil?
11 api.parent(:id => @issue.parent_id) unless @issue.parent.nil?
11 api.parent(:id => @issue.parent_id) unless @issue.parent.nil?
12
12
13 api.subject @issue.subject
13 api.subject @issue.subject
14 api.description @issue.description
14 api.description @issue.description
15 api.start_date @issue.start_date
15 api.start_date @issue.start_date
16 api.due_date @issue.due_date
16 api.due_date @issue.due_date
17 api.done_ratio @issue.done_ratio
17 api.done_ratio @issue.done_ratio
18 api.estimated_hours @issue.estimated_hours
18 api.estimated_hours @issue.estimated_hours
19 api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
19 api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
20
20
21 render_api_custom_values @issue.custom_field_values, api
21 render_api_custom_values @issue.custom_field_values, api
22
22
23 api.created_on @issue.created_on
23 api.created_on @issue.created_on
24 api.updated_on @issue.updated_on
24 api.updated_on @issue.updated_on
25
25
26 render_api_issue_children(@issue, api) if include_in_api_response?('children')
26 render_api_issue_children(@issue, api) if include_in_api_response?('children')
27
27
28 api.array :relations do
28 api.array :relations do
29 @issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation|
29 @relations.each do |relation|
30 api.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
30 api.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
31 end
31 end
32 end if include_in_api_response?('relations')
32 end if include_in_api_response?('relations') && @relations.present?
33
33
34 api.array :changesets do
34 api.array :changesets do
35 @issue.changesets.each do |changeset|
35 @issue.changesets.each do |changeset|
36 api.changeset :revision => changeset.revision do
36 api.changeset :revision => changeset.revision do
37 api.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
37 api.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
38 api.comments changeset.comments
38 api.comments changeset.comments
39 api.committed_on changeset.committed_on
39 api.committed_on changeset.committed_on
40 end
40 end
41 end
41 end
42 end if include_in_api_response?('changesets') && User.current.allowed_to?(:view_changesets, @project)
42 end if include_in_api_response?('changesets') && User.current.allowed_to?(:view_changesets, @project)
43
43
44 api.array :journals do
44 api.array :journals do
45 @issue.journals.each do |journal|
45 @issue.journals.each do |journal|
46 api.journal :id => journal.id do
46 api.journal :id => journal.id do
47 api.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
47 api.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
48 api.notes journal.notes
48 api.notes journal.notes
49 api.created_on journal.created_on
49 api.created_on journal.created_on
50 api.array :details do
50 api.array :details do
51 journal.details.each do |detail|
51 journal.details.each do |detail|
52 api.detail :property => detail.property, :name => detail.prop_key do
52 api.detail :property => detail.property, :name => detail.prop_key do
53 api.old_value detail.old_value
53 api.old_value detail.old_value
54 api.new_value detail.value
54 api.new_value detail.value
55 end
55 end
56 end
56 end
57 end
57 end
58 end
58 end
59 end
59 end
60 end if include_in_api_response?('journals')
60 end if include_in_api_response?('journals')
61 end
61 end
General Comments 0
You need to be logged in to leave comments. Login now