From cbd4af236cd34b54f250dfbdd94f3176582b7b6c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 1 May 2010 14:07:36 +0000 Subject: [PATCH] Adds issue relations to individual issue XML (#5305). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3729 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue_relation.rb | 25 ++++++++++++++++++------- app/views/issues/show.xml.builder | 6 ++++++ test/unit/issue_relation_test.rb | 9 +++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index a28175d48..b79592291 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -27,13 +27,13 @@ class IssueRelation < ActiveRecord::Base TYPE_PRECEDES = "precedes" TYPE_FOLLOWS = "follows" - TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, - TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 }, - TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :reverse => TYPE_DUPLICATES }, - TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4 }, - TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :reverse => TYPE_BLOCKS }, - TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6 }, - TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :reverse => TYPE_PRECEDES } + TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES }, + TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED }, + TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES }, + TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED }, + TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS }, + TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS }, + TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES } }.freeze validates_presence_of :issue_from, :issue_to, :relation_type @@ -56,6 +56,17 @@ class IssueRelation < ActiveRecord::Base (self.issue_from_id == issue.id) ? issue_to : issue_from end + # Returns the relation type for +issue+ + def relation_type_for(issue) + if TYPES[relation_type] + if self.issue_from_id == issue.id + relation_type + else + TYPES[relation_type][:sym] + end + end + end + def label_for(issue) TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow end diff --git a/app/views/issues/show.xml.builder b/app/views/issues/show.xml.builder index 4b1373955..bd3448cc8 100644 --- a/app/views/issues/show.xml.builder +++ b/app/views/issues/show.xml.builder @@ -30,6 +30,12 @@ xml.issue do xml.created_on @issue.created_on xml.updated_on @issue.updated_on + xml.relations do + @issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation| + xml.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay) + end + end + xml.changesets do @issue.changesets.each do |changeset| xml.changeset :revision => changeset.revision do diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb index 92316dede..6544c5203 100644 --- a/test/unit/issue_relation_test.rb +++ b/test/unit/issue_relation_test.rb @@ -54,4 +54,13 @@ class IssueRelationTest < ActiveSupport::TestCase assert_equal from, relation.issue_from assert_equal to, relation.issue_to end + + def test_relation_type_for + from = Issue.find(1) + to = Issue.find(2) + + relation = IssueRelation.new :issue_from => from, :issue_to => to, :relation_type => IssueRelation::TYPE_PRECEDES + assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) + assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) + end end