2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class Board < ApplicationRecord
|
2018-02-19 14:06:16 -05:00
|
|
|
belongs_to :group
|
2016-07-27 15:32:32 -04:00
|
|
|
belongs_to :project
|
|
|
|
|
2017-06-08 11:16:27 -04:00
|
|
|
has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
|
2016-07-27 15:32:32 -04:00
|
|
|
|
2017-08-28 17:56:49 -04:00
|
|
|
validates :project, presence: true, if: :project_needed?
|
2018-02-19 14:06:16 -05:00
|
|
|
validates :group, presence: true, unless: :project
|
2017-08-28 17:56:49 -04:00
|
|
|
|
|
|
|
def project_needed?
|
2018-02-19 14:06:16 -05:00
|
|
|
!group
|
2017-08-28 17:56:49 -04:00
|
|
|
end
|
2016-09-26 13:39:41 -04:00
|
|
|
|
2017-08-31 15:34:57 -04:00
|
|
|
def parent
|
2018-02-19 14:06:16 -05:00
|
|
|
@parent ||= group || project
|
2017-08-31 15:34:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def group_board?
|
2018-02-19 14:06:16 -05:00
|
|
|
group_id.present?
|
2017-08-31 15:34:57 -04:00
|
|
|
end
|
|
|
|
|
2019-02-14 16:19:59 -05:00
|
|
|
def project_board?
|
|
|
|
project_id.present?
|
|
|
|
end
|
|
|
|
|
2017-05-31 07:34:54 -04:00
|
|
|
def backlog_list
|
|
|
|
lists.merge(List.backlog).take
|
|
|
|
end
|
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
def closed_list
|
|
|
|
lists.merge(List.closed).take
|
2016-09-26 13:39:41 -04:00
|
|
|
end
|
2018-06-29 06:51:48 -04:00
|
|
|
|
|
|
|
def scoped?
|
|
|
|
false
|
|
|
|
end
|
2016-07-27 15:32:32 -04:00
|
|
|
end
|