Skip to content

Commit

Permalink
Merge pull request #572 from sam-warren/EMBCDFA-1066-Environment-Banner
Browse files Browse the repository at this point in the history
EMBCDFA-1066: Environment Banners
  • Loading branch information
GeorgeWalker authored Sep 11, 2024
2 parents 01d4b40 + d8889f9 commit 5e226a8
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 4,751 deletions.
11 changes: 5 additions & 6 deletions dfa/src/UI/embc-dfa/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
(closeEvent)="closeOutageBanner($event)"
></app-outage-banner>

<!--<app-environment-banner
[environment]="environment"
*ngIf="environment !== null && environment !== undefined"
></app-environment-banner>-->
@if (environment !== null && environment !== undefined) {
<app-environment-banner [environment]="environment"></app-environment-banner>
}

<app-header
[ngStyle]="
Expand All @@ -30,9 +29,9 @@
"
[class.body-border]="environment !== null && environment !== undefined"
>
<!--<div class="app-error">
<div class="app-error">
<app-alert></app-alert>
</div>-->
</div>

<div>
<router-outlet *ngIf="!isLoading"></router-outlet>
Expand Down
5 changes: 3 additions & 2 deletions dfa/src/UI/embc-dfa/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfigService } from './core/services/config.service';
import { EnvironmentInformation } from './core/model/environment-information.model';
import { OutageService } from './feature-components/outage/outage.service';
import { ScriptService } from "./core/services/scriptServices";
import { EnvironmentBannerService } from './core/layout/environment-banner/environment-banner.service';

const SCRIPT_PATH = 'http://ws1.postescanada-canadapost.ca/js/addresscomplete-2.30.min.js?key=ea53-hg74-kb59-ym41';

Expand All @@ -23,6 +24,7 @@ export class AppComponent implements OnInit {
public gapi: any;

constructor(
public envBannerService: EnvironmentBannerService,
public outageService: OutageService,
private alertService: AlertService,
private bootstrapService: BootstrapService,
Expand All @@ -34,8 +36,7 @@ export class AppComponent implements OnInit {

public async ngOnInit(): Promise<void> {
try {
//this.environment = await this.configService.loadEnvironmentBanner();
this.environment = null;
this.environment = await this.envBannerService.loadEnvironmentBanner();
await this.bootstrapService.init();
await this.loginService.tryLogin();
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<div *ngFor="let alert of alerts">
<div class="alert alert-danger" role="alert">
{{ alert?.message }}
@for (alert of alerts; track alert) {
<div>
@if (alert.type === 'danger') {
<div class="alert alert-danger" role="alert">
{{ alert?.message }}
</div>
}
@if (alert.type === 'warning') {
<div class="alert alert-warning" role="alert">
{{ alert?.message }}
</div>
}
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { Alert } from '../../model/alert';
import { AlertService } from '../../services/alert.service';
import { Alert } from 'src/app/core/model/alert';
import { AlertService } from 'src/app/core/services/alert.service';

@Component({
selector: 'app-alert',
templateUrl: './alert.component.html',
styleUrls: ['./alert.component.scss']
styleUrls: ['./alert.component.scss'],
standalone: true,
imports: []
})
export class AlertComponent implements OnInit {
type: string;
Expand Down
2 changes: 1 addition & 1 deletion dfa/src/UI/embc-dfa/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { SecondaryApplicantWarningDialogComponent } from './components/dialog-co

@NgModule({
imports: [
AlertComponent,
CommonModule,
FormsModule,
MatCardModule,
Expand All @@ -63,7 +64,6 @@ import { SecondaryApplicantWarningDialogComponent } from './components/dialog-co
],
declarations: [
AppLoaderComponent,
AlertComponent,
HeaderComponent,
FooterComponent,
DialogComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div
class="container main-style"
[ngStyle]="{ 'background-color': environment?.bannerColor }"
>
<div class="container main-style" [ngStyle]="{ 'background-color': environment?.bannerColor }">
<p>
<markdown [data]="environment?.bannerTitle"></markdown>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
p {
margin: 0px;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Component, Input, OnInit } from '@angular/core';
import { EnvironmentInformation } from '../../model/environment-information.model';
import { EnvironmentBannerService } from './environment-banner.service';
import { MarkdownComponent } from 'ngx-markdown';
import { NgStyle } from '@angular/common';

@Component({
selector: 'app-environment-banner',
templateUrl: './environment-banner.component.html',
styleUrls: ['./environment-banner.component.scss']
styleUrls: ['./environment-banner.component.scss'],
})
export class EnvironmentBannerComponent {
@Input() environment?: EnvironmentInformation;
export class EnvironmentBannerComponent implements OnInit {
environment: EnvironmentInformation;

constructor() {}
constructor(private envBannerService: EnvironmentBannerService) {}

ngOnInit(): void {
this.environment = this.envBannerService.getEnvironmentBanner();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { AlertService } from 'src/app/core/services/alert.service';
import { EnvironmentInformation } from 'src/app/core/model/environment-information.model';
import { CacheService } from 'src/app/core/services/cache.service';
import * as globalConst from 'src/app/core/services/globalConstants';

@Injectable({
providedIn: 'root'
})
export class EnvironmentBannerService {
public environmentBanner: EnvironmentInformation;
private configurationGetEnvironmentInfoPath = '/env/info.json';

constructor(
private http: HttpClient,
private cacheService: CacheService,
private alertService: AlertService
) {}

public loadEnvironmentBanner(): Promise<EnvironmentInformation> {
return new Promise<EnvironmentInformation>((resolve, reject) => {
let environment: EnvironmentInformation = {};
this.getEnvironment().subscribe({
next: (env) => {
environment = env;
this.setEnvironmentBanner(env);
resolve(environment);
},
error: (error) => {
if (error.status === 400 || error.status === 404) {
this.environmentBanner = null;
resolve(environment);
} else {
this.alertService.clearAlert();
this.alertService.setAlert('danger', globalConst.systemError);
reject(error);
}
}
});
});
}

public getEnvironmentBanner(): EnvironmentInformation {
return this.environmentBanner
? this.environmentBanner
: JSON.parse(this.cacheService.get('environment'))
? JSON.parse(this.cacheService.get('environment'))
: this.getEnvironmentInfo();
}

public setEnvironmentBanner(environmentBanner: EnvironmentInformation): void {
this.cacheService.set('environment', environmentBanner);
this.environmentBanner = environmentBanner;
}

private getEnvironment(): Observable<EnvironmentInformation> {
const envUrl = this.configurationGetEnvironmentInfoPath;
return this.http.get(envUrl);
}

private getEnvironmentInfo(): EnvironmentInformation {
let environment: EnvironmentInformation = {};
this.getEnvironment().subscribe({
next: (env) => {
environment = env;
this.setEnvironmentBanner(env);
},
error: (error) => {
if (error.status === 400 || error.status === 404) {
this.environmentBanner = null;
} else {
this.alertService.clearAlert();
this.alertService.setAlert('danger', globalConst.systemError);
}
}
});
return environment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class HeaderComponent implements OnInit {
) {}

ngOnInit(): void {
console.log('header comp');
this.loginService.isLoggedIn$.subscribe((val) => {
this.showLoginMatMenu = val;
});
Expand Down
Loading

0 comments on commit 5e226a8

Please sign in to comment.