From db0b5840f2e0765f899c1a74c1d1ab475c5a00e3 Mon Sep 17 00:00:00 2001 From: Manuel Kasper Date: Fri, 20 Nov 2020 17:35:30 +0100 Subject: [PATCH] Allow multiple callsigns for (not) activated by filters In case of "activated by", summits are shown if they have been activated by all activators In case of "not activated by", summits are shown if they have not been activated by any of the activators --- src/components/MapFilterControl.vue | 48 +++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/components/MapFilterControl.vue b/src/components/MapFilterControl.vue index 9cec842..76c824b 100644 --- a/src/components/MapFilterControl.vue +++ b/src/components/MapFilterControl.vue @@ -46,7 +46,7 @@ Activated by - + Me This year @@ -56,7 +56,7 @@ Not activated by - + Me This year @@ -233,19 +233,43 @@ export default { return null } + let callsigns = this[paramField].trim().split(/\s*,\s*/) + this.filterLoadingCount++ - return this.loadActivations(this[paramField].toUpperCase().trim()) - .then(activations => { + return Promise.all(callsigns.map(callsign => { + return this.loadActivations(callsign.toUpperCase()) + })) + .then(allActivations => { this.filterLoadingCount-- + let summitCodes + + allActivations.forEach(activations => { + // Filter for this year if necessary + if (this[paramField + 'ThisYear']) { + let now = moment.utc() + activations = activations.filter(activation => { + return moment.utc(activation.date).isSame(now, 'year') + }) + } + + let curSummitCodes = new Set(activations.map(activation => activation.summit.code)) + + if (summitCodes === undefined) { + summitCodes = curSummitCodes + } else { + // activatedBy: calculate intersection + // notActivatedBy: calculate union + if (paramField.startsWith('not')) { + summitCodes = new Set([...summitCodes, ...curSummitCodes]) + } else { + summitCodes = new Set([...summitCodes].filter(x => curSummitCodes.has(x))) + } + } + }) + let filter = filterTemplate - if (this[paramField + 'ThisYear']) { - let now = moment.utc() - activations = activations.filter(activation => { - return moment.utc(activation.date).isSame(now, 'year') - }) - } - activations.forEach(activation => { - filter.push(activation.summit.code) + summitCodes.forEach(summitCode => { + filter.push(summitCode) }) return filter })