- catalogo
- corretto logica del RefreshToken che non richiedeva il nuovo token, quindi scadeva tutte le volte, richiedendo sempre l'accesso !
This commit is contained in:
@@ -66,7 +66,6 @@ export default defineComponent({
|
||||
|
||||
const filter = ref(<IFilterCatalogo>{
|
||||
author: '',
|
||||
sort: 1,
|
||||
publisher: '',
|
||||
type: '',
|
||||
ageGroup: ''
|
||||
@@ -158,7 +157,14 @@ export default defineComponent({
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => filter.value.sort, (newval, oldval) => {
|
||||
watch(() => filter.value.sort_field, (newval, oldval) => {
|
||||
|
||||
calcArrProducts()
|
||||
if (tools.scrollTop() > 300) {
|
||||
tools.scrollToTopValue(300)
|
||||
}
|
||||
})
|
||||
watch(() => filter.value.sort_dir, (newval, oldval) => {
|
||||
|
||||
calcArrProducts()
|
||||
if (tools.scrollTop() > 300) {
|
||||
@@ -203,7 +209,9 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function calcArrProducts() {
|
||||
console.log('calcArrProducts')
|
||||
// console.log('calcArrProducts')
|
||||
|
||||
let arrargomstr: any = []
|
||||
|
||||
// eventuali titoli specifici estratti dall'array di Prodotti Selezionati
|
||||
//const searchtext = getSearchText()
|
||||
@@ -219,12 +227,19 @@ export default defineComponent({
|
||||
let boolfiltroVuotoProductTypes = (filtroProductTypes.length === 0 || (filtroProductTypes.length === 1 && (filtroProductTypes[0] === 0)))
|
||||
let boolfiltroVuotoExcludeProductTypes = filtroExcludeProductTypes.length === 0
|
||||
|
||||
let filtroPublishers = optcatalogo.value.Editore || []
|
||||
let filtroPublishers = optcatalogo.value.editore || []
|
||||
let boolfiltroVuotoEditore = (filtroPublishers.length === 0)
|
||||
|
||||
//console.log('filtroVersione', filtroProductTypes)
|
||||
|
||||
let catstr = cat.value || ''
|
||||
let catstr = ''
|
||||
|
||||
if (optcatalogo.value.argomenti) {
|
||||
// ha la priorità questo scelto sul catalogo
|
||||
arrargomstr = optcatalogo.value.argomenti
|
||||
} else {
|
||||
catstr = cat.value || ''
|
||||
}
|
||||
|
||||
let gasselstr = ''
|
||||
if (cosa.value === shared_consts.PROD.GAS) {
|
||||
@@ -240,6 +255,12 @@ export default defineComponent({
|
||||
if (product && product.productInfo) {
|
||||
let lowerName = (product.productInfo.name || '').toLowerCase();
|
||||
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
|
||||
let hasArgomentiCat = true
|
||||
if (arrargomstr && arrargomstr.length > 0) {
|
||||
hasArgomentiCat = (product.productInfo.idCatProds || []).some(idCat => arrargomstr.includes(idCat))
|
||||
hasCategoria = true
|
||||
}
|
||||
|
||||
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
|
||||
|
||||
let hasProductTypes = true
|
||||
@@ -253,7 +274,7 @@ export default defineComponent({
|
||||
hasProductTypes = !optcatalogo.value.productTypes || (optcatalogo.value.productTypes && (product.productInfo.productTypes || []).some((item: any) => optcatalogo.value.productTypes!.includes(item)))
|
||||
}
|
||||
if (optcatalogo.value && !boolfiltroVuotoEditore) {
|
||||
hasPublished = !optcatalogo.value.Editore || (optcatalogo.value.Editore && optcatalogo.value.Editore.includes(product.productInfo.idPublisher!))
|
||||
hasPublished = !optcatalogo.value.editore || (optcatalogo.value.editore && optcatalogo.value.editore.includes(product.productInfo.idPublisher!))
|
||||
}
|
||||
|
||||
if (optcatalogo.value && !boolfiltroVuotoExcludeProductTypes) {
|
||||
@@ -273,7 +294,7 @@ export default defineComponent({
|
||||
// Check if all words in lowerSearchText are present in lowerName
|
||||
let allWordsPresent = lowerSearchText.split(/\s+/).every(word => new RegExp(`\\b${word}\\b`, 'i').test(lowerName));
|
||||
|
||||
return (codeMatch.test(product.productInfo.code || '') || allWordsPresent) && hasCategoria && hasAuthor && productgassel && hasProductTypes && hasPublished && !hasExcludeProductTypes;
|
||||
return (codeMatch.test(product.productInfo.code || '') || allWordsPresent) && hasCategoria && hasArgomentiCat && hasAuthor && productgassel && hasProductTypes && hasPublished && !hasExcludeProductTypes;
|
||||
} else {
|
||||
console.error('product or product.productInfo is null');
|
||||
return false;
|
||||
@@ -281,7 +302,7 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
|
||||
arrprod = getProductsSorted(arrprod, filter.value.sort);
|
||||
arrprod = getProductsSorted(arrprod, filter.value.sort_field, filter.value.sort_dir);
|
||||
|
||||
arrProducts.value = arrprod
|
||||
|
||||
@@ -346,6 +367,8 @@ export default defineComponent({
|
||||
|
||||
const searchtext = scheda.arrProdottiSpeciali
|
||||
|
||||
let arrargomstr: any = []
|
||||
|
||||
let arrprod = productStore.getProducts(cosa.value) || [];
|
||||
let filtroAuthor = filter.value.author || '';
|
||||
|
||||
@@ -359,7 +382,14 @@ export default defineComponent({
|
||||
|
||||
//console.log('filtroVersione', filtroProductTypes)
|
||||
|
||||
let catstr = cat.value || ''
|
||||
let catstr = ''
|
||||
|
||||
if (optcatalogo.value.argomenti) {
|
||||
// ha la priorità questo scelto sul catalogo
|
||||
arrargomstr = optcatalogo.value.argomenti
|
||||
} else {
|
||||
catstr = cat.value || ''
|
||||
}
|
||||
|
||||
let gasselstr = ''
|
||||
if (cosa.value === shared_consts.PROD.GAS) {
|
||||
@@ -376,6 +406,12 @@ export default defineComponent({
|
||||
let lowerCode = (product.productInfo.code || '').toLowerCase();
|
||||
|
||||
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
|
||||
let hasArgomentiCat = true
|
||||
if (arrargomstr && arrargomstr.length > 0) {
|
||||
hasArgomentiCat = (product.productInfo.idCatProds || []).some(idCat => arrargomstr.includes(idCat))
|
||||
hasCategoria = true
|
||||
}
|
||||
|
||||
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
|
||||
|
||||
// Check if ANY search term matches the product name or code
|
||||
@@ -408,47 +444,49 @@ export default defineComponent({
|
||||
hasExcludeProductTypes = !scheda.excludeproductTypes || (scheda.excludeproductTypes && (product.productInfo.productTypes || []).every((item: any) => scheda.excludeproductTypes!.includes(item)))
|
||||
}
|
||||
|
||||
return searchMatch && hasCategoria && hasAuthor && hasProductTypes && hasPublished && !hasExcludeProductTypes;
|
||||
return searchMatch && hasCategoria && hasArgomentiCat && hasAuthor && hasProductTypes && hasPublished && !hasExcludeProductTypes;
|
||||
} else {
|
||||
console.error('product or product.productInfo is null');
|
||||
return false;
|
||||
}
|
||||
})
|
||||
|
||||
arrprod = getProductsSorted(arrprod, scheda?.sort!);
|
||||
arrprod = getProductsSorted(arrprod, scheda?.sort_field!, scheda?.sort_dir!);
|
||||
|
||||
return arrprod
|
||||
|
||||
}
|
||||
|
||||
function getProductsSorted(arrprod: IProduct[], sort: number) {
|
||||
// console.log('getProductsSorted', sort)
|
||||
if (sort === costanti.SORT_PUBDATE) {
|
||||
function getProductsSorted(arrprod: IProduct[], sort_field: string, sort_dir: number): IProduct[] {
|
||||
if (sort_field) {
|
||||
// Crea una copia dell'array per non modificare l'originale
|
||||
const sortedArr = [...arrprod].sort((a: IProduct, b: IProduct) => {
|
||||
const valA = a.productInfo?.[sort_field];
|
||||
const valB = b.productInfo?.[sort_field];
|
||||
|
||||
arrprod = arrprod.sort((a: IProduct, b: IProduct) => {
|
||||
return b.productInfo.date_pub_ts - a.productInfo.date_pub_ts
|
||||
})
|
||||
} else if (sort === costanti.SORT_BESTSELLER) {
|
||||
if (valA === undefined || valB === undefined) {
|
||||
return 0; // Gestisce il caso in cui il campo non esiste
|
||||
}
|
||||
|
||||
arrprod = arrprod.sort((a: IProduct, b: IProduct) => {
|
||||
return b.productInfo.vLast6M! - a.productInfo.vLast6M!
|
||||
})
|
||||
|
||||
arrprod = arrprod.map((product, index) => {
|
||||
return {
|
||||
...product,
|
||||
indiceRanking: index + 1
|
||||
};
|
||||
})
|
||||
|
||||
console.log('arr', arrprod)
|
||||
|
||||
} else if (sort === costanti.SORT_DEFAULT) {
|
||||
if (typeof valA === 'number' && typeof valB === 'number') {
|
||||
return sort_dir === 1 ? valA - valB : valB - valA;
|
||||
} else {
|
||||
// Per stringhe o altri tipi
|
||||
const compA = valA.toString().toLowerCase();
|
||||
const compB = valB.toString().toLowerCase();
|
||||
return sort_dir === 1
|
||||
? compA.localeCompare(compB)
|
||||
: compB.localeCompare(compA);
|
||||
}
|
||||
});
|
||||
|
||||
return sortedArr.map((product, index) => ({
|
||||
...product,
|
||||
indiceRanking: index + 1
|
||||
}));
|
||||
}
|
||||
|
||||
return arrprod
|
||||
|
||||
return arrprod;
|
||||
}
|
||||
|
||||
function addNextProductToTheView(arrproductfiltrati: IProduct[], indprod: number) {
|
||||
@@ -518,8 +556,8 @@ export default defineComponent({
|
||||
arrProdFiltrati = getProductsFilteredByScheda(recscheda.scheda)
|
||||
indprod = 0
|
||||
} else {
|
||||
if (recscheda.scheda?.sort! > 0) {
|
||||
arrProdFiltrati = getProductsSorted(arrGeneraleProdotti, recscheda.scheda.sort!);
|
||||
if (recscheda.scheda?.sort_field!) {
|
||||
arrProdFiltrati = getProductsSorted(arrGeneraleProdotti, recscheda.scheda.sort_field!, recscheda.scheda.sort_dir!);
|
||||
indprod = 0
|
||||
} else {
|
||||
indprod = indprodGenerale
|
||||
@@ -577,7 +615,7 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Fine...')
|
||||
// console.log('Fine...')
|
||||
}
|
||||
|
||||
function getNextProd() {
|
||||
@@ -610,7 +648,7 @@ export default defineComponent({
|
||||
}*/
|
||||
|
||||
async function mounted() {
|
||||
console.log('mounted Catalogo')
|
||||
// console.log('mounted Catalogo')
|
||||
loadpage.value = false
|
||||
await productStore.loadProducts()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user