mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 18:21:50 +08:00
Fix acivities and error handeling
This commit is contained in:
parent
3d59bbd50e
commit
8d43603789
6 changed files with 38 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
/* global HelperModule DataTableHelpers DataTableCheckboxes */
|
||||
/* global I18n animateSpinner HelperModule DataTableHelpers DataTableCheckboxes */
|
||||
(function(global) {
|
||||
'use strict';
|
||||
|
||||
|
@ -92,6 +92,18 @@
|
|||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
initRepositoriesDataTable('#repositoriesList');
|
||||
reloadSidebar();
|
||||
},
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -106,6 +118,18 @@
|
|||
HelperModule.flashAlertMsg(data.flash, 'success');
|
||||
initRepositoriesDataTable('#repositoriesList', true);
|
||||
reloadSidebar();
|
||||
},
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -8,12 +8,13 @@ module Repositories
|
|||
ActiveRecord::Base.transaction do
|
||||
@repositories.each do |repository|
|
||||
log_activity(:archive_inventory, repository)
|
||||
repository.archive!(@user)
|
||||
|
||||
repository.archive!(@user)
|
||||
RepositoryActions::ArchiveRowsService.call(repository: repository,
|
||||
repository_rows: repository.repository_rows.pluck(:id),
|
||||
user: @user,
|
||||
team: @team)
|
||||
team: @team,
|
||||
log_activities: false)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
@errors[:archiving_error] = I18n.t('repositories.archive_inventories.unsuccess_flash')
|
||||
|
|
|
@ -12,7 +12,9 @@ module Repositories
|
|||
RepositoryActions::RestoreRowsService.call(repository: repository,
|
||||
repository_rows: repository.repository_rows.pluck(:id),
|
||||
user: @user,
|
||||
team: @team)
|
||||
team: @team,
|
||||
log_activities: false)
|
||||
|
||||
log_activity(:restore_inventory, repository)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
|
|
|
@ -6,11 +6,12 @@ module RepositoryActions
|
|||
|
||||
attr_reader :errors
|
||||
|
||||
def initialize(user:, team:, repository:, repository_rows:)
|
||||
def initialize(user:, team:, repository:, repository_rows:, log_activities: true)
|
||||
@user = user
|
||||
@team = team
|
||||
@repository = repository
|
||||
@repository_rows = scoped_repository_rows(repository_rows)
|
||||
@log_activities = log_activities
|
||||
@errors = {}
|
||||
end
|
||||
|
||||
|
@ -51,7 +52,7 @@ module RepositoryActions
|
|||
Activities::CreateActivityService
|
||||
.call(activity_type: type,
|
||||
owner: @user,
|
||||
subject: row,
|
||||
subject: row.repository,
|
||||
team: @team,
|
||||
message_items: {
|
||||
repository_row: row.id
|
||||
|
|
|
@ -6,9 +6,9 @@ module RepositoryActions
|
|||
return self unless valid?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@repository_rows.each do |row|
|
||||
@repository_rows.find_each(batch_size: 100) do |row|
|
||||
row.archive!(@user)
|
||||
log_activity(:archive_inventory_item, row)
|
||||
log_activity(:archive_inventory_item, row) if @log_activities
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
@errors[:archiving_error] = I18n.t('repositories.archive_records.unsuccess_flash', @repository.name)
|
||||
|
|
|
@ -6,9 +6,9 @@ module RepositoryActions
|
|||
return self unless valid?
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@repository_rows.each do |row|
|
||||
@repository_rows.find_each(batch_size: 100) do |row|
|
||||
row.restore!(@user)
|
||||
log_activity(:restore_inventory_item, row)
|
||||
log_activity(:restore_inventory_item, row) if @log_activities
|
||||
end
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
@errors[:restoring_error] = I18n.t('repositories.restore_records.unsuccess_flash', @repository.name)
|
||||
|
|
Loading…
Reference in a new issue