- Creazione di un Nuovo Catalogo (e la sua relativa pagina), a partire da un modello ed un catalogo esistente.
- Aggiunta dei bottoni sul Ccatalogocard
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import type { ICatalogState } from '@src/model';
|
||||
import { IAccount, ICircuit, ICatalog, IGlobalState, IGroupShort, IMyCircuit, IMyGroup, IUserFields } from '@src/model';
|
||||
import {
|
||||
IAccount,
|
||||
ICircuit,
|
||||
ICatalog,
|
||||
IGlobalState,
|
||||
IGroupShort,
|
||||
IMyCircuit,
|
||||
IMyGroup,
|
||||
IUserFields,
|
||||
} from '@src/model';
|
||||
import { tools } from '@tools';
|
||||
import translate from '@src/globalroutines/util';
|
||||
|
||||
@@ -26,18 +35,28 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getCatalogById: (state) => (id: string): ICatalog => {
|
||||
return state.catalogs.find((cat: ICatalog) => cat._id === id) || null;
|
||||
getCatalogById:
|
||||
(state) =>
|
||||
(id: string): ICatalog => {
|
||||
return state.catalogs.find((cat: ICatalog) => cat._id === id) || null;
|
||||
},
|
||||
|
||||
getCatalogsList: (state) => (): { label: string; value: string }[] => {
|
||||
return [
|
||||
{ label: '[Nessuno]', value: '' },
|
||||
...state.catalogs.map((cat: ICatalog) => {
|
||||
return { label: cat.title, value: cat._id };
|
||||
}),
|
||||
];
|
||||
},
|
||||
|
||||
getCatalogsList: (state) => (): {label: string, value: string}[] => {
|
||||
return state.catalogs.map((cat: ICatalog) => {
|
||||
return {label: cat.title, value: cat._id};
|
||||
});
|
||||
},
|
||||
getCatalogByIdPageAssigned: (state) => (idPage: string): ICatalog => {
|
||||
return state.catalogs.find((cat: ICatalog) => cat.idPageAssigned === idPage) || null;
|
||||
},
|
||||
getCatalogByIdPageAssigned:
|
||||
(state) =>
|
||||
(idPage: string): ICatalog => {
|
||||
return (
|
||||
state.catalogs.find((cat: ICatalog) => cat.idPageAssigned === idPage) || null
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
@@ -72,13 +91,21 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error loadCatalogById', error);
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error);
|
||||
return new Types.AxiosError(
|
||||
serv_constants.RIS_CODE_ERR,
|
||||
null,
|
||||
toolsext.ERR_GENERICO,
|
||||
error
|
||||
);
|
||||
});
|
||||
|
||||
return ris;
|
||||
},
|
||||
|
||||
async loadProductsOnlyByIdPageCatalog(idPage: string, forzacaricamento: boolean = false) {
|
||||
async loadProductsOnlyByIdPageCatalog(
|
||||
idPage: string,
|
||||
forzacaricamento: boolean = false
|
||||
) {
|
||||
// controlla se è stata già caricata in memoria
|
||||
|
||||
const productStore = useProducts();
|
||||
@@ -101,7 +128,9 @@ export const useCatalogStore = defineStore('CatalogStore', {
|
||||
updateDataCatalog(catalog: ICatalog) {
|
||||
if (catalog) {
|
||||
// Update catalog from server
|
||||
const indelem = this.catalogs.findIndex((reccatalog: ICatalogCompleto) => reccatalog._id === catalog._id);
|
||||
const indelem = this.catalogs.findIndex(
|
||||
(reccatalog: ICatalogCompleto) => reccatalog._id === catalog._id
|
||||
);
|
||||
if (indelem >= 0) {
|
||||
this.catalogs[indelem] = { ...catalog };
|
||||
this.catalogs[indelem].prodotti_caricati_inmem = true;
|
||||
|
||||
@@ -544,7 +544,7 @@ export const colmypage = [
|
||||
AddCol({ name: 'order', label_trans: 'pages.order', fieldtype: costanti.FieldType.number }),
|
||||
AddCol({ name: 'active', label_trans: 'pages.active', fieldtype: costanti.FieldType.boolean }),
|
||||
AddCol({ name: 'inmenu', label_trans: 'pages.inmenu', fieldtype: costanti.FieldType.boolean }),
|
||||
AddCol({ name: 'isTemplate', label_trans: 'pages.isTemplate', fieldtype: costanti.FieldType.boolean }),
|
||||
AddCol({ name: 'isTemplate', label_trans: 'mypages.isTemplate', fieldtype: costanti.FieldType.boolean }),
|
||||
AddCol({ name: 'title', label_trans: 'pages.title' }),
|
||||
AddCol({ name: 'subtitle', label_trans: 'pages.subtitle' }),
|
||||
AddCol({ name: 'mainMenu', label_trans: 'pages.mainMenu', fieldtype: costanti.FieldType.boolean }),
|
||||
|
||||
@@ -8978,6 +8978,9 @@ export const tools = {
|
||||
} else if (table === toolsext.TABMYHOSPS) {
|
||||
nome = rec ? rec.descr : '';
|
||||
str = 'l\'Ospitalità "' + nome + '"';
|
||||
} else if (table === toolsext.TABCATALOGS) {
|
||||
nome = rec ? rec.title : '';
|
||||
str = 'il Catalogo "' + nome + '"';
|
||||
}
|
||||
|
||||
if (!str) {
|
||||
@@ -10694,6 +10697,16 @@ export const tools = {
|
||||
return this.removeFileExtension(filename) + `_compressed.pdf`;
|
||||
},
|
||||
|
||||
|
||||
convertTitleToFileName(title: string): string {
|
||||
return title
|
||||
.replace(/ /g, '_')
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/[^a-zA-Z0-9_]/g, '')
|
||||
}
|
||||
|
||||
|
||||
// FINE !
|
||||
|
||||
// getLocale() {
|
||||
|
||||
@@ -1509,7 +1509,7 @@ export const useProducts = defineStore('Products', {
|
||||
codice_sconto,
|
||||
}: {
|
||||
cart_id: string;
|
||||
codice_sconto: number;
|
||||
codice_sconto: string;
|
||||
}) {
|
||||
const userStore = useUserStore();
|
||||
const globalStore = useGlobalStore();
|
||||
|
||||
@@ -1694,6 +1694,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
async setGlobal(router: Router, isLogged: boolean) {
|
||||
const globalStore = useGlobalStore();
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import type {
|
||||
IProductInfo,
|
||||
IVariazione,
|
||||
IDestNewsletter,
|
||||
ICatalog,
|
||||
INewCatalog,
|
||||
} from '@model';
|
||||
import { ICity, IMySkill, ISites, IMyScheda } from '@model';
|
||||
import { static_data } from '@src/db/static_data';
|
||||
@@ -391,7 +393,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
|
||||
getMyPagesOptionsTemplate: (state: IGlobalState) => (): any[] => {
|
||||
return state.mypage
|
||||
.filter((page: IMyPage) => page.isTemplate === true)
|
||||
.filter((mypage: IMyPage) => mypage.isTemplate === true)
|
||||
.map((page: IMyPage) => ({
|
||||
label: page.title,
|
||||
value: page._id,
|
||||
@@ -921,6 +923,10 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
}
|
||||
},
|
||||
|
||||
async aggiornaMenu(router: Router) {
|
||||
await this.addDynamicPages(router);
|
||||
},
|
||||
|
||||
setPaoArray_Delete(state: IGlobalState) {
|
||||
state.testp1.mioarray.pop();
|
||||
},
|
||||
@@ -2131,7 +2137,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
if (page.loadFirst) page.loaded = true;
|
||||
}
|
||||
this.myelems = res.data.myelems ? [...res.data.myelems] : [];
|
||||
this.crons = res.data.crons ? [...res.data.crons] : [];
|
||||
this.lista_cron = res.data.crons ? [...res.data.crons] : [];
|
||||
this.myschedas = [];
|
||||
this.myschedas = res.data.myschedas ? [...res.data.myschedas] : [];
|
||||
// console.log('this.mypage', this.mypage)
|
||||
@@ -2236,6 +2242,67 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
});
|
||||
},
|
||||
|
||||
async addNewCatalog(newCatalog: INewCatalog, router: Router): Promise<any> {
|
||||
const catalogStore = useCatalogStore();
|
||||
|
||||
return Api.SendReq('/catalogs/addnew', 'POST', { newCatalog })
|
||||
.then((res: any) => {
|
||||
let newPage: any = null;
|
||||
let newCatalog: any = null;
|
||||
let newElems: any = null;
|
||||
// console.table(res)
|
||||
if (res.data) {
|
||||
newPage = res.data.data.newPage;
|
||||
newElems = res.data.data.newElems;
|
||||
newCatalog = res.data.data.newCatalog;
|
||||
|
||||
// aggiorna i dati su mypage e Catalog in memoria
|
||||
if (newPage) {
|
||||
const index = this.mypage.findIndex(
|
||||
(rec: IMyPage) => rec._id === newPage._id
|
||||
);
|
||||
if (index >= 0) {
|
||||
this.mypage[index] = newPage;
|
||||
} else {
|
||||
this.mypage.push(newPage);
|
||||
}
|
||||
}
|
||||
|
||||
if (newCatalog) {
|
||||
const index = catalogStore.catalogs.findIndex(
|
||||
(rec: ICatalog) => rec._id === newCatalog._id
|
||||
);
|
||||
if (index >= 0) {
|
||||
catalogStore.catalogs[index] = newCatalog;
|
||||
} else {
|
||||
catalogStore.catalogs.push(newCatalog);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElems && Array.isArray(newElems)) {
|
||||
newElems.forEach((newElem) => {
|
||||
const index = this.myelems.findIndex(
|
||||
(rec: IMyElem) => rec._id === newElem._id
|
||||
);
|
||||
if (index >= 0) {
|
||||
this.myelems[index] = newElem;
|
||||
} else {
|
||||
this.myelems.push(newElem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.aggiornaMenu(router);
|
||||
}
|
||||
|
||||
return { page: newPage, catalog: newCatalog };
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.log('error addNewCatalog', error);
|
||||
return { page: null, catalog: null };
|
||||
});
|
||||
},
|
||||
|
||||
getArrStrByValueBinary(col: IColGridTable, val: any) {
|
||||
const arr = this.getArrByValueBinary(null, col, val);
|
||||
if (arr.length > 0) return arr.join(' - ');
|
||||
|
||||
Reference in New Issue
Block a user