function ElasticTemplates() { // RATES SETTER, GETTER AND CONVERT ACTION "use strict"; this.rates = { from: { title: "JPY - 日本円", iso_code: "JPY", symbol_left: "", symbol_right: " YEN", decimal_point: ".", thousands_point: ",", decimal_places: "0", default_flag: "1", rate: "1.00000000000" }, to: { title: "JPY - 日本円", iso_code: "JPY", symbol_left: "", symbol_right: " YEN", decimal_point: ".", thousands_point: ",", decimal_places: "0", default_flag: "1", rate: "1.00000000000" } }; this.setRates = r => { this.rates = r; }; this.priceToCurrency = price => { let p = (price / this.rates.from.rate) * this.rates.to.rate; p = p.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: this.rates.to.decimal_places }); return this.rates.to.symbol_left + p + this.rates.to.symbol_right; }; // LOADING DESIGN this.loading = () => { return `
`; }; // // FOR PRODUCT CARD TEMPLATE // // FROM REVIEW TO STAR TEMPLATE this.starRating = (review, review_count) => { return `
(${review_count})
`; }; this.tagLinks = tags => { tags = tags.split("//"); let res = ""; for (var key in tags) { let t = tags[key]; res += ` ${t} `; if (key >= 2) { break; } } return res; }; this.productCard = product => { let price = this.priceToCurrency(product.price); let rating = ""; let tags = ""; if (product.review > 0) { rating = this.starRating(product.review, product.review_count); } if (product.tags) { tags = this.tagLinks(product.tags); } let type = ""; if (product.product_type) { type = ` ${product.product_type} `; if(product.product_type.includes('畅销书')) { type = ` Bestseller `; } } else if (product.shipping_label) { type = ` Free Shipping `; } if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { return `
${type}
${product.title}
${rating}
${price}
In Stock
`; } else{ return `
${type}
${product.title}
${rating}
${price}
In Stock
`; } // return `
//
// ${type} // //
// //
//
//
${product.title}
// ${rating} //
// ${price} //
${product.stock} In Stock //
//
//
//
//
`; }; // // FOR PAGINATION VIEW // this.pagination = page => { let items = ""; let startPage = 1; if (page.current > 1) { items += `
  • <<
  • `; } if (page.current > 3) { startPage = page.current - 3; } if (startPage > 1) { items += `
  • ...
  • `; } for (let x = startPage; x <= page.total_pages && x <= startPage + 6; x++) { items += this.paginationItem(x, page.current); } if (page.total_pages > startPage + 6) { items += `
  • ...
  • `; } if (page.current < page.total_pages) { items += `
  • >>
  • `; } let res = `
    Page: ${page.current} of ${page.total_pages}
    `; return res; }; this.paginationItem = (item, current = 1) => { return `
  • ${item}
  • `; }; this.paginationDetails = page => { if (page.total_results > 9999) { return `${page.current * page.size - 19}-${page.current * page.size} of over ${page.total_results}+`; } return `${page.current * page.size - 19}-${page.current * page.size} of over ${page.total_results}`; }; // // FOR FILTER SIDEBAR // this.filterFilter = currentFilters => { let items = '
    Filters
    '; console.log(currentFilters); for (const [key, value] of Object.entries(currentFilters)) { let filter = value[Object.keys(value)[0]][0]; if (filter) { items += `
    ${filter}
    `; } // console.log(items); } return items; }; this.priceFilter = priceBounds => { let items = ""; for (let x = 0; x < priceBounds.length; x++) { let item = priceBounds[x]; let formTxt = this.priceToCurrency(item.from); let toTxt = this.priceToCurrency(item.to); if (x < priceBounds.length - 1) { items += `
    ${formTxt} - ${toTxt}
    `; } else { items += `
    Over ${formTxt}
    `; } } return items; }; this.brandFilter = (brands, filtered) => { let items = ""; for (let x = 0; x < brands.length; x++) { let item = brands[x]; let selected = ""; if (item.value == "") { continue; } if (filtered.indexOf(item.value) > -1) { selected = "checked"; } // ${item.isRefined ? 'checked' : ''} items += `
    ${item.count}
    `; } let res = `${items}`; return res; }; this.reviewFilter = data => { let res = ""; for (let x = 5; x >= 0; x--) { let item = data.filter(row => row.value == x); if (item.length > 0) { item = item[0]; } else { item.count = 0; } if (item.count == 0){ continue; } if (x ==0) { continue; } res += ` `; } return res; }; this.categoryFilter = (data, filtered, className) => { let items = ""; for (let x = 0; x < data.length; x++) { let item = data[x]; let titleTxt = item.value.split("||").pop(); let selected = ""; if (titleTxt == "") { continue; } if (filtered == item.value) { selected = "bg-primary text-light"; } // ${item.isRefined ? 'checked' : ''} items += ``; } let res = `
    ${items}
    `; return res; }; this.colorFilter = colors => { let items = ""; for (let x = 0; x < colors.length; x++) { let item = colors[x]; items += `
    `; } let res = `${items}`; return res; }; } function ElasticClient() { // this.key = "search-yyikxku2k6kzeoxzwsg7iowj"; // this.endPoint = "https://discovery-japan.ent.ap-southeast-1.aws.found.io"; // this.engine = "discovery-search-2"; this.key = "search-tokcuf7uku9n18cr83ktidpy"; this.endPoint = "https://discovery-japan-tky.ent.ap-northeast-1.aws.found.io"; this.engine = "discovery-japan-engine"; this.client = ElasticAppSearch.createClient({ searchKey: this.key, endpointBase: this.endPoint, engineName: this.engine }); return this.client; } function Helper() { this.getParam = p => { var url = new URL(location.href); return url.searchParams.get(p) || ""; }; this.setParams = (k, v) => { var url = new URL(location.href); url.searchParams.set(k, v); window.history.pushState("", "Search Page", url.href); }; this.deleteParam = k => { var url = new URL(location.href); url.searchParams.delete(k); window.history.pushState("", "Search Page", url.href); }; this.getParams = p => { var url = new URL(location.href); }; this.priceBounds = [ { from: 0, to: 1500 }, { from: 1500, to: 10000 }, { from: 10000, to: 50000 }, { from: 50000, to: 100000 }, { from: 100000, to: 9999999999999999999 } ]; this.colors = [ "Red", "Yellow", "Green", "Blue", "Purple", "Pink", "Gold", "Silver", "Brown" ]; this.setFilters = filters => { let res = []; for (var key in filters) { let fil = filters[key]; if (Array.isArray(fil) && fil.length > 0) { res.push({ [key]: fil }); continue; } if (typeof fil == "object" && Object.entries(fil).length > 0) { res.push({ [key]: fil }); continue; } if (!Array.isArray(fil) && typeof fil != "object") { if (fil) { res.push({ [key]: [fil] }); continue; } } } return res; }; }