2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class Board < ApplicationRecord
|
2018-03-27 19:54:05 +05:30
|
|
|
belongs_to :group
|
2016-09-13 17:45:13 +05:30
|
|
|
belongs_to :project
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
has_many :lists, -> { ordered }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
|
|
|
|
has_many :destroyable_lists, -> { destroyable.ordered }, class_name: "List"
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
validates :name, presence: true
|
2018-03-17 18:26:18 +05:30
|
|
|
validates :project, presence: true, if: :project_needed?
|
2018-03-27 19:54:05 +05:30
|
|
|
validates :group, presence: true, unless: :project
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
scope :with_associations, -> { preload(:destroyable_lists) }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
# Sort by case-insensitive name, then ascending ids. This ensures that we will always
|
|
|
|
# get the same list/first board no matter how many other boards are named the same
|
|
|
|
scope :order_by_name_asc, -> { order(arel_table[:name].lower.asc).order(id: :asc) }
|
|
|
|
scope :first_board, -> { where(id: self.order_by_name_asc.limit(1).select(:id)) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def project_needed?
|
2018-03-27 19:54:05 +05:30
|
|
|
!group
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def resource_parent
|
|
|
|
@resource_parent ||= group || project
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def group_board?
|
2018-03-27 19:54:05 +05:30
|
|
|
group_id.present?
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def project_board?
|
|
|
|
project_id.present?
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def backlog_list
|
|
|
|
lists.merge(List.backlog).take
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def closed_list
|
|
|
|
lists.merge(List.closed).take
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
def scoped?
|
|
|
|
false
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
def self.to_type
|
|
|
|
name.demodulize
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_type
|
|
|
|
self.class.to_type
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Board.prepend_if_ee('EE::Board')
|