diff options
Diffstat (limited to 'client/lib')
-rw-r--r-- | client/lib/filter.js | 156 | ||||
-rw-r--r-- | client/lib/utils.js | 47 |
2 files changed, 154 insertions, 49 deletions
diff --git a/client/lib/filter.js b/client/lib/filter.js index a4e58692..c3c1b070 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -3,7 +3,6 @@ // RangeFilter, dateFilter, etc.). We then define a global `Filter` object whose // goal is to filter complete documents by using the local filters for each // fields. - function showFilterSidebar() { Sidebar.setView('filter'); } @@ -64,7 +63,9 @@ class SetFilter { _getMongoSelector() { this._dep.depend(); - return { $in: this._selectedElements }; + return { + $in: this._selectedElements, + }; } _getEmptySelector() { @@ -75,7 +76,9 @@ class SetFilter { includeEmpty = true; } }); - return includeEmpty ? { $eq: [] } : null; + return includeEmpty ? { + $eq: [], + } : null; } } @@ -119,7 +122,7 @@ class AdvancedFilter { current += char; continue; } - if (char === '/'){ + if (char === '/') { string = !string; if (string) regex = true; current += char; @@ -135,7 +138,11 @@ class AdvancedFilter { continue; } if (char === ' ' && !string) { - commands.push({ 'cmd': current, 'string': wasString, regex}); + commands.push({ + 'cmd': current, + 'string': wasString, + regex, + }); wasString = false; current = ''; continue; @@ -143,25 +150,29 @@ class AdvancedFilter { current += char; } if (current !== '') { - commands.push({ 'cmd': current, 'string': wasString, regex}); + commands.push({ + 'cmd': current, + 'string': wasString, + regex, + }); } return commands; } _fieldNameToId(field) { - const found = CustomFields.findOne({ 'name': field }); + const found = CustomFields.findOne({ + 'name': field, + }); return found._id; } - _fieldValueToId(field, value) - { - const found = CustomFields.findOne({ 'name': field }); - if (found.settings.dropdownItems && found.settings.dropdownItems.length > 0) - { - for (let i = 0; i < found.settings.dropdownItems.length; i++) - { - if (found.settings.dropdownItems[i].name === value) - { + _fieldValueToId(field, value) { + const found = CustomFields.findOne({ + 'name': field, + }); + if (found.settings.dropdownItems && found.settings.dropdownItems.length > 0) { + for (let i = 0; i < found.settings.dropdownItems.length; i++) { + if (found.settings.dropdownItems[i].name === value) { return found.settings.dropdownItems[i]._id; } } @@ -173,10 +184,15 @@ class AdvancedFilter { try { //let changed = false; this._processSubCommands(commands); + } catch (e) { + return this._lastValide; } - catch (e) { return this._lastValide; } - this._lastValide = { $or: commands }; - return { $or: commands }; + this._lastValide = { + $or: commands, + }; + return { + $or: commands, + }; } _processSubCommands(commands) { @@ -232,19 +248,24 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - if (commands[i + 1].regex) - { + if (commands[i + 1].regex) { const match = str.match(new RegExp('^/(.*?)/([gimy]*)$')); let regex = null; if (match.length > 2) regex = new RegExp(match[1], match[2]); else regex = new RegExp(match[1]); - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': regex }; - } - else - { - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': regex, + }; + } else { + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $in: [this._fieldValueToId(field, str), parseInt(str, 10)], + }, + }; } commands.splice(i - 1, 1); commands.splice(i, 1); @@ -257,19 +278,28 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - if (commands[i + 1].regex) - { + if (commands[i + 1].regex) { const match = str.match(new RegExp('^/(.*?)/([gimy]*)$')); let regex = null; if (match.length > 2) regex = new RegExp(match[1], match[2]); else regex = new RegExp(match[1]); - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: regex } }; - } - else - { - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} } }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $not: regex, + }, + }; + } else { + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $not: { + $in: [this._fieldValueToId(field, str), parseInt(str, 10)], + }, + }, + }; } commands.splice(i - 1, 1); commands.splice(i, 1); @@ -284,7 +314,12 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gt: parseInt(str, 10) } }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $gt: parseInt(str, 10), + }, + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; @@ -299,7 +334,12 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gte: parseInt(str, 10) } }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $gte: parseInt(str, 10), + }, + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; @@ -313,7 +353,12 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lt: parseInt(str, 10) } }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $lt: parseInt(str, 10), + }, + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; @@ -328,14 +373,18 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lte: parseInt(str, 10) } }; + commands[i] = { + 'customFields._id': this._fieldNameToId(field), + 'customFields.value': { + $lte: parseInt(str, 10), + }, + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; i--; break; } - } } } @@ -353,7 +402,9 @@ class AdvancedFilter { { const op1 = commands[i - 1]; const op2 = commands[i + 1]; - commands[i] = { $or: [op1, op2] }; + commands[i] = { + $or: [op1, op2], + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; @@ -368,27 +419,29 @@ class AdvancedFilter { { const op1 = commands[i - 1]; const op2 = commands[i + 1]; - commands[i] = { $and: [op1, op2] }; + commands[i] = { + $and: [op1, op2], + }; commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; i--; break; } - case 'not': case 'Not': case 'NOT': case '!': { const op1 = commands[i + 1]; - commands[i] = { $not: op1 }; + commands[i] = { + $not: op1, + }; commands.splice(i + 1, 1); //changed = true; i--; break; } - } } } @@ -441,8 +494,7 @@ Filter = { if (filter._isActive()) { if (filter.subField !== '') { filterSelector[`${fieldName}.${filter.subField}`] = filter._getMongoSelector(); - } - else { + } else { filterSelector[fieldName] = filter._getMongoSelector(); } emptySelector[fieldName] = filter._getEmptySelector(); @@ -452,7 +504,11 @@ Filter = { } }); - const exceptionsSelector = { _id: { $in: this._exceptions } }; + const exceptionsSelector = { + _id: { + $in: this._exceptions, + }, + }; this._exceptionsDep.depend(); const selectors = [exceptionsSelector]; @@ -463,7 +519,9 @@ Filter = { if (includeEmptySelectors) selectors.push(emptySelector); if (this.advanced._isActive()) selectors.push(this.advanced._getMongoSelector()); - return { $or: selectors }; + return { + $or: selectors, + }; }, mongoSelector(additionalSelector) { @@ -471,7 +529,9 @@ Filter = { if (_.isUndefined(additionalSelector)) return filterSelector; else - return { $and: [filterSelector, additionalSelector] }; + return { + $and: [filterSelector, additionalSelector], + }; }, reset() { diff --git a/client/lib/utils.js b/client/lib/utils.js index 44ca3a4a..a15dac39 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -145,6 +145,51 @@ Utils = { }); }, +<<<<<<< HEAD + setMatomo(data){ + window._paq = window._paq || []; + window._paq.push(['setDoNotTrack', data.doNotTrack]); + if (data.withUserName){ + window._paq.push(['setUserId', Meteor.user().username]); + } + window._paq.push(['trackPageView']); + window._paq.push(['enableLinkTracking']); + + (function() { + window._paq.push(['setTrackerUrl', `${data.address}piwik.php`]); + window._paq.push(['setSiteId', data.siteId]); + + const script = document.createElement('script'); + Object.assign(script, { + id: 'scriptMatomo', + type: 'text/javascript', + async: 'true', + defer: 'true', + src: `${data.address}piwik.js`, + }); + + const s = document.getElementsByTagName('script')[0]; + s.parentNode.insertBefore(script, s); + })(); + + Session.set('matomo', true); + }, + + manageMatomo() { + const matomo = Session.get('matomo'); + if (matomo === undefined){ + Meteor.call('getMatomoConf', (err, data) => { + if (err && err.error[0] === 'var-not-exist'){ + Session.set('matomo', false); // siteId || address server not defined + } + if (!err){ + Utils.setMatomo(data); + } + }); + } else if (matomo) { + window._paq.push(['trackPageView']); + } + getTriggerActionDesc(event, tempInstance) { const jqueryEl = tempInstance.$(event.currentTarget.parentNode); const triggerEls = jqueryEl.find(".trigger-content").children(); @@ -171,4 +216,4 @@ Utils = { // resized. This is used to reactively re-calculate the popup position in case // of a window resize. This is the equivalent of a "Signal" in some other // programming environments (eg, elm). -$(window).on('resize', () => Utils.windowResizeDep.changed());
\ No newline at end of file +$(window).on('resize', () => Utils.windowResizeDep.changed()); |