fix(fe archive): updated logic with dialogs
This commit is contained in:
parent
685651884c
commit
f357826b95
1 changed files with 135 additions and 54 deletions
|
@ -1,74 +1,152 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {useAuthStore} from "@/stores/auth.store.ts";
|
import {ref, reactive, watch, computed, onMounted} from "vue";
|
||||||
import {ref, onMounted, reactive, computed} from "vue";
|
import { archive } from "@/composables/content/archive.js.ts";
|
||||||
const auth = useAuthStore()
|
import FileUpload from "@/components/content/partials/dialogs/FileUpload.vue";
|
||||||
const items = ref([])
|
import FileEdit from "@/components/content/partials/dialogs/FileEdit.vue";
|
||||||
|
import ConfirmDelete from "@/components/content/partials/dialogs/ConfirmDelete.vue";
|
||||||
|
|
||||||
const listData = reactive({
|
const { items, listData, headers, selected, loading, search, getItems, editItem, deleteItem } = archive()
|
||||||
'per_page': 5,
|
|
||||||
'first_page': null,
|
const itemEdited = ref({})
|
||||||
'last_page': null,
|
const bulk = ref(false)
|
||||||
'total_items': 0,
|
const dialog = reactive({
|
||||||
'current_page': 1,
|
open: false,
|
||||||
|
type: '',
|
||||||
|
title: '',
|
||||||
|
text: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const active_columns = reactive({
|
const openDialog = (type, title = '', text = '', bulk = false) => {
|
||||||
'track_title': 'Track Title',
|
dialog.open = true
|
||||||
'artist_name': 'Artist',
|
dialog.type = type
|
||||||
'genre': 'Genre',
|
dialog.title = title
|
||||||
'track_type': 'Track Type',
|
dialog.text = text
|
||||||
'length': 'Length',
|
|
||||||
'mtime': 'Uploaded'
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ToDo: understand why per_page and other filters doesn't work
|
|
||||||
* @param page_info created by v-data-table-server on update
|
|
||||||
*/
|
|
||||||
const getItems = (page_info) => {
|
|
||||||
console.log(page_info);
|
|
||||||
return axios.get(`/file`, {
|
|
||||||
params: {
|
|
||||||
page: page_info.page,
|
|
||||||
per_page: page_info.itemsPerPage,
|
|
||||||
}
|
|
||||||
}).then((response) => {
|
|
||||||
console.log(response)
|
|
||||||
listData.per_page = response.data.per_page;
|
|
||||||
listData.first_page = response.data.from;
|
|
||||||
listData.last_page = response.data.last_page;
|
|
||||||
listData.current_page = response.data.current_page;
|
|
||||||
listData.total_items = response.data.total;
|
|
||||||
|
|
||||||
items.value = response.data.data.map((el) => {
|
|
||||||
Object.keys(el).forEach((key) => {
|
|
||||||
if (Object.keys(active_columns).includes(key)) {
|
|
||||||
el[active_columns[key]] = el[key];
|
|
||||||
}
|
|
||||||
delete el[key];
|
|
||||||
})
|
|
||||||
return el;
|
|
||||||
});
|
|
||||||
console.log(listData);
|
|
||||||
}).catch((error) => {
|
|
||||||
console.log("Error: "+error);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const edit = (item) => {
|
||||||
|
console.log(item)
|
||||||
|
itemEdited.value = item
|
||||||
|
openDialog('edit')
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveItem = (item) => {
|
||||||
|
const saved = editItem(item)
|
||||||
|
closeDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancel = (item) => {
|
||||||
|
bulk.value = Array.isArray(item)
|
||||||
|
itemEdited.value = item
|
||||||
|
openDialog(
|
||||||
|
'delete',
|
||||||
|
'Cancella',
|
||||||
|
bulk.value ? 'Vuoi cancellare i file selezionati?' : 'Vuoi cancellare il file selezionato?'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmDelete = (confirm, bulk) => {
|
||||||
|
if (confirm) {
|
||||||
|
if (!bulk) {
|
||||||
|
deleteItem(itemEdited.value.id)
|
||||||
|
} else {
|
||||||
|
itemEdited.value.forEach(el => {
|
||||||
|
deleteItem(el.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closeDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeDialog = () => dialog.open = false
|
||||||
|
|
||||||
|
watch(search, (newValue, oldValue) => {
|
||||||
|
getItems(listData)
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<v-data-table-server
|
<v-data-table-server
|
||||||
v-model:items-per-page="listData.per_page"
|
:headers="headers"
|
||||||
|
v-model="selected"
|
||||||
|
v-model:items-per-page="listData.itemsPerPage"
|
||||||
:items="items"
|
:items="items"
|
||||||
:items-length="listData.total_items"
|
:items-length="listData.total_items"
|
||||||
loading-text="Loading..."
|
loading-text="Loading..."
|
||||||
:loading="items.length === 0"
|
:loading="loading"
|
||||||
@update:options="getItems"
|
@update:options="getItems"
|
||||||
@update:items-per-page="getItems"
|
item-value="track_title"
|
||||||
disable-sort
|
disable-sort
|
||||||
|
return-object
|
||||||
|
show-select
|
||||||
>
|
>
|
||||||
|
<template v-slot:top>
|
||||||
|
<v-toolbar flat>
|
||||||
|
<v-text-field
|
||||||
|
v-model="search"
|
||||||
|
class="ma-2 search"
|
||||||
|
density="compact"
|
||||||
|
placeholder="Cerca"
|
||||||
|
hide-details
|
||||||
|
></v-text-field>
|
||||||
|
<v-divider />
|
||||||
|
<v-btn color="primary" @click="openDialog('upload')">
|
||||||
|
Upload
|
||||||
|
</v-btn>
|
||||||
|
<v-divider />
|
||||||
|
<v-btn color="primary">
|
||||||
|
<v-icon
|
||||||
|
class="me-2"
|
||||||
|
size="small"
|
||||||
|
:disabled="selected.length === 0"
|
||||||
|
@click="cancel(selected)"
|
||||||
|
>
|
||||||
|
mdi-delete
|
||||||
|
</v-icon>
|
||||||
|
</v-btn>
|
||||||
|
</v-toolbar>
|
||||||
|
<v-dialog v-model="dialog.open">
|
||||||
|
<FileUpload
|
||||||
|
v-if="dialog.type === 'upload'"
|
||||||
|
@close-dialog="closeDialog"
|
||||||
|
/>
|
||||||
|
<FileEdit
|
||||||
|
v-else-if="dialog.type === 'edit'"
|
||||||
|
:item="itemEdited"
|
||||||
|
@edit-item="saveItem"
|
||||||
|
/>
|
||||||
|
<ConfirmDelete
|
||||||
|
v-else-if="dialog.type === 'delete'"
|
||||||
|
:title="dialog.title"
|
||||||
|
:text="dialog.text"
|
||||||
|
:bulk="bulk"
|
||||||
|
@confirm="confirmDelete"
|
||||||
|
/>
|
||||||
|
</v-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-slot:item.artwork="{ item }">
|
||||||
|
<div v-if="item.artwork != ''" v-html="`<img src='/${item.artwork}.jpg' />`"></div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-slot:item.actions="{ item }">
|
||||||
|
<v-icon
|
||||||
|
class="me-2"
|
||||||
|
size="small"
|
||||||
|
@click="edit(item)"
|
||||||
|
>
|
||||||
|
mdi-pencil
|
||||||
|
</v-icon>
|
||||||
|
<v-icon
|
||||||
|
size="small"
|
||||||
|
@click="cancel(item)"
|
||||||
|
>
|
||||||
|
mdi-delete
|
||||||
|
</v-icon>
|
||||||
|
</template>
|
||||||
</v-data-table-server>
|
</v-data-table-server>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -77,4 +155,7 @@ const getItems = (page_info) => {
|
||||||
.v-data-table {
|
.v-data-table {
|
||||||
width:100%;
|
width:100%;
|
||||||
}
|
}
|
||||||
|
.search {
|
||||||
|
min-width:250px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
Loading…
Add table
Add a link
Reference in a new issue