Fix inventory table custom error messages [SCI-6532] (#3855)

This commit is contained in:
Alex Kriuchykhin 2022-02-15 14:37:26 +01:00 committed by GitHub
parent fa6f883fc7
commit 0ce6f43cbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

View file

@ -24,8 +24,6 @@ var RepositoryDatatable = (function(global) {
// Tells whether we're currently viewing or editing table
var currentMode = 'viewMode';
// var selectedRecord;
// Extend datatables API with searchable options
// (http://stackoverflow.com/questions/39912395/datatables-dynamically-set-columns-searchable)
$.fn.dataTable.Api.register('isColumnSearchable()', function(colSelector) {
@ -419,13 +417,7 @@ var RepositoryDatatable = (function(global) {
return JSON.stringify(d);
},
global: false,
type: 'POST',
error: function(e) {
$('#filtersDropdownButton').removeClass('active-filters');
$('#saveRepositoryFilters').addClass('hidden');
$('.repository-table-error').addClass('active').html(e.responseJSON.error);
animateSpinner(null, false);
}
type: 'POST'
},
columnDefs: [{
// Checkbox column needs special handling
@ -613,6 +605,20 @@ var RepositoryDatatable = (function(global) {
$(this).parent().find('.repository-row-selector').trigger('click');
});
// Handling of special errors
$(TABLE_ID).on('xhr.dt', function(e, settings, json) {
if (json.custom_error) {
json.data = [];
json.recordsFiltered = 0;
json.recordsTotal = 0;
TABLE.one('draw', function() {
$('#filtersDropdownButton').removeClass('active-filters');
$('#saveRepositoryFilters').addClass('hidden');
$('.repository-table-error').addClass('active').text(json.custom_error);
});
}
})
initRowSelection();
bindExportActions();
$(window).resize(() => {

View file

@ -32,9 +32,9 @@ class RepositoryRowsController < ApplicationController
@repository_rows = @repository_rows.where(archived: params[:archived]) unless @repository.archived?
rescue RepositoryFilters::ColumnNotFoundException
render json: { error: I18n.t('repositories.show.repository_filter.errors.column_not_found') }, status: :not_found
render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.column_not_found') }
rescue RepositoryFilters::ValueNotFoundException
render json: { error: I18n.t('repositories.show.repository_filter.errors.value_not_found') }, status: :not_found
render json: { custom_error: I18n.t('repositories.show.repository_filter.errors.value_not_found') }
end
def create

View file

@ -1398,7 +1398,7 @@ en:
filter_inventory_items: "Filter items"
no_items: "No items here"
no_items_matched: "No items matched your search request"
no_items_matched: "No items here"
no_archived_items: "No archived items here"
no_archived_items_matched: "No archived items matched your search request"
error_searching: "Error searching, please try again"