Moves contents of PlanningElementType into Type.

This leaves PlanningElementType an almost empty subclass of Type, soon
to be removed entirely.
pull/287/head
Martin Czuchra 11 years ago
parent 0f9544ab14
commit af666d3582
  1. 58
      app/models/planning_element_type.rb
  2. 66
      app/models/type.rb

@ -9,62 +9,6 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
class PlanningElementType < ActiveRecord::Base
unloadable
class PlanningElementType < Type
self.table_name = 'planning_element_types'
acts_as_list
default_scope :order => 'position ASC'
extend Pagination::Model
has_many :default_planning_element_types, :class_name => 'DefaultPlanningElementType',
:foreign_key => 'planning_element_type_id',
:dependent => :delete_all
has_many :project_types, :through => :default_planning_element_types
has_many :enabled_planning_element_types, :class_name => 'EnabledPlanningElementType',
:foreign_key => 'planning_element_type_id',
:dependent => :delete_all
has_many :projects, :through => :enabled_planning_element_types
belongs_to :color, :class_name => 'PlanningElementTypeColor',
:foreign_key => 'color_id'
has_many :planning_elements, :class_name => 'PlanningElement',
:foreign_key => 'planning_element_type_id',
:dependent => :nullify
include ActiveModel::ForbiddenAttributesProtection
validates_presence_of :name
validates_inclusion_of :in_aggregation, :is_default, :is_milestone, :in => [true, false]
validates_length_of :name, :maximum => 255, :unless => lambda { |e| e.name.blank? }
scope :like, lambda { |q|
s = "%#{q.to_s.strip.downcase}%"
{ :conditions => ["LOWER(name) LIKE :s", {:s => s}],
:order => "name" }
}
def self.search_scope(query)
like(query)
end
def enabled_in?(object)
case object
when ProjectType
object.planning_element_types.include?(self)
when Project
object.planning_element_types.include?(self)
else
false
end
end
def available_colors
PlanningElementTypeColor.all
end
end

@ -11,7 +11,13 @@
#++
class Type < ActiveRecord::Base
extend Pagination::Model
include ActiveModel::ForbiddenAttributesProtection
before_destroy :check_integrity
has_many :issues
has_many :workflows, :dependent => :delete_all do
def copy(source_type)
@ -20,12 +26,47 @@ class Type < ActiveRecord::Base
end
has_and_belongs_to_many :projects
has_and_belongs_to_many :custom_fields, :class_name => 'WorkPackageCustomField', :join_table => "#{table_name_prefix}custom_fields_types#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
has_and_belongs_to_many :custom_fields,
:class_name => 'WorkPackageCustomField',
:join_table => "#{table_name_prefix}custom_fields_types#{table_name_suffix}",
:association_foreign_key => 'custom_field_id'
has_many :default_planning_element_types, :class_name => 'DefaultPlanningElementType',
:foreign_key => 'planning_element_type_id',
:dependent => :delete_all
has_many :project_types, :through => :default_planning_element_types
has_many :enabled_planning_element_types, :class_name => 'EnabledPlanningElementType',
:foreign_key => 'planning_element_type_id',
:dependent => :delete_all
has_many :projects, :through => :enabled_planning_element_types
belongs_to :color, :class_name => 'PlanningElementTypeColor',
:foreign_key => 'color_id'
has_many :planning_elements, :class_name => 'PlanningElement',
:foreign_key => 'planning_element_type_id',
:dependent => :nullify
acts_as_list
validates_presence_of :name
validates_presence_of :name
validates_uniqueness_of :name
validates_length_of :name, :maximum => 30
validates_length_of :name,
:maximum => 255,
:unless => lambda { |e| e.name.blank? }
validates_inclusion_of :in_aggregation, :is_default, :is_milestone, :in => [true, false]
default_scope :order => 'position ASC'
scope :like, lambda { |q|
s = "%#{q.to_s.strip.downcase}%"
{ :conditions => ["LOWER(name) LIKE :s", {:s => s}],
:order => "name" }
}
def to_s; name end
@ -54,6 +95,25 @@ class Type < ActiveRecord::Base
@issue_statuses = IssueStatus.find_all_by_id(ids).sort
end
def self.search_scope(query)
like(query)
end
def enabled_in?(object)
case object
when ProjectType
object.planning_element_types.include?(self)
when Project
object.planning_element_types.include?(self)
else
false
end
end
def available_colors
PlanningElementTypeColor.all
end
private
def check_integrity
raise "Can't delete type" if Issue.find(:first, :conditions => ["type_id=?", self.id])

Loading…
Cancel
Save