mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 20:54:27 +08:00
Stock column fixes [SCI-6455] (#3878)
* Fix issues with stock column management [SCI-6455] * Refactor stock column in datatables [SCI-6455]
This commit is contained in:
parent
ea6873b465
commit
20ef08907a
12 changed files with 74 additions and 49 deletions
|
@ -11,7 +11,7 @@ var MyModuleRepositories = (function() {
|
|||
var FULL_VIEW_TABLE_SCROLLBAR;
|
||||
var SELECTED_ROWS = {};
|
||||
|
||||
function stockManagementColumns(otherColumnCount) {
|
||||
function stockManagementColumns() {
|
||||
return [
|
||||
{
|
||||
visible: true,
|
||||
|
@ -65,17 +65,20 @@ var MyModuleRepositories = (function() {
|
|||
columns[i].defaultContent = '';
|
||||
if (skipCheckbox && i === 0) columns[i].visible = false;
|
||||
}
|
||||
|
||||
customColumns.each((i, column) => {
|
||||
columns.push({
|
||||
visible: true,
|
||||
searchable: true,
|
||||
data: String(columns.length),
|
||||
defaultContent: $.fn.dataTable.render['default' + column.dataset.type](column.id)
|
||||
});
|
||||
if (!$(column).hasClass('item-stock')) {
|
||||
columns.push({
|
||||
visible: true,
|
||||
searchable: true,
|
||||
data: String(columns.length),
|
||||
defaultContent: $.fn.dataTable.render['default' + column.dataset.type](column.id)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if ($(tableContainer).data('stock-management')) {
|
||||
columns.push(stockManagementColumns(columns.length)[1]);
|
||||
columns = columns.concat(stockManagementColumns());
|
||||
}
|
||||
|
||||
return columns;
|
||||
|
@ -121,6 +124,9 @@ var MyModuleRepositories = (function() {
|
|||
});
|
||||
}
|
||||
|
||||
if ($(tableContainer).data('stock-management')) {
|
||||
columnDefs = columnDefs.concat(stockManagementColumnDefs());
|
||||
}
|
||||
|
||||
columnDefs.push(
|
||||
{
|
||||
|
@ -137,11 +143,6 @@ var MyModuleRepositories = (function() {
|
|||
}
|
||||
);
|
||||
|
||||
if ($(tableContainer).data('stock-management')) {
|
||||
let stockColumnDef = stockManagementColumnDefs()[1];
|
||||
columnDefs.push(stockColumnDef);
|
||||
}
|
||||
|
||||
return columnDefs;
|
||||
}
|
||||
|
||||
|
@ -155,7 +156,7 @@ var MyModuleRepositories = (function() {
|
|||
];
|
||||
|
||||
if ($(tableContainer).data('stock-management')) {
|
||||
columns = columns.concat(stockManagementColumns(columns.length));
|
||||
columns = columns.concat(stockManagementColumns());
|
||||
}
|
||||
|
||||
return columns;
|
||||
|
|
|
@ -86,6 +86,15 @@
|
|||
}, {
|
||||
targets: 8,
|
||||
visible: archived
|
||||
},
|
||||
{
|
||||
visible: true,
|
||||
searchable: false,
|
||||
data: 'stock',
|
||||
render: {
|
||||
_: 'display',
|
||||
sort: 'sort'
|
||||
}
|
||||
}],
|
||||
fnInitComplete: function(e) {
|
||||
var dataTableWrapper = $(e.nTableWrapper);
|
||||
|
|
|
@ -181,24 +181,26 @@ $.fn.dataTable.render.AssignedTasksValue = function(data) {
|
|||
return "<div class='assign-counter-container'><span class='assign-counter'>0</span></div>";
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.RepositoryStockValue = function(data, row) {
|
||||
if (data && data.value) {
|
||||
if (row && row.manageStockUrl) {
|
||||
return `<a class="manage-repository-stock-value-link stock-value-view-render
|
||||
${data.value.stock_amount <= 0 ? 'stock-alert' : ''}">
|
||||
$.fn.dataTable.render.RepositoryStockValue = function(data) {
|
||||
if (data) {
|
||||
if (data.value) {
|
||||
if (data.stock_managable) {
|
||||
return `<a class="manage-repository-stock-value-link stock-value-view-render
|
||||
${data.value.stock_amount <= 0 ? 'stock-alert' : ''}">
|
||||
${data.value.stock_formatted}
|
||||
</a>`;
|
||||
}
|
||||
return `<span class="stock-value-view-render
|
||||
${data.value.stock_amount <= 0 ? 'stock-alert' : ''}">
|
||||
${data.value.stock_formatted}
|
||||
</a>`;
|
||||
</span>`;
|
||||
}
|
||||
if (data.stock_managable) {
|
||||
return `<a class="manage-repository-stock-value-link not-assigned-stock">
|
||||
<i class="fas fa-box-open"></i>
|
||||
${I18n.t('libraries.manange_modal_column.stock_type.add_stock')}
|
||||
</a>`;
|
||||
}
|
||||
return `<span class="stock-value-view-render
|
||||
${data.value.stock_amount <= 0 ? 'stock-alert' : ''}">
|
||||
${data.value.stock_formatted}
|
||||
</span>`;
|
||||
}
|
||||
if (data && row && row.manageStockUrl) {
|
||||
return `<a class="manage-repository-stock-value-link not-assigned-stock">
|
||||
<i class="fas fa-box-open"></i>
|
||||
${I18n.t('libraries.manange_modal_column.stock_type.add_stock')}
|
||||
</a>`;
|
||||
}
|
||||
return `<span class="empty-stock-render">
|
||||
${I18n.t('libraries.manange_modal_column.stock_type.no_item_stock')}
|
||||
|
|
|
@ -458,12 +458,20 @@ var RepositoryDatatable = (function(global) {
|
|||
visible: true
|
||||
}, {
|
||||
targets: '_all',
|
||||
render: function(data, type, row) {
|
||||
render: function(data) {
|
||||
if (typeof data === 'object' && $.fn.dataTable.render[data.value_type]) {
|
||||
return $.fn.dataTable.render[data.value_type](data, row);
|
||||
return $.fn.dataTable.render[data.value_type](data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
},
|
||||
{
|
||||
targets: 'row-stock',
|
||||
className: 'item-stock',
|
||||
sWidth: '1%',
|
||||
render: function(data) {
|
||||
return $.fn.dataTable.render.RepositoryStockValue(data);
|
||||
}
|
||||
}],
|
||||
language: {
|
||||
emptyTable: I18n.t('repositories.show.no_items'),
|
||||
|
@ -488,13 +496,15 @@ var RepositoryDatatable = (function(global) {
|
|||
columns[i].defaultContent = '';
|
||||
}
|
||||
customColumns.each((i, column) => {
|
||||
var columnData = $(column).data('type') === 'RepositoryStockValue' ? 'stock' : String(columns.length);
|
||||
columns.push({
|
||||
visible: true,
|
||||
searchable: true,
|
||||
data: String(columns.length),
|
||||
data: columnData,
|
||||
defaultContent: $.fn.dataTable.render['default' + column.dataset.type](column.id)
|
||||
});
|
||||
});
|
||||
|
||||
return columns;
|
||||
}()),
|
||||
drawCallback: function() {
|
||||
|
|
|
@ -5,7 +5,7 @@ var RepositoryStockColumnType = (function() {
|
|||
var delimiterDropdown = '.stock-column-type #delimiter';
|
||||
var itemsTextarea = '.stock-column-type .items-textarea';
|
||||
var previewContainer = '.stock-column-type .dropdown-preview';
|
||||
var dropdownOptions = '.stock-column-type .dropdown-options';
|
||||
var dropdownOptions = '.stock-column-type #dropdown-options';
|
||||
|
||||
function initStockUnitDropdown() {
|
||||
dropdownSelector.init(previewContainer + ' .preview-select', {
|
||||
|
|
|
@ -162,6 +162,8 @@ class MyModuleRepositoriesController < ApplicationController
|
|||
module_repository_row.with_lock do
|
||||
module_repository_row.assign_attributes(
|
||||
stock_consumption: params[:stock_consumption],
|
||||
repository_stock_unit_item_id:
|
||||
module_repository_row.repository_row.repository_stock_value.repository_stock_unit_item_id,
|
||||
last_modified_by: current_user,
|
||||
comment: params[:comment]
|
||||
)
|
||||
|
|
|
@ -46,15 +46,22 @@ module RepositoryDatatableHelper
|
|||
row['0'] = record[:row_assigned] if options[:my_module]
|
||||
|
||||
# Add custom columns
|
||||
custom_cells = record.repository_cells
|
||||
custom_cells = record.repository_cells.where.not(value_type: 'RepositoryStockValue')
|
||||
|
||||
custom_cells.each do |cell|
|
||||
row[columns_mappings[cell.repository_column.id]] =
|
||||
display_cell_value(cell, team)
|
||||
end
|
||||
|
||||
stock_present = record.repository_stock_cell.present?
|
||||
stock_managable = !options[:include_stock_consumption] && can_manage_repository_rows?(record.repository)
|
||||
|
||||
# always add stock cell, even if empty
|
||||
row['stock'] = stock_present ? display_cell_value(record.repository_stock_cell, team) : {}
|
||||
row['stock'][:stock_managable] = stock_managable
|
||||
row['stock']['value_type'] = 'RepositoryStockValue'
|
||||
|
||||
if options[:include_stock_consumption] && record.repository.has_stock_management? && options[:my_module]
|
||||
stock_present = record.repository_stock_cell.present?
|
||||
consumption_managable =
|
||||
stock_present && record.repository.is_a?(Repository) && can_update_my_module_stock_consumption?(options[:my_module])
|
||||
|
||||
|
@ -68,7 +75,8 @@ module RepositoryDatatableHelper
|
|||
),
|
||||
value: {
|
||||
consumed_stock: record.consumed_stock,
|
||||
unit: record.repository_stock_value&.repository_stock_unit_item&.data
|
||||
consumed_stock_formatted:
|
||||
"#{record.consumed_stock} #{record.repository_stock_value&.repository_stock_unit_item&.data}"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
module RepositoryDatatable
|
||||
class RepositoryStockValueSerializer < RepositoryBaseValueSerializer
|
||||
include Canaid::Helpers::PermissionsHelper
|
||||
|
||||
def value
|
||||
{
|
||||
stock_formatted: object.formatted,
|
||||
|
|
|
@ -13,7 +13,7 @@ module RepositoryColumns
|
|||
|
||||
@column.lock!
|
||||
|
||||
updating_units_names = @params[:repository_stock_unit_items_attributes].to_a.map { |e| e[:data] }
|
||||
updating_units_names = @params[:repository_stock_unit_items_attributes].to_a.pluck(:data)
|
||||
existing_units_names = @column.repository_stock_unit_items.pluck(:data)
|
||||
to_be_deleted = existing_units_names - updating_units_names
|
||||
to_be_created = updating_units_names - existing_units_names
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<th id="archived-by"><%= t("repositories.table.archived_by") %></th>
|
||||
<% @repository.repository_columns.order(:id).each do |column| %>
|
||||
<th
|
||||
class="repository-column"
|
||||
class="repository-column <%= 'row-stock item-stock' if column.data_type == 'RepositoryStockValue' %>"
|
||||
id="<%= column.id %>"
|
||||
data-type="<%= column.data_type %>"
|
||||
<% column.metadata.each do |k, v| %>
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<th id="archived-by"><%= t("repositories.table.archived_by") %></th>
|
||||
<% repository.repository_columns.order(:id).each do |column| %>
|
||||
<th
|
||||
class="repository-column"
|
||||
class="repository-column <%= 'row-stock item-stock' if column.data_type == 'RepositoryStockValue' %>"
|
||||
id="<%= column.id %>"
|
||||
data-type="<%= column.data_type %>"
|
||||
data-edit-column-url="<%= edit_repository_repository_column_path(repository, column) %>"
|
||||
|
|
|
@ -109,15 +109,6 @@
|
|||
<%= 'selected' if @repository_column.repository_time_value? || @repository_column.repository_time_range_value? %> >
|
||||
<%= t('libraries.manange_modal_column.select.repository_time_value') %>
|
||||
</option>
|
||||
|
||||
<option data-delimiter=true></option>
|
||||
|
||||
<option data-create-url="<%= repository_repository_columns_stock_columns_path(@repository) %>"
|
||||
data-edit-url="<%= repository_repository_columns_stock_column_path(@repository, @repository_column) unless @repository_column.new_record? %>"
|
||||
value="RepositoryStockValue"
|
||||
<%= 'selected' if @repository_column.repository_stock_value? %> >
|
||||
<%= t('libraries.manange_modal_column.select.repository_stock_value') %>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue