diff --git a/app/models/relation.rb b/app/models/relation.rb index f4586932e6..87c9426acb 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -33,22 +33,60 @@ class Relation < ActiveRecord::Base scope :of_work_package, ->(work_package) { where('from_id = ? OR to_id = ?', work_package, work_package) } - TYPE_RELATES = 'relates' - TYPE_DUPLICATES = 'duplicates' - TYPE_DUPLICATED = 'duplicated' - TYPE_BLOCKS = 'blocks' - TYPE_BLOCKED = 'blocked' - TYPE_PRECEDES = 'precedes' - TYPE_FOLLOWS = 'follows' - - 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 + TYPE_RELATES = 'relates'.freeze + TYPE_DUPLICATES = 'duplicates'.freeze + TYPE_DUPLICATED = 'duplicated'.freeze + TYPE_BLOCKS = 'blocks'.freeze + TYPE_BLOCKED = 'blocked'.freeze + TYPE_PRECEDES = 'precedes'.freeze + TYPE_FOLLOWS = 'follows'.freeze + TYPE_INCLUDES = 'includes'.freeze + TYPE_PARTOF = 'partof'.freeze + TYPE_REQUIRES = 'requires'.freeze + TYPE_REQUIRED = 'required'.freeze + + 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 + }, + TYPE_INCLUDES => { + name: :label_includes, sym_name: :label_includes, order: 8, + sym: TYPE_INCLUDES, reverse: TYPE_PARTOF + }, + TYPE_PARTOF => { + name: :label_part_of, sym_name: :label_part_of, order: 9, + sym: TYPE_PARTOF, reverse: TYPE_INCLUDES + }, + TYPE_REQUIRES => { + name: :label_requires, sym_name: :label_requires, order: 10, + sym: TYPE_REQUIRES, reverse: TYPE_REQUIRED + }, + TYPE_REQUIRED => { + name: :label_required, sym_name: :label_required, order: 11, + sym: TYPE_REQUIRED, reverse: TYPE_REQUIRES + } + }.freeze validates_presence_of :from, :to, :relation_type validates_inclusion_of :relation_type, in: TYPES.keys @@ -84,7 +122,7 @@ class Relation < ActiveRecord::Base end def label_for(work_package) - TYPES[relation_type] ? TYPES[relation_type][(from_id == work_package.id) ? :name : :sym_name] : :unknow + TYPES[relation_type] ? TYPES[relation_type][(from_id == work_package.id) ? :name : :sym_name] : :unknown end def update_schedule