- Catalogo: Aggiunta di Schede

This commit is contained in:
Surya Paolo
2024-10-31 23:23:06 +01:00
parent b6f73019fe
commit 2ea6468100
123 changed files with 3382 additions and 3595327 deletions

View File

@@ -14,7 +14,7 @@ import { CProductCard } from '@src/components/CProductCard'
import { CMySelect } from '@src/components/CMySelect'
import { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard'
import { CSelectUserActive } from '@src/components/CSelectUserActive'
import { ICatalogo, IProduct, ISearchList } from 'model'
import { ICatalogo, IFilterCatalogo, IMyScheda, IProdView, IProduct, ISearchList } from 'model'
import html2canvas from 'html2canvas'
// import { VueHtmlToPaper } from 'vue-html-to-paper'
@@ -54,7 +54,7 @@ export default defineComponent({
const pdfContent = ref(null);
const filter = ref(<any>{
const filter = ref(<IFilterCatalogo>{
author: '',
sort: 1,
publisher: '',
@@ -76,7 +76,8 @@ export default defineComponent({
const searchList = ref([] as ISearchList[])
const arrProducts = ref<any>([])
const arrProducts = ref<IProduct[]>([])
const arrProdToView = ref<IProdView[]>([])
const numRecLoaded = ref(0)
@@ -189,15 +190,15 @@ export default defineComponent({
}
function calcArrProducts() {
// console.log('calcArrProducts')
console.log('calcArrProducts')
// eventuali titoli specifici estratti dall'array di Prodotti Selezionati
//const searchtext = getSearchText()
const searchtext = getSearchText()
refreshpage.value = true
let arrprod = productStore.getProducts(cosa.value) || [];
let filtroAuthor = filter.value.author || '';
//++AddCATALOGO_FIELDS
let filtroProductTypes = props.optcatalogo.productTypes || [0]
@@ -280,10 +281,206 @@ export default defineComponent({
}
arrProducts.value = arrprod
generatearrProdToViewSorted()
loaddata()
refreshpage.value = false
}
function getProductsFilteredByScheda(scheda: IMyScheda) {
const searchtext = scheda.arrProdottiSpeciali
let arrprod = productStore.getProducts(cosa.value) || [];
let filtroAuthor = filter.value.author || '';
let filtroProductTypes = scheda.productTypes || [0]
let filtroExcludeProductTypes = scheda.excludeproductTypes || [0]
let boolfiltroVuotoProductTypes = (filtroProductTypes.length === 0 || (filtroProductTypes.length === 1 && (filtroProductTypes[0] === 0)))
let boolfiltroVuotoExcludeProductTypes = filtroExcludeProductTypes.length === 0
let filtroPublishers = scheda.editore || []
let boolfiltroVuotoEditore = (filtroPublishers.length === 0)
//console.log('filtroVersione', filtroProductTypes)
let catstr = cat.value || ''
let gasselstr = ''
if (cosa.value === shared_consts.PROD.GAS) {
gasselstr = idGasSel.value || '';
}
let lowerSearchTexts = (searchtext || []).map((text: string) =>
text.toLowerCase().trim().replace(/[-@:=]/g, '')
)
// Remove the condition that skips filtering if search text is too short
// Now it will work with multiple search terms
arrprod = arrprod.filter((product: IProduct) => {
if (product && product.productInfo) {
let lowerName = (product.productInfo.name || '').toLowerCase();
let lowerCode = (product.productInfo.code || '').toLowerCase();
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
// Check if ANY search term matches the product name or code
let searchMatch = lowerSearchTexts.length === 0 || lowerSearchTexts.some((searchTerm: any) => {
// Check if the entire search term is a whole word in name or code
let codeMatch = new RegExp(`\\b${searchTerm}\\b`, 'i').test(lowerCode);
// Check if all words in the search term are present in the name
let allWordsPresent = searchTerm.split(/\s+/).every((word: string) =>
new RegExp(`\\b${word}\\b`, 'i').test(lowerName)
);
return codeMatch || allWordsPresent;
});
let hasProductTypes = true
let hasPublished = true
let hasExcludeProductTypes = false
if (!boolfiltroVuotoProductTypes) {
// check if productInfo.productTypes array includes some item in scheda.ProductTypes array
hasProductTypes = !scheda.productTypes || (scheda.productTypes && (product.productInfo.productTypes || []).some((item: any) => scheda.productTypes.includes(item)))
}
if (!boolfiltroVuotoEditore) {
hasPublished = !scheda.editore || (scheda.editore && scheda.editore.includes(product.productInfo.idPublisher!))
}
if (!boolfiltroVuotoExcludeProductTypes) {
// check if productInfo.productTypes array exclude some item in scheda.ProductTypes array
hasExcludeProductTypes = !scheda.excludeproductTypes || (scheda.excludeproductTypes && (product.productInfo.productTypes || []).every((item: any) => scheda.excludeproductTypes.includes(item)))
}
return searchMatch && hasCategoria && hasAuthor && hasProductTypes && hasPublished && !hasExcludeProductTypes;
} else {
console.error('product or product.productInfo is null');
return false;
}
})
// console.log('filter.value.sort', filter.value.sort)
// sort using filter.value.sort :
if (scheda.sort === costanti.SORT_PUBDATE) {
arrprod = arrprod.sort((a: IProduct, b: IProduct) => {
return b.productInfo.date_publishing_ts - a.productInfo.date_publishing_ts
})
} else if (scheda.sort === costanti.SORT_ALPHA) {
}
return arrprod
}
function addNextProductToTheView(arrproductfiltrati: IProduct[], indprod: number) {
try {
let rectrovato = null;
while (true) {
if (indprod >= arrproductfiltrati.length) {
return { end: true }
}
rectrovato = arrProdToView.value.find(
(prodview: IProdView) => prodview.id === arrproductfiltrati[indprod]._id
);
if (rectrovato) {
indprod++
continue; // Era stato già aggiunto, quindi prova col prossimo
} else {
// Non è stato ancora aggiunto, quindi prendo questo e lo aggiungo alla lista !
const myrec = arrproductfiltrati[indprod]
arrProdToView.value.push({ id: myrec._id, showed: false });
return { myrec, added: true, indprod }
}
}
} catch (e) {
console.error(e);
return { rec: null, indprod }; // Assicurati di gestire correttamente l'errore
}
}
function getProdBySchedaRigaCol(scheda: IMyScheda, riga: number, col: number) {
try {
return scheda.arrProdToShow![riga][col]
} catch (e) {
return null
}
}
function generatearrProdToViewSorted() {
console.log('generatearrProdToViewSorted')
// Svuota
arrProdToView.value = []
for (const recscheda of props.optcatalogo.arrSchede!) {
if (recscheda && recscheda.scheda) {
let schedePerRiga = recscheda.scheda.numschede_perRiga || 1
let schedePerCol = recscheda.scheda.numschede_perCol || 1
let schedePerPagina = schedePerRiga * schedePerCol
// Filtra i prodotti in base ai filtri impostati !
const arrProdFiltrati = getProductsFilteredByScheda(recscheda.scheda)
let indprod = 0
let indadded = 0
recscheda.scheda.arrProdToShow = []
let riga = 0
let col = 0
for (let giro = 0; giro < schedePerPagina; giro++) {
// Aggiunge il prossimo prodotto che non è stato ancora inserito
const result = addNextProductToTheView(arrProdFiltrati, indprod);
if (result.end) {
break; // Esci dal ciclo se non ci sono più prodotti disponibili
} else {
if (result.indprod)
indprod = result.indprod // Aggiorna indprod per il prossimo giro
if (result.myrec) {
indadded++
let riga = Math.floor(indadded / schedePerCol)
let col = indadded % schedePerCol
if (!recscheda.scheda.arrProdToShow[riga]) {
recscheda.scheda.arrProdToShow[riga] = [];
}
recscheda.scheda.arrProdToShow[riga][col] = result.myrec
}
}
}
console.log('*** arrProdToShow', recscheda.scheda.arrProdToShow)
}
}
}
function getNextProd() {
let nextRecord = arrProdToView.value.find((rec: any) => !rec.showed)
// Se un tale record esiste, impostalo su mostrato
if (nextRecord) {
nextRecord.showed = true
return arrProducts.value.find((recprod: IProduct) => recprod._id === nextRecord.id)
}
return null
}
/*function getProducts() {
let arrprod = productStore.getProducts(cosa.value)
@@ -302,6 +499,7 @@ export default defineComponent({
}*/
async function mounted() {
console.log('mounted Catalogo')
loadpage.value = false
await productStore.loadProducts()
@@ -418,7 +616,7 @@ export default defineComponent({
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
})
const loadImage = (src) => {
const loadImage = (src: any) => {
return new Promise((resolve, reject) => {
const img = new Image()
img.onload = () => resolve(img)
@@ -476,55 +674,41 @@ export default defineComponent({
}
}
function getWidthPerc(): string {
function groupedPages(scheda: IMyScheda) {
if (scheda) {
const schedePerRiga = scheda.numschede_perRiga || 1
const schedePerCol = scheda.numschede_perCol || 1
const schedePerPagina = schedePerRiga * schedePerCol
let mynum = props.optcatalogo.numschede_perRiga! + 0
let indiceprodotto = 0
return (100 / mynum) + '%'
}
const pages = []
function getCardStyle(index: any) {
return {
'place-content': 'center',
'flex': `0 1 ${props.optcatalogo.widthscheda}`,
'width': getWidthPerc(), // per N elementi per riga
// 'margin-bottom': props.optcatalogo.margine_pagina, // spazio tra le righe
}
}
// Iterate attraverso l'array prodotti con step = schedePerPagina
for (let pageStart = 0; pageStart < arrProducts.value.length; pageStart += schedePerPagina) {
const page = []
function groupedPages() {
const schedePerRiga = props.optcatalogo.numschede_perRiga || 1
const schedePerCol = props.optcatalogo.numschede_perCol || 1
const schedePerPagina = schedePerRiga * schedePerCol
// Crea le righe per questa pagina
for (let rowStart = 0; rowStart < schedePerCol; rowStart++) {
const row = []
const pages = []
// Iterate attraverso l'array prodotti con step = schedePerPagina
for (let pageStart = 0; pageStart < arrProducts.value.length; pageStart += schedePerPagina) {
const page = []
// Crea le righe per questa pagina
for (let rowStart = 0; rowStart < schedePerCol; rowStart++) {
const row = []
// Riempi ogni riga con il numero corretto di prodotti
for (let col = 0; col < schedePerRiga; col++) {
const productIndex = pageStart + (rowStart * schedePerRiga) + col
if (productIndex < arrProducts.value.length) {
row.push(arrProducts.value[productIndex])
} else {
// Opzionale: riempi con null se non ci sono abbastanza prodotti
row.push(null)
// Riempi ogni riga con il numero corretto di prodotti
for (let col = 0; col < schedePerRiga; col++) {
const productIndex = pageStart + (rowStart * schedePerRiga) + col
row.push(indiceprodotto)
indiceprodotto++
}
page.push(row)
}
page.push(row)
pages.push(page)
}
pages.push(page)
return pages
}
return pages
return null
}
@@ -567,9 +751,9 @@ export default defineComponent({
generatePDF,
pdfContent,
tabcatalogo,
getCardStyle,
getWidthPerc,
groupedPages,
getNextProd,
getProdBySchedaRigaCol,
}
}
})