diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 824d66b..981657f 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -28,6 +28,7 @@ import {MatInputModule} from '@angular/material/input'; import {MatCheckboxModule} from '@angular/material/checkbox'; import {MatButtonToggleModule} from '@angular/material/button-toggle'; import {MatAutocompleteModule} from '@angular/material/autocomplete'; +import {MatCardModule} from '@angular/material/card'; import { MultiselectAutocompleteComponent} from './multiselect-autocomplete/multiselect-autocomplete.component'; import {MatChipsModule} from '@angular/material/chips'; @@ -41,6 +42,7 @@ import { DeletePresetDialogComponent } from './delete-preset-dialog/delete-prese import { SavePresetUnderDialogComponent } from './save-preset-under-dialog/save-preset-under-dialog.component'; + @NgModule({ declarations: [ AppComponent, @@ -81,7 +83,8 @@ import { SavePresetUnderDialogComponent } from './save-preset-under-dialog/save- MatIconModule, ScrollingModule, MomentDateModule, - MatButtonToggleModule + MatButtonToggleModule, + MatCardModule ], diff --git a/frontend/src/app/data.service.ts b/frontend/src/app/data.service.ts index 4a15ddb..9368a80 100644 --- a/frontend/src/app/data.service.ts +++ b/frontend/src/app/data.service.ts @@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { ResourceFields } from '@syncfusion/ej2-angular-gantt'; import { LanguageService } from './language.service'; +import { ErrorService } from './error.service'; interface Preset { id: string; @@ -32,7 +33,9 @@ export class DataService { private contracts: any []; private paketTypes: any []; private totalSize: number = null; + private user: string = null; public userSupportGroup: string; + //public selectedLanguage: string = 'DE'; /** @@ -40,7 +43,10 @@ export class DataService { * @param languageService injection of the languageService * @param http representation of the HttpClient */ - constructor(public languageService: LanguageService, private http: HttpClient) { + constructor(public languageService: LanguageService, private http: HttpClient, public errorService: ErrorService) { + this.getUser().then((res: any )=>{ + this.user = res.userId; + }); this.fetchStates().then((res: any [])=>{ this.states = res; }); @@ -143,7 +149,9 @@ export class DataService { .subscribe((response: any)=>{ res = response; resolve(res); - }) + },(error=>{ + this.errorService.handleRssoError(error); + })) }) return promise; } @@ -159,71 +167,79 @@ export class DataService { .subscribe((response: any)=>{ console.log(response); if(response.status == 500){ - return ""+response.error.message; - } - res.selectedPreset = response.selectedPreset; - let userPreferences = {language: 'DE', showDetails: true, view: 2}; - if(response.userPreferences.language == "EN"){ - userPreferences.language = "EN"; - } - if(response.userPreferences.showDetails == 0){ - userPreferences.showDetails = false; - } - if(response.userPreferences.view == 1){ - userPreferences.view = 0; - } - if(response.userPreferences.view == 2){ - userPreferences.view = 1; - } - if(response.userPreferences.view == 3){ - userPreferences.view = 2; - } - res.userPreferences = userPreferences; - response.presets.forEach(preset => { - console.log(preset); - res.presets.push({ - id: preset.id, - name: preset.name, - presetType: preset.presetType, - definition: JSON.parse(preset.definition) + resolve({status: response.status ,message: response.error.message}); + + }else{ + res.selectedPreset = response.selectedPreset; + let userPreferences = {language: 'DE', showDetails: true, view: 2}; + if(response.userPreferences.language == "EN"){ + userPreferences.language = "EN"; + } + if(response.userPreferences.showDetails == 0){ + userPreferences.showDetails = false; + } + if(response.userPreferences.view == 1){ + userPreferences.view = 0; + } + if(response.userPreferences.view == 2){ + userPreferences.view = 1; + } + if(response.userPreferences.view == 3){ + userPreferences.view = 2; + } + res.userPreferences = userPreferences; + response.presets.forEach(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 == response.selectedPreset){ + res.selectedPreset = preset; + } + } }); + let presetGroups : presetGroup[] = []; + let system = []; + let user = []; + let admin = []; for (const preset of res.presets) { - if(preset.id == response.selectedPreset){ - res.selectedPreset = preset; + if(preset.presetType == "System"){ + system.push(preset); + }else{ + user.push(preset); } } - }); - let presetGroups : presetGroup[] = []; - let system = []; - let user = []; - let admin = []; - for (const preset of res.presets) { - if(preset.presetType == "System"){ - system.push(preset); - }else{ - user.push(preset); - } - } - presetGroups = [ - { - name: 'System', - presets: system, - }, - { - name: 'Admin', - presets: admin - }, - { - name: 'User', - presets: user, - }, + presetGroups = [ + { + name: 'System', + presets: system, + }, + { + name: 'Admin', + presets: admin + }, + { + name: 'User', + presets: user, + }, - ]; - res.presetGroups = presetGroups; - console.log(res.presetGroups); + ]; + res.presetGroups = presetGroups; + // console.log(res.presetGroups); + if(response.status!=500){ resolve(res); + } + + } + }) }) + + return promise; } @@ -354,7 +370,11 @@ export class DataService { res.push(state) }); resolve(res); - }) + + }, (error=>{ + this.errorService.handleInitError(error); + } + )) }) return promise; } @@ -427,11 +447,14 @@ export class DataService { this.userSupportGroup = res.name; res = response; resolve(res); - }) + },(error=>{ + this.errorService.handleInitError(error); + })) }) return promise; } + /** * The function fetchPlanTimes fetches the plan times per week from the backend * @param filters current applied filters for the planTime calculation diff --git a/frontend/src/app/error.service.spec.ts b/frontend/src/app/error.service.spec.ts new file mode 100644 index 0000000..71f2b7a --- /dev/null +++ b/frontend/src/app/error.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ErrorService } from './error.service'; + +describe('ErrorService', () => { + let service: ErrorService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ErrorService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/error.service.ts b/frontend/src/app/error.service.ts new file mode 100644 index 0000000..08c4385 --- /dev/null +++ b/frontend/src/app/error.service.ts @@ -0,0 +1,70 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) + +export class ErrorService { + public rsso: boolean = false; + public rssoMsg: string; + + public init: boolean = false; + public initMsg: string; + + public critical: boolean = false; + public error: boolean = false; + + + public errors: any[] = []; + + constructor() { } + + public handleRssoError(error: any){ + this.errors.push({name: "RSSO Fehler",userInfo: "Der User konnte nicht angemeldet werden", message: error.message, type: 'rsso'}); + this.rsso = true; + console.log("RSSO ERROR"); + console.log(error); + } + public handleInitError(error: any){ + this.errors.push({name: "Fehler beim Laden der Daten",userInfo: "Bitte laden Sie die Seite erneut.", message: error.message, type: 'critical'}); + this.initMsg = error.message; + this.init = true; + this.critical = true; + console.log("CRITICAL ERROR"); + console.log(error.message); + } + public handleError(error: any){ + this.errors.push({name: "Fehler",userInfo: "Nicht kritischer Fehler", message: error.message, type: 'error'}); + this.error = true; + console.log("ERROR"); + console.log(error); + } + + public handleCostumError(name: string, userInfo: string, message: string, type: string){ + this.errors.push({name: name,userInfo: userInfo, message: message, type: type}); + this.rsso = true; + console.log("RSSO ERROR"); + } + + public getLastError(type: string){ + console.log(this.errors); + for (const error of this.errors) { + if(error.type == type){ + console.log(type +'/'+ error.message); + return error; + } + + } + + } + + + public getInitMsg(){ + return this.initMsg; + } + + public resetCritical(){ + this.critical = false; + } + +} diff --git a/frontend/src/app/ntt-gantt/ntt-gantt.component.html b/frontend/src/app/ntt-gantt/ntt-gantt.component.html index c4f52f2..f3ac639 100644 --- a/frontend/src/app/ntt-gantt/ntt-gantt.component.html +++ b/frontend/src/app/ntt-gantt/ntt-gantt.component.html @@ -1,4 +1,4 @@ -
{{errorService.getLastError('rsso').message}}
+{{errorService.getLastError('critical').message}}
+