From: Vincent Vanwaelscappel Date: Thu, 6 May 2021 11:05:55 +0000 (+0200) Subject: wait #4423 @6 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0dbe71af0a7774c2ea76f7f0643faa604f855c4f;p=fluidbook-html5.git wait #4423 @6 --- diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 353f6ef2..1aed7e9b 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -461,7 +461,7 @@ FluidbookSearch.prototype = { return source; }, setHighlightTerms: function (terms) { - if (!this.highlightEnabled) { + if (!this.highlightEnabled || window.HIGHLIGHTS === undefined) { return; } this.termsToHighlight = terms; @@ -714,7 +714,6 @@ FluidbookSearch.prototype = { if (!continueProcessingAfterPlugins) { continue; } - var plugin = this.plugins[p]; continueProcessingAfterPlugins = plugin.submitQuery(q); } diff --git a/js/libs/fluidbook/fluidbook.utils.js b/js/libs/fluidbook/fluidbook.utils.js index dffe061a..0c87ea3b 100644 --- a/js/libs/fluidbook/fluidbook.utils.js +++ b/js/libs/fluidbook/fluidbook.utils.js @@ -119,4 +119,34 @@ function getIframeDocument(iframe) { doc = doc.document; } return doc; +} + +function parseRange(string) { + let res = []; + let m; + + for (let str of string.split(",").map((str) => str.trim())) { + // just a number + if (/^-?\d+$/.test(str)) { + res.push(parseInt(str, 10)); + } else if ( + (m = str.match(/^(-?\d+)(-|\.\.\.?|\u2025|\u2026|\u22EF)(-?\d+)$/)) + ) { + // 1-5 or 1..5 (equivalent) or 1...5 (doesn't include 5) + let [_, lhs, sep, rhs] = m; + + if (lhs && rhs) { + lhs = parseInt(lhs); + rhs = parseInt(rhs); + const incr = lhs < rhs ? 1 : -1; + + // Make it inclusive by moving the right 'stop-point' away by one. + if (sep === "-" || sep === ".." || sep === "\u2025") rhs += incr; + + for (let i = lhs; i !== rhs; i += incr) res.push(i); + } + } + } + + return res; } \ No newline at end of file diff --git a/js/libs/fluidbook/special/wescosales.js b/js/libs/fluidbook/special/wescosales.js index c516caaf..f635649b 100644 --- a/js/libs/fluidbook/special/wescosales.js +++ b/js/libs/fluidbook/special/wescosales.js @@ -63,7 +63,7 @@ function wescoResize() { $("#wescosalesselector").css('left', sl); $(".wescosaleswindow").each(function () { - setInteractPanel($(this).data('ref'), true); + setInteractPanel($(this).data('id'), true); }); } @@ -71,58 +71,91 @@ function setWescoSalesPanel(ref, e, updateOnly) { if (updateOnly === undefined) { updateOnly = false; } - - var id = "wescosaleswindow-" + normalizeRef(ref); + var refs = getWescoReferences(ref); + var rid = forge_sha256(refs.join('-')).substr(0, 10); + var id = "wescosaleswindow-" + rid; if ($("#" + id).length != 0) { updateOnly = true; } - var r = getWescoRef(ref); - if (r.ref === undefined) { - return; - } - var rref = r.ref; var activeCountry = $("#wescosalesselect").val(); + var first = true; + var wtitle = ''; + var wrefs = []; + var unique = refs.length === 1; + var wlines = {}; + var suppLines = {}; + $.each(refs, function (k, ref) { + var r = getWescoRef(ref); + if (r.ref === undefined) { + return; + } + if (first) { + first = false; + wtitle = r.title; + } + + var rref = r.ref; + if (rref.length === 9) { + wrefs.push(rref.substr(0, 3) + ' ' + rref.substr(3, 3) + ' ' + rref.substr(6)); + } else if (rref.length === 5) { + wrefs.push(rref.substr(0, 2) + ' ' + rref.substr(2)); + } + + + for (var i in r.countries[activeCountry]) { + var d = r.countries[activeCountry][i]; + if (d[1] === null) { + continue; + } + if (unique) { + if (d[2] === null) { + suppLines[d[0]] = d[1]; + } else { + wlines[d[0]] = {ca: d[1], qte: d[2]}; + } + } else { + if (wlines[d[0]] == null || wlines[d[0]] == undefined) { + wlines[d[0]] = {ca: 0, qte: 0}; + } + wlines[d[0]].ca += parseInt(d[1].toString().replace(/,/g, '')); + wlines[d[0]].qte += parseInt(d[2].toString().replace(/,/g, '')); + } + } + }); + var w = ''; w += ''; - w += '

' + r.title + '

'; - if (rref.length == 9) { - w += '

' + rref.substr(0, 3) + ' ' + rref.substr(3, 3) + ' ' + rref.substr(6) + '

'; - } else if (rref.length == 5) { - w += '

' + rref.substr(0, 2) + ' ' + rref.substr(2) + '

'; - } + w += '

' + wtitle + '

'; + w += '

' + wrefs.join(', ') + '

'; w += '
'; if (!updateOnly) { - $('body').append('
'); + $('body').append('
'); } - var seenNotFigure = false; - w += ''; w += ''; - for (var i in r.countries[activeCountry]) { - var d = r.countries[activeCountry][i]; - if (d[1] === null) { - continue; - } - if (d[2] == null) { - var cl = ''; - if (!seenNotFigure) { - w += ''; - seenNotFigure = true; - } - w += ''; - w += ''; - w += ''; - } else { + var format = new Intl.NumberFormat('en-US'); + + $.each(wlines, function (date, line) { + var ca = unique ? line.ca : format.format(line.ca); + var qte = unique ? line.qte : format.format(line.qte); + w += ''; + w += ''; + w += ''; + w += ''; + w += ''; + }); + if (Object.keys(suppLines).length > 0) { + w += ''; + $.each(suppLines, function (t, line) { w += ''; - w += ''; - w += ''; - w += ''; - } - w + ''; + w += ''; + w += ''; + w += ''; + }); } w += '
QtéCA

' + d[0] + '' + d[1] + '
' + date + '' + ca + '' + qte + '

' + d[0] + '' + d[1] + '' + d[2] + '
' + t + '' + line + '
'; $('#' + id).html(w); @@ -132,7 +165,7 @@ function setWescoSalesPanel(ref, e, updateOnly) { $("#" + id).css({left: x, top: y}).data({x: x, y: y}); } - setInteractPanel(ref, updateOnly); + setInteractPanel(id, updateOnly); } function getAllRefs() { @@ -176,8 +209,10 @@ function getPagesOfRefs() { } function getPossibleReferences(ref) { - var trimmedRef = ref.toString().replace(/^0+/, ""); - var res = [trimmedRef]; + var nospaceref = ref.toString().replace(/\s*/g, ''); + var spaceref = nospaceref.toString().substr(0, 2) + ' ' + nospaceref.toString().substr(2, 3); + var trimmedRef = nospaceref.toString().replace(/^0+/, ""); + var res = [ref, spaceref, trimmedRef, nospaceref]; var tr = trimmedRef; for (var i = 0; i < (5 - trimmedRef.length); i++) { tr = '0' + tr; @@ -186,11 +221,19 @@ function getPossibleReferences(ref) { return res; } -function setInteractPanel(ref, onlyRect) { +function getWescoReferences(ref) { + var range = parseRange(ref.toString().replace(/\s*/g, '')); + var res = []; + $.each(range, function (k, v) { + res.push(normalizeRef(v)); + }); + return res; +} + +function setInteractPanel(id, onlyRect) { if (onlyRect === undefined) { onlyRect = false; } - var id = "wescosaleswindow-" + normalizeRef(ref); var maxx = fluidbook.resize.ww - 20; var maxy = fluidbook.resize.hh - 70; @@ -370,7 +413,7 @@ WescoSalesSearchPlugin.prototype = { q = q.replace(/\s/gm, ''); if (q.length != 5) { - console.log('not ref (length)'); + console.log('not ref (length)', q); return true; } var all = getAllRefs();