feat: add editExclusion mode
This commit is contained in:
parent
a907354cc3
commit
bbdaa7de39
|
@ -1,11 +1,11 @@
|
|||
CREATE TABLE `vn`.`zoneExclusionGeo` (
|
||||
CREATE TABLE `zoneExclusionGeo` (
|
||||
`zoneExclusionFk` int(11) NOT NULL,
|
||||
`geoFk` int(11) NOT NULL,
|
||||
PRIMARY KEY (`zoneExclusionFk`,`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
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
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=utf8
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `vn`.`zone_excludeFromGeo`;
|
|
@ -146,11 +146,13 @@ class Controller extends Component {
|
|||
onSelection($event, $days, $type, $weekday) {
|
||||
let $events = [];
|
||||
let $exclusions = [];
|
||||
let $geoExclusions = [];
|
||||
|
||||
for (let day of $days) {
|
||||
let stamp = day.getTime();
|
||||
$events = $events.concat(this.days[stamp] || []);
|
||||
$exclusions = $exclusions.concat(this.exclusions[stamp] || []);
|
||||
$geoExclusions = $geoExclusions.concat(this.geoExclusions[stamp] || []);
|
||||
}
|
||||
|
||||
this.emit('selection', {
|
||||
|
@ -159,7 +161,8 @@ class Controller extends Component {
|
|||
$type,
|
||||
$weekday,
|
||||
$events,
|
||||
$exclusions
|
||||
$exclusions,
|
||||
$geoExclusions
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
id="calendar"
|
||||
vn-id="calendar"
|
||||
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()"
|
||||
class="vn-w-md">
|
||||
</vn-zone-calendar>
|
||||
|
@ -201,7 +207,7 @@
|
|||
<vn-dialog
|
||||
vn-id="excludeDialog"
|
||||
on-response="$ctrl.onExcludeResponse($response)"
|
||||
message="Exclusion">
|
||||
message="{{$ctrl.isNew ? 'Exclusion' : 'Edit exclusion'}}">
|
||||
<tpl-body>
|
||||
<vn-date-picker
|
||||
label="Day"
|
||||
|
@ -222,11 +228,7 @@
|
|||
val="specificLocations">
|
||||
</vn-radio>
|
||||
</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'">
|
||||
<vn-textfield
|
||||
label="Search"
|
||||
|
@ -244,7 +246,6 @@
|
|||
sort-func="$ctrl.onSort($a, $b)">
|
||||
<vn-check
|
||||
ng-model="item.checked"
|
||||
on-change="$ctrl.onSelection2(value, item)"
|
||||
ng-click="$event.preventDefault()"
|
||||
label="{{::item.name}}">
|
||||
</vn-check>
|
||||
|
|
|
@ -61,24 +61,56 @@ class Controller extends Section {
|
|||
: this.$t('Everyday');
|
||||
}
|
||||
|
||||
onSelection(days, type, weekday, events, exclusions) {
|
||||
onSelection(days, type, weekday, events, exclusions, geoExclusions) {
|
||||
if (this.editMode == 'include') {
|
||||
if (events.length)
|
||||
this.edit(events[0]);
|
||||
else
|
||||
this.create(type, days, weekday);
|
||||
} else {
|
||||
this.excludeSelected = {
|
||||
type: 'all',
|
||||
dated: days[0]
|
||||
};
|
||||
this.exclusions = exclusions;
|
||||
this.days = days;
|
||||
|
||||
this.$.excludeDialog.show();
|
||||
if (geoExclusions.length)
|
||||
this.editExclusion(geoExclusions);
|
||||
else if (exclusions.length)
|
||||
this.editExclusion(exclusions);
|
||||
else
|
||||
this.createExclusion(exclusions, days);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (event.defaultPrevented) return;
|
||||
this.edit(row);
|
||||
|
@ -150,6 +182,8 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
onExcludeResponse(response) {
|
||||
console.log(this.$.model.data);
|
||||
|
||||
switch (response) {
|
||||
case 'accept': {
|
||||
let excludeSelected = this.excludeSelected;
|
||||
|
@ -267,14 +301,6 @@ class Controller extends Section {
|
|||
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'];
|
||||
|
||||
|
|
Loading…
Reference in New Issue