2024-07-16 21:20:02 +08:00
|
|
|
<template>
|
|
|
|
<div class="h-full">
|
|
|
|
<DataTable :columnDefs="columnDefs"
|
|
|
|
tableId="StorageLocationsTable"
|
|
|
|
:dataUrl="dataSource"
|
|
|
|
:reloadingTable="reloadingTable"
|
|
|
|
:toolbarActions="toolbarActions"
|
|
|
|
:actionsUrl="actionsUrl"
|
2024-08-02 19:59:01 +08:00
|
|
|
:filters="filters"
|
2024-07-19 19:24:23 +08:00
|
|
|
@create_location="openCreateLocationModal"
|
2024-07-29 15:44:15 +08:00
|
|
|
@create_container="openCreateContainerModal"
|
2024-07-19 19:24:23 +08:00
|
|
|
@edit="edit"
|
2024-07-16 21:20:02 +08:00
|
|
|
@duplicate="duplicate"
|
|
|
|
@tableReloaded="reloadingTable = false"
|
2024-07-23 14:50:17 +08:00
|
|
|
@move="move"
|
2024-07-23 20:50:39 +08:00
|
|
|
@delete="deleteStorageLocation"
|
2024-07-16 21:20:02 +08:00
|
|
|
/>
|
2024-07-19 19:24:23 +08:00
|
|
|
<Teleport to="body">
|
|
|
|
<EditModal v-if="openEditModal"
|
|
|
|
@close="openEditModal = false"
|
|
|
|
@tableReloaded="reloadingTable = true"
|
|
|
|
:createUrl="createUrl"
|
|
|
|
:editModalMode="editModalMode"
|
|
|
|
:directUploadUrl="directUploadUrl"
|
|
|
|
:editStorageLocation="editStorageLocation"
|
|
|
|
/>
|
2024-07-23 14:50:17 +08:00
|
|
|
<MoveModal v-if="objectToMove" :moveToUrl="moveToUrl"
|
2024-07-29 21:41:40 +08:00
|
|
|
:selectedObject="objectToMove"
|
2024-07-23 14:50:17 +08:00
|
|
|
@close="objectToMove = null" @move="updateTable()" />
|
2024-07-23 20:50:39 +08:00
|
|
|
<ConfirmationModal
|
|
|
|
:title="storageLocationDeleteTitle"
|
|
|
|
:description="storageLocationDeleteDescription"
|
|
|
|
confirmClass="btn btn-danger"
|
|
|
|
:confirmText="i18n.t('general.delete')"
|
|
|
|
ref="deleteStorageLocationModal"
|
|
|
|
></ConfirmationModal>
|
2024-07-19 19:24:23 +08:00
|
|
|
</Teleport>
|
2024-07-16 21:20:02 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-07-22 18:12:47 +08:00
|
|
|
/* global HelperModule */
|
2024-07-16 21:20:02 +08:00
|
|
|
|
2024-07-22 18:12:47 +08:00
|
|
|
import axios from '../../packs/custom_axios.js';
|
2024-07-16 21:20:02 +08:00
|
|
|
import DataTable from '../shared/datatable/table.vue';
|
2024-07-19 19:24:23 +08:00
|
|
|
import EditModal from './modals/new_edit.vue';
|
2024-07-23 14:50:17 +08:00
|
|
|
import MoveModal from './modals/move.vue';
|
2024-07-23 20:50:39 +08:00
|
|
|
import ConfirmationModal from '../shared/confirmation_modal.vue';
|
2024-07-16 21:20:02 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'RepositoriesTable',
|
|
|
|
components: {
|
2024-07-19 19:24:23 +08:00
|
|
|
DataTable,
|
2024-07-23 14:50:17 +08:00
|
|
|
EditModal,
|
2024-07-23 20:50:39 +08:00
|
|
|
MoveModal,
|
|
|
|
ConfirmationModal
|
2024-07-16 21:20:02 +08:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
dataSource: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
actionsUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
2024-08-02 20:40:02 +08:00
|
|
|
createLocationUrl: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
createLocationInstanceUrl: {
|
2024-07-16 21:20:02 +08:00
|
|
|
type: String
|
2024-07-19 19:24:23 +08:00
|
|
|
},
|
|
|
|
directUploadUrl: {
|
2024-07-16 21:20:02 +08:00
|
|
|
type: String
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-07-19 19:24:23 +08:00
|
|
|
reloadingTable: false,
|
|
|
|
openEditModal: false,
|
|
|
|
editModalMode: null,
|
2024-07-23 14:50:17 +08:00
|
|
|
editStorageLocation: null,
|
|
|
|
objectToMove: null,
|
2024-07-23 20:50:39 +08:00
|
|
|
moveToUrl: null,
|
|
|
|
storageLocationDeleteTitle: '',
|
|
|
|
storageLocationDeleteDescription: ''
|
2024-07-16 21:20:02 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
columnDefs() {
|
|
|
|
const columns = [{
|
|
|
|
field: 'name',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.name'),
|
|
|
|
sortable: true,
|
|
|
|
notSelectable: true,
|
|
|
|
cellRenderer: this.nameRenderer
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'code',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.id'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
2024-07-18 19:05:59 +08:00
|
|
|
field: 'sub_location_count',
|
2024-07-16 21:20:02 +08:00
|
|
|
headerName: this.i18n.t('storage_locations.index.table.sub_locations'),
|
2024-07-18 19:05:59 +08:00
|
|
|
width: 250,
|
2024-07-16 21:20:02 +08:00
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'items',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.items'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'free_spaces',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.free_spaces'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'shared',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.shared'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'owned_by',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.owned_by'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'created_on',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.created_on'),
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'description',
|
|
|
|
headerName: this.i18n.t('storage_locations.index.table.description'),
|
|
|
|
sortable: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
return columns;
|
|
|
|
},
|
|
|
|
toolbarActions() {
|
|
|
|
const left = [];
|
2024-08-02 20:40:02 +08:00
|
|
|
if (this.createLocationUrl) {
|
2024-07-16 21:20:02 +08:00
|
|
|
left.push({
|
|
|
|
name: 'create_location',
|
|
|
|
icon: 'sn-icon sn-icon-new-task',
|
|
|
|
label: this.i18n.t('storage_locations.index.new_location'),
|
|
|
|
type: 'emit',
|
2024-08-02 20:40:02 +08:00
|
|
|
path: this.createLocationUrl,
|
2024-07-16 21:20:02 +08:00
|
|
|
buttonStyle: 'btn btn-primary'
|
|
|
|
});
|
2024-08-02 20:40:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.createLocationInstanceUrl) {
|
2024-07-16 21:20:02 +08:00
|
|
|
left.push({
|
2024-07-29 15:44:15 +08:00
|
|
|
name: 'create_container',
|
2024-07-16 21:20:02 +08:00
|
|
|
icon: 'sn-icon sn-icon-item',
|
2024-07-29 15:44:15 +08:00
|
|
|
label: this.i18n.t('storage_locations.index.new_container'),
|
2024-07-16 21:20:02 +08:00
|
|
|
type: 'emit',
|
2024-08-02 20:40:02 +08:00
|
|
|
path: this.createLocationInstanceUrl,
|
2024-07-16 21:20:02 +08:00
|
|
|
buttonStyle: 'btn btn-secondary'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
left,
|
|
|
|
right: []
|
|
|
|
};
|
2024-08-02 19:59:01 +08:00
|
|
|
},
|
|
|
|
filters() {
|
|
|
|
const filters = [
|
|
|
|
{
|
|
|
|
key: 'query',
|
|
|
|
type: 'Text'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'search_tree',
|
|
|
|
type: 'Checkbox',
|
|
|
|
label: this.i18n.t('storage_locations.index.filters_modal.search_tree')
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
return filters;
|
2024-08-02 20:40:02 +08:00
|
|
|
},
|
|
|
|
createUrl() {
|
|
|
|
return this.editModalMode === 'location' ? this.createLocationUrl : this.createLocationInstanceUrl;
|
2024-07-16 21:20:02 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-07-19 19:24:23 +08:00
|
|
|
openCreateLocationModal() {
|
|
|
|
this.openEditModal = true;
|
|
|
|
this.editModalMode = 'location';
|
|
|
|
this.editStorageLocation = null;
|
|
|
|
},
|
2024-07-29 15:44:15 +08:00
|
|
|
openCreateContainerModal() {
|
2024-07-19 19:24:23 +08:00
|
|
|
this.openEditModal = true;
|
2024-07-29 15:44:15 +08:00
|
|
|
this.editModalMode = 'container';
|
2024-07-19 19:24:23 +08:00
|
|
|
this.editStorageLocation = null;
|
|
|
|
},
|
|
|
|
edit(action, params) {
|
|
|
|
this.openEditModal = true;
|
2024-07-29 15:44:15 +08:00
|
|
|
this.editModalMode = params[0].container ? 'container' : 'location';
|
2024-07-19 19:24:23 +08:00
|
|
|
[this.editStorageLocation] = params;
|
|
|
|
},
|
2024-07-22 18:12:47 +08:00
|
|
|
duplicate(action) {
|
|
|
|
axios.post(action.path)
|
|
|
|
.then(() => {
|
|
|
|
this.reloadingTable = true;
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('storage_locations.index.duplicate.success_message'), 'success');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
});
|
|
|
|
},
|
2024-07-16 21:20:02 +08:00
|
|
|
// Renderers
|
|
|
|
nameRenderer(params) {
|
|
|
|
const {
|
|
|
|
name,
|
|
|
|
urls
|
|
|
|
} = params.data;
|
2024-07-29 15:44:15 +08:00
|
|
|
let containerIcon = '';
|
2024-07-19 19:24:23 +08:00
|
|
|
if (params.data.container) {
|
2024-07-29 15:44:15 +08:00
|
|
|
containerIcon = '<i class="sn-icon sn-icon-item"></i>';
|
2024-07-19 19:24:23 +08:00
|
|
|
}
|
2024-07-16 21:20:02 +08:00
|
|
|
return `<a class="hover:no-underline flex items-center gap-1"
|
|
|
|
title="${name}" href="${urls.show}">
|
2024-07-29 15:44:15 +08:00
|
|
|
${containerIcon}
|
2024-07-16 21:20:02 +08:00
|
|
|
<span class="truncate">${name}</span>
|
|
|
|
</a>`;
|
2024-07-23 14:50:17 +08:00
|
|
|
},
|
|
|
|
updateTable() {
|
|
|
|
this.reloadingTable = true;
|
|
|
|
this.objectToMove = null;
|
|
|
|
},
|
|
|
|
move(event, rows) {
|
|
|
|
[this.objectToMove] = rows;
|
|
|
|
this.moveToUrl = event.path;
|
2024-07-23 20:50:39 +08:00
|
|
|
},
|
|
|
|
async deleteStorageLocation(event, rows) {
|
2024-07-29 15:44:15 +08:00
|
|
|
const storageLocationType = rows[0].container ? this.i18n.t('storage_locations.container') : this.i18n.t('storage_locations.location');
|
2024-07-23 20:50:39 +08:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
}
|
2024-07-16 21:20:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
</script>
|