fix(fe smartblock): refactored all code with stores and interfaces

This commit is contained in:
Marco Cavalli 2025-04-03 14:42:44 +02:00
parent 9e690dc0c9
commit fa96a43ba4
10 changed files with 738 additions and 261 deletions

View file

@ -4,6 +4,8 @@ import ConfirmDelete from "@/components/content/partials/dialogs/ConfirmDelete.v
import {onBeforeMount, reactive, ref, watch} from "vue";
import {blocks_page} from "@/composables/content/blocks_page.ts";
import SmartBlockEditor from "@partials/SmartBlockEditor.vue";
import {useSmartBlockStore} from "@/stores/smartblock.store.ts";
import {baseSmartBlock} from "@models/smartblock/smartblock.ts";
const props = defineProps({
hideColumns: {
@ -16,11 +18,15 @@ const props = defineProps({
}
});
const smartBlockStore = useSmartBlockStore()
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,
@ -31,7 +37,7 @@ const dialog = reactive({
const visibleHeaders = ref(headers)
const openDialog = (type, title = '', text = '', bulk = false) => {
const openDialog = (type, title = '', text = '') => {
dialog.open = true
dialog.type = type
dialog.title = title
@ -39,18 +45,24 @@ const openDialog = (type, title = '', text = '', bulk = false) => {
}
const edit = (item) => {
console.log(item)
itemEdited.value = item
if (item === 0) {
item = baseSmartBlock();
}
smartBlockStore.loadSmartBlock(item);
itemEdited.value = item;
console.log(smartBlockStore)
}
const saveItem = (item) => {
const saved = editItem(item)
closeDialog()
const saved = editItem(item);
console.log(saved)
smartBlockStore.updateField({key: 'id', value: saved.id});
// resetItemEdited()
}
const cancel = (item) => {
bulk.value = Array.isArray(item)
itemEdited.value = item
bulk.value = Array.isArray(item);
itemEdited.value = item;
openDialog(
'delete',
'Cancella',
@ -58,7 +70,7 @@ const cancel = (item) => {
)
}
const confirmDelete = (confirm, bulk) => {
const confirmDelete = (confirm) => {
if (confirm) {
if (!bulk) {
deleteItem(itemEdited.value.id)
@ -68,6 +80,8 @@ const confirmDelete = (confirm, bulk) => {
})
}
}
itemEdited.value = {}
selected.value = []
closeDialog()
}
@ -92,6 +106,7 @@ const resetItemEdited = () => {
itemEdited.value = {
id: null,
}
smartBlockStore.loadSmartBlock(baseSmartBlock())
}
watch(search, (newValue, oldValue) => {
@ -103,8 +118,9 @@ watch(search, (newValue, oldValue) => {
<template>
<SmartBlockEditor
v-if="itemEdited.id !== null && !dialog.open"
:item="itemEdited"
:item="smartBlockStore.currentSmartBlock"
@go-back="resetItemEdited"
@save-item="saveItem"
/>
<Table
v-else