feat: add editExclusion mode

This commit is contained in:
Vicent Llopis 2022-05-26 08:33:45 +02:00
parent a907354cc3
commit bbdaa7de39
5 changed files with 60 additions and 30 deletions

View File

@ -1,11 +1,11 @@
CREATE TABLE `vn`.`zoneExclusionGeo` ( CREATE TABLE `zoneExclusionGeo` (
`zoneExclusionFk` int(11) NOT NULL, `zoneExclusionFk` int(11) NOT NULL,
`geoFk` int(11) NOT NULL, `geoFk` int(11) NOT NULL,
PRIMARY KEY (`zoneExclusionFk`,`geoFk`), PRIMARY KEY (`zoneExclusionFk`,`geoFk`),
KEY `zoneExclusionGeo2_FK_1` (`geoFk`), KEY `zoneExclusionGeo2_FK_1` (`geoFk`),
CONSTRAINT `zoneExclusionGeo2_FK` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON UPDATE CASCADE, CONSTRAINT `zoneExclusionGeo2_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE,
CONSTRAINT `zoneExclusionGeo2_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE CONSTRAINT `zoneExclusionGeo_FK` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; ) ENGINE=InnoDB DEFAULT CHARSET=utf8
DROP PROCEDURE IF EXISTS `vn`.`zone_excludeFromGeo`; DROP PROCEDURE IF EXISTS `vn`.`zone_excludeFromGeo`;

View File

@ -146,11 +146,13 @@ class Controller extends Component {
onSelection($event, $days, $type, $weekday) { onSelection($event, $days, $type, $weekday) {
let $events = []; let $events = [];
let $exclusions = []; let $exclusions = [];
let $geoExclusions = [];
for (let day of $days) { for (let day of $days) {
let stamp = day.getTime(); let stamp = day.getTime();
$events = $events.concat(this.days[stamp] || []); $events = $events.concat(this.days[stamp] || []);
$exclusions = $exclusions.concat(this.exclusions[stamp] || []); $exclusions = $exclusions.concat(this.exclusions[stamp] || []);
$geoExclusions = $geoExclusions.concat(this.geoExclusions[stamp] || []);
} }
this.emit('selection', { this.emit('selection', {
@ -159,7 +161,8 @@ class Controller extends Component {
$type, $type,
$weekday, $weekday,
$events, $events,
$exclusions $exclusions,
$geoExclusions
}); });
} }

View File

@ -1,8 +1,14 @@
<vn-crud-model
vn-id="model"
url="Zones/{{$ctrl.$params.id}}/getLeaves"
filter="$ctrl.filter"
auto-load="true">
</vn-crud-model>
<vn-zone-calendar <vn-zone-calendar
id="calendar" id="calendar"
vn-id="calendar" vn-id="calendar"
data="data" data="data"
on-selection="$ctrl.onSelection($days, $type, $weekday, $events, $exclusions)" on-selection="$ctrl.onSelection($days, $type, $weekday, $events, $exclusions, $geoExclusions)"
on-step="$ctrl.refresh()" on-step="$ctrl.refresh()"
class="vn-w-md"> class="vn-w-md">
</vn-zone-calendar> </vn-zone-calendar>
@ -201,7 +207,7 @@
<vn-dialog <vn-dialog
vn-id="excludeDialog" vn-id="excludeDialog"
on-response="$ctrl.onExcludeResponse($response)" on-response="$ctrl.onExcludeResponse($response)"
message="Exclusion"> message="{{$ctrl.isNew ? 'Exclusion' : 'Edit exclusion'}}">
<tpl-body> <tpl-body>
<vn-date-picker <vn-date-picker
label="Day" label="Day"
@ -222,11 +228,7 @@
val="specificLocations"> val="specificLocations">
</vn-radio> </vn-radio>
</vn-vertical> </vn-vertical>
<vn-crud-model
vn-id="model"
url="Zones/{{$ctrl.$params.id}}/getLeaves"
filter="$ctrl.filter">
</vn-crud-model>
<div ng-if="$ctrl.excludeSelected.type == 'specificLocations'"> <div ng-if="$ctrl.excludeSelected.type == 'specificLocations'">
<vn-textfield <vn-textfield
label="Search" label="Search"
@ -244,7 +246,6 @@
sort-func="$ctrl.onSort($a, $b)"> sort-func="$ctrl.onSort($a, $b)">
<vn-check <vn-check
ng-model="item.checked" ng-model="item.checked"
on-change="$ctrl.onSelection2(value, item)"
ng-click="$event.preventDefault()" ng-click="$event.preventDefault()"
label="{{::item.name}}"> label="{{::item.name}}">
</vn-check> </vn-check>

View File

@ -61,24 +61,56 @@ class Controller extends Section {
: this.$t('Everyday'); : this.$t('Everyday');
} }
onSelection(days, type, weekday, events, exclusions) { onSelection(days, type, weekday, events, exclusions, geoExclusions) {
if (this.editMode == 'include') { if (this.editMode == 'include') {
if (events.length) if (events.length)
this.edit(events[0]); this.edit(events[0]);
else else
this.create(type, days, weekday); this.create(type, days, weekday);
} else { } else {
this.excludeSelected = { if (geoExclusions.length)
type: 'all', this.editExclusion(geoExclusions);
dated: days[0] else if (exclusions.length)
}; this.editExclusion(exclusions);
this.exclusions = exclusions; else
this.days = days; this.createExclusion(exclusions, days);
this.$.excludeDialog.show();
} }
} }
editExclusion(rows) {
this.isNew = false;
this.exclusions = rows;
this.excludeSelected = angular.copy(rows[0]);
if (this.excludeSelected.geoFk)
this.excludeSelected.type = 'specificLocations';
else
this.excludeSelected.type = 'all';
console.log(this.excludeSelected);
// const geos = this.$.model.data || [];
// for (let geo of geos) {
// for (let row of rows) {
// if (geo.id == row.geoFk) {
// geo.checked = true;
// console.log(geo);
// }
// }
// }
this.$.excludeDialog.show();
}
createExclusion(exclusions, days) {
this.isNew = true;
this.excludeSelected = {
type: 'all',
dated: days[0]
};
this.exclusions = exclusions;
this.days = days;
this.$.excludeDialog.show();
}
onEditClick(row, event) { onEditClick(row, event) {
if (event.defaultPrevented) return; if (event.defaultPrevented) return;
this.edit(row); this.edit(row);
@ -150,6 +182,8 @@ class Controller extends Section {
} }
onExcludeResponse(response) { onExcludeResponse(response) {
console.log(this.$.model.data);
switch (response) { switch (response) {
case 'accept': { case 'accept': {
let excludeSelected = this.excludeSelected; let excludeSelected = this.excludeSelected;
@ -267,14 +301,6 @@ class Controller extends Section {
return {name: {like: `%${value}%`}}; return {name: {like: `%${value}%`}};
} }
} }
onSelection2(value, item) {
if (value == null)
value = undefined;
const params = {geoId: item.id, isIncluded: value};
const path = `zones/${this.zone.id}/toggleIsIncluded`;
this.$http.post(path, params);
}
} }
Controller.$inject = ['$element', '$scope', 'vnWeekDays']; Controller.$inject = ['$element', '$scope', 'vnWeekDays'];