Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async ngOnInit() {
this.route.params.subscribe(params => {
this.groupName = params.groupName;
});
try {
const data: any = await this.http.get(`/editor/${this.groupName}/content/${this.locationListFileName}`).toPromise();
const flatLocationList = Loc.flatten(data);
// TODO Why do we need zoneLevelLocations???
const zoneLevelLocations = flatLocationList.locations.filter(location => location.level === 'zone');
this.locationsLevels = data.locationsLevels;
this.locationsLevelsLength = data.locationsLevels.length;
await this.setLocationList(data);
} catch (error) {
this.errorHandler.handleError('Could Not Load Location List Data');
}
}
async editItem() {
const flatLocationList = Loc.flatten(this.locationList);
const index = flatLocationList.locations.findIndex(location => location.id === this.form.id);
flatLocationList.locations[index] = { ...flatLocationList.locations[index], ...this.form };
this.locationList = Loc.unflatten(flatLocationList);
await this.setLocationList(this.locationList);
await this.saveLocationListToDisk();
this.isItemMarkedForUpdate = false;
this.hideLocationForm();
}
hideLocationForm() {
generateLocationIDs(locations) {
const flatLocationList = Loc.flatten(locations);
const ID = this.generateID();
const index = flatLocationList.locations.findIndex(location => location.id === ID);
if (index < 0) {
return ID;
} else {
return this.generateLocationIDs(locations);
}
}