Remove date red dots for snapshots [SCI-6715] (#4004)

Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
aignatov-bio 2022-04-12 13:14:11 +02:00 committed by GitHub
parent a9fc4c3c44
commit 433d69c10a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 14 deletions

View file

@ -50,14 +50,14 @@ module RepositoryDatatableHelper
custom_cells.each do |cell| custom_cells.each do |cell|
row[columns_mappings[cell.repository_column.id]] = row[columns_mappings[cell.repository_column.id]] =
display_cell_value(cell, team) display_cell_value(cell, team, repository)
end end
stock_present = record.repository_stock_cell.present? stock_present = record.repository_stock_cell.present?
stock_managable = !options[:disable_stock_management] && can_manage_repository_stock?(record.repository) stock_managable = !options[:disable_stock_management] && can_manage_repository_stock?(record.repository)
# always add stock cell, even if empty # always add stock cell, even if empty
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team) : {} row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team, repository) : {}
row['stock'][:stock_managable] = stock_managable row['stock'][:stock_managable] = stock_managable
row['stock']['value_type'] = 'RepositoryStockValue' row['stock']['value_type'] = 'RepositoryStockValue'
@ -109,12 +109,12 @@ module RepositoryDatatableHelper
consumption_managable = stock_consumption_managable?(record, repository, my_module) consumption_managable = stock_consumption_managable?(record, repository, my_module)
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, record.repository.team) : {} row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, record.repository.team, repository) : {}
row['stock'][:stock_managable] = stock_managable row['stock'][:stock_managable] = stock_managable
if record.repository.is_a?(RepositorySnapshot) if record.repository.is_a?(RepositorySnapshot)
row['consumedStock'] = row['consumedStock'] =
if record.repository_stock_consumption_value.present? if record.repository_stock_consumption_value.present?
display_cell_value(record.repository_stock_consumption_cell, record.repository.team) display_cell_value(record.repository_stock_consumption_cell, record.repository.team, repository)
else else
{} {}
end end
@ -142,7 +142,7 @@ module RepositoryDatatableHelper
end end
end end
def prepare_snapshot_row_columns(repository_rows, columns_mappings, team, options = {}) def prepare_snapshot_row_columns(repository_rows, columns_mappings, team, repository_snapshot, options = {})
repository_rows.map do |record| repository_rows.map do |record|
row = { row = {
'DT_RowId': record.id, 'DT_RowId': record.id,
@ -151,20 +151,20 @@ module RepositoryDatatableHelper
'2': escape_input(record.name), '2': escape_input(record.name),
'3': I18n.l(record.created_at, format: :full), '3': I18n.l(record.created_at, format: :full),
'4': escape_input(record.created_by.full_name), '4': escape_input(record.created_by.full_name),
'recordInfoUrl': Rails.application.routes.url_helpers.repository_repository_row_path(record.repository, record) 'recordInfoUrl': Rails.application.routes.url_helpers.repository_repository_row_path(repository_snapshot, record)
} }
# Add custom columns # Add custom columns
record.repository_cells.each do |cell| record.repository_cells.each do |cell|
row[columns_mappings[cell.repository_column.id]] = display_cell_value(cell, team) row[columns_mappings[cell.repository_column.id]] = display_cell_value(cell, team, repository_snapshot)
end end
if options[:include_stock_consumption] && record.repository.has_stock_management? if options[:include_stock_consumption] && repository_snapshot.has_stock_management?
stock_present = record.repository_stock_cell.present? stock_present = record.repository_stock_cell.present?
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, record.repository.team) : {} row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team, repository_snapshot) : {}
row['consumedStock'] = row['consumedStock'] =
if stock_present if stock_present
display_cell_value(record.repository_stock_consumption_cell, record.repository.team) display_cell_value(record.repository_stock_consumption_cell, team, repository_snapshot)
else else
{} {}
end end
@ -226,11 +226,16 @@ module RepositoryDatatableHelper
} }
end end
def display_cell_value(cell, team) def display_cell_value(cell, team, repository)
serializer_class = "RepositoryDatatable::#{cell.repository_column.data_type}Serializer".constantize serializer_class = "RepositoryDatatable::#{cell.repository_column.data_type}Serializer".constantize
serializer_class.new( serializer_class.new(
cell.value, cell.value,
scope: { team: team, user: current_user, column: cell.repository_column } scope: {
team: team,
user: current_user,
column: cell.repository_column,
repository: repository
}
).serializable_hash ).serializable_hash
end end

View file

@ -11,7 +11,9 @@ module RepositoryDatatable
} }
reminder_delta = scope[:column].metadata['reminder_delta'] reminder_delta = scope[:column].metadata['reminder_delta']
data[:reminder] = reminder_delta.to_i + DateTime.now.to_i >= object.data.to_i if reminder_delta if !scope[:repository].is_a?(RepositorySnapshot) && reminder_delta
data[:reminder] = reminder_delta.to_i + DateTime.now.to_i >= object.data.to_i
end
data data
end end

View file

@ -9,7 +9,9 @@ module RepositoryDatatable
} }
reminder_delta = scope[:column].metadata['reminder_delta'] reminder_delta = scope[:column].metadata['reminder_delta']
data[:reminder] = DateTime.now.to_date + reminder_delta.to_i.seconds >= object.data if reminder_delta if !scope[:repository].is_a?(RepositorySnapshot) && reminder_delta
data[:reminder] = DateTime.now.to_date + reminder_delta.to_i.seconds >= object.data
end
data data
end end

View file

@ -5,6 +5,7 @@ json.data do
json.array! prepare_snapshot_row_columns(@repository_rows, json.array! prepare_snapshot_row_columns(@repository_rows,
@columns_mappings, @columns_mappings,
@repository_snapshot.team, @repository_snapshot.team,
@repository_snapshot,
{ include_stock_consumption: @repository_snapshot.has_stock_management? }) { include_stock_consumption: @repository_snapshot.has_stock_management? })
end end
json.recordsFiltered @repository_rows.first ? @repository_rows.first.filtered_count : 0 json.recordsFiltered @repository_rows.first ? @repository_rows.first.filtered_count : 0