2019-09-25 18:06:42 +00:00
|
|
|
import ngModule from '../module';
|
2019-11-18 15:31:37 +00:00
|
|
|
import Section from 'salix/components/section';
|
2022-05-16 05:17:29 +00:00
|
|
|
import './style.scss';
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2019-11-18 15:31:37 +00:00
|
|
|
class Controller extends Section {
|
2019-10-24 10:44:36 +00:00
|
|
|
constructor($element, $, vnWeekDays) {
|
|
|
|
super($element, $);
|
2019-10-23 15:38:35 +00:00
|
|
|
this.vnWeekDays = vnWeekDays;
|
2022-05-27 11:54:35 +00:00
|
|
|
this.editMode = 'exclude';
|
2022-05-12 11:53:13 +00:00
|
|
|
this.exclusions;
|
2022-06-02 08:40:02 +00:00
|
|
|
this.exclusionsGeo;
|
2020-06-18 10:43:33 +00:00
|
|
|
}
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2020-06-18 10:43:33 +00:00
|
|
|
$onInit() {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2021-11-04 06:56:12 +00:00
|
|
|
get path() {
|
|
|
|
return `Zones/${this.$params.id}/events`;
|
|
|
|
}
|
|
|
|
|
|
|
|
get exclusionsPath() {
|
|
|
|
return `Zones/${this.$params.id}/exclusions`;
|
|
|
|
}
|
|
|
|
|
2022-06-02 08:40:02 +00:00
|
|
|
get exclusionsGeoPath() {
|
2022-05-27 11:54:35 +00:00
|
|
|
return `Zones/exclusionGeo`;
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:02:07 +00:00
|
|
|
get checked() {
|
|
|
|
const geos = this.$.model.data || [];
|
|
|
|
const checkedLines = [];
|
|
|
|
for (let geo of geos) {
|
|
|
|
if (geo.checked)
|
|
|
|
checkedLines.push(geo);
|
|
|
|
}
|
|
|
|
return checkedLines;
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
refresh() {
|
2021-11-02 06:55:35 +00:00
|
|
|
this.$.data = null;
|
2021-11-08 10:30:00 +00:00
|
|
|
this.$.$applyAsync(() => {
|
|
|
|
const params = {
|
|
|
|
zoneFk: this.$params.id,
|
|
|
|
started: this.$.calendar.firstDay,
|
|
|
|
ended: this.$.calendar.lastDay
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$http.get(`Zones/getEventsFiltered`, {params}).then(res => {
|
|
|
|
const data = res.data;
|
|
|
|
this.$.data = data;
|
|
|
|
});
|
2019-10-23 15:38:35 +00:00
|
|
|
});
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
formatWdays(weekDays) {
|
|
|
|
if (!weekDays) return;
|
|
|
|
|
2019-11-18 15:31:37 +00:00
|
|
|
let abrWdays = weekDays
|
|
|
|
.split(',')
|
|
|
|
.map(wday => this.vnWeekDays.map[wday].localeAbr);
|
2019-09-25 18:06:42 +00:00
|
|
|
|
|
|
|
return abrWdays.length < 7
|
|
|
|
? abrWdays.join(', ')
|
2019-11-18 15:31:37 +00:00
|
|
|
: this.$t('Everyday');
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 08:40:02 +00:00
|
|
|
onSelection(days, type, weekday, events, exclusions, exclusionsGeo) {
|
2019-10-23 15:38:35 +00:00
|
|
|
if (this.editMode == 'include') {
|
2019-11-19 12:49:10 +00:00
|
|
|
if (events.length)
|
2022-05-27 11:54:35 +00:00
|
|
|
this.editInclusion(events[0]);
|
2022-05-12 11:53:13 +00:00
|
|
|
else
|
2022-05-27 11:54:35 +00:00
|
|
|
this.createInclusion(type, days, weekday);
|
2019-10-23 15:38:35 +00:00
|
|
|
} else {
|
2022-06-02 08:40:02 +00:00
|
|
|
if (exclusionsGeo.length) {
|
|
|
|
this.exclusionsGeo = exclusionsGeo;
|
2022-05-31 10:21:04 +00:00
|
|
|
this.editExclusion();
|
|
|
|
} else if (exclusions.length) {
|
|
|
|
this.exclusions = exclusions;
|
|
|
|
this.editExclusion();
|
|
|
|
} else
|
2022-05-27 11:54:35 +00:00
|
|
|
this.createExclusion(days);
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 10:21:04 +00:00
|
|
|
editExclusion() {
|
2022-05-26 06:33:45 +00:00
|
|
|
this.isNew = false;
|
2022-06-02 08:40:02 +00:00
|
|
|
if (this.exclusionsGeo && this.exclusionsGeo.length) {
|
|
|
|
this.excludeSelected = angular.copy(this.exclusionsGeo[0]);
|
2022-05-26 06:33:45 +00:00
|
|
|
this.excludeSelected.type = 'specificLocations';
|
2022-05-31 10:21:04 +00:00
|
|
|
}
|
2022-06-01 11:47:46 +00:00
|
|
|
if (this.exclusions && this.exclusions.length) {
|
2022-05-31 10:21:04 +00:00
|
|
|
this.excludeSelected = angular.copy(this.exclusions[0]);
|
2022-05-26 06:33:45 +00:00
|
|
|
this.excludeSelected.type = 'all';
|
2022-05-27 11:54:35 +00:00
|
|
|
}
|
2022-05-26 09:09:03 +00:00
|
|
|
|
2022-05-26 06:33:45 +00:00
|
|
|
this.$.excludeDialog.show();
|
|
|
|
}
|
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
createExclusion(days) {
|
2022-05-26 06:33:45 +00:00
|
|
|
this.isNew = true;
|
|
|
|
this.excludeSelected = {
|
|
|
|
type: 'all',
|
|
|
|
dated: days[0]
|
|
|
|
};
|
2022-06-02 08:40:02 +00:00
|
|
|
this.exclusionsGeo = [];
|
2022-05-26 06:33:45 +00:00
|
|
|
this.$.excludeDialog.show();
|
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
onEditClick(row, event) {
|
2019-09-25 18:06:42 +00:00
|
|
|
if (event.defaultPrevented) return;
|
2022-05-27 11:54:35 +00:00
|
|
|
this.editInclusion(row);
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
editInclusion(row) {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.isNew = false;
|
|
|
|
this.selected = angular.copy(row);
|
2019-11-18 15:31:37 +00:00
|
|
|
this.selected.wdays = this.vnWeekDays.fromSet(row.weekDays);
|
2022-05-12 11:53:13 +00:00
|
|
|
this.$.includeDialog.show();
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
createInclusion(type, days, weekday) {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.isNew = true;
|
2019-10-01 11:45:43 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
if (type == 'weekday') {
|
2019-10-01 11:45:43 +00:00
|
|
|
let wdays = [];
|
2020-05-08 11:23:06 +00:00
|
|
|
if (weekday) wdays[weekday] = true;
|
2019-11-18 15:31:37 +00:00
|
|
|
|
|
|
|
this.selected = {
|
|
|
|
type: 'indefinitely',
|
|
|
|
wdays
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.selected = {
|
|
|
|
type: 'day',
|
|
|
|
dated: days[0]
|
|
|
|
};
|
|
|
|
}
|
2019-10-01 11:45:43 +00:00
|
|
|
|
2022-05-12 11:53:13 +00:00
|
|
|
this.$.includeDialog.show();
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
onIncludeResponse(response) {
|
|
|
|
switch (response) {
|
|
|
|
case 'accept': {
|
2019-10-23 15:38:35 +00:00
|
|
|
let selected = this.selected;
|
2019-11-18 15:31:37 +00:00
|
|
|
let type = selected.type;
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2019-11-18 15:31:37 +00:00
|
|
|
selected.weekDays = this.vnWeekDays.toSet(selected.wdays);
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2019-11-18 15:31:37 +00:00
|
|
|
if (type == 'day')
|
2019-10-23 15:38:35 +00:00
|
|
|
selected.weekDays = '';
|
2019-11-18 15:31:37 +00:00
|
|
|
else
|
|
|
|
selected.dated = null;
|
|
|
|
|
|
|
|
if (type != 'range') {
|
|
|
|
selected.started = null;
|
|
|
|
selected.ended = null;
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
let req;
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
if (this.isNew)
|
|
|
|
req = this.$http.post(this.path, selected);
|
|
|
|
else
|
|
|
|
req = this.$http.put(`${this.path}/${selected.id}`, selected);
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
return req.then(() => {
|
2019-10-23 15:38:35 +00:00
|
|
|
this.selected = null;
|
|
|
|
this.isNew = null;
|
|
|
|
this.refresh();
|
|
|
|
});
|
2019-10-30 15:57:14 +00:00
|
|
|
}
|
2019-11-18 15:31:37 +00:00
|
|
|
case 'delete':
|
2019-10-30 15:57:14 +00:00
|
|
|
return this.onDelete(this.selected.id)
|
|
|
|
.then(response => response == 'accept');
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 11:53:13 +00:00
|
|
|
onExcludeResponse(response) {
|
2022-05-27 11:54:35 +00:00
|
|
|
const type = this.excludeSelected.type;
|
2022-05-12 11:53:13 +00:00
|
|
|
switch (response) {
|
|
|
|
case 'accept': {
|
|
|
|
if (type == 'all')
|
2022-05-27 11:54:35 +00:00
|
|
|
return this.exclusionCreate();
|
|
|
|
else
|
|
|
|
return this.exclusionGeoCreate();
|
2022-05-12 11:53:13 +00:00
|
|
|
}
|
|
|
|
case 'delete':
|
2022-05-27 11:54:35 +00:00
|
|
|
if (type == 'all')
|
|
|
|
return this.exclusionDelete(this.exclusions);
|
|
|
|
if (type == 'specificLocations')
|
2022-06-02 08:40:02 +00:00
|
|
|
return this.exclusionGeoDelete(this.exclusionsGeo);
|
2022-05-12 11:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 15:38:35 +00:00
|
|
|
onDeleteClick(id, event) {
|
|
|
|
if (event.defaultPrevented) return;
|
2019-09-25 18:06:42 +00:00
|
|
|
event.preventDefault();
|
2019-10-23 15:38:35 +00:00
|
|
|
this.onDelete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDelete(id) {
|
2019-10-30 15:57:14 +00:00
|
|
|
return this.$.confirm.show(
|
|
|
|
response => this.onDeleteResponse(response, id));
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
onDeleteResponse(response, id) {
|
|
|
|
if (response != 'accept' || !id) return;
|
|
|
|
return this.$http.delete(`${this.path}/${id}`)
|
|
|
|
.then(() => this.refresh());
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
2019-10-23 15:38:35 +00:00
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
exclusionCreate() {
|
|
|
|
const excludeSelected = this.excludeSelected;
|
|
|
|
const dated = excludeSelected.dated;
|
|
|
|
let req;
|
|
|
|
|
|
|
|
if (this.isNew)
|
|
|
|
req = this.$http.post(this.exclusionsPath, [{dated}]);
|
|
|
|
else
|
|
|
|
req = this.$http.put(`${this.exclusionsPath}/${excludeSelected.id}`, {dated});
|
|
|
|
|
|
|
|
return req.then(() => {
|
|
|
|
this.excludeSelected = null;
|
|
|
|
this.isNew = null;
|
|
|
|
this.refresh();
|
2019-10-23 15:38:35 +00:00
|
|
|
});
|
2022-05-27 11:54:35 +00:00
|
|
|
}
|
2019-10-23 15:38:35 +00:00
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
exclusionGeoCreate() {
|
|
|
|
const excludeSelected = this.excludeSelected;
|
|
|
|
let req;
|
|
|
|
const geoIds = [];
|
|
|
|
for (let zoneGeo of this.checked) {
|
|
|
|
geoIds.push({
|
|
|
|
id: zoneGeo.id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const params = {
|
|
|
|
zoneFk: parseInt(this.$params.id),
|
|
|
|
date: excludeSelected.dated,
|
2022-06-02 09:52:53 +00:00
|
|
|
geoIds: geoIds
|
2022-05-27 11:54:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.isNew)
|
2022-06-02 08:40:02 +00:00
|
|
|
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;
|
|
|
|
|
2022-06-02 09:52:53 +00:00
|
|
|
if (geoId && geoId == exclusionGeo.geoFk) {
|
2022-06-02 08:40:02 +00:00
|
|
|
const params = {
|
2022-06-02 09:52:53 +00:00
|
|
|
zoneExclusionFk: exclusionGeo.zoneExclusionFk,
|
2022-06-02 08:40:02 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
2022-05-27 11:54:35 +00:00
|
|
|
return req.then(() => {
|
|
|
|
this.excludeSelected = null;
|
|
|
|
this.isNew = null;
|
|
|
|
this.refresh();
|
|
|
|
});
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 12:49:10 +00:00
|
|
|
exclusionDelete(exclusions) {
|
|
|
|
let reqs = [];
|
2019-10-23 15:38:35 +00:00
|
|
|
|
2019-11-19 12:49:10 +00:00
|
|
|
for (let exclusion of exclusions) {
|
|
|
|
if (!exclusion.id) continue;
|
|
|
|
let path = `${this.exclusionsPath}/${exclusion.id}`;
|
|
|
|
reqs.push(this.$http.delete(path));
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 12:49:10 +00:00
|
|
|
this.$q.all(reqs)
|
2022-06-01 11:47:46 +00:00
|
|
|
.then(() => {
|
|
|
|
this.excludeSelected = null;
|
|
|
|
this.exclusions = null;
|
|
|
|
this.refresh();
|
|
|
|
});
|
2019-10-23 15:38:35 +00:00
|
|
|
}
|
2022-05-11 12:53:52 +00:00
|
|
|
|
2022-06-02 08:40:02 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:02:07 +00:00
|
|
|
set excludeSearch(value) {
|
|
|
|
this._excludeSearch = value;
|
|
|
|
if (!value) this.onSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
get excludeSearch() {
|
|
|
|
return this._excludeSearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyDown(event) {
|
|
|
|
if (event.key == 'Enter') {
|
|
|
|
event.preventDefault();
|
|
|
|
this.onSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSearch() {
|
|
|
|
const params = {search: this._excludeSearch};
|
2022-05-16 05:17:29 +00:00
|
|
|
if (this.excludeSelected.type == 'specificLocations') {
|
2022-05-12 11:53:13 +00:00
|
|
|
this.$.model.applyFilter({}, params).then(() => {
|
|
|
|
const data = this.$.model.data;
|
2022-05-26 09:09:03 +00:00
|
|
|
|
|
|
|
for (let geo of data) {
|
2022-06-02 08:40:02 +00:00
|
|
|
for (let exclusionGeo of this.exclusionsGeo) {
|
|
|
|
if (geo.id == exclusionGeo.geoFk)
|
2022-05-26 09:09:03 +00:00
|
|
|
geo.checked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 11:53:13 +00:00
|
|
|
this.$.treeview.data = data;
|
|
|
|
});
|
|
|
|
}
|
2022-05-11 12:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onFetch(item) {
|
|
|
|
const params = item ? {parentId: item.id} : null;
|
|
|
|
return this.$.model.applyFilter({}, params)
|
|
|
|
.then(() => this.$.model.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
onSort(a, b) {
|
|
|
|
if (b.selected !== a.selected) {
|
|
|
|
if (a.selected == null)
|
|
|
|
return 1;
|
|
|
|
if (b.selected == null)
|
|
|
|
return -1;
|
|
|
|
return b.selected - a.selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
|
|
|
case 'search':
|
|
|
|
return {name: {like: `%${value}%`}};
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
2019-10-24 10:44:36 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnZoneEvents', {
|
2019-09-25 18:06:42 +00:00
|
|
|
template: require('./index.html'),
|
2022-05-12 13:02:07 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
zone: '<'
|
|
|
|
},
|
|
|
|
require: {
|
|
|
|
card: '^vnZoneCard'
|
|
|
|
}
|
2019-09-25 18:06:42 +00:00
|
|
|
});
|