1781-zoneHoliday #994

Merged
joan merged 49 commits from 1781-zoneHoliday into dev 2022-08-03 06:41:31 +00:00
4 changed files with 64 additions and 26 deletions
Showing only changes of commit b5fa360960 - Show all commits

View File

@ -30,7 +30,7 @@ module.exports = Self => {
}
});
vicent marked this conversation as resolved
Review

where are my tests and my transaction?

where are my tests and my transaction?
Self.exclusionGeo = async(zoneFk, date, geoIds, options) => {
Self.exclusionGeo = async(zoneFk, date, geoIds) => {
const models = Self.app.models;
const newZoneExclusion = await models.ZoneExclusion.create({

View File

@ -52,7 +52,7 @@ module.exports = Self => {
const events = await Self.rawSql(query, [zoneFk, started, ended, started, ended, started, ended], myOptions);
query = `
SELECT *
SELECT e.*
FROM vn.zoneExclusion e
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
WHERE zoneFk = ?
@ -61,7 +61,7 @@ module.exports = Self => {
const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions);
query = `
SELECT *
SELECT eg.*, e.zoneFk, e.dated, e.created, e.userFk
FROM vn.zoneExclusion e
LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id
WHERE zoneFk = ?

View File

@ -7,14 +7,15 @@
}
},
"properties": {
"zoneExclusionFk": {
"id": {
"id": true,
"type": "number",
"required": true
"type": "number"
},
"zoneExclusionFk": {
"type": "number"
},
"geoFk": {
"type": "number",
"required": true
"type": "number"
}
}
}

View File

@ -8,7 +8,7 @@ class Controller extends Section {
this.vnWeekDays = vnWeekDays;
this.editMode = 'exclude';
this.exclusions;
vicent marked this conversation as resolved Outdated

this is undefined anyways

this is undefined anyways
this.geoExclusions;
this.exclusionsGeo;
}
$onInit() {
@ -23,7 +23,7 @@ class Controller extends Section {
return `Zones/${this.$params.id}/exclusions`;
}
get geoExclusionsPath() {
get exclusionsGeoPath() {
return `Zones/exclusionGeo`;
vicent marked this conversation as resolved Outdated

no need for a getter if you don't use a setter in this case.

no need for a getter if you don't use a setter in this case.
}
@ -65,15 +65,15 @@ class Controller extends Section {
: this.$t('Everyday');
}
onSelection(days, type, weekday, events, exclusions, geoExclusions) {
onSelection(days, type, weekday, events, exclusions, exclusionsGeo) {
if (this.editMode == 'include') {
if (events.length)
this.editInclusion(events[0]);
else
this.createInclusion(type, days, weekday);
} else {
if (geoExclusions.length) {
this.geoExclusions = geoExclusions;
if (exclusionsGeo.length) {
this.exclusionsGeo = exclusionsGeo;
this.editExclusion();
} else if (exclusions.length) {
this.exclusions = exclusions;
@ -85,8 +85,8 @@ class Controller extends Section {
editExclusion() {
this.isNew = false;
if (this.geoExclusions && this.geoExclusions.length) {
this.excludeSelected = angular.copy(this.geoExclusions[0]);
if (this.exclusionsGeo && this.exclusionsGeo.length) {
this.excludeSelected = angular.copy(this.exclusionsGeo[0]);
this.excludeSelected.type = 'specificLocations';
}
if (this.exclusions && this.exclusions.length) {
@ -103,7 +103,7 @@ class Controller extends Section {
type: 'all',
dated: days[0]
};
this.geoExclusions = [];
this.exclusionsGeo = [];
this.$.excludeDialog.show();
}
@ -190,7 +190,7 @@ class Controller extends Section {
if (type == 'all')
return this.exclusionDelete(this.exclusions);
if (type == 'specificLocations')
return this.exclusionDelete(this.geoExclusions);
return this.exclusionGeoDelete(this.exclusionsGeo);
}
}
@ -240,21 +240,42 @@ class Controller extends Section {
const params = {
zoneFk: parseInt(this.$params.id),
date: excludeSelected.dated,
geoIds: geoIds
geoFk: geoIds
};
if (this.isNew)
req = this.$http.post(this.geoExclusionsPath, params);
else
req = this.$http.put(`${this.geoExclusionsPath}/${excludeSelected.zoneExclusionFk}`, params);
req = this.$http.post(this.exclusionsGeoPath, params);
else {
let actualPosition = 0;
let geoId;
for (let exclusionGeo of this.exclusionsGeo) {
if (geoIds[actualPosition]) geoId = geoIds[actualPosition].id;
else geoId = null;
if (geoId) {
const params = {
zoneExclusionFk: excludeSelected.zoneExclusionFk,
geoFk: geoId
};
req = this.$http.put(`ZoneExclusionGeos/${exclusionGeo.id}`, params);
actualPosition++;
} else
req = this.$http.delete(`ZoneExclusionGeos/${exclusionGeo.id}`);
}
while (actualPosition <= geoIds.length - 1) {
const params = {
zoneExclusionFk: excludeSelected.zoneExclusionFk,
geoFk: geoIds[actualPosition].id
};
req = this.$http.post(`ZoneExclusionGeos`, params);
actualPosition++;
}
}
return req.then(() => {
this.excludeSelected = null;
this.isNew = null;
this.refresh();
});
// return this.$http.post(`Zones/exclusionGeo`, params)
// .then(() => this.refresh());
}
exclusionDelete(exclusions) {
@ -269,12 +290,28 @@ class Controller extends Section {
this.$q.all(reqs)
.then(() => {
this.excludeSelected = null;
this.geoExclusions = null;
this.exclusions = null;
this.refresh();
});
}
exclusionGeoDelete(exclusionsGeo) {
let reqs = [];
for (let exclusionGeo of exclusionsGeo) {
if (!exclusionGeo.id) continue;
let path = `${this.exclusionsPath}/${exclusionGeo.zoneExclusionFk}`;
reqs.push(this.$http.delete(path));
}
this.$q.all(reqs)
.then(() => {
this.excludeSelected = null;
this.exclusionsGeo = null;
this.refresh();
});
}
set excludeSearch(value) {
this._excludeSearch = value;
if (!value) this.onSearch();
@ -298,8 +335,8 @@ class Controller extends Section {
const data = this.$.model.data;
for (let geo of data) {
for (let geoExclusion of this.geoExclusions) {
if (geo.id == geoExclusion.geoFk)
for (let exclusionGeo of this.exclusionsGeo) {
if (geo.id == exclusionGeo.geoFk)
geo.checked = true;
}
}