| Server IP : 185.208.173.17 / Your IP : 87.236.161.98 Web Server : Microsoft-IIS/10.0 System : Windows NT SRV8576125506 10.0 build 26100 (Windows Server 2016) AMD64 User : IUSR ( 0) PHP Version : 7.4.13 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/parsmega.nuxt/helper/ |
Upload File : |
const categoriesMapList = {
"technical": "Technical Properties",
"electrical": "Electrical Properties",
"display": "Display Properties",
"physical": "Physical Properties",
"analog_output": "Analog Output Properties",
"digital_input": "Digital Input Properties",
"digital_output": "Digital Output Properties",
"serial": "Serial Communication Properties",
"fieldbus": "Fieldbus Properties",
"analog_input": "Analog Input Properties"
};
export function cetegorizeAcsObject(acfObject) {
const acfKeys = Object.keys(acfObject);
let result = {};
for (let i = 0; i < acfKeys.length; i++) {
let tempAcfKey = acfKeys[i];
const tempSections = tempAcfKey.split("__");
if (tempSections.length < 2) continue;
let categorySection = tempSections[0];
let category = categoriesMapList[categorySection];
const categoryCreated = result[category];
if (!categoryCreated) {
result[category] = {
name: category,
properties: []
};
}
let propertyName = tempSections[1].substr(4);
result[category].properties.push({
key: propertyName.replace(new RegExp('_', 'g'), ' '),
value: acfObject[tempAcfKey]
});
}
return result;
}
export function filterProductsBaseOnAcf(filters, products) {
if (!filters || filters.length == 0) return products;
let result = [];
products.forEach(currentProduct => {
let isProductMatchFilters = true;
filters.forEach(filter => {
const filterKey = filter.key;
let filterSelectedValues = filter.selectedValues;
const isArrayFilterSelectedValues = Array.isArray(filterSelectedValues);
const productAcfList = currentProduct.acf || {};
const productAcfItem = productAcfList[filterKey];
const isArrayProductAcfItem = Array.isArray(productAcfItem);
const isProductAcfItemValid= productAcfItem != null && productAcfItem != undefined;
if (!isProductAcfItemValid) return isProductMatchFilters = false;
const stringAcfValue = String(productAcfItem).toLowerCase().trim();
const stringFilterValue = String(filterSelectedValues).toLowerCase().trim();
//single acf value vs single filter value
if (!isArrayProductAcfItem && !isArrayFilterSelectedValues) {
isProductMatchFilters = stringAcfValue != stringFilterValue ? false : isProductMatchFilters;
return;
}
//single acf value vs array of filter values
if (!isArrayProductAcfItem && isArrayFilterSelectedValues) {
let temp = filterSelectedValues.filter(fiVal => String(fiVal).toLowerCase().trim() == stringAcfValue);
isProductMatchFilters = temp.length == 0 ? false : isProductMatchFilters;
return;
}
//list acf vs single filter value
if (isArrayProductAcfItem && !isArrayFilterSelectedValues) {
let temp = productAcfItem.filter(acfVal => String(acfVal).toLowerCase().trim() == stringFilterValue);
isProductMatchFilters = temp.length == 0 ? false : isProductMatchFilters;
return;
}
//list acf vs list filter value
let localMatch = false;
productAcfItem.forEach(acfVal => {
let localAcf = String(acfVal).toLowerCase().trim();
let temp = filterSelectedValues.filter(fiVal => String(fiVal).toLowerCase().trim() == localAcf);
if (temp.length > 0) localMatch = true;
});
if (!localMatch) isProductMatchFilters = false;
});
if (isProductMatchFilters) result.push(currentProduct);
});
return result;
}