From 56e77f1660cff62ef186d2a5b6ee2d772c100766 Mon Sep 17 00:00:00 2001 From: manueltauber Date: Fri, 20 Oct 2023 17:04:57 +0200 Subject: [PATCH] preset Functions --- frontend/src/app/data.service.ts | 31 ++++++++++++- .../app/ntt-gantt/ntt-gantt.component.html | 4 +- .../src/app/ntt-gantt/ntt-gantt.component.ts | 46 +++++++++++++------ 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/data.service.ts b/frontend/src/app/data.service.ts index 8c3ee83..fd2769b 100644 --- a/frontend/src/app/data.service.ts +++ b/frontend/src/app/data.service.ts @@ -146,7 +146,18 @@ export class DataService { } res.userPreferences = userPreferences; response.presets.forEach(preset => { - res.presets.push(preset); + console.log(preset); + res.presets.push({ + id: preset.id, + name: preset.name, + presetType: preset.presetType, + definition: JSON.parse(preset.definition) + }); + for (const preset of res.presets) { + if(preset.id == 'AGGAA5V0G2LS6ASCSVD9SBS7MO40RV'){ + res.selectedPreset = preset; + } + } }); resolve(res); }) @@ -174,6 +185,24 @@ export class DataService { return promise; } + /** + * The function updateDatePerChange sends the new date to the backend if the date was moved + * @param change the Change (the Resource) from which the date should be changed + */ + public async updatePreset(preset: any){ + const promise = new Promise(resolve=>{ + let serializableResource = {id: preset.id, definition: preset.definition}; + let strigifiedResource = JSON.stringify(serializableResource); + let resJson = JSON.parse(strigifiedResource) as typeof strigifiedResource; + this.http.post('http://localhost:8080/api/updatePreset', resJson).subscribe((response:any)=>{ + resolve(response); + },(error:any)=>{ + resolve(error); + }); + }); + return promise; + } + /** * The function fetchStates fetches an array from the possible statuses per state * @returns promise for the fetched Status Array diff --git a/frontend/src/app/ntt-gantt/ntt-gantt.component.html b/frontend/src/app/ntt-gantt/ntt-gantt.component.html index 9b7c824..b8c1322 100644 --- a/frontend/src/app/ntt-gantt/ntt-gantt.component.html +++ b/frontend/src/app/ntt-gantt/ntt-gantt.component.html @@ -29,9 +29,9 @@ - {{selectedPreset}} + Preset - + {{preset.name}} diff --git a/frontend/src/app/ntt-gantt/ntt-gantt.component.ts b/frontend/src/app/ntt-gantt/ntt-gantt.component.ts index af6afb2..625b5ce 100644 --- a/frontend/src/app/ntt-gantt/ntt-gantt.component.ts +++ b/frontend/src/app/ntt-gantt/ntt-gantt.component.ts @@ -118,7 +118,7 @@ export class NttGanttComponent implements OnInit { public sortSelectorName: any; public presets : any[] = []; - public selectedPreset : {} = {}; + public selectedPreset: any; /**###################################################################### Initial Loading functions ######################################################################*/ @@ -142,20 +142,12 @@ export class NttGanttComponent implements OnInit { this.firstLoad = true; this.sliceStart = 0; this.sliceEnd = 20; - this.dataService.initPresets().then((res: any)=>{ - let currentPreset; - console.log(res); - for (const preset of res.presets) { - if(preset.id == 'AGGAA5V0G2LS6ASCSVD9SBS7MO40RV'){ - currentPreset = preset; - } - } - console.log(currentPreset); - this.presets = res.presets; - this.selectedPreset = currentPreset; - this.filters = JSON.parse(currentPreset.definition); - this.filterEnabled = true; + this.dataService.initPresets().then((res: any)=>{ + this.presets = res.presets; + this.selectedPreset = res.selectedPreset; + this.filters = this.selectedPreset.definition; + this.filterEnabled = true; this.showDetails = res.userPreferences.showDetails; this.selectedScalar = this.scalars[res.userPreferences.view]; @@ -230,6 +222,29 @@ export class NttGanttComponent implements OnInit { this.inputForTimeline = [this.splitterSettings, this.projectStartDate, this.projectEndDate]; } + public selectPreset(preset: any){ + + } + public savePreset(preset: any){ + this.dataService.savePreset(preset).then((res)=>{{ + console.log(res); + }}) + } + public updatePreset(preset: any){ + + } + public renamePreset(preset: any){ + + } + public deletePreset(preset: any){ + + } + + public editUserPreferences(language: any, showDetails: any, view: any){ + + } + + /**###################################################################### Data Mapping, Filter and Sorting Functions ######################################################################*/ @@ -338,6 +353,9 @@ export class NttGanttComponent implements OnInit { // this.dataService.savePreset({name: "FRONTEND TEST PRESET", definition: JSON.stringify(this.filters)}).then((res)=>{ // console.log(res); // }); + // this.dataService.updatePreset({id: 'AGGAA5V0G2LS6ASCSUZZSBS79E40O5', definition: JSON.stringify(this.filters)}).then((res)=>{ + // console.log(res); + // }); this.refreshData(); } });