From ab13c16948111fbc42bc2ccacc3ebf76d0be82d6 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 16 May 2022 07:17:29 +0200 Subject: [PATCH] feat: add dialog --- .../10460-mothersDay/00-zoneHoliday.sql | 5 +- .../zone/back/methods/zone/exclusionGeo.js | 48 +++++++++++++++++++ .../back/methods/zone/getEventsFiltered.js | 17 +++++-- .../zone/back/models/zone-exclusion-geo.json | 2 +- modules/zone/back/models/zone.js | 1 + modules/zone/front/calendar/index.js | 20 ++++++-- modules/zone/front/calendar/style.scss | 3 ++ modules/zone/front/events/index.html | 23 +++++---- modules/zone/front/events/index.js | 35 ++++++++------ modules/zone/front/events/style.scss | 11 +++++ modules/zone/front/location/index.js | 2 - 11 files changed, 133 insertions(+), 34 deletions(-) create mode 100644 modules/zone/back/methods/zone/exclusionGeo.js create mode 100644 modules/zone/front/events/style.scss diff --git a/db/changes/10460-mothersDay/00-zoneHoliday.sql b/db/changes/10460-mothersDay/00-zoneHoliday.sql index cacf5ba84..badae1c3e 100644 --- a/db/changes/10460-mothersDay/00-zoneHoliday.sql +++ b/db/changes/10460-mothersDay/00-zoneHoliday.sql @@ -81,11 +81,14 @@ BEGIN SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays FROM tZone t JOIN zoneEvent e ON e.zoneFk = t.id; + SELECT e.zoneFk, e.dated FROM tZone t JOIN zoneExclusion e ON e.zoneFk = t.id LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id - WHERE eg.zoneExclusionFk IS NULL; + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vGeoFk + WHERE eg.zoneExclusionFk IS NULL OR zg2.`path` LIKE CONCAT(zg1.`path`,'%'); DROP TEMPORARY TABLE tZone; END$$ diff --git a/modules/zone/back/methods/zone/exclusionGeo.js b/modules/zone/back/methods/zone/exclusionGeo.js new file mode 100644 index 000000000..0bd6075b9 --- /dev/null +++ b/modules/zone/back/methods/zone/exclusionGeo.js @@ -0,0 +1,48 @@ + +module.exports = Self => { + Self.remoteMethod('exclusionGeo', { + description: 'Exclude a zoneGeo for a zone', + accepts: [ + { + arg: 'zoneFk', + type: 'number', + description: 'The zone id' + }, + { + arg: 'date', + type: 'date', + description: 'The date to exclude' + }, + { + arg: 'geoIds', + type: 'any', + description: 'The geos id' + } + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/exclusionGeo`, + verb: 'POST' + } + }); + + Self.exclusionGeo = async(zoneFk, date, geoIds, options) => { + const models = Self.app.models; + + const newZoneExclusion = await models.ZoneExclusion.create({ + zoneFk: zoneFk, + dated: date + }); + + for (let geoId of geoIds) { + await models.ZoneExclusionGeo.create({ + zoneExclusionFk: newZoneExclusion.id, + geoFk: geoId.id + }); + } + }; +}; diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js index 5e9cbae5a..b97e49b1c 100644 --- a/modules/zone/back/methods/zone/getEventsFiltered.js +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -53,11 +53,22 @@ module.exports = Self => { query = ` SELECT * - FROM vn.zoneExclusion + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE zoneFk = ? - AND dated BETWEEN ? AND ?;`; + AND dated BETWEEN ? AND ? + AND eg.zoneExclusionFk IS NULL;`; const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); - return {events, exclusions}; + query = ` + SELECT * + FROM vn.zoneExclusion e + LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE zoneFk = ? + AND dated BETWEEN ? AND ? + AND eg.zoneExclusionFk IS NOT NULL;`; + const geoExclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); + + return {events, exclusions, geoExclusions}; }; }; diff --git a/modules/zone/back/models/zone-exclusion-geo.json b/modules/zone/back/models/zone-exclusion-geo.json index a578a07d0..7c77c5458 100644 --- a/modules/zone/back/models/zone-exclusion-geo.json +++ b/modules/zone/back/models/zone-exclusion-geo.json @@ -12,7 +12,7 @@ "required": true }, "geoFk": { - "type": "date", + "type": "number", "required": true } } diff --git a/modules/zone/back/models/zone.js b/modules/zone/back/models/zone.js index ef1c8c5d9..c580a2f15 100644 --- a/modules/zone/back/models/zone.js +++ b/modules/zone/back/models/zone.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/zone/deleteZone')(Self); require('../methods/zone/includingExpired')(Self); require('../methods/zone/getZoneClosing')(Self); + require('../methods/zone/exclusionGeo')(Self); Self.validatesPresenceOf('agencyModeFk', { message: `Agency cannot be blank` diff --git a/modules/zone/front/calendar/index.js b/modules/zone/front/calendar/index.js index a24d10aef..bdec1b949 100644 --- a/modules/zone/front/calendar/index.js +++ b/modules/zone/front/calendar/index.js @@ -75,6 +75,17 @@ class Controller extends Component { } } + this.geoExclusions = {}; + let geoExclusions = value.geoExclusions; + + if (geoExclusions) { + for (let geoExclusion of geoExclusions) { + let stamp = toStamp(geoExclusion.dated); + if (!this.geoExclusions[stamp]) this.geoExclusions[stamp] = []; + this.geoExclusions[stamp].push(geoExclusion); + } + } + let events = value.events; if (events) { @@ -154,13 +165,16 @@ class Controller extends Component { hasEvents(day) { let stamp = day.getTime(); - return this.days[stamp] || this.exclusions[stamp]; + return this.days[stamp] || this.exclusions[stamp] || this.geoExclusions[stamp]; } getClass(day) { let stamp = day.getTime(); - return this.exclusions[stamp] && !this.days[stamp] - ? 'excluded' : ''; + if (this.geoExclusions[stamp] && !this.days[stamp]) + return 'geoExcluded'; + else if (this.exclusions[stamp] && !this.days[stamp]) + return 'excluded'; + else return ''; } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/zone/front/calendar/style.scss b/modules/zone/front/calendar/style.scss index 25b6a87d1..d6853e33c 100644 --- a/modules/zone/front/calendar/style.scss +++ b/modules/zone/front/calendar/style.scss @@ -33,6 +33,9 @@ vn-zone-calendar { &.excluded .day-number { background-color: $color-alert; } + &.geoExcluded .day-number { + background-color: #33CAFF; + } } } } diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index 67657e665..45e2ec671 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -205,18 +205,18 @@ + ng-model="$ctrl.excludeSelected.dated"> - + @@ -227,20 +227,23 @@ url="Zones/{{$ctrl.$params.id}}/getLeaves" filter="$ctrl.filter"> -
+
+ + + -
+
@@ -254,13 +257,15 @@ + translate-attr="{value: 'Cancel'}" + tabindex="0"> + translate-attr="{value: 'Delete'}" + tabindex="0">