-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #572 from sam-warren/EMBCDFA-1066-Environment-Banner
EMBCDFA-1066: Environment Banners
- Loading branch information
Showing
19 changed files
with
181 additions
and
4,751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 13 additions & 4 deletions
17
dfa/src/UI/embc-dfa/src/app/core/components/alert/alert.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
8 changes: 5 additions & 3 deletions
8
dfa/src/UI/embc-dfa/src/app/core/components/alert/alert.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
dfa/src/UI/embc-dfa/src/app/core/layout/environment-banner/environment-banner.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
p { | ||
margin: 0px; | ||
} | ||
} | ||
} |
15 changes: 11 additions & 4 deletions
15
dfa/src/UI/embc-dfa/src/app/core/layout/environment-banner/environment-banner.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
dfa/src/UI/embc-dfa/src/app/core/layout/environment-banner/environment-banner.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.