mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-12 08:04:34 +08:00
Add repository_rows restoring and archiving actions on FE
This commit is contained in:
parent
fabfd7ddaf
commit
c7d6c4d60e
8 changed files with 92 additions and 21 deletions
|
@ -64,7 +64,7 @@ var RepositoryDatatable = (function(global) {
|
|||
$('#exportRepositoriesButton').addClass('disabled');
|
||||
$('#copyRepositoryRecords').prop('disabled', true);
|
||||
$('#editRepositoryRecord').prop('disabled', true);
|
||||
$('#deleteRepositoryRecordsButton').prop('disabled', true);
|
||||
$('#archiveRepositoryRecordsButton').prop('disabled', true);
|
||||
$('#assignRepositoryRecords').prop('disabled', true);
|
||||
$('#unassignRepositoryRecords').prop('disabled', true);
|
||||
$('#editDeleteCopy').hide();
|
||||
|
@ -75,14 +75,14 @@ var RepositoryDatatable = (function(global) {
|
|||
$('#editRepositoryRecord').prop('disabled', true);
|
||||
}
|
||||
$('#exportRepositoriesButton').removeClass('disabled');
|
||||
$('#deleteRepositoryRecordsButton').prop('disabled', false);
|
||||
$('#archiveRepositoryRecordsButton').prop('disabled', false);
|
||||
$('#copyRepositoryRecords').prop('disabled', false);
|
||||
$('#assignRepositoryRecords').prop('disabled', false);
|
||||
$('#unassignRepositoryRecords').prop('disabled', false);
|
||||
|
||||
if (rowsSelected.some(r=> rowsLocked.indexOf(r) >= 0)) { // Some selected rows is rowsLocked
|
||||
$('#editRepositoryRecord').prop('disabled', true);
|
||||
$('#deleteRepositoryRecordsButton').prop('disabled', true);
|
||||
$('#archiveRepositoryRecordsButton').prop('disabled', true);
|
||||
}
|
||||
$('#editDeleteCopy').show();
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ var RepositoryDatatable = (function(global) {
|
|||
$('.dataTables_length select').prop('disabled', true);
|
||||
$('#addRepositoryRecord').prop('disabled', true);
|
||||
$('#editRepositoryRecord').prop('disabled', true);
|
||||
$('#deleteRepositoryRecordsButton').prop('disabled', true);
|
||||
$('#archiveRepositoryRecordsButton').prop('disabled', true);
|
||||
$('#assignRepositoryRecords').prop('disabled', true);
|
||||
$('#unassignRepositoryRecords').prop('disabled', true);
|
||||
$('#repository-columns-dropdown').find('.dropdown-toggle').prop('disabled', true);
|
||||
|
@ -727,6 +727,60 @@ var RepositoryDatatable = (function(global) {
|
|||
});
|
||||
};
|
||||
|
||||
global.onClickArchiveRepositoryRecords = function() {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
url: $('table' + TABLE_ID).data('archive-records'),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_rows: rowsSelected },
|
||||
success: function(data) {
|
||||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
rowsSelected = [];
|
||||
resetTableView();
|
||||
},
|
||||
error: function(ev) {
|
||||
if (ev.status === 403) {
|
||||
HelperModule.flashAlertMsg(
|
||||
I18n.t('repositories.js.permission_error'), ev.responseJSON.style
|
||||
);
|
||||
} else if (ev.status === 422) {
|
||||
HelperModule.flashAlertMsg(
|
||||
ev.responseJSON.error, 'danger'
|
||||
);
|
||||
animateSpinner(null, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
global.onClickRestoreRepositoryRecords = function() {
|
||||
animateSpinner();
|
||||
$.ajax({
|
||||
url: $('table' + TABLE_ID).data('restore-records'),
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: { selected_rows: rowsSelected },
|
||||
success: function(data) {
|
||||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
rowsSelected = [];
|
||||
resetTableView();
|
||||
},
|
||||
error: function(ev) {
|
||||
if (ev.status === 403) {
|
||||
HelperModule.flashAlertMsg(
|
||||
I18n.t('repositories.js.permission_error'), ev.responseJSON.style
|
||||
);
|
||||
} else if (ev.status === 422) {
|
||||
HelperModule.flashAlertMsg(
|
||||
ev.responseJSON.error, 'danger'
|
||||
);
|
||||
animateSpinner(null, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Edit record
|
||||
global.onClickEdit = function() {
|
||||
checkAvailableColumns();
|
||||
|
|
|
@ -21,6 +21,7 @@ class RepositoryRowsController < ApplicationController
|
|||
@all_rows_count = datatable_service.all_count
|
||||
@columns_mappings = datatable_service.mappings
|
||||
@repository_rows = datatable_service.repository_rows
|
||||
.active
|
||||
.preload(:repository_columns,
|
||||
:created_by,
|
||||
repository_cells: @repository.cell_preload_includes)
|
||||
|
@ -177,9 +178,9 @@ class RepositoryRowsController < ApplicationController
|
|||
team: current_team)
|
||||
|
||||
if service.succeed?
|
||||
render json: {}, status: :ok
|
||||
render json: { flash: t('repositories.archive_records.success_flash', repository: @repository.name) }, status: :ok
|
||||
else
|
||||
render json: { status: service.errors }, status: :unprocessable_entity
|
||||
render json: { error: service.error_message }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -190,9 +191,9 @@ class RepositoryRowsController < ApplicationController
|
|||
team: current_team)
|
||||
|
||||
if service.succeed?
|
||||
render json: {}, status: :ok
|
||||
render json: { flash: t('repositories.restore_records.success_flash', repository: @repository.name) }, status: :ok
|
||||
else
|
||||
render json: { status: service.errors }, status: :unprocessable_entity
|
||||
render json: { error: service.error_message }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ module RepositoryActions
|
|||
class ArchiveRowsBaseService
|
||||
extend Service
|
||||
|
||||
attr_reader :errors, :column
|
||||
attr_reader :errors
|
||||
|
||||
def initialize(user:, team:, repository:, repository_rows:)
|
||||
@user = user
|
||||
|
@ -22,6 +22,10 @@ module RepositoryActions
|
|||
@errors.none?
|
||||
end
|
||||
|
||||
def error_message
|
||||
@errors.values.join(', ')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def scoped_repository_rows(_ids)
|
||||
|
@ -38,7 +42,7 @@ module RepositoryActions
|
|||
end.compact
|
||||
end
|
||||
|
||||
@errors[:repository_rows] = 'Please provide valid rows' if @repository_rows.blank?
|
||||
@errors[:repository_rows] = I18n.t('repositories.archive_records.invalid_rows_flash') if @repository_rows.blank?
|
||||
|
||||
succeed?
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module RepositoryActions
|
|||
log_activity(:archive_inventory_item, row)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
@errors[:archiving_error] = 'Cannot archive all items'
|
||||
@errors[:archiving_error] = I18n.t('repositories.archive_records.unsuccess_flash', @repository.name)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module RepositoryActions
|
|||
log_activity(:restore_inventory_item, row)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
@errors[:restoring_error] = 'Cannot restore all items'
|
||||
@errors[:restoring_error] = I18n.t('repositories.restore_records.unsuccess_flash', @repository.name)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
data-create-record="<%= repository_repository_rows_path(repository) %>"
|
||||
data-delete-record="<%= repository_delete_records_path(repository) %>"
|
||||
data-copy-records="<%= repository_copy_records_path(repository) %>"
|
||||
data-archive-records="<%= repository_archive_records_path(repository) %>"
|
||||
data-restore-records="<%= repository_restore_records_path(repository) %>"
|
||||
data-direct-upload-url="<%= rails_direct_uploads_url %>"
|
||||
data-max-dropdown-length="<%= Constants::MODAL_TEXT_MAX_LENGTH %>"
|
||||
data-repository-columns-ids="<%= repository.repository_columns.pluck(:id) %>"
|
||||
|
|
|
@ -22,21 +22,23 @@
|
|||
</button>
|
||||
<% end %>
|
||||
|
||||
<% if can_delete_repository_rows?(@repository) %>
|
||||
<button type="button" class="btn btn-light"
|
||||
id="deleteRepositoryRecordsButton" onclick="onClickDelete()" disabled>
|
||||
<span class="fas fa-trash"></span>
|
||||
<span class="hidden-xs-custom"><%= t'repositories.delete_record' %></span>
|
||||
<%= submit_tag I18n.t('repositories.delete_record'), :class => "hidden delete_repository_records_submit" %>
|
||||
</button>
|
||||
<% end %>
|
||||
|
||||
<% if can_create_repository_rows?(@repository) %>
|
||||
<button type="button" class="btn btn-light copyRow" id="copyRepositoryRecords" onclick="onClickCopyRepositoryRecords()" disabled>
|
||||
<span class="fas fa-copy"></span>
|
||||
<span class="hidden-xs-custom"><%= t("repositories.copy_record") %></span>
|
||||
</button>
|
||||
<%end%>
|
||||
<% end %>
|
||||
|
||||
<% if can_delete_repository_rows?(@repository) %>
|
||||
<button type="button" class="btn btn-light"
|
||||
id="archiveRepositoryRecordsButton" onclick="onClickArchiveRepositoryRecords()" disabled>
|
||||
<span class="fas fa-archive"></span>
|
||||
<span class="hidden-xs-custom"><%= t'repositories.archive_record' %></span>
|
||||
<%= submit_tag I18n.t('repositories.delete_record'), :class => "hidden delete_repository_records_submit" %>
|
||||
</button>
|
||||
<% end %>
|
||||
|
||||
</span>
|
||||
|
||||
<span id="saveCancel" data-toggle="buttons" style="display:none">
|
||||
|
|
|
@ -1172,6 +1172,7 @@ en:
|
|||
edit_record: "Edit"
|
||||
copy_record: "Duplicate"
|
||||
delete_record: "Delete"
|
||||
archive_record: "Archive"
|
||||
save_record: "Save"
|
||||
cancel_save: "Cancel"
|
||||
assign_records_to_module: "Assign"
|
||||
|
@ -1222,6 +1223,13 @@ en:
|
|||
no_deleted_records_flash: "No items were deleted. %{other_records_number} of the selected items were created by other users and were not deleted."
|
||||
default_column: 'Name'
|
||||
copy_records_report: "%{number} item(s) successfully copied."
|
||||
archive_records:
|
||||
success_flash: "Successfully archived items in inventory <strong>%{repository}</strong>"
|
||||
unsuccess_flash: "Unsuccessfully archived items in inventory <strong>%{repository}</strong>"
|
||||
invalid_rows_flash: "Please provide valid rows"
|
||||
restore_records:
|
||||
success_flash: "Successfully restored items in inventory <strong>%{repository}</strong>"
|
||||
unsuccess_flash: "Unsuccessfully restored items in inventory <strong>%{repository}</strong>"
|
||||
multiple_share_service:
|
||||
unable_to_share: "Unable to share %{repository} inventory with %{team} team."
|
||||
unable_to_unshare: "Unable to unshare %{repository} inventory with %{team} team."
|
||||
|
|
Loading…
Add table
Reference in a new issue