2014-08-25 05:25:02 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: labels
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# title :string(255)
|
|
|
|
# color :string(255)
|
|
|
|
# project_id :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
#
|
|
|
|
|
2014-07-29 10:10:15 -04:00
|
|
|
class Label < ActiveRecord::Base
|
2014-08-15 05:02:05 -04:00
|
|
|
DEFAULT_COLOR = '#428BCA'
|
2014-08-14 04:17:52 -04:00
|
|
|
|
2014-07-29 10:10:15 -04:00
|
|
|
belongs_to :project
|
|
|
|
has_many :label_links, dependent: :destroy
|
2014-07-30 08:15:39 -04:00
|
|
|
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
|
2014-07-29 10:10:15 -04:00
|
|
|
|
2014-08-11 17:59:30 -04:00
|
|
|
validates :color,
|
2014-08-17 16:22:01 -04:00
|
|
|
format: { with: /\A#[0-9A-Fa-f]{6}\Z/ },
|
2014-08-11 17:59:30 -04:00
|
|
|
allow_blank: false
|
2014-07-29 10:10:15 -04:00
|
|
|
validates :project, presence: true
|
2014-07-30 06:26:54 -04:00
|
|
|
|
2014-08-11 17:59:30 -04:00
|
|
|
# Don't allow '?', '&', and ',' for label titles
|
2014-08-12 04:53:50 -04:00
|
|
|
validates :title,
|
|
|
|
presence: true,
|
2014-08-17 16:22:01 -04:00
|
|
|
format: { with: /\A[^&\?,&]+\z/ },
|
2014-08-13 08:12:05 -04:00
|
|
|
uniqueness: { scope: :project_id }
|
2014-07-29 12:19:26 -04:00
|
|
|
|
2015-02-05 23:29:41 -05:00
|
|
|
default_scope { order(title: :asc) }
|
2014-07-30 12:13:35 -04:00
|
|
|
|
2014-08-12 08:16:25 -04:00
|
|
|
alias_attribute :name, :title
|
2014-07-30 08:15:39 -04:00
|
|
|
|
|
|
|
def open_issues_count
|
|
|
|
issues.opened.count
|
|
|
|
end
|
2014-07-29 10:10:15 -04:00
|
|
|
end
|