diff --git a/db/changes/10081-agency/00-zone_getEvents.sql b/db/changes/10081-agency/00-zone_getEvents.sql index 6e47bad22..be50f602d 100644 --- a/db/changes/10081-agency/00-zone_getEvents.sql +++ b/db/changes/10081-agency/00-zone_getEvents.sql @@ -16,7 +16,7 @@ BEGIN * @param vPostCode The postcode or %NULL to use the province */ DECLARE vGeoFk INT; - + IF vPostCode IS NOT NULL THEN SELECT p.geoFk INTO vGeoFk FROM postCode p @@ -37,11 +37,11 @@ BEGIN WHERE z.agencyModeFk != vAgencyModeFk; END IF; - SELECT e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays FROM tmp.zone t JOIN zoneEvent e ON e.zoneFk = t.id; - SELECT DISTINCT e.dated + SELECT e.zoneFk, e.dated FROM tmp.zone t JOIN zoneExclusion e ON e.zoneFk = t.id; diff --git a/modules/agency/front/calendar/index.js b/modules/agency/front/calendar/index.js index ec28fa134..88f16d334 100644 --- a/modules/agency/front/calendar/index.js +++ b/modules/agency/front/calendar/index.js @@ -62,12 +62,15 @@ class Controller extends Component { return date && new Date(date).setHours(0, 0, 0, 0); } - this.exclusionsMap = {}; + this.exclusions = {}; let exclusions = value.exclusions; if (exclusions) { - for (let exclusion of exclusions) - this.exclusionsMap[toStamp(exclusion.dated)] = exclusion; + for (let exclusion of exclusions) { + let stamp = toStamp(exclusion.dated); + if (!this.exclusions[stamp]) this.exclusions[stamp] = []; + this.exclusions[stamp].push(exclusion); + } } let events = value.events; @@ -98,6 +101,7 @@ class Controller extends Component { let stamp = day.getTime(); let wday = day.getDay(); let dayEvents = []; + let exclusions = this.exclusions[stamp] || []; if (this.events) { for (let event of this.events) { @@ -114,46 +118,46 @@ class Controller extends Component { break; } - if (match) + if (match && !exclusions.find(e => e.zoneFk == event.zoneFk)) dayEvents.push(event); } } - let exclusion = this.exclusionsMap[stamp]; - - if (dayEvents.length || exclusion) { - let dayData = {}; - if (dayEvents.length) dayData.events = dayEvents; - if (exclusion) dayData.exclusion = exclusion; - this.days[stamp] = dayData; - } + if (dayEvents.length) + this.days[stamp] = dayEvents; day.setDate(day.getDate() + 1); } } onSelection($days, $type, $weekday) { - let $data = []; + let $events = []; + let $exclusions = []; + for (let day of $days) { - let dayData = this.days[day.getTime()]; - if (dayData) $data.push(dayData); + let stamp = day.getTime(); + $events = $events.concat(this.days[stamp] || []); + $exclusions = $exclusions.concat(this.exclusions[stamp] || []); } this.emit('selection', { $days, $type, $weekday, - $data + $events, + $exclusions }); } hasEvents(day) { - return this.days[day.getTime()] != null; + let stamp = day.getTime(); + return this.days[stamp] || this.exclusions[stamp]; } getClass(day) { - let dayData = this.days[day.getTime()]; - return dayData && dayData.exclusion ? 'excluded' : ''; + let stamp = day.getTime(); + return this.exclusions[stamp] && !this.days[stamp] + ? 'excluded' : ''; } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/agency/front/events/index.html b/modules/agency/front/events/index.html index 1b8c1e871..274d79997 100644 --- a/modules/agency/front/events/index.html +++ b/modules/agency/front/events/index.html @@ -1,7 +1,7 @@ diff --git a/modules/agency/front/events/index.js b/modules/agency/front/events/index.js index b6352802a..90f06c8d1 100644 --- a/modules/agency/front/events/index.js +++ b/modules/agency/front/events/index.js @@ -36,22 +36,14 @@ class Controller extends Section { : this.$t('Everyday'); } - onSelection(days, type, weekday, data) { + onSelection(days, type, weekday, events, exclusions) { + console.log(events, exclusions); if (this.editMode == 'include') { - let dayData = data[0] || {}; - let event = dayData.events && dayData.events[0]; - - if (event) - this.edit(event); + if (events.length) + this.edit(events[0]); else this.create(days, type, weekday); } else { - let exclusions = []; - for (let dayData of data) { - if (dayData.exclusion) - exclusions.push(dayData.exclusion.id); - } - if (exclusions.length) this.exclusionDelete(exclusions); else @@ -155,16 +147,16 @@ class Controller extends Section { .then(() => this.refresh()); } - exclusionDelete(ids) { - let promises = []; + exclusionDelete(exclusions) { + let reqs = []; - for (let id of ids) { - promises.push( - this.$http.delete(`${this.exclusionsPath}/${id}`) - ); + for (let exclusion of exclusions) { + if (!exclusion.id) continue; + let path = `${this.exclusionsPath}/${exclusion.id}`; + reqs.push(this.$http.delete(path)); } - this.$q.all(promises) + this.$q.all(reqs) .then(() => this.refresh()); } }