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
This commit is contained in:
Jean-Philippe Lang 2010-05-01 14:07:36 +00:00
parent a499efd328
commit cbd4af236c
3 changed files with 33 additions and 7 deletions

View File

@ -27,13 +27,13 @@ class IssueRelation < ActiveRecord::Base
TYPE_PRECEDES = "precedes" TYPE_PRECEDES = "precedes"
TYPE_FOLLOWS = "follows" TYPE_FOLLOWS = "follows"
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, 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 }, 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, :reverse => TYPE_DUPLICATES }, 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 }, 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, :reverse => TYPE_BLOCKS }, 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 }, 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, :reverse => TYPE_PRECEDES } TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }
}.freeze }.freeze
validates_presence_of :issue_from, :issue_to, :relation_type 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 (self.issue_from_id == issue.id) ? issue_to : issue_from
end 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) def label_for(issue)
TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
end end

View File

@ -30,6 +30,12 @@ xml.issue do
xml.created_on @issue.created_on xml.created_on @issue.created_on
xml.updated_on @issue.updated_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 xml.changesets do
@issue.changesets.each do |changeset| @issue.changesets.each do |changeset|
xml.changeset :revision => changeset.revision do xml.changeset :revision => changeset.revision do

View File

@ -54,4 +54,13 @@ class IssueRelationTest < ActiveSupport::TestCase
assert_equal from, relation.issue_from assert_equal from, relation.issue_from
assert_equal to, relation.issue_to assert_equal to, relation.issue_to
end 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 end