Merge pull request #3756 from okriuchykhin/ok_SCI_6396

Finalyze repository filter elements management backend [SCI-6396]
This commit is contained in:
Alex Kriuchykhin 2022-01-26 10:22:04 +01:00 committed by GitHub
commit 4342831dab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -10,9 +10,7 @@ class RepositoryTableFiltersController < ApplicationController
before_action :check_manage_permissions, only: %i(update destroy)
def index
render json: @repository.repository_table_filters, each_serializer: RepositoryFilterSerializer
render json: @repository.repository_table_filters.order(:name), each_serializer: RepositoryFilterSerializer
end
def show

View file

@ -14,6 +14,8 @@ class RepositoryChecklistItem < ApplicationRecord
uniqueness: { scope: :repository_column_id },
length: { maximum: Constants::NAME_MAX_LENGTH }
before_destroy :update_table_fiter_elements
private
def validate_per_column_limit
@ -22,4 +24,11 @@ class RepositoryChecklistItem < ApplicationRecord
errors.add(:base, :per_column_limit)
end
end
def update_table_fiter_elements
repository_column.repository_table_filter_elements.find_each do |filter_element|
filter_element.parameters['item_ids']&.delete(id)
filter_element.parameters['item_ids'].blank? ? filter_element.destroy! : filter_element.save!
end
end
end

View file

@ -11,6 +11,8 @@ class RepositoryListItem < ApplicationRecord
uniqueness: { scope: :repository_column_id },
length: { maximum: Constants::TEXT_MAX_LENGTH }
before_destroy :update_table_fiter_elements
private
def validate_per_column_limit
@ -19,4 +21,11 @@ class RepositoryListItem < ApplicationRecord
errors.add(:base, :per_column_limit)
end
end
def update_table_fiter_elements
repository_column.repository_table_filter_elements.find_each do |filter_element|
filter_element.parameters['item_ids']&.delete(id)
filter_element.parameters['item_ids'].blank? ? filter_element.destroy! : filter_element.save!
end
end
end

View file

@ -11,7 +11,18 @@ class RepositoryStatusItem < ApplicationRecord
inverse_of: :modified_repository_status_types
has_many :repository_status_values, inverse_of: :repository_status_item, dependent: :destroy
before_destroy :update_table_fiter_elements
def data
"#{icon} #{status}"
end
private
def update_table_fiter_elements
repository_column.repository_table_filter_elements.find_each do |filter_element|
filter_element.parameters['status_ids']&.delete(id)
filter_element.parameters['status_ids'].blank? ? filter_element.destroy! : filter_element.save!
end
end
end