From d7fe6203ed9e9a6c0ee9c2df7b4b96ef67a54150 Mon Sep 17 00:00:00 2001 From: Matthias Griebl Date: Fri, 14 Jun 2024 15:42:12 +0200 Subject: [PATCH] Extract the error snackbar into its onw component It now disappears properly and can be reused for other components. --- .../src/main/angular/src/app/app.module.ts | 4 +++- .../keycerts/identityrenewest.component.html | 10 +-------- .../keycerts/identityrenewest.component.ts | 14 ++++++++----- .../src/app/keycerts/snackbar.component.css | 13 ++++++++++++ .../src/app/keycerts/snackbar.component.html | 9 ++++++++ .../src/app/keycerts/snackbar.component.ts | 21 +++++++++++++++++++ 6 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.css create mode 100644 ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.html create mode 100644 ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.ts diff --git a/ids-webconsole/src/main/angular/src/app/app.module.ts b/ids-webconsole/src/main/angular/src/app/app.module.ts index 48662099..1153869d 100644 --- a/ids-webconsole/src/main/angular/src/app/app.module.ts +++ b/ids-webconsole/src/main/angular/src/app/app.module.ts @@ -55,6 +55,7 @@ import { UserCardComponent } from './users/user-card.component'; import { NewIdentityESTComponent } from './keycerts/identitynewest.component'; import { ESTService } from './keycerts/est-service'; import { RenewIdentityESTComponent } from './keycerts/identityrenewest.component'; +import { SnackbarComponent } from './keycerts/snackbar.component'; @NgModule({ declarations: [ AppComponent, @@ -90,7 +91,8 @@ import { RenewIdentityESTComponent } from './keycerts/identityrenewest.component UserCardComponent, UsersComponent, NewIdentityESTComponent, - RenewIdentityESTComponent + RenewIdentityESTComponent, + SnackbarComponent ], bootstrap: [ AppComponent diff --git a/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.html b/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.html index 2fc0eed1..9014bb8d 100644 --- a/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.html +++ b/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.html @@ -27,12 +27,4 @@
EST Re-Enrollment
-
-
- {{ error }} - - Check the trusted connector log for more details - -
- -
\ No newline at end of file + diff --git a/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.ts b/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.ts index 94e86cb4..36f9d33a 100644 --- a/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.ts +++ b/ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.ts @@ -1,8 +1,9 @@ -import { Component } from '@angular/core'; +import { Component, ViewChild } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { ESTService } from './est-service'; import { ActivatedRoute, Router } from '@angular/router'; import { HttpErrorResponse } from '@angular/common/http'; +import { SnackbarComponent } from './snackbar.component'; @Component({ templateUrl: './identityrenewest.component.html' @@ -10,7 +11,9 @@ import { HttpErrorResponse } from '@angular/common/http'; export class RenewIdentityESTComponent { estUrl = 'https://daps-dev.aisec.fraunhofer.de'; rootCertHash = '7d3f260abb4b0bfa339c159398c0ab480a251faa385639218198adcad9a3c17d'; - error = null; + + @ViewChild("errorSnackbar") + errorSnackbar: SnackbarComponent; constructor(private readonly titleService: Title, private readonly estService: ESTService, @@ -21,16 +24,17 @@ export class RenewIdentityESTComponent { handleError(err: HttpErrorResponse) { if (err.status === 0) { - this.error = 'Network Error'; + this.errorSnackbar.title = 'Network Error'; } else { const errObj = JSON.parse(err.error); if (errObj.message) { - this.error = errObj.message; + this.errorSnackbar.title = errObj.message; } else { // Errors have no message if it is disabled by the spring application - this.error = `Error response from connector: ${err.status}: ${errObj.error}`; + this.errorSnackbar.title = `Error response from connector: ${err.status}: ${errObj.error}`; } } + this.errorSnackbar.visible = true; } onSubmit() { diff --git a/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.css b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.css new file mode 100644 index 00000000..eecfe1b5 --- /dev/null +++ b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.css @@ -0,0 +1,13 @@ +.snackbar { + -webkit-transform: translate(-50%, 100px); + transform: translate(-50%, 100px); +} + +.snackbar-content { + display: flex; + flex-direction: column; +} + +.snackbar-subtitle { + font-size: smaller; +} diff --git a/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.html b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.html new file mode 100644 index 00000000..4c12ca43 --- /dev/null +++ b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.html @@ -0,0 +1,9 @@ +
+
+ {{ title }} + + {{ subtitle }} + +
+ +
diff --git a/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.ts b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.ts new file mode 100644 index 00000000..595724fa --- /dev/null +++ b/ids-webconsole/src/main/angular/src/app/keycerts/snackbar.component.ts @@ -0,0 +1,21 @@ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'snackbar', + templateUrl: './snackbar.component.html', + styleUrl: './snackbar.component.css' +}) +export class SnackbarComponent { + @Input() title: string = null; + @Input() subtitle: string = null; + @Input() visible: boolean = false; + @Input() onDismiss: ()=>void = null; + + invokeOnDismiss() { + if (this.onDismiss !== null) { + this.onDismiss() + } else { + this.visible = false; + } + } +} \ No newline at end of file