##// END OF EJS Templates
code layout cleanup app/models/issue_relation.rb...
Toshi MARUYAMA -
r10662:f4cf7bc6f5dd
parent child
Show More
@@ -43,26 +43,34 class IssueRelation < ActiveRecord::Base
43 43 TYPE_COPIED_TO = "copied_to"
44 44 TYPE_COPIED_FROM = "copied_from"
45 45
46 TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
47 TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
48 TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates, :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
49 TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
50 TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
51 TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
52 TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES },
53 TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, :order => 8, :sym => TYPE_COPIED_FROM },
54 TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO }
55 }.freeze
46 TYPES = {
47 TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to,
48 :order => 1, :sym => TYPE_RELATES },
49 TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by,
50 :order => 2, :sym => TYPE_DUPLICATED },
51 TYPE_DUPLICATED => { :name => :label_duplicated_by, :sym_name => :label_duplicates,
52 :order => 3, :sym => TYPE_DUPLICATES, :reverse => TYPE_DUPLICATES },
53 TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by,
54 :order => 4, :sym => TYPE_BLOCKED },
55 TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks,
56 :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
57 TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows,
58 :order => 6, :sym => TYPE_FOLLOWS },
59 TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes,
60 :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES },
61 TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from,
62 :order => 8, :sym => TYPE_COPIED_FROM },
63 TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to,
64 :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO }
65 }.freeze
56 66
57 67 validates_presence_of :issue_from, :issue_to, :relation_type
58 68 validates_inclusion_of :relation_type, :in => TYPES.keys
59 69 validates_numericality_of :delay, :allow_nil => true
60 70 validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
61
62 71 validate :validate_issue_relation
63 72
64 73 attr_protected :issue_from_id, :issue_to_id
65
66 74 before_save :handle_issue_order
67 75
68 76 def visible?(user=User.current)
@@ -87,14 +95,19 class IssueRelation < ActiveRecord::Base
87 95 def validate_issue_relation
88 96 if issue_from && issue_to
89 97 errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
90 errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
91 #detect circular dependencies depending wether the relation should be reversed
98 unless issue_from.project_id == issue_to.project_id ||
99 Setting.cross_project_issue_relations?
100 errors.add :issue_to_id, :not_same_project
101 end
102 # detect circular dependencies depending wether the relation should be reversed
92 103 if TYPES.has_key?(relation_type) && TYPES[relation_type][:reverse]
93 104 errors.add :base, :circular_dependency if issue_from.all_dependent_issues.include? issue_to
94 105 else
95 106 errors.add :base, :circular_dependency if issue_to.all_dependent_issues.include? issue_from
96 107 end
97 errors.add :base, :cant_link_an_issue_with_a_descendant if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
108 if issue_from.is_descendant_of?(issue_to) || issue_from.is_ancestor_of?(issue_to)
109 errors.add :base, :cant_link_an_issue_with_a_descendant
110 end
98 111 end
99 112 end
100 113
@@ -114,7 +127,9 class IssueRelation < ActiveRecord::Base
114 127 end
115 128
116 129 def label_for(issue)
117 TYPES[relation_type] ? TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] : :unknow
130 TYPES[relation_type] ?
131 TYPES[relation_type][(self.issue_from_id == issue.id) ? :name : :sym_name] :
132 :unknow
118 133 end
119 134
120 135 def css_classes_for(issue)
@@ -140,7 +155,8 class IssueRelation < ActiveRecord::Base
140 155 end
141 156
142 157 def successor_soonest_start
143 if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date)
158 if (TYPE_PRECEDES == self.relation_type) && delay && issue_from &&
159 (issue_from.start_date || issue_from.due_date)
144 160 (issue_from.due_date || issue_from.start_date) + 1 + delay
145 161 end
146 162 end
General Comments 0
You need to be logged in to leave comments. Login now