Project

General

Profile

Feature #1005 » issue1005-trunk-r11711.diff

Toshi MARUYAMA, 2013-04-10 15:26

View differences:

app/models/issue_relation.rb
72 72

  
73 73
  attr_protected :issue_from_id, :issue_to_id
74 74
  before_save :handle_issue_order
75
  after_create  :create_journal_after_create
76
  after_destroy :create_journal_after_delete
75 77

  
76 78
  def visible?(user=User.current)
77 79
    (issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user))
......
179 181
      self.relation_type = TYPES[relation_type][:reverse]
180 182
    end
181 183
  end
184

  
185
  def create_journal_after_create
186
    journal = issue_from.init_journal(User.current)
187
    journal.details << JournalDetail.new(:property => 'relation',
188
                                         :prop_key => label_for(issue_from).to_s,
189
                                         :value    => issue_to.id)
190
    journal.save
191

  
192
    # issue-to
193
    journal = issue_to.init_journal(User.current)
194
    journal.details << JournalDetail.new(:property => 'relation',
195
                                         :prop_key => label_for(issue_to).to_s,
196
                                         :value    => issue_from.id)
197
    journal.save
198
  end
199

  
200
  def create_journal_after_delete
201
    journal = issue_from.init_journal(User.current)
202
    journal.details << JournalDetail.new(:property  => 'relation',
203
                                         :prop_key  => label_for(issue_from).to_s,
204
                                         :old_value => issue_to.id)
205
    journal.save
206

  
207
    # issue-to
208
    journal = issue_to.init_journal(User.current)
209
    journal.details << JournalDetail.new(:property  => 'relation',
210
                                         :prop_key  => label_for(issue_to).to_s,
211
                                         :old_value => issue_from.id)
212
    journal.save
213
  end
182 214
end
app/helpers/issues_helper.rb
292 292
      end
293 293
    when 'attachment'
294 294
      label = l(:label_attachment)
295
    when 'relation'
296
      if detail.value && !detail.old_value
297
        rel_issue = Issue.find_by_id(detail.value)
298
        value = rel_issue ? link_to_issue(rel_issue) : "#{l(:label_issue)} #{detail.value}"
299
        label = l(detail.prop_key.to_sym)
300
      elsif detail.old_value && !detail.value
301
        rel_issue = Issue.find_by_id(detail.old_value)
302
        old_value = rel_issue ? link_to_issue(Issue.find(rel_issue)) : "#{l(:label_issue)} #{detail.old_value}"
303
        label = l(detail.prop_key.to_sym)
304
      end
295 305
    end
296 306
    call_hook(:helper_issues_show_detail_after_setting,
297 307
              {:detail => detail, :label => label, :value => value, :old_value => old_value })
......
341 351
        end
342 352
      when 'attachment'
343 353
        l(:text_journal_added, :label => label, :value => value).html_safe
354
      when 'relation'
355
        l(:text_journal_added, :label => label, :value => value).html_safe
344 356
      end
345 357
    else
346 358
      l(:text_journal_deleted, :label => label, :old => old_value).html_safe
app/helpers/issues_helper.rb
295 295
    when 'relation'
296 296
      if detail.value && !detail.old_value
297 297
        rel_issue = Issue.find_by_id(detail.value)
298
        value = rel_issue ? link_to_issue(rel_issue) : "#{l(:label_issue)} #{detail.value}"
299
        label = l(detail.prop_key.to_sym)
298
        value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.value}" :
299
                  (no_html ? rel_issue : link_to_issue(rel_issue))
300 300
      elsif detail.old_value && !detail.value
301 301
        rel_issue = Issue.find_by_id(detail.old_value)
302
        old_value = rel_issue ? link_to_issue(Issue.find(rel_issue)) : "#{l(:label_issue)} #{detail.old_value}"
303
        label = l(detail.prop_key.to_sym)
302
        old_value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.old_value}" :
303
                          (no_html ? rel_issue : link_to_issue(rel_issue))
304 304
      end
305
      label = l(detail.prop_key.to_sym)
305 306
    end
306 307
    call_hook(:helper_issues_show_detail_after_setting,
307 308
              {:detail => detail, :label => label, :value => value, :old_value => old_value })
app/helpers/issues_helper.rb
314 314
    unless no_html
315 315
      label = content_tag('strong', label)
316 316
      old_value = content_tag("i", h(old_value)) if detail.old_value
317
      old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
317
      if detail.old_value and detail.value.blank? and detail.property != 'relation'
318
        old_value = content_tag("del", old_value)
319
      end
318 320
      if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
319 321
        # Link to the attachment if it has not been removed
320 322
        value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
(8-8/9)