refactor: delete duplicated code
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-06-13 12:26:40 +02:00
parent 06f181e913
commit 8d4c735744
1 changed files with 18 additions and 17 deletions

View File

@ -7,8 +7,8 @@ class Controller extends Section {
super($element, $);
this.vnWeekDays = vnWeekDays;
this.editMode = 'exclude';
this.exclusions;
this.exclusionsGeo;
this.exclusions = null;
this.exclusionsGeo = null;
}
$onInit() {
@ -23,10 +23,6 @@ class Controller extends Section {
return `Zones/${this.$params.id}/exclusions`;
}
get exclusionsGeoPath() {
return `Zones/exclusionGeo`;
}
get checked() {
const geos = this.$.model.data || [];
const checkedLines = [];
@ -244,7 +240,7 @@ class Controller extends Section {
};
if (this.isNew)
req = this.$http.post(this.exclusionsGeoPath, params);
req = this.$http.post(`Zones/exclusionGeo`, params);
else {
let actualPosition = 0;
let geoId;
@ -333,14 +329,7 @@ class Controller extends Section {
if (this.excludeSelected.type == 'specificLocations') {
this.$.model.applyFilter({}, params).then(() => {
const data = this.$.model.data;
for (let geo of data) {
for (let exclusionGeo of this.exclusionsGeo) {
if (geo.id == exclusionGeo.geoFk)
geo.checked = true;
}
}
this.getChecked(data);
this.$.treeview.data = data;
});
}
@ -348,8 +337,20 @@ class Controller extends Section {
onFetch(item) {
const params = item ? {parentId: item.id} : null;
return this.$.model.applyFilter({}, params)
.then(() => this.$.model.data);
return this.$.model.applyFilter({}, params).then(() => {
const data = this.$.model.data;
this.getChecked(data);
return data;
});
}
getChecked(data) {
for (let geo of data) {
for (let exclusionGeo of this.exclusionsGeo) {
if (geo.id == exclusionGeo.geoFk)
geo.checked = true;
}
}
}
onSort(a, b) {