mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 10:14:17 +08:00
Add delete location action [SCI-10864]
This commit is contained in:
parent
d96ef5751e
commit
9d541e28b2
4 changed files with 54 additions and 4 deletions
|
@ -49,7 +49,7 @@ class StorageLocationsController < ApplicationController
|
|||
if @storage_location.discard
|
||||
render json: {}
|
||||
else
|
||||
render json: { errors: @storage_location.errors.full_messages }, status: :unprocessable_entity
|
||||
render json: { error: @storage_location.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
@duplicate="duplicate"
|
||||
@tableReloaded="reloadingTable = false"
|
||||
@move="move"
|
||||
@delete="deleteStorageLocation"
|
||||
/>
|
||||
<Teleport to="body">
|
||||
<EditModal v-if="openEditModal"
|
||||
|
@ -25,6 +26,13 @@
|
|||
<MoveModal v-if="objectToMove" :moveToUrl="moveToUrl"
|
||||
:selectedObject="objectToMove" :storageLocationTreeUrl="storageLocationTreeUrl"
|
||||
@close="objectToMove = null" @move="updateTable()" />
|
||||
<ConfirmationModal
|
||||
:title="storageLocationDeleteTitle"
|
||||
:description="storageLocationDeleteDescription"
|
||||
confirmClass="btn btn-danger"
|
||||
:confirmText="i18n.t('general.delete')"
|
||||
ref="deleteStorageLocationModal"
|
||||
></ConfirmationModal>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -36,13 +44,15 @@ import axios from '../../packs/custom_axios.js';
|
|||
import DataTable from '../shared/datatable/table.vue';
|
||||
import EditModal from './modals/new_edit.vue';
|
||||
import MoveModal from './modals/move.vue';
|
||||
import ConfirmationModal from '../shared/confirmation_modal.vue';
|
||||
|
||||
export default {
|
||||
name: 'RepositoriesTable',
|
||||
components: {
|
||||
DataTable,
|
||||
EditModal,
|
||||
MoveModal
|
||||
MoveModal,
|
||||
ConfirmationModal
|
||||
},
|
||||
props: {
|
||||
dataSource: {
|
||||
|
@ -70,7 +80,9 @@ export default {
|
|||
editModalMode: null,
|
||||
editStorageLocation: null,
|
||||
objectToMove: null,
|
||||
moveToUrl: null
|
||||
moveToUrl: null,
|
||||
storageLocationDeleteTitle: '',
|
||||
storageLocationDeleteDescription: ''
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -200,6 +212,29 @@ export default {
|
|||
move(event, rows) {
|
||||
[this.objectToMove] = rows;
|
||||
this.moveToUrl = event.path;
|
||||
},
|
||||
async deleteStorageLocation(event, rows) {
|
||||
const storageLocationType = rows[0].container ? this.i18n.t('storage_locations.box') : this.i18n.t('storage_locations.location');
|
||||
const description = `
|
||||
<p>${this.i18n.t('storage_locations.index.delete_modal.description_1_html',
|
||||
{ name: rows[0].name, type: storageLocationType, num_of_items: event.number_of_items })}</p>
|
||||
<p>${this.i18n.t('storage_locations.index.delete_modal.description_2_html')}</p>`;
|
||||
|
||||
this.storageLocationDeleteDescription = description;
|
||||
this.storageLocationDeleteTitle = this.i18n.t('storage_locations.index.delete_modal.title', { type: storageLocationType });
|
||||
const ok = await this.$refs.deleteStorageLocationModal.show();
|
||||
if (ok) {
|
||||
axios.delete(event.path).then((_) => {
|
||||
this.reloadingTable = true;
|
||||
HelperModule.flashAlertMsg(this.i18n.t('storage_locations.index.delete_modal.success_message',
|
||||
{
|
||||
type: storageLocationType[0].toUpperCase() + storageLocationType.slice(1),
|
||||
name: rows[0].name
|
||||
}), 'success');
|
||||
}).catch((error) => {
|
||||
HelperModule.flashAlertMsg(error.response.data.error, 'danger');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -74,11 +74,19 @@ module Toolbars
|
|||
|
||||
return unless can_manage_storage_locations?(current_user.current_team)
|
||||
|
||||
storage_location = @storage_locations.first
|
||||
|
||||
number_of_items = storage_location.storage_location_repository_rows.count +
|
||||
StorageLocation.inner_storage_locations(current_user.current_team, storage_location)
|
||||
.where(container: true)
|
||||
.joins(:storage_location_repository_rows)
|
||||
.count
|
||||
{
|
||||
name: 'delete',
|
||||
label: I18n.t('storage_locations.index.toolbar.delete'),
|
||||
icon: 'sn-icon sn-icon-delete',
|
||||
path: storage_location_path(@storage_locations.first),
|
||||
number_of_items: number_of_items,
|
||||
path: storage_location_path(storage_location),
|
||||
type: :emit
|
||||
}
|
||||
end
|
||||
|
|
|
@ -2671,6 +2671,8 @@ en:
|
|||
errors:
|
||||
my_module_references_missing: 'Task references are not set'
|
||||
storage_locations:
|
||||
box: 'box'
|
||||
location: 'location'
|
||||
show:
|
||||
table:
|
||||
position: "Position"
|
||||
|
@ -2733,6 +2735,11 @@ en:
|
|||
error_flash: "An error occurred. The selected location/box has not been moved."
|
||||
placeholder:
|
||||
find_storage_locations: 'Find location'
|
||||
delete_modal:
|
||||
title: 'Delete a %{type}'
|
||||
description_1_html: "You're about to delete <b>%{name}</b>. This action will delete the %{type}. <b>%{num_of_items}</b> items inside will lose their assigned positions."
|
||||
description_2_html: '<b>Are you sure you want to delete it?</b>'
|
||||
success_message: "%{type} %{name} successfully deleted."
|
||||
|
||||
libraries:
|
||||
manange_modal_column_index:
|
||||
|
|
Loading…
Reference in a new issue