Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/_layout/app-header/app-header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,8 @@ <h6>
</h6>
</ng-template>
</mat-toolbar>
<app-status-banner
(dismiss)="showStatusBanner = false"
*ngIf="showStatusBanner"
></app-status-banner>
</div>
3 changes: 3 additions & 0 deletions src/app/_layout/app-header/app-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { map, Observable, Subscription } from "rxjs";
})
export class AppHeaderComponent implements OnInit {
private sub: Subscription;
showStatusBanner: boolean;

config = this.appConfigService.getConfig();
facility = this.config.facility ?? "";
Expand Down Expand Up @@ -89,6 +90,8 @@ export class AppHeaderComponent implements OnInit {
this.isSiteHeaderLogoUrlExternal$ = this.siteHeaderLogoUrl$.pipe(
map((siteHeaderLogoUrl) => this.isFullUrl(siteHeaderLogoUrl)),
);

this.showStatusBanner = !!this.config.statusBannerMessage;
}

logout(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<mat-toolbar [ngClass]="['toolbar', 'toolbar-' + code]">
<span class="status-message">
<mat-icon class="status-icon">
{{ code === "INFO" ? "info" : "warning" }}
</mat-icon>
<span [innerHTML]="message"></span>
</span>
<span class="spacer"></span>
<button mat-icon-button aria-label="Dismiss" (click)="onDismiss()">
<mat-icon>close</mat-icon>
</button>
</mat-toolbar>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.spacer {
flex: 1 1 auto;
}

.toolbar {
height: fit-content;
border: none;
box-shadow: none;
}

.status-message {
text-align: center;
text-wrap: wrap;
width: 100%;
font-size: 16px;
line-height: 20px;
padding: 10px 0;
}
.status-icon {
margin-right: 6px;
font-size: 20px;
vertical-align: middle;
}
.toolbar-WARN {
background-color: #feefb3;
color: #9f6000;
}

.toolbar-INFO {
color: #4f8a10;
background-color: #dff2bf;
}

:host ::ng-deep a {
text-decoration: underline;
color: inherit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { StatusBannerComponent } from "./status-banner.component";
import { CommonModule } from "@angular/common";
import { MatButtonModule } from "@angular/material/button";
import { MatIconModule } from "@angular/material/icon";
import { MatToolbarModule } from "@angular/material/toolbar";
import { AppConfigInterface, AppConfigService } from "app-config.service";

describe("StatusBannerComponent", () => {
let component: StatusBannerComponent;
let fixture: ComponentFixture<StatusBannerComponent>;
let appConfigServiceSpy: jasmine.SpyObj<AppConfigService>;

beforeEach(async () => {
appConfigServiceSpy = jasmine.createSpyObj("AppConfigService", [
"getConfig",
]);
appConfigServiceSpy.getConfig.and.returnValue({
statusBannerMessage: "test",
statusBannerCode: "INFO",
} as AppConfigInterface);
await TestBed.configureTestingModule({
declarations: [StatusBannerComponent],
imports: [CommonModule, MatToolbarModule, MatButtonModule, MatIconModule],
providers: [
{
provide: AppConfigService,
useValue: appConfigServiceSpy,
},
],
}).compileComponents();
});

function initComponent() {
fixture = TestBed.createComponent(StatusBannerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}

it("should create", () => {
initComponent();
expect(component).toBeTruthy();
});

it("should set the status banner message and code from the app config", () => {
initComponent();
expect(component.message).toBe("test");
expect(component.code).toBe("INFO");
});

it("should set default code to INFO when neither INFO or WARN is provided", () => {
appConfigServiceSpy.getConfig.and.returnValue({
statusBannerMessage: "test123",
statusBannerCode: "ERROR",
} as unknown as AppConfigInterface);
initComponent();
expect(component.code).toBe("INFO");
expect(component.message).toBe("test123");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, Output, EventEmitter } from "@angular/core";
import { AppConfigService } from "app-config.service";

@Component({
selector: "app-status-banner",
templateUrl: "./status-banner.component.html",
styleUrls: ["./status-banner.component.scss"],
standalone: false,
})
export class StatusBannerComponent {
@Output() dismiss = new EventEmitter<void>();
message: string;
code: "INFO" | "WARN";

constructor(private appConfigService: AppConfigService) {
const appConfig = this.appConfigService.getConfig();
this.message = appConfig.statusBannerMessage;
if (["INFO", "WARN"].includes(appConfig.statusBannerCode)) {
this.code = appConfig.statusBannerCode;
} else {
this.code = "INFO";
}
}

onDismiss() {
this.dismiss.emit();
}
}
2 changes: 2 additions & 0 deletions src/app/_layout/layout.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { BatchCardModule } from "datasets/batch-card/batch-card.module";
import { BreadcrumbModule } from "shared/modules/breadcrumb/breadcrumb.module";
import { UsersModule } from "../users/users.module";
import { MatChipsModule } from "@angular/material/chips";
import { StatusBannerComponent } from "./app-header/status-banner/status-banner.component";
import { MatTooltipModule } from "@angular/material/tooltip";

@NgModule({
declarations: [
StatusBannerComponent,
AppLayoutComponent,
AppHeaderComponent,
AppMainLayoutComponent,
Expand Down
8 changes: 8 additions & 0 deletions src/app/admin/schema/frontend.config.jsonforms.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
"metadataEditingUnitListDisabled": { "type": "boolean" },
"hideEmptyMetadataTable": { "type": "boolean" },
"datafilesActionsEnabled": { "type": "boolean" },
"statusBannerMessage": { "type": "string" },
"statusBannerCode": {
"type": "string",
"enum": ["INFO", "WARN"],
"default": "INFO"
},
"datafilesActions": {
"type": "array",
"items": {
Expand Down Expand Up @@ -409,6 +415,8 @@
{ "type": "Control", "scope": "#/properties/siteIcon" },
{ "type": "Control", "scope": "#/properties/siteTitle" },
{ "type": "Control", "scope": "#/properties/siteSciCatLogo" },
{ "type": "Control", "scope": "#/properties/statusBannerMessage" },
{ "type": "Control", "scope": "#/properties/statusBannerCode" },
{
"type": "Control",
"scope": "#/properties/checkBoxFilterClickTrigger"
Expand Down
3 changes: 2 additions & 1 deletion src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export interface AppConfigInterface {
hideEmptyMetadataTable?: boolean;
ingestorComponent?: IngestorComponentConfig;
defaultTab?: DefaultTab;
statusBannerMessage?: string;
statusBannerCode?: "INFO" | "WARN";
}

function isMainPageConfiguration(obj: any): obj is MainPageConfiguration {
Expand Down Expand Up @@ -275,7 +277,6 @@ export class AppConfigService {
if (!this.appConfig) {
console.error("AppConfigService: Configuration not loaded!");
}

return this.appConfig as AppConfigInterface;
}
}
Loading