From ce65ca36432bb4159ca2864265811f4af0339088 Mon Sep 17 00:00:00 2001 From: George Nash Date: Thu, 4 Jan 2024 14:58:31 +0000 Subject: [PATCH 01/10] basic infrastructure --- .../shared/error/error-alert.component.html | 1 + .../shared/error/error-alert.component.scss | 0 .../error/error-alert.component.spec.ts | 21 +++++++++++++++++++ .../app/shared/error/error-alert.component.ts | 16 ++++++++++++++ ui/src/app/shared/shared.module.ts | 5 +++-- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 ui/src/app/shared/error/error-alert.component.html create mode 100644 ui/src/app/shared/error/error-alert.component.scss create mode 100644 ui/src/app/shared/error/error-alert.component.spec.ts create mode 100644 ui/src/app/shared/error/error-alert.component.ts diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html new file mode 100644 index 000000000..1ece46aa9 --- /dev/null +++ b/ui/src/app/shared/error/error-alert.component.html @@ -0,0 +1 @@ +

error-alert works!

diff --git a/ui/src/app/shared/error/error-alert.component.scss b/ui/src/app/shared/error/error-alert.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/ui/src/app/shared/error/error-alert.component.spec.ts b/ui/src/app/shared/error/error-alert.component.spec.ts new file mode 100644 index 000000000..73234dc4f --- /dev/null +++ b/ui/src/app/shared/error/error-alert.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ErrorAlertComponent } from './error-alert.component'; + +describe('ErrorAlertComponent', () => { + let component: ErrorAlertComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ErrorAlertComponent] + }); + fixture = TestBed.createComponent(ErrorAlertComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ui/src/app/shared/error/error-alert.component.ts b/ui/src/app/shared/error/error-alert.component.ts new file mode 100644 index 000000000..e924a2f40 --- /dev/null +++ b/ui/src/app/shared/error/error-alert.component.ts @@ -0,0 +1,16 @@ +import { Component } from '@angular/core' + +@Component({ + selector: 'app-error-alert', + templateUrl: './error-alert.component.html', + styleUrls: ['./error-alert.component.scss'], +}) +export class ErrorAlertComponent { + constructor() { + // subscribe to error handler + // find 400 errors + // look for translation key - if present somehow translate the fucker + // set error fields in component for template to read + // make it show + } +} diff --git a/ui/src/app/shared/shared.module.ts b/ui/src/app/shared/shared.module.ts index 7eb237e81..89149611d 100644 --- a/ui/src/app/shared/shared.module.ts +++ b/ui/src/app/shared/shared.module.ts @@ -1,8 +1,9 @@ import { NgModule } from '@angular/core' -import { FindLanguageFromKeyPipe } from './pipe/find-language-from-key' +import { FindLanguageFromKeyPipe } from './pipe/find-language-from-key'; +import { ErrorAlertComponent } from './error/error-alert.component' @NgModule({ - declarations: [FindLanguageFromKeyPipe], + declarations: [FindLanguageFromKeyPipe, ErrorAlertComponent], exports: [FindLanguageFromKeyPipe], }) export class SharedModule { From 0fd2408af7e85a582cf847beca598ad94aa03428 Mon Sep 17 00:00:00 2001 From: George Nash Date: Thu, 4 Jan 2024 15:20:44 +0000 Subject: [PATCH 02/10] alert template --- ui/src/app/shared/error/error-alert.component.html | 8 +++++++- ui/src/app/shared/error/error-alert.component.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html index 1ece46aa9..74b3081e1 100644 --- a/ui/src/app/shared/error/error-alert.component.html +++ b/ui/src/app/shared/error/error-alert.component.html @@ -1 +1,7 @@ -

error-alert works!

+ \ No newline at end of file diff --git a/ui/src/app/shared/error/error-alert.component.ts b/ui/src/app/shared/error/error-alert.component.ts index e924a2f40..1e5ef2e03 100644 --- a/ui/src/app/shared/error/error-alert.component.ts +++ b/ui/src/app/shared/error/error-alert.component.ts @@ -12,5 +12,16 @@ export class ErrorAlertComponent { // look for translation key - if present somehow translate the fucker // set error fields in component for template to read // make it show + + // build list of alerts called alerts + const newAlert = { + type: 'danger', + msg: message, + params: data, + toast: this.alertService.isToast(), + scoped: true, + } + + this.alerts.push(this.alertService.addAlert(newAlert, this.alerts)) } } From d8873dbcb6ea0978549672bb0b9e442a0d5b9a12 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:47:06 +0200 Subject: [PATCH 03/10] add error handler and error alert component --- ui/src/app/app.module.ts | 7 ++- .../shared/error/error-alert.component.html | 21 ++++++--- .../app/shared/error/error-alert.component.ts | 44 ++++++++++++++++--- ui/src/app/shared/service/error.service.ts | 19 ++++++++ ui/src/app/shared/shared.module.ts | 7 ++- 5 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 ui/src/app/shared/service/error.service.ts diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts index 565cfec67..6626d517b 100644 --- a/ui/src/app/app.module.ts +++ b/ui/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core' +import { ErrorHandler, NgModule } from '@angular/core' import { BrowserModule } from '@angular/platform-browser' import { AppRoutingModule } from './app-routing.module' @@ -15,6 +15,7 @@ import { HomeModule } from './home/home.module' import { FooterComponent } from './layout/footer/footer.component' import { SharedModule } from './shared/shared.module' import { HeaderInterceptor } from './shared/interceptor/header.interceptor' +import { ErrorService } from './shared/service/error.service' @NgModule({ declarations: [AppComponent, NavbarComponent, HasAnyAuthorityDirective, FooterComponent], @@ -36,6 +37,10 @@ import { HeaderInterceptor } from './shared/interceptor/header.interceptor' useClass: HeaderInterceptor, multi: true, }, + { + provide: ErrorHandler, + useClass: ErrorService, + }, ], bootstrap: [AppComponent], }) diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html index 74b3081e1..58aa2a050 100644 --- a/ui/src/app/shared/error/error-alert.component.html +++ b/ui/src/app/shared/error/error-alert.component.html @@ -1,7 +1,16 @@ \ No newline at end of file +
+ +
{{ alert.msg }}
+ + + + + +
+
+ diff --git a/ui/src/app/shared/error/error-alert.component.ts b/ui/src/app/shared/error/error-alert.component.ts index 1e5ef2e03..8a76462c1 100644 --- a/ui/src/app/shared/error/error-alert.component.ts +++ b/ui/src/app/shared/error/error-alert.component.ts @@ -1,20 +1,24 @@ -import { Component } from '@angular/core' +import { ChangeDetectorRef, Component, ErrorHandler, Inject, OnInit } from '@angular/core' +import { ErrorService } from '../service/error.service' @Component({ selector: 'app-error-alert', templateUrl: './error-alert.component.html', styleUrls: ['./error-alert.component.scss'], }) -export class ErrorAlertComponent { - constructor() { +export class ErrorAlertComponent implements OnInit { + alerts: any = [] + constructor( + @Inject(ErrorHandler) private errorService: ErrorService, + private cdr: ChangeDetectorRef + ) { // subscribe to error handler // find 400 errors // look for translation key - if present somehow translate the fucker // set error fields in component for template to read // make it show - // build list of alerts called alerts - const newAlert = { + /* const newAlert = { type: 'danger', msg: message, params: data, @@ -22,6 +26,34 @@ export class ErrorAlertComponent { scoped: true, } - this.alerts.push(this.alertService.addAlert(newAlert, this.alerts)) + */ + } + + ngOnInit(): void { + this.errorService.on().subscribe((err) => { + const alerts = [...this.alerts] + alerts.push({ + type: 'danger', + msg: err.message, + params: err.params, + toast: false, + dismiss: true, + }) + this.alerts = alerts + this.cdr.detectChanges() + }) + } + + setClasses(alert: any) { + return { + 'jhi-toast': alert.toast, + [alert.position]: true, + } + } + + close(alertToRemove: any) { + this.alerts = this.alerts.filter((alert: any) => alert !== alertToRemove) + this.cdr.detectChanges() + console.log(this.alerts) } } diff --git a/ui/src/app/shared/service/error.service.ts b/ui/src/app/shared/service/error.service.ts new file mode 100644 index 000000000..4d5731329 --- /dev/null +++ b/ui/src/app/shared/service/error.service.ts @@ -0,0 +1,19 @@ +import { ErrorHandler, Injectable } from '@angular/core' +import { Observable, Subject } from 'rxjs' + +// To inject this service, you have to include '@Inject(ErrorHandler)' to be able to subscribe to observables, e.g.: +// @Inject(ErrorHandler) private errorService: ErrorService + +@Injectable({ providedIn: 'root' }) +export class ErrorService implements ErrorHandler { + private errors: Subject = new Subject() + + handleError(error: any): void { + console.error('Unknown error:', error) + this.errors.next(error) + } + + on(): Observable { + return this.errors.asObservable() + } +} diff --git a/ui/src/app/shared/shared.module.ts b/ui/src/app/shared/shared.module.ts index 89149611d..d58e8ae35 100644 --- a/ui/src/app/shared/shared.module.ts +++ b/ui/src/app/shared/shared.module.ts @@ -1,10 +1,13 @@ import { NgModule } from '@angular/core' -import { FindLanguageFromKeyPipe } from './pipe/find-language-from-key'; +import { FindLanguageFromKeyPipe } from './pipe/find-language-from-key' import { ErrorAlertComponent } from './error/error-alert.component' +import { CommonModule } from '@angular/common' +import { NgbModule } from '@ng-bootstrap/ng-bootstrap' @NgModule({ + imports: [CommonModule, NgbModule], declarations: [FindLanguageFromKeyPipe, ErrorAlertComponent], - exports: [FindLanguageFromKeyPipe], + exports: [FindLanguageFromKeyPipe, ErrorAlertComponent], }) export class SharedModule { static forRoot() { From eb761cdc7d031a66ed6829c1615632ec412b2405 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:47:42 +0200 Subject: [PATCH 04/10] Revert "added line accidentally removed" This reverts commit a8e9ced4aa2eab2fe4f0219bb04d280b6087c50f. --- gateway/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/package.json b/gateway/package.json index 4e0828f16..22555e519 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -134,7 +134,7 @@ "webpack:dev": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9060 --watch-content-base --env.stats=minimal", "webpack:dev-verbose": "npm run webpack-dev-server -- --config webpack/webpack.dev.js --inline --hot --port=9060 --watch-content-base --profile --progress --env.stats=normal", "webpack:build:main": "npm run webpack -- --config webpack/webpack.dev.js --env.stats=minimal", - "webpack:build": "./node/node_modules/npm/bin/npm run cleanup && ./node/node_modules/npm/bin/npm run webpack:build:main", + "webpack:build": "npm run cleanup && npm run webpack:build:main", "webpack:local:main": "npm run webpack -- --config webpack/webpack.local.js --profile", "webpack:local": "npm run cleanup && npm run webpack:local:main && npm run clean-www", "webpack:qa:main": "npm run webpack -- --config webpack/webpack.qa.js --profile", From c7e6c3d132c076c9254ee4cee788435bb1bde9c8 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:26:41 +0200 Subject: [PATCH 05/10] add header --- .../shared/error/error-alert.component.html | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html index 58aa2a050..0d27df376 100644 --- a/ui/src/app/shared/error/error-alert.component.html +++ b/ui/src/app/shared/error/error-alert.component.html @@ -1,16 +1,19 @@ From 78ee1c2c41e601f9e0c1ca445b131895d5abced7 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:29:35 +0200 Subject: [PATCH 06/10] remove unused model params --- ui/src/app/shared/model/error-alert.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui/src/app/shared/model/error-alert.ts b/ui/src/app/shared/model/error-alert.ts index 3ba2f8906..396582898 100644 --- a/ui/src/app/shared/model/error-alert.ts +++ b/ui/src/app/shared/model/error-alert.ts @@ -4,8 +4,6 @@ export class ErrorAlert { constructor( public type: 'danger', public msg: string, - public params: string, - public toast: boolean, - public scoped: boolean + public toast: boolean ) {} } From 77b6c1b6a6e2fb5b4ee19a0082849c46b97c8880 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:52:18 +0200 Subject: [PATCH 07/10] add tabindex --- ui/src/app/shared/error/error-alert.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html index 0d27df376..fc4390be7 100644 --- a/ui/src/app/shared/error/error-alert.component.html +++ b/ui/src/app/shared/error/error-alert.component.html @@ -3,7 +3,7 @@

Sorry, an error has occurred

- + Date: Tue, 9 Jan 2024 18:52:43 +0200 Subject: [PATCH 08/10] add keydown event, remove logging ,fix bug --- ui/src/app/shared/error/error-alert.component.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/src/app/shared/error/error-alert.component.ts b/ui/src/app/shared/error/error-alert.component.ts index 322d284d0..b3abf4316 100644 --- a/ui/src/app/shared/error/error-alert.component.ts +++ b/ui/src/app/shared/error/error-alert.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectorRef, Component, ErrorHandler, Inject, OnInit } from '@angular/core' +import { ChangeDetectorRef, Component, ErrorHandler, HostListener, Inject, OnInit } from '@angular/core' import { ErrorService } from '../service/error.service' import { Subscription } from 'rxjs' import { ErrorAlert } from '../model/error-alert' @@ -27,7 +27,6 @@ export class ErrorAlertComponent implements OnInit { toast: false, } this.alerts.push(alert) - this.alerts.push(alerts) this.cdr.detectChanges() }) } @@ -36,9 +35,14 @@ export class ErrorAlertComponent implements OnInit { this.sub?.unsubscribe() } + @HostListener('document:keydown.escape', ['$event']) + closeOldestAlert() { + this.alerts.shift() + this.cdr.detectChanges() + } + close(alertToRemove: any) { this.alerts = this.alerts.filter((alert: any) => alert !== alertToRemove) this.cdr.detectChanges() - console.log(this.alerts) } } From 29810cfa7f674c119977d0f876dc6e0f90c581b5 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:33:38 +0200 Subject: [PATCH 09/10] fix keyup event --- ui/src/app/shared/error/error-alert.component.html | 2 +- ui/src/app/shared/error/error-alert.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/app/shared/error/error-alert.component.html b/ui/src/app/shared/error/error-alert.component.html index fc4390be7..ae40901aa 100644 --- a/ui/src/app/shared/error/error-alert.component.html +++ b/ui/src/app/shared/error/error-alert.component.html @@ -3,7 +3,7 @@

Sorry, an error has occurred

-
+ Date: Tue, 9 Jan 2024 19:51:53 +0200 Subject: [PATCH 10/10] fix unit test --- .../error/error-alert.component.spec.ts | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ui/src/app/shared/error/error-alert.component.spec.ts b/ui/src/app/shared/error/error-alert.component.spec.ts index 73234dc4f..42c71e68d 100644 --- a/ui/src/app/shared/error/error-alert.component.spec.ts +++ b/ui/src/app/shared/error/error-alert.component.spec.ts @@ -1,21 +1,24 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ErrorAlertComponent } from './error-alert.component'; +import { ErrorAlertComponent } from './error-alert.component' +import { ErrorService } from '../service/error.service' +import { AppModule } from 'src/app/app.module' describe('ErrorAlertComponent', () => { - let component: ErrorAlertComponent; - let fixture: ComponentFixture; + let component: ErrorAlertComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ErrorAlertComponent] - }); - fixture = TestBed.createComponent(ErrorAlertComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [AppModule], + declarations: [ErrorAlertComponent], + }) + fixture = TestBed.createComponent(ErrorAlertComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +})