From 3710101d247839eb20e4ff4a491a7605741c6a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szrnka?= Date: Wed, 11 Dec 2024 11:59:28 +0100 Subject: [PATCH] GMS-179 New reusable Angular component has been created to simplify message displays --- .../components/gms-components-module.ts | 5 ++- .../info-dialog/info-dialog.component.scss | 3 -- .../info-dialog/info-dialog.component.ts | 1 - .../information-message.component.html | 4 ++ .../information-message.component.scss | 13 +++++++ .../information-message.component.spec.ts | 37 +++++++++++++++++++ .../information-message.component.ts | 30 +++++++++++++++ .../secret/secret-detail.component.html | 32 +++++----------- .../secret/secret-detail.component.scss | 10 +++++ .../app/components/secret/secret-module.ts | 4 +- code/gms-frontend/src/styles.scss | 6 ++- 11 files changed, 115 insertions(+), 30 deletions(-) delete mode 100644 code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.scss create mode 100644 code/gms-frontend/src/app/common/components/information-message/information-message.component.html create mode 100644 code/gms-frontend/src/app/common/components/information-message/information-message.component.scss create mode 100644 code/gms-frontend/src/app/common/components/information-message/information-message.component.spec.ts create mode 100644 code/gms-frontend/src/app/common/components/information-message/information-message.component.ts diff --git a/code/gms-frontend/src/app/common/components/gms-components-module.ts b/code/gms-frontend/src/app/common/components/gms-components-module.ts index b16f471b..f17b6971 100644 --- a/code/gms-frontend/src/app/common/components/gms-components-module.ts +++ b/code/gms-frontend/src/app/common/components/gms-components-module.ts @@ -9,16 +9,17 @@ import { InfoDialog } from "./info-dialog/info-dialog.component"; import { MomentPipe } from "./pipes/date-formatter.pipe"; import { NavButtonVisibilityPipe } from "./pipes/nav-button-visibility.pipe"; import { TranslatorModule } from "./pipes/translator/translator.module"; +import { InformationMessageComponent } from "./information-message/information-message.component"; /** * @author Peter Szrnka */ @NgModule({ declarations: [ - ConfirmDeleteDialog, InfoDialog + ConfirmDeleteDialog, InfoDialog, InformationMessageComponent ], exports: [ - ConfirmDeleteDialog, InfoDialog + ConfirmDeleteDialog, InfoDialog, InformationMessageComponent ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], imports: [ diff --git a/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.scss b/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.scss deleted file mode 100644 index 2d2c6f14..00000000 --- a/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.scss +++ /dev/null @@ -1,3 +0,0 @@ -.v-bottom { - vertical-align: bottom; -} \ No newline at end of file diff --git a/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.ts b/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.ts index 156f70f7..d0beadbe 100644 --- a/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.ts +++ b/code/gms-frontend/src/app/common/components/info-dialog/info-dialog.component.ts @@ -7,7 +7,6 @@ import { DialogData } from "./dialog-data.model"; */ @Component({ selector: 'info-dialog', - styleUrls: ['./info-dialog.component.scss'], templateUrl: './info-dialog.component.html' }) export class InfoDialog { diff --git a/code/gms-frontend/src/app/common/components/information-message/information-message.component.html b/code/gms-frontend/src/app/common/components/information-message/information-message.component.html new file mode 100644 index 00000000..7f8b9d11 --- /dev/null +++ b/code/gms-frontend/src/app/common/components/information-message/information-message.component.html @@ -0,0 +1,4 @@ +
+ {{icon}} + +
\ No newline at end of file diff --git a/code/gms-frontend/src/app/common/components/information-message/information-message.component.scss b/code/gms-frontend/src/app/common/components/information-message/information-message.component.scss new file mode 100644 index 00000000..34df6e9d --- /dev/null +++ b/code/gms-frontend/src/app/common/components/information-message/information-message.component.scss @@ -0,0 +1,13 @@ +@import '../../../../globals.scss'; + +.green { + color: $success_dark; +} + +.orange { + color: $warning; +} + +.blue { + color: $information; +} \ No newline at end of file diff --git a/code/gms-frontend/src/app/common/components/information-message/information-message.component.spec.ts b/code/gms-frontend/src/app/common/components/information-message/information-message.component.spec.ts new file mode 100644 index 00000000..815d3d11 --- /dev/null +++ b/code/gms-frontend/src/app/common/components/information-message/information-message.component.spec.ts @@ -0,0 +1,37 @@ +import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from "@angular/core"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { MatDialogModule } from "@angular/material/dialog"; +import { TranslatorModule } from "../pipes/translator/translator.module"; +import { InformationMessageComponent } from "./information-message.component"; + +/** + * @author Peter Szrnka + */ +describe('InformationMessageComponent', () => { + let component : InformationMessageComponent; + + // Fixtures + let fixture : ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports : [MatDialogModule, TranslatorModule ], + declarations : [InformationMessageComponent], + schemas : [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], + providers: [ + ] + }); + }); + + it('onInit when component loaded then set parameters properly', () => { + fixture = TestBed.createComponent(InformationMessageComponent); + component = fixture.componentInstance; + component.severity = 'information'; + fixture.detectChanges(); + + expect(component).toBeTruthy(); + expect(component.severity).toBe('information'); + expect(component.icon).toBe('information'); + expect(component.iconColor).toBe('blue'); + }); +}); \ No newline at end of file diff --git a/code/gms-frontend/src/app/common/components/information-message/information-message.component.ts b/code/gms-frontend/src/app/common/components/information-message/information-message.component.ts new file mode 100644 index 00000000..5a301d72 --- /dev/null +++ b/code/gms-frontend/src/app/common/components/information-message/information-message.component.ts @@ -0,0 +1,30 @@ +import { Component, Input, OnInit } from "@angular/core"; + +const SETTINGS_MAP: any = { + 'success': { icon: 'check_circle', iconColor: 'green', styleClass: 'success' }, + 'information': { icon: 'information', iconColor: 'blue', styleClass: 'information' }, + 'warning': { icon: 'warning', iconColor: 'orange', styleClass: 'warning' } +}; + +/** + * @author Peter Szrnka + */ +@Component({ + + selector: 'information-message', + templateUrl: './information-message.component.html', + styleUrls: ['./information-message.component.scss'] +}) +export class InformationMessageComponent implements OnInit { + + @Input() severity: 'success' | 'information' | 'warning' = 'warning'; + icon: string = ''; + iconColor: string = ''; + styleClass: string = ''; + + ngOnInit(): void { + this.icon = SETTINGS_MAP[this.severity].icon; + this.iconColor = SETTINGS_MAP[this.severity].iconColor; + this.styleClass = SETTINGS_MAP[this.severity].styleClass; + } +} \ No newline at end of file diff --git a/code/gms-frontend/src/app/components/secret/secret-detail.component.html b/code/gms-frontend/src/app/components/secret/secret-detail.component.html index 31352866..bb2474da 100644 --- a/code/gms-frontend/src/app/components/secret/secret-detail.component.html +++ b/code/gms-frontend/src/app/components/secret/secret-detail.component.html @@ -3,7 +3,7 @@ @if (error) { -
{{ 'messages.error' | translate }}: {{error}}
+ {{ 'messages.error' | translate }}: {{error}} } @if (!error) {
@@ -20,9 +20,7 @@ @if (data.value === undefined) { -
- {{ 'secrets.info' | translate }} -
+ {{ 'secrets.info' | translate }} } {{ 'secrets.keystoreId' | translate }} @@ -66,22 +64,16 @@ } @if (validationState === 'IN_PROGRESS') { -
+ {{ 'secrets.validation.inProgress' | translate }} -
+ } @else if (validationState === 'VALID') { -
- {{ 'secrets.validation.success' | translate }} -
+ {{ 'secrets.validation.success' | translate }} } @else if (validationState === 'INVALID') { -
- {{ 'secrets.validation.invalid' | translate }} -
+ {{ 'secrets.validation.invalid' | translate }} } @else if (validationState === 'INVALID_INPUT') { -
- {{ 'secrets.validation.invalidInput' | translate }} -
+ {{ 'secrets.validation.invalidInput' | translate }} } @if (data.value !== undefined && data.type === 'SIMPLE_CREDENTIAL') { @@ -93,9 +85,7 @@ -
- {{ 'secrets.capacityWarning' | translate }} -
+ {{ 'secrets.capacityWarning' | translate }} @@ -158,9 +148,7 @@ @if (formData.allApiKeysAllowed === true) { -
- {{ 'secrets.label.allApiKeys' | translate }} -
+ {{ 'secrets.label.allApiKeys' | translate }} } @if (formData.allApiKeysAllowed !== true) { @@ -222,7 +210,7 @@
@if (ipRestrictions.length === 0) { -
{{ 'secrets.allIpAddresses' | translate }}
+ {{ 'secrets.allIpAddresses' | translate }} } @if (data.id !== undefined) { diff --git a/code/gms-frontend/src/app/components/secret/secret-detail.component.scss b/code/gms-frontend/src/app/components/secret/secret-detail.component.scss index 90f6f639..12da83d0 100644 --- a/code/gms-frontend/src/app/components/secret/secret-detail.component.scss +++ b/code/gms-frontend/src/app/components/secret/secret-detail.component.scss @@ -1,3 +1,5 @@ +@import '../../../globals.scss'; + .margin-right { margin-right: 5px; } @@ -13,4 +15,12 @@ .all-allowed { padding: 10px 0 10px 10px; margin-bottom:10px; +} + +.green { + color: $success_dark; +} + +.orange { + color: $warning; } \ No newline at end of file diff --git a/code/gms-frontend/src/app/components/secret/secret-module.ts b/code/gms-frontend/src/app/components/secret/secret-module.ts index c3a5285b..b0dec30b 100644 --- a/code/gms-frontend/src/app/components/secret/secret-module.ts +++ b/code/gms-frontend/src/app/components/secret/secret-module.ts @@ -15,6 +15,7 @@ import { SecretService } from "./service/secret-service"; import { NavBackComponent } from "../../common/components/nav-back/nav-back.component"; import { StatusToggleComponent } from "../../common/components/status-toggle/status-toggle.component"; import { TranslatorModule } from "../../common/components/pipes/translator/translator.module"; +import { GmsComponentsModule } from "../../common/components/gms-components-module"; /** * @author Peter Szrnka @@ -33,7 +34,8 @@ import { TranslatorModule } from "../../common/components/pipes/translator/trans MomentPipe, NavButtonVisibilityPipe, StatusToggleComponent, - TranslatorModule + TranslatorModule, + GmsComponentsModule ], providers: [ SecretService, SecretListResolver, SecretDetailResolver, diff --git a/code/gms-frontend/src/styles.scss b/code/gms-frontend/src/styles.scss index 83046e10..f4e1e779 100644 --- a/code/gms-frontend/src/styles.scss +++ b/code/gms-frontend/src/styles.scss @@ -190,4 +190,8 @@ td { padding: 5px; margin-left: 5px; color: white; - } \ No newline at end of file +} + +.v-bottom { + vertical-align: bottom !important; +}