issueRelationFollows_r2924.patch

Adds "follows" issue relation type (Propper) - Anonymous, 2009-10-14 17:47

Download (2.66 KB)

View differences:

app/models/issue_relation.rb (kopia robocza)
23 23
  TYPE_DUPLICATES   = "duplicates"
24 24
  TYPE_BLOCKS       = "blocks"
25 25
  TYPE_PRECEDES     = "precedes"
26
  TYPE_FOLLOWS      = "follows"
26 27
  
27 28
  TYPES = { TYPE_RELATES =>     { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 },
28
            TYPE_DUPLICATES =>  { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
29
            TYPE_BLOCKS =>      { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
30
            TYPE_PRECEDES =>    { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
31
          }.freeze
32
  
29
    TYPE_DUPLICATES =>  { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
30
    TYPE_BLOCKS =>      { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
31
    TYPE_PRECEDES =>    { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
32
    TYPE_FOLLOWS =>    { :name => :label_follows, :sym_name => :label_precedes, :order => 5 },
33
  }.freeze
34

  
33 35
  validates_presence_of :issue_from, :issue_to, :relation_type
34 36
  validates_inclusion_of :relation_type, :in => TYPES.keys
35 37
  validates_numericality_of :delay, :allow_nil => true
36 38
  validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
37
  
39

  
38 40
  attr_protected :issue_from_id, :issue_to_id
39
  
41

  
42
  def before_validation
43
    convert_to_precedes if TYPE_FOLLOWS == relation_type
44
  end
45

  
40 46
  def validate
41 47
    if issue_from && issue_to
42 48
      errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
......
78 84
  def <=>(relation)
79 85
    TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
80 86
  end
87

  
88
  private
89

  
90
  def convert_to_precedes
91
    if (TYPE_FOLLOWS == self.relation_type)
92
      issue_tmp = self.issue_to
93
      self.issue_to = self.issue_from
94
      self.issue_from = issue_tmp
95
      self.relation_type = TYPE_PRECEDES
96
    end
97
  end
98

  
81 99
end
public/javascripts/application.js (kopia robocza)
75 75

  
76 76
function setPredecessorFieldsVisibility() {
77 77
    relationType = $('relation_relation_type');
78
    if (relationType && relationType.value == "precedes") {
78
    if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
79 79
        Element.show('predecessor_fields');
80 80
    } else {
81 81
        Element.hide('predecessor_fields');