feat(fe blocks): adding smart blocks page
This commit is contained in:
parent
191f8d8951
commit
9de83d062f
4 changed files with 203 additions and 2 deletions
126
resources/js/components/content/Blocks.vue
Normal file
126
resources/js/components/content/Blocks.vue
Normal file
|
@ -0,0 +1,126 @@
|
|||
<script setup lang="ts">
|
||||
import Table from "@/components/content/partials/Table.vue";
|
||||
import PlaylistEditor from "@/components/content/partials/PlaylistEditor.vue";
|
||||
import ConfirmDelete from "@/components/content/partials/dialogs/ConfirmDelete.vue";
|
||||
import {reactive, ref, watch} from "vue";
|
||||
import {blocks_page} from "@/composables/content/blocks_page.ts";
|
||||
|
||||
const { items, listData, headers, selected, loading, search, getItems, editItem, deleteItem } = blocks_page()
|
||||
|
||||
const itemEdited = ref({
|
||||
id: null
|
||||
})
|
||||
const bulk = ref(false)
|
||||
const dialog = reactive({
|
||||
open: false,
|
||||
type: '',
|
||||
title: '',
|
||||
text: ''
|
||||
})
|
||||
|
||||
const openDialog = (type, title = '', text = '', bulk = false) => {
|
||||
dialog.open = true
|
||||
dialog.type = type
|
||||
dialog.title = title
|
||||
dialog.text = text
|
||||
}
|
||||
|
||||
const edit = (item) => {
|
||||
console.log(item)
|
||||
itemEdited.value = item
|
||||
}
|
||||
|
||||
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
|
||||
resetItemEdited()
|
||||
}
|
||||
|
||||
const updateSearch = (text) => {
|
||||
search.value = text
|
||||
}
|
||||
|
||||
const resetItemEdited = () => {
|
||||
itemEdited.value = {
|
||||
id: null,
|
||||
}
|
||||
}
|
||||
|
||||
watch(search, (newValue, oldValue) => {
|
||||
getItems(listData)
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PlaylistEditor
|
||||
v-if="itemEdited.id !== null && !dialog.open"
|
||||
:item="itemEdited"
|
||||
@go-back="resetItemEdited"
|
||||
/>
|
||||
<Table
|
||||
v-else
|
||||
:headers="headers"
|
||||
v-model:selected="selected"
|
||||
v-model:search="search"
|
||||
:list-data="listData"
|
||||
:items="items"
|
||||
:loading="loading"
|
||||
:get-items="getItems"
|
||||
:actions="true"
|
||||
:show-select="true"
|
||||
@update-table="getItems"
|
||||
@update-search="updateSearch"
|
||||
@delete-item="cancel"
|
||||
@edit-item="edit"
|
||||
>
|
||||
<template v-slot:header-buttons>
|
||||
<v-btn color="primary" @click="edit(0)">
|
||||
Crea una nuova Playlist
|
||||
</v-btn>
|
||||
</template>
|
||||
<template v-slot:dialog>
|
||||
<v-dialog v-model="dialog.open">
|
||||
<ConfirmDelete
|
||||
v-if="dialog.type === 'delete'"
|
||||
:title="dialog.title"
|
||||
:text="dialog.text"
|
||||
:bulk="bulk"
|
||||
@confirm="confirmDelete"
|
||||
@after-leave="closeDialog"
|
||||
/>
|
||||
</v-dialog>
|
||||
</template>
|
||||
</Table>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
69
resources/js/composables/content/blocks_page.ts
Normal file
69
resources/js/composables/content/blocks_page.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import {reactive, ref} from "vue";
|
||||
import axios from "axios";
|
||||
|
||||
export function blocks_page() {
|
||||
const items = ref([])
|
||||
const selected = ref([])
|
||||
const loading = ref(false)
|
||||
const search = ref('')
|
||||
const listData = reactive({
|
||||
'itemsPerPage': 5,
|
||||
'first_page': null,
|
||||
'last_page': null,
|
||||
'total_items': 0,
|
||||
'page': 1,
|
||||
})
|
||||
|
||||
const headers = [
|
||||
{title: 'Nome', value: 'name'},
|
||||
{title: 'Creato da', value: 'creator'},
|
||||
{title: 'Durata', value: 'length'},
|
||||
{title: 'Ultima modifica', value: 'utime'},
|
||||
{title: 'Azioni', value: 'actions'}
|
||||
];
|
||||
|
||||
const getItems = async (page_info) => {
|
||||
loading.value = true;
|
||||
return await axios.get(`/smartblock`, {
|
||||
params: {
|
||||
page: page_info.page,
|
||||
per_page: page_info.itemsPerPage,
|
||||
all: search.value
|
||||
}
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
listData.itemsPerPage = response.data.per_page;
|
||||
listData.first_page = response.data.from;
|
||||
listData.last_page = response.data.last_page;
|
||||
listData.page = response.data.current_page;
|
||||
listData.total_items = response.data.total;
|
||||
|
||||
items.value = response.data.data
|
||||
loading.value = false;
|
||||
|
||||
}).catch((error) => {
|
||||
console.log("Error: "+error);
|
||||
})
|
||||
}
|
||||
|
||||
const editItem = (item) => {
|
||||
item['_method'] = 'PUT'
|
||||
|
||||
return axios.post(`file/${item.id}`, item
|
||||
).then((response) => {
|
||||
console.log(response)
|
||||
})
|
||||
}
|
||||
|
||||
const deleteItem = (id) => {
|
||||
|
||||
return axios.post(`file/${id}`, {
|
||||
_method: 'DELETE'
|
||||
}).then((response) => {
|
||||
getItems(listData)
|
||||
// items.value = response.status === 200 ? items.value.filter(obj => obj.id !== id) : items
|
||||
})
|
||||
}
|
||||
|
||||
return { items, listData, headers, selected, loading, search, getItems, editItem, deleteItem }
|
||||
}
|
|
@ -14,6 +14,7 @@ const tabs = {
|
|||
dashboard: defineAsyncComponent(() => import('../../components/content/Dashboard.vue')),
|
||||
archive: defineAsyncComponent(() => import('../../components/content/Archive.vue')),
|
||||
playlist: defineAsyncComponent(() => import('../../components/content/Playlist.vue')),
|
||||
blocks: defineAsyncComponent(() => import('../../components/content/Blocks.vue')),
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -9,13 +9,18 @@ const pages = [
|
|||
},
|
||||
{
|
||||
id: 'archive',
|
||||
name: 'Archive',
|
||||
component: '../../components/content/Dashboard.vue',
|
||||
name: 'Archivio',
|
||||
component: '../../components/content/Archive.vue',
|
||||
},
|
||||
{
|
||||
id: 'playlist',
|
||||
name: 'Playlist',
|
||||
component: '../../components/content/Playlist.vue',
|
||||
},
|
||||
{
|
||||
id: 'blocks',
|
||||
name: 'Blocchi dinamici',
|
||||
component: '../../components/content/Blocks.vue',
|
||||
}
|
||||
];
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue