mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-24 15:54:00 +08:00
Add aibility to delete stock column [SCI-6723] (#4017)
Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
parent
36639727a1
commit
5ac9f51220
3 changed files with 8 additions and 17 deletions
|
@ -34,8 +34,6 @@ class RepositoryCell < ApplicationRecord
|
|||
|
||||
has_many :hidden_repository_cell_reminders, dependent: :destroy
|
||||
|
||||
before_destroy :prevent_stock_cell_destroy
|
||||
|
||||
validates :repository_column,
|
||||
inclusion: { in: (lambda do |repository_cell|
|
||||
repository_cell.repository_row&.repository&.repository_columns || []
|
||||
|
@ -92,8 +90,4 @@ class RepositoryCell < ApplicationRecord
|
|||
errors.add(:value_type, 'must match column data type')
|
||||
end
|
||||
end
|
||||
|
||||
def prevent_stock_cell_destroy
|
||||
raise NotImplementedError if value.class.name == 'RepositoryStockValue'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,8 +39,8 @@ class RepositoryColumn < ApplicationRecord
|
|||
after_create :update_repository_table_states_with_new_column
|
||||
after_update :clear_hidden_repository_cell_reminders
|
||||
|
||||
before_destroy :prevent_stock_column_destroy
|
||||
around_destroy :update_repository_table_states_with_removed_column
|
||||
before_destroy :nulify_stock_consumption
|
||||
|
||||
scope :list_type, -> { where(data_type: 'RepositoryListValue') }
|
||||
scope :asset_type, -> { where(data_type: 'RepositoryAssetValue') }
|
||||
|
@ -116,11 +116,6 @@ class RepositoryColumn < ApplicationRecord
|
|||
Constants::REPOSITORY_LIST_ITEMS_DELIMITERS_MAP[metadata['delimiter']&.to_sym] || "\n"
|
||||
end
|
||||
|
||||
|
||||
def deletable?
|
||||
data_type != 'RepositoryStockValue'
|
||||
end
|
||||
|
||||
def items
|
||||
items_method_name = "#{data_type.chomp('Value').underscore}_items"
|
||||
items_method_name = 'repository_stock_unit_items' if data_type == 'RepositoryStockValue'
|
||||
|
@ -172,7 +167,11 @@ class RepositoryColumn < ApplicationRecord
|
|||
.delete_all
|
||||
end
|
||||
|
||||
def prevent_stock_column_destroy
|
||||
raise NotImplementedError unless deletable?
|
||||
def nulify_stock_consumption
|
||||
if data_type == 'RepositoryStockValue'
|
||||
MyModuleRepositoryRow.where(repository_row_id: repository.repository_rows.select(:id))
|
||||
.where.not(stock_consumption: nil)
|
||||
.update_all(stock_consumption: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,9 +48,7 @@
|
|||
id="<%= column.id %>"
|
||||
data-type="<%= column.data_type %>"
|
||||
data-edit-column-url="<%= edit_repository_repository_column_path(repository, column) %>"
|
||||
<% if column.deletable? %>
|
||||
data-destroy-column-url="<%= repository_columns_destroy_html_path(repository, column) %>"
|
||||
<% end %>
|
||||
data-destroy-column-url="<%= repository_columns_destroy_html_path(repository, column) %>"
|
||||
data-editable-row="<%= can_manage_repository_column?(column) %>"
|
||||
<% column.metadata.each do |k, v| %>
|
||||
<%= "data-metadata-#{k}=#{v}" %>
|
||||
|
|
Loading…
Reference in a new issue