Skip to content

Commit d7fe620

Browse files
author
Matthias Griebl
committed
Extract the error snackbar into its onw component
It now disappears properly and can be reused for other components.
1 parent e6d0fc0 commit d7fe620

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

ids-webconsole/src/main/angular/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { UserCardComponent } from './users/user-card.component';
5555
import { NewIdentityESTComponent } from './keycerts/identitynewest.component';
5656
import { ESTService } from './keycerts/est-service';
5757
import { RenewIdentityESTComponent } from './keycerts/identityrenewest.component';
58+
import { SnackbarComponent } from './keycerts/snackbar.component';
5859

5960
@NgModule({ declarations: [
6061
AppComponent,
@@ -90,7 +91,8 @@ import { RenewIdentityESTComponent } from './keycerts/identityrenewest.component
9091
UserCardComponent,
9192
UsersComponent,
9293
NewIdentityESTComponent,
93-
RenewIdentityESTComponent
94+
RenewIdentityESTComponent,
95+
SnackbarComponent
9496
],
9597
bootstrap: [
9698
AppComponent

ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,4 @@ <h5>EST Re-Enrollment</h5>
2727
</div>
2828
</div>
2929
</div>
30-
<div id="est-error-snackbar" [ngClass]="{'mdl-snackbar': true, 'mdl-snackbar--active': error}">
31-
<div class="mdl-snackbar__text" style="display: flex; flex-direction: column;">
32-
<span>{{ error }}</span>
33-
<span class="mdl-color-text--grey-300" style="font-size: smaller;">
34-
Check the trusted connector log for more details
35-
</span>
36-
</div>
37-
<button class="mdl-snackbar__action" type="button" (click)="error = null">Dismiss</button>
38-
</div>
30+
<snackbar #errorSnackbar subtitle="Check the trusted connector log for more details"/>

ids-webconsole/src/main/angular/src/app/keycerts/identityrenewest.component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ViewChild } from '@angular/core';
22
import { Title } from '@angular/platform-browser';
33
import { ESTService } from './est-service';
44
import { ActivatedRoute, Router } from '@angular/router';
55
import { HttpErrorResponse } from '@angular/common/http';
6+
import { SnackbarComponent } from './snackbar.component';
67

78
@Component({
89
templateUrl: './identityrenewest.component.html'
910
})
1011
export class RenewIdentityESTComponent {
1112
estUrl = 'https://daps-dev.aisec.fraunhofer.de';
1213
rootCertHash = '7d3f260abb4b0bfa339c159398c0ab480a251faa385639218198adcad9a3c17d';
13-
error = null;
14+
15+
@ViewChild("errorSnackbar")
16+
errorSnackbar: SnackbarComponent;
1417

1518
constructor(private readonly titleService: Title,
1619
private readonly estService: ESTService,
@@ -21,16 +24,17 @@ export class RenewIdentityESTComponent {
2124

2225
handleError(err: HttpErrorResponse) {
2326
if (err.status === 0) {
24-
this.error = 'Network Error';
27+
this.errorSnackbar.title = 'Network Error';
2528
} else {
2629
const errObj = JSON.parse(err.error);
2730
if (errObj.message) {
28-
this.error = errObj.message;
31+
this.errorSnackbar.title = errObj.message;
2932
} else {
3033
// Errors have no message if it is disabled by the spring application
31-
this.error = `Error response from connector: ${err.status}: ${errObj.error}`;
34+
this.errorSnackbar.title = `Error response from connector: ${err.status}: ${errObj.error}`;
3235
}
3336
}
37+
this.errorSnackbar.visible = true;
3438
}
3539

3640
onSubmit() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.snackbar {
2+
-webkit-transform: translate(-50%, 100px);
3+
transform: translate(-50%, 100px);
4+
}
5+
6+
.snackbar-content {
7+
display: flex;
8+
flex-direction: column;
9+
}
10+
11+
.snackbar-subtitle {
12+
font-size: smaller;
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div id="est-error-snackbar" class="mdl-snackbar" [ngClass]="{'snackbar': !visible, 'mdl-snackbar--active': visible}">
2+
<div class="mdl-snackbar__text snackbar-content">
3+
<span>{{ title }}</span>
4+
<span *ngIf="subtitle !== null" class="mdl-color-text--grey-300 snackbar-subtitle">
5+
{{ subtitle }}
6+
</span>
7+
</div>
8+
<button class="mdl-snackbar__action" type="button" (click)="invokeOnDismiss()">Dismiss</button>
9+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, Input } from '@angular/core';
2+
3+
@Component({
4+
selector: 'snackbar',
5+
templateUrl: './snackbar.component.html',
6+
styleUrl: './snackbar.component.css'
7+
})
8+
export class SnackbarComponent {
9+
@Input() title: string = null;
10+
@Input() subtitle: string = null;
11+
@Input() visible: boolean = false;
12+
@Input() onDismiss: ()=>void = null;
13+
14+
invokeOnDismiss() {
15+
if (this.onDismiss !== null) {
16+
this.onDismiss()
17+
} else {
18+
this.visible = false;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)