- 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

@@ -729,6 +729,11 @@
color="positive"
@click="EseguiFunz('listCollectionsBySize')"
></q-btn>
<q-btn
label="MyElem (imposta come chiave l'ID della Pagina e non il path !)"
color="positive"
@click="EseguiFunz('MyElemSetIdPageInsteadThePah')"
></q-btn>
<br />
</div>

View File

@@ -60,4 +60,11 @@ $heightBtn: 100%;
.break {
flex-basis: 100%;
height: 0;
}
.first_page{
padding-top: 40px;
padding-bottom: 40px;
padding-left: 30px;
padding-right: 30px;
}

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,
}
}
})

View File

@@ -8,6 +8,7 @@
>
<q-tab name="visu" icon="fas fa-eye" label="Visualizza"> </q-tab>
<q-tab name="sfondo" icon="fas fa-image" label="Sfondo"> </q-tab>
<q-tab name="pagine" icon="fas fa-book-reader" label="Pagine"> </q-tab>
<q-tab name="opzioni" icon="fas fa-save" label="Opzioni"> </q-tab>
</q-tabs>
<q-tab-panels v-model="tabcatalogo" animated class="">
@@ -60,18 +61,6 @@
>{{ reccat.label }}
</span>
|
<!--<q-btn
:push="cat === reccat.value"
dense
:size="tools.isMobile() ? '0.70rem' : '1rem'"
:icon="reccat.icon ? reccat.icon : undefined"
:color="cat === reccat.value ? 'primary' : undefined"
:text-color="cat === reccat.value ? 'white' : 'black'"
rounded
:label="reccat.label"
@click="cat = reccat.value"
>
</q-btn>-->
</div>
</div>
</q-tab-panel>
@@ -216,128 +205,226 @@
id="pdf-content"
ref="pdfContent"
:class="{ 'fixed-width': true }"
:style="{
backgroundImage: `url(${
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
(optcatalogo.printable
? optcatalogo.backgroundimage_printable
: optcatalogo.backgroundimage)
})`,
backgroundSize: 'contain',
'--width':
(optcatalogo.printable
? optcatalogo.widthpagPrintable
: optcatalogo.widthpag) + 'px',
}"
>
<div class="flex-container-book">
<q-infinite-scroll
v-if="!optcatalogo.pdf && arrLoaded && arrLoaded.length > 0"
ref="myinfscroll"
:initial-index="0"
@load="onLoadScroll"
:offset="2000"
debounce="200"
class="q-pa-xs row items-start"
style="place-content: center"
>
<div
class="q-pa-xs"
v-for="(product, index) in arrLoaded"
:key="index"
<div
v-if="optcatalogo.first_page_img"
:style="{
backgroundImage: `url(${
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
(optcatalogo.printable
? optcatalogo.first_page_img
: optcatalogo.first_page_img)
})`,
backgroundSize: 'cover',
height: optcatalogo.first_page_height + 'px',
width: optcatalogo.first_page_width + 'px',
}"
>
<div
class="first_page"
v-html="optcatalogo.first_page_html"
></div>
</div>
<div
:class="{ 'fixed-width': true }"
:style="{
backgroundImage: `url(${
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
(optcatalogo.printable
? optcatalogo.backgroundimage_printable
: optcatalogo.backgroundimage)
})`,
backgroundSize: 'contain',
'--width':
(optcatalogo.printable
? optcatalogo.widthpagPrintable
: optcatalogo.widthpag) + 'px',
}"
>
<div class="flex-container-book">
<q-infinite-scroll
v-if="
!optcatalogo.pdf && arrLoaded && arrLoaded.length > 0
"
ref="myinfscroll"
:initial-index="0"
@load="onLoadScroll"
:offset="2000"
debounce="200"
class="q-pa-xs row items-start"
style="place-content: center"
>
<CContainerCatalogoCard
v-if="
product.active ||
(show_hide &&
productInfo.productTypes.includes(
shared_consts.PRODUCTTYPE.PRODUCT
))
"
:id="product._id"
:complete="false"
:cosa="cosa"
:optcatalogo="optcatalogo"
:options="{
show_short_descr: false,
show_price: false,
show_cat: false,
quante_col: 'c2',
in_3d: false,
}"
@selauthor="selauthor"
/>
<CProductCard
v-else-if="product.active || show_hide"
:id="product._id"
:complete="false"
:cosa="cosa"
/>
</div>
<template v-slot:loading>
<div class="text-center">
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
<div v-else class="cards-container">
<!-- Itera sulle pagine -->
<div
v-for="(page, pageIndex) in groupedPages()"
:key="pageIndex"
class="card-page"
:style="`margin-bottom: ${optcatalogo.printable ? optcatalogo.margine_paginaPrintable : optcatalogo.margine_pagina};`"
>
<!-- Itera sulle righe di ogni pagina -->
<div
v-for="(row, rowIndex) in page"
:key="`${pageIndex}-${rowIndex}`"
class="card-row"
:style="`margin-bottom: ${optcatalogo.printable ? optcatalogo.margine_rigaPrintable : optcatalogo.margine_riga};`"
class="q-pa-xs"
v-for="(product, index) in arrLoaded"
:key="index"
>
<!-- Itera sui prodotti di ogni riga -->
<div
v-for="(product, colIndex) in row"
:key="`${pageIndex}-${rowIndex}-${colIndex}`"
class="flex-item-book image-container"
:style="
'place-content: center; ' +
('flex: 0 1 ' + optcatalogo.widthscheda + '; ')
<CContainerCatalogoCard
v-if="
product.active ||
(show_hide &&
productInfo.productTypes.includes(
shared_consts.PRODUCTTYPE.PRODUCT
))
"
>
<CContainerCatalogoCard
v-if="
product && product.active ||
(show_hide &&
productInfo.productTypes.includes(
shared_consts.PRODUCTTYPE.PRODUCT
))
"
:id="product._id"
:complete="false"
:cosa="cosa"
:optcatalogo="optcatalogo"
:options="{
show_short_descr: false,
show_price: false,
show_cat: false,
quante_col: 'c2',
in_3d: false,
}"
@selauthor="selauthor"
/>
<CProductCard
v-else-if="product && (product.active || show_hide)"
:id="product._id"
:complete="false"
:cosa="cosa"
/>
:id="product._id"
:complete="false"
:cosa="cosa"
:optcatalogo="optcatalogo"
:options="{
show_short_descr: false,
show_price: false,
show_cat: false,
quante_col: 'c2',
in_3d: false,
}"
@selauthor="selauthor"
/>
<CProductCard
v-else-if="product.active || show_hide"
:id="product._id"
:complete="false"
:cosa="cosa"
/>
</div>
<template v-slot:loading>
<div class="text-center">
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
<div v-else class="cards-container">
<!-- Itera sulle schede -->
<div
v-for="(
recscheda, schedaIndex
) in optcatalogo.arrSchede"
:key="schedaIndex"
>
<div v-if="recscheda && recscheda.scheda">
<!-- Itera sulle pagine -->
<div
v-for="(page, pageIndex) in groupedPages(
recscheda.scheda
)"
:key="pageIndex"
class="card-page"
:style="`margin-bottom: ${
optcatalogo.printable
? optcatalogo.margine_paginaPrintable
: optcatalogo.margine_pagina
}; margin-top: ${optcatalogo.margine_top + 'px'};`"
>
<!-- Itera sulle righe di ogni pagina -->
<div
v-for="(row, rowIndex) in page"
:key="`${pageIndex}-${rowIndex}`"
class="card-row"
:style="`margin-bottom: ${
optcatalogo.printable
? optcatalogo.margine_rigaPrintable
: optcatalogo.margine_riga
};`"
>
<!-- Itera sui prodotti di ogni riga -->
<div
v-for="(indprod, colIndex) in row"
:key="`${pageIndex}-${rowIndex}-${colIndex}`"
class="flex-item-book image-container"
:style="
'place-content: center; ' +
('flex: 0 1 ' +
recscheda.scheda.widthscheda ||
'100px' + '; ')
"
>
<CContainerCatalogoCard
v-if="
getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
) &&
getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
).active
"
:id="
getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
)._id
"
:complete="false"
:cosa="cosa"
:optcatalogo="optcatalogo"
:options="{
show_short_descr: false,
show_price: false,
show_cat: false,
quante_col: 'c2',
in_3d: false,
}"
@selauthor="selauthor"
/>
<CProductCard
v-else-if="
getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
) &&
(getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
).active ||
show_hide)
"
:id="
getProdBySchedaRigaCol(
recscheda.scheda,
rowIndex,
colIndex
)._id
"
:complete="false"
:cosa="cosa"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
v-if="optcatalogo.last_page_img"
:style="{
backgroundImage: `url(${
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
(optcatalogo.printable
? optcatalogo.last_page_img
: optcatalogo.last_page_img)
})`,
backgroundSize: 'cover',
height: optcatalogo.last_page_height + 'px',
width: optcatalogo.last_page_width + 'px',
}"
>
<div
class="last_page"
v-html="optcatalogo.last_page_html"
></div>
</div>
</div>
</div>
</div>
@@ -381,6 +468,44 @@
</q-img>
</div>
</q-tab-panel>
<q-tab-panel name="pagine">
<div class="row q-gutter-xs justify-center q-mx-auto bg-blue-1">
<div>
Prima Pagina:
{{
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
optcatalogo.first_page_img
}}
</div>
<q-img
:src="
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
optcatalogo.first_page_img
"
>
</q-img>
<div>
Ultima Pagina:
{{
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
optcatalogo.last_page_img
}}
</div>
<q-img
:src="
costanti.DIR_UPLOAD +
costanti.DIR_CATALOGO +
optcatalogo.last_page_img
"
>
</q-img>
</div>
</q-tab-panel>
<q-tab-panel name="opzioni">
<div class="row q-gutter-xs justify-center q-mx-auto bg-blue-1"></div>
</q-tab-panel>