2019-10-08 19:38:57 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RepositoryStatusItem < ApplicationRecord
|
2020-04-09 23:11:58 +08:00
|
|
|
validates :repository_column, :icon, presence: true
|
2019-10-08 19:38:57 +08:00
|
|
|
validates :status, presence: true, length: { minimum: Constants::NAME_MIN_LENGTH,
|
|
|
|
maximum: Constants::NAME_MAX_LENGTH }
|
|
|
|
belongs_to :repository_column
|
|
|
|
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', optional: true,
|
2019-12-10 16:40:40 +08:00
|
|
|
inverse_of: :created_repository_status_types
|
2019-10-08 19:38:57 +08:00
|
|
|
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true,
|
2019-12-10 16:40:40 +08:00
|
|
|
inverse_of: :modified_repository_status_types
|
2020-01-09 00:32:07 +08:00
|
|
|
has_many :repository_status_values, inverse_of: :repository_status_item, dependent: :destroy
|
2020-05-14 17:47:19 +08:00
|
|
|
|
2022-01-26 17:12:46 +08:00
|
|
|
before_destroy :update_table_fiter_elements
|
|
|
|
|
2020-05-14 17:47:19 +08:00
|
|
|
def data
|
|
|
|
"#{icon} #{status}"
|
|
|
|
end
|
2022-01-26 17:12:46 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_table_fiter_elements
|
|
|
|
repository_column.repository_table_filter_elements.find_each do |filter_element|
|
2022-02-11 20:50:42 +08:00
|
|
|
filter_element.parameters['item_ids']&.delete(id.to_s)
|
|
|
|
filter_element.parameters['item_ids'].blank? ? filter_element.destroy! : filter_element.save!
|
2022-01-26 17:12:46 +08:00
|
|
|
end
|
|
|
|
end
|
2019-10-08 19:38:57 +08:00
|
|
|
end
|