Refactor and fix display of stock warnings and stock consumption [SCI-6734] ()

* Refactor and fix how stock consumption is displayed [SCI-6734]

* Refactor and fix display of stock warnings [SCI-6734]
This commit is contained in:
artoscinote 2022-04-14 14:27:31 +02:00 committed by GitHub
parent 4a232ac391
commit 30ee6cd40c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 43 deletions
app
assets
javascripts/repositories/renderers
stylesheets
helpers
models

View file

@ -189,7 +189,7 @@ $.fn.dataTable.render.AssignedTasksValue = function(data, row) {
}
if (row.hasActiveReminders) {
return `<div class="dropdown row-reminders-dropdown" data-row-reminders-url="${row.rowRemindersUrl}" tabindex='-1'>
<i class="fas fa-bell dropdown-toggle row-reminders-icon" data-toggle="dropdown"
<i class="fas fa-bell dropdown-toggle row-reminders-icon" data-toggle="dropdown"
id="rowReminders${row.DT_RowId}}"></i>
<ul class="dropdown-menu" role="menu" aria-labelledby="rowReminders${row.DT_RowId}">
</ul>
@ -201,23 +201,15 @@ $.fn.dataTable.render.AssignedTasksValue = function(data, row) {
};
$.fn.dataTable.render.RepositoryStockValue = function(data) {
var stockAlertTag;
if (data) {
if (data.value) {
if (data.value.stock_amount <= 0) {
stockAlertTag = 'stock-alert';
} else {
stockAlertTag = parseFloat(data.value.stock_amount) < parseFloat(data.value.low_stock_threshold)
? 'stock-low-stock-alert' : '';
}
if (data.stock_managable) {
return `<a class="manage-repository-stock-value-link stock-value-view-render ${stockAlertTag}">
return `<a class="manage-repository-stock-value-link stock-value-view-render stock-${data.stock_status}">
${data.value.stock_formatted}
</a>`;
}
return `<span class="stock-value-view-render
${data.stock_managable !== undefined ? stockAlertTag : ''}">
${data.stock_managable !== undefined ? `stock-${data.stock_status}` : ''}">
${data.value.stock_formatted}
</span>`;
}
@ -238,27 +230,27 @@ $.fn.dataTable.render.defaultRepositoryStockValue = function() {
};
$.fn.dataTable.render.RepositoryStockConsumptionValue = function(data = {}) {
if (data.value && data.value.consumed_stock !== null) {
if (data.consumptionManagable) {
return `<a href="${data.updateStockConsumptionUrl}"
class="manage-repository-consumed-stock-value-link stock-value-view-render">
${data.value.consumed_stock_formatted}
</a>`;
}
return `<span class="stock-value-view-render">${data.value.consumed_stock_formatted}</span>`;
if (!data.stock_present) {
return '<span class="empty-consumed-stock-render"> - </span>';
}
if (data.stock_present && data.consumptionManagable) {
if (!data.consumptionManagable) {
return `<span class="consumption-locked">
${I18n.t('libraries.manange_modal_column.stock_type.stock_consumption_locked')}
</span>`;
}
if (!data.consumptionPermitted) {
return `<span class="empty-consumed-stock-render">${data.value.consumed_stock_formatted}</span>`;
}
if (!data.value.consumed_stock) {
return `<a href="${data.updateStockConsumptionUrl}" class="manage-repository-consumed-stock-value-link">
<i class="fas fa-vial"></i>
${I18n.t('libraries.manange_modal_column.stock_type.add_stock_consumption')}
</a>`;
}
if (data.stock_present && !data.consumptionManagable) {
return `<span class="consumption-locked">
${I18n.t('libraries.manange_modal_column.stock_type.stock_consumption_locked')}
</span>`;
}
return '<span class="empty-consumed-stock-render"> - </span>';
return `<a href="${data.updateStockConsumptionUrl}"
class="manage-repository-consumed-stock-value-link stock-value-view-render">
${data.value.consumed_stock_formatted}
</a>`;
};
$.fn.dataTable.render.defaultRepositoryStockConsumptionValue = function() {

View file

@ -193,7 +193,7 @@
padding: 0;
}
.stock-low-stock-alert {
.stock-low {
&::before {
@include font-awesome;
color: $brand-warning;
@ -201,7 +201,7 @@
}
}
.stock-alert {
.stock-empty {
color: $brand-danger;
&::before {

View file

@ -229,7 +229,7 @@
// Stock
.stock-value-view-render {
&.stock-alert {
&.stock-empty {
color: $brand-danger;
&::before {
@ -238,7 +238,7 @@
}
}
&.stock-low-stock-alert {
&.stock-low {
&::before {
@include font-awesome;
color: $brand-warning;

View file

@ -59,13 +59,18 @@ module RepositoryDatatableHelper
# always add stock cell, even if empty
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team, repository) : {}
row['stock'][:stock_managable] = stock_managable
if !options[:include_stock_consumption] || can_update_my_module_stock_consumption?(options[:my_module])
row['stock'][:stock_status] = record.repository_stock_cell&.value&.status
end
row['stock']['value_type'] = 'RepositoryStockValue'
if options[:include_stock_consumption] && record.repository.has_stock_management? && options[:my_module]
consumption_managable = stock_consumption_managable?(record, repository, options[:my_module])
row['consumedStock'] = {
stock_present: stock_present,
consumptionPermitted: can_update_my_module_stock_consumption?(options[:my_module]),
consumptionManagable: consumption_managable,
updateStockConsumptionUrl: Rails.application.routes.url_helpers.consume_modal_my_module_repository_path(
options[:my_module],
@ -75,7 +80,7 @@ module RepositoryDatatableHelper
value: {
consumed_stock: record.consumed_stock,
consumed_stock_formatted:
"#{record.consumed_stock} #{record.repository_stock_value&.repository_stock_unit_item&.data}"
"#{record.consumed_stock || 0} #{record.repository_stock_value&.repository_stock_unit_item&.data}"
}
}
end
@ -110,6 +115,11 @@ module RepositoryDatatableHelper
consumption_managable = stock_consumption_managable?(record, repository, my_module)
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, record.repository.team, repository) : {}
if !options[:include_stock_consumption] || can_update_my_module_stock_consumption?(my_module)
row['stock'][:stock_status] = record.repository_stock_cell&.value&.status
end
row['stock'][:stock_managable] = stock_managable
if record.repository.is_a?(RepositorySnapshot)
row['consumedStock'] =
@ -126,15 +136,15 @@ module RepositoryDatatableHelper
my_module, record.repository, row_id: record.id
)
end
if record.consumed_stock.present?
row['consumedStock'][:value] = {
consumed_stock: record.consumed_stock,
consumed_stock_formatted:
"#{record.consumed_stock} #{record.repository_stock_value&.repository_stock_unit_item&.data}"
}
end
row['consumedStock'][:value] = {
consumed_stock: record.consumed_stock,
consumed_stock_formatted:
"#{record.consumed_stock || 0} #{record.repository_stock_value&.repository_stock_unit_item&.data}"
}
end
row['consumedStock']['stock_present'] = stock_present
row['consumedStock']['consumptionPermitted'] = can_update_my_module_stock_consumption?(my_module)
row['consumedStock']['consumptionManagable'] = consumption_managable
end
@ -260,6 +270,6 @@ module RepositoryDatatableHelper
return false unless record.repository.is_a?(Repository)
return false if repository.archived? || record.archived?
can_update_my_module_stock_consumption?(my_module)
true
end
end

View file

@ -39,10 +39,12 @@ class RepositoryStockValue < ApplicationRecord
end
end
def low_stock?
return false unless low_stock_threshold
def status
return :empty if amount <= 0
amount <= low_stock_threshold
return :low if low_stock_threshold && amount <= low_stock_threshold
:normal
end
def self.add_filter_condition(repository_rows, join_alias, filter_element)