mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
adds an additional check if some other user has added/removed repository columns [fixes SCI-2408]
This commit is contained in:
parent
8e90efa94b
commit
f8ac083d39
6 changed files with 49 additions and 3 deletions
|
@ -391,7 +391,34 @@ var RepositoryDatatable = (function(global) {
|
|||
}
|
||||
}
|
||||
|
||||
function checkAvailibleColumns() {
|
||||
$.ajax({
|
||||
url: $(TABLE_ID).data('available-columns'),
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
var columns_ids = data.columns;
|
||||
var present_columns = [];
|
||||
$('table' + TABLE_ID + ' thead tr').children('th').each(function() {
|
||||
var id = parseInt($(this).attr('id'));
|
||||
if(id) {
|
||||
present_columns.push(id);
|
||||
}
|
||||
});
|
||||
if( !_.isEqual(columns_ids, present_columns) ) {
|
||||
alert($(TABLE_ID).data('columns-changed'));
|
||||
animateSpinner();
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function(data) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
global.onClickAddRecord = function() {
|
||||
checkAvailibleColumns();
|
||||
changeToEditMode();
|
||||
updateButtons();
|
||||
|
||||
|
@ -581,7 +608,6 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
global.onClickCopyRepositoryRecords = function() {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
|
@ -606,6 +632,7 @@ var RepositoryDatatable = (function(global) {
|
|||
|
||||
// Edit record
|
||||
global.onClickEdit = function() {
|
||||
checkAvailibleColumns();
|
||||
if (rowsSelected.length !== 1) {
|
||||
return;
|
||||
}
|
||||
|
@ -1205,6 +1232,7 @@ var RepositoryDatatable = (function(global) {
|
|||
loadColumnsNames();
|
||||
}
|
||||
});
|
||||
$('.sorting').on('click', checkAvailibleColumns);
|
||||
}
|
||||
|
||||
// calculate the max height of window and adjust dropdown max-height
|
||||
|
@ -1238,6 +1266,7 @@ var RepositoryDatatable = (function(global) {
|
|||
$('#repository-columns-dropdown').on('show.bs.dropdown', function() {
|
||||
loadColumnsNames();
|
||||
dropdownList.sortable('enable');
|
||||
checkAvailibleColumns();
|
||||
});
|
||||
|
||||
$('#repository-columns-dropdown').on('shown.bs.dropdown', function() {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class RepositoryColumnsController < ApplicationController
|
||||
include InputSanitizeHelper
|
||||
ACTIONS = %i(create index create_html available_asset_type_columns).freeze
|
||||
ACTIONS = %i(
|
||||
create index create_html available_asset_type_columns available_columns
|
||||
).freeze
|
||||
before_action :load_vars,
|
||||
except: ACTIONS
|
||||
before_action :load_vars_nested,
|
||||
|
@ -155,6 +157,10 @@ class RepositoryColumnsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def available_columns
|
||||
render json: { columns: @repository.available_columns_ids }, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
include StringUtility
|
||||
|
|
|
@ -66,6 +66,10 @@ class Repository < ApplicationRecord
|
|||
where('repositories.name ILIKE ?', "%#{query}%")
|
||||
end
|
||||
|
||||
def available_columns_ids
|
||||
repository_columns.pluck(:id)
|
||||
end
|
||||
|
||||
def importable_repository_fields
|
||||
fields = {}
|
||||
# First and foremost add record name
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
data-edit-text="<%= I18n.t('general.edit') %>"
|
||||
data-cancel-text="<%= I18n.t('general.cancel') %>"
|
||||
data-columns-visibility-text="<%= I18n.t('repositories.columns_visibility') %>"
|
||||
data-columns-delete-text="<%= I18n.t('repositories.columns_delete') %>">
|
||||
data-columns-delete-text="<%= I18n.t('repositories.columns_delete') %>"
|
||||
data-available-columns="<%= repository_available_columns_path(repository) %>"
|
||||
data-columns-changed="<%= I18n.t('repositories.columns_changed') %>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th id="checkbox"><input name="select_all" value="1" type="checkbox"></th>
|
||||
|
|
|
@ -984,6 +984,7 @@ en:
|
|||
column_new_text: "New column"
|
||||
column_create: "Create"
|
||||
columns_delete: "Delete"
|
||||
columns_changed: "Someone removed/added a new column to the inventory in use. To prevent data inconsistency we will reload this page for you."
|
||||
columns_reorder: "Re-Order Columns"
|
||||
columns_visibility: "Visible columns"
|
||||
view_all_records: "View All Items"
|
||||
|
|
|
@ -490,6 +490,10 @@ Rails.application.routes.draw do
|
|||
to: 'repository_columns#create_html',
|
||||
as: 'columns_create_html',
|
||||
defaults: { format: 'json' }
|
||||
get 'available_columns',
|
||||
to: 'repository_columns#available_columns',
|
||||
as: 'available_columns',
|
||||
defaults: { format: 'json' }
|
||||
|
||||
resources :repository_columns, only: %i(index create edit update destroy)
|
||||
resources :repository_rows, only: %i(create edit update)
|
||||
|
|
Loading…
Reference in a new issue