- aggiornamento lista catalogo, ordinamento tabelle

This commit is contained in:
Surya Paolo
2025-05-08 11:06:01 +02:00
parent 82e10ef6cf
commit ef36cd5e11
5 changed files with 165 additions and 80 deletions

View File

@@ -106,6 +106,19 @@ export default defineComponent({
selectedColumns.value = savedColumns;
}
const savedSortAttribute = tools.getCookie("sortAttr");
if (savedSortAttribute) {
if (isColumnVisible(savedSortAttribute)) {
sortAttribute.value = savedSortAttribute;
const savedSortDir = tools.getCookie("sortDir");
if (savedSortDir) {
sortDirection.value = savedSortDir;
}
}
}
loading.value = false
}
@@ -119,11 +132,12 @@ export default defineComponent({
// Colonne della tabella
const allColumns = [
{ name: "pos", label: "Ind", field: "pos", align: "left", style: "width: 50px" },
{ name: "drag", label: "Ord", field: "", align: "left", style: "width: 50px", edit: true, noexp: true },
{ name: "validato", label: "Val", field: "validato", align: "left", style: "" },
{ name: "image", label: "Foto", field: "image", align: "center", noexp: true },
{ name: "name", label: "Titolo del Libro", field: "name", align: "left" },
{ name: "pos", label: "Ind", field: "pos", align: "left", style: "width: 50px", notsortable: true },
{ name: "drag", label: "Ord", field: "", align: "left", style: "width: 50px", edit: true, noexp: true, notsortable: true },
{ name: "validato", label: "Val", field: "validato", align: "left", style: "", },
{ name: "image", label: "Foto", field: "image", align: "center", noexp: true, notsortable: true },
{ name: "name", label: "Titolo", field: "name", align: "left" },
{ name: "sottotitolo", label: "Sottotitolo", field: "sottotitolo", align: "left" },
{ name: "authors", label: "Autore", field: "authors", align: "left" },
{ name: "isbn", label: "ISBN", field: "isbn", align: "left" },
{ name: "trafiletto", label: "Sinossi", field: "trafiletto", align: "left" },
@@ -150,7 +164,7 @@ export default defineComponent({
{ name: "totFat", label: "Fat 5A", field: "totFat", align: "right", visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: "ult_ord", label: "Ult. Ordine", field: "ult_ord", align: "left", visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: "quantity", label: "Magazz.", field: "quantity", align: "right", visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: "actions", label: "Azioni", field: "", align: "center", visu: costanti.VISUCAMPI.PER_EDITORE, noexp: true },
{ name: "actions", label: "Azioni", field: "", align: "center", visu: costanti.VISUCAMPI.PER_EDITORE, noexp: true, notsortable: true },
];
function getFieldValue(element: any, field: any): any {
@@ -167,6 +181,9 @@ export default defineComponent({
case 'name':
return element.productInfo?.name;
case 'sottotitolo':
return element.productInfo?.sottotitolo;
case 'authors':
return formatAuthors(element.productInfo?.authors);
@@ -240,7 +257,10 @@ export default defineComponent({
return tools.getstrDate(element.productInfo?.dataUltimoOrdine);
case 'quantity':
return element.arrvariazioni?.[0]?.quantita;
if (tools.isUtente())
return tools.getDescrQuantitàByQuantity(element.arrvariazioni?.[0]?.quantita);
else
return element.arrvariazioni?.[0]?.quantita;
default:
return null;
@@ -351,12 +371,13 @@ export default defineComponent({
}
}
let cookieValue: [] | null = null;
let keyvalue = 'selColCat_2'
if (tools.isUtente())
keyvalue += '_utente'
try {
cookieValue = tools.getCookie("selColCat_2");
cookieValue = tools.getCookie(keyvalue);
// Se il cookie esiste e contiene una stringa JSON valida
cookieValue = cookieValue ? cookieValue : [];
} catch (error) {
@@ -364,8 +385,19 @@ export default defineComponent({
cookieValue = []; // In caso di errore, inizializza come array vuoto
}
const selectedColumns = ref(cookieValue.length > 0 ? cookieValue : ["pos", "drag", "validato", "image", "name", "authors", "isbn", "catprods", "stato", "date_pub", "pagine", "trafiletto", "fatLast1Y", "quantity", "actions"]);
const selectedColumns_Editori = ref(cookieValue.length > 0 ? cookieValue : ["pos", "drag", "validato", "image", "name", "authors", "isbn", "catprods", "stato", "date_pub", "pagine", "trafiletto", "fatLast1Y", "quantity", "actions"]);
const selectedColumns_Utenti = ref(cookieValue.length > 0 ? cookieValue : ["pos", "image", "name", "authors", "isbn", "catprods", "stato", "date_pub", "pagine", "trafiletto", "quantity"]);
const selectedColumns = computed({
get: () => tools.isUtente() ? selectedColumns_Utenti.value : selectedColumns_Editori.value,
set: (value) => {
if (tools.isUtente()) {
selectedColumns_Utenti.value = value;
} else {
selectedColumns_Editori.value = value;
}
}
});
// 3. Funzione per verificare se una colonna è visibile (isColumnVisible)
const isColumnVisible = (column, real?: boolean) => {
@@ -402,6 +434,15 @@ export default defineComponent({
saveSelectedColumns();
});
watch(() => sortAttribute.value, (newVal) => {
tools.setCookie("sortAttr", newVal);
});
watch(() => sortDirection.value, (newVal) => {
tools.setCookie("sortDir", newVal);
});
// Funzione chiamata alla fine del drag-and-drop
const onDragEnd = () => {
// console.log("Nuovo ordine:", internalProducts.value);
@@ -504,6 +545,11 @@ export default defineComponent({
if (aVal instanceof Date && bVal instanceof Date) {
return sortDirection.value === 1 ? aVal.getTime() - bVal.getTime() : bVal.getTime() - aVal.getTime();
}
if (typeof aVal === 'string' && typeof bVal === 'string' && aVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/) && bVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/)) {
const aDate = new Date(aVal.split('/').reverse().join('-'));
const bDate = new Date(bVal.split('/').reverse().join('-'));
return sortDirection.value === 1 ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime();
}
if (typeof aVal === 'number' && typeof bVal === 'number') {
return sortDirection.value === 1 ? aVal - bVal : bVal - aVal;
}
@@ -529,13 +575,13 @@ export default defineComponent({
case 'stato':
return () => {
// esempio: mostra dettagli dello stato
console.log('Stato prodotto:', element.productInfo?.idStatoProdotto);
// console.log('Stato prodotto:', element.productInfo?.idStatoProdotto);
};
case 'quantity':
return () => {
// esempio: mostra log disponibilità
console.log('Quantità disponibile:', element.arrvariazioni?.[0]?.quantita);
// console.log('Quantità disponibile:', element.arrvariazioni?.[0]?.quantita);
};
default:
@@ -574,6 +620,9 @@ export default defineComponent({
}
function isSortable(field: string) : boolean {
return allColumns && !allColumns.find((col) => col.name === field)?.notsortable;
}
onMounted(mounted)
@@ -615,6 +664,7 @@ export default defineComponent({
getFieldClick,
handleUpdate,
exportToCSV,
isSortable,
}
}
})