Error handling

main
Manuel Tauber 2024-02-08 14:09:03 +01:00
parent 5f236d56b2
commit 501cb33406
6 changed files with 215 additions and 72 deletions

View File

@ -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
],

View File

@ -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

View File

@ -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();
});
});

View File

@ -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;
}
}

View File

@ -1,4 +1,4 @@
<div id="topbar">
<div *ngIf="!errorService.rsso && !rssoInit" id="topbar">
<mat-form-field class="datePicker" appearance="fill" >
<mat-label>{{languageService.lMap.get('dateRangeLabel')}}</mat-label>
@ -55,12 +55,12 @@
<button mat-basic-button *ngIf="isUserPreset" class="editButton" (click)="openRenameDialog()" color="" style="" ><mat-icon>edit</mat-icon></button>
<button mat-basic-button *ngIf="isUserPreset" class="deleteButton" (click)="openDeleteDialog()" color="" style="" ><mat-icon>delete_forever</mat-icon></button>
<h3 *ngIf="userId" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: green;">verified_user</mat-icon> RSSO User: {{this.userId}}</h3>
<h3 *ngIf="!userId && !rssoInit" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: red;">verified_user</mat-icon> RSSO Auth Failed</h3>
<h3 *ngIf="rssoInit" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: orange;">verified_user</mat-icon> RSSO: initializing</h3>
<h3 *ngIf="userId" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: green;">verified_user</mat-icon>{{this.userId}}</h3>
<h3 *ngIf="errorService.rsso" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: red;">verified_user</mat-icon> RSSO Auth Failed</h3>
<h3 *ngIf="!errorService.rsso &&rssoInit" style="font-family: Arial, Helvetica, sans-serif;"><mat-icon style="color: orange;">verified_user</mat-icon> RSSO: initializing</h3>
</div>
<div class="filterContainer">
<div *ngIf="!errorService.rsso && !rssoInit" class="filterContainer">
<button mat-raised-button class="filterButton" aria-label="Filtern" (click)="openFilterDialog()">
{{languageService.lMap.get('nttGanttFilterButton')}} <mat-icon style="color: #00a79d;">filter_alt</mat-icon>
</button>
@ -75,12 +75,14 @@
<div
*ngIf="!this.showNoResultsError" id="showSpin" data-bind="visible: spin"
style=" position: absolute; top: auto; left: 45%;">
*ngIf="!this.showNoResultsError && !this.errorService.critical && !this.errorService.rsso" id="showSpin" data-bind="visible: spin"
style=" position: absolute; top: auto; left: 30%;">
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b1/Loading_icon.gif" rel="stylesheet"/>
</div>
<!-- <button ejs-button id='filterRecord' (click)='filter()'>Filter</button> -->
<ejs-gantt *ngIf="renderGantt" #ganttObject id="ganttDefault"
[ngStyle]="{'visibility':spin ? 'hidden' : 'visible'}"
@ -206,7 +208,7 @@
</ng-template>
</ejs-gantt>
<app-plan-time-bar #plantimeComponent *ngIf="renderplanTime"
<app-plan-time-bar #plantimeComponent *ngIf="!errorService.rsso && renderplanTime && renderGantt"
[inputData]="inputForTimeline"
[splitterSettings]="splitterSettings"
[parentResources]="allResources"
@ -218,7 +220,7 @@
<div *ngIf="this.showNoResultsError && this.languageService.language =='EN'"><h2>The search did not return any results</h2></div>
<!-- [filterSettings]="filterSettings" -->
<mat-paginator #paginator
<mat-paginator *ngIf="renderGantt" #paginator
[ngStyle]="{'visibility':spin ? 'hidden' : 'visible'}"
class="demo-paginator"
(page)="handlePageEvent($event)"
@ -232,6 +234,26 @@
aria-label="Seite auswählen">
</mat-paginator>
<mat-card style="width: 50%; margin: auto;" *ngIf="errorService.rsso">
<mat-card-header>
<mat-card-title><mat-icon style="color: red;">error</mat-icon> {{errorService.getLastError('rsso').name}}</mat-card-title>
<mat-card-subtitle>{{errorService.getLastError('rsso').userInfo}}</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<p style="padding-left: 15px;">{{errorService.getLastError('rsso').message}}</p>
</mat-card-content>
</mat-card>
<mat-card style="width: 50%; margin: auto;" *ngIf="!errorService.rsso && errorService.critical">
<mat-card-header>
<mat-card-title><mat-icon style="color: red;">error</mat-icon> {{errorService.getLastError('critical').name}}</mat-card-title>
<mat-card-subtitle>{{errorService.getLastError('critical').userInfo}}</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<p style="padding-left: 15px;">{{errorService.getLastError('critical').message}}</p>
</mat-card-content>

View File

@ -1,3 +1,4 @@
import { ErrorService } from './../error.service';
import { remoteData } from './../../data';
import { LanguageService } from '../language.service';
import { PlanTimeBarComponent } from '../plan-time-bar/plan-time-bar.component';
@ -167,6 +168,8 @@ export class NttGanttComponent implements OnInit {
public userId : string = null;
public rssoInit: boolean = true;
public showInitPresetsError: boolean = false;
/**###################################################################### Initial Loading functions ######################################################################*/
@ -176,7 +179,7 @@ export class NttGanttComponent implements OnInit {
* @param dataService injects the dataService for data management and backend communication
* @param matDialog injects the matDialog
*/
constructor(public languageService: LanguageService, public dataService: DataService, public matDialog : MatDialog, private _snackBar: MatSnackBar ) {
constructor(public languageService: LanguageService, public dataService: DataService, public matDialog : MatDialog, private _snackBar: MatSnackBar, public errorService: ErrorService ) {
this.initLanguge(true);
}
@ -196,6 +199,9 @@ export class NttGanttComponent implements OnInit {
console.log(res);
this.rssoInit = false;
this.userId = res.userId;
if(res.userId == null){
this.errorService.handleCostumError("RSSO Fehler", "Melden Sie sich erneut an", "USER ID = NULL", "rsso");
}
});
@ -381,6 +387,9 @@ export class NttGanttComponent implements OnInit {
this.showSaveButton = false;
this.showSaveUnderButton = false;
this.dataService.initPresets().then((res: any)=>{
if(res.status){
this.showInitPresetsError = true;
}
this.presets = res.presets;
this.selectedPreset = res.selectedPreset;
if(this.selectedPreset.presetType == 'User' ){