|
debugToolsToggleVisible
|
Type : boolean
|
Default value : true
|
|
|
Methods
|
enterPresentationMode
|
enterPresentationMode()
|
|
|
|
|
|
toggleDesignMode
|
toggleDesignMode(enabled: boolean)
|
|
|
Parameters :
| Name |
Type |
Optional |
| enabled |
boolean
|
No
|
|
|
hasLocaleWarning
|
Type : unknown
|
Default value : false
|
|
|
|
journeyDetailsExpanded
|
Type : unknown
|
Default value : false
|
|
|
|
presentationMode
|
Type : unknown
|
Default value : false
|
|
|
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
inject,
Input,
LOCALE_ID,
OnInit
} from '@angular/core';
import * as windowUtils from '../utils/window-utils';
import { NxMessageToastService } from '@allianz/ng-aquila/message';
import { DebugToolsService } from '../utils/debug-tools.service';
import {
IS_A1,
IS_NDBX,
THEME,
SHOWROOM_THEME_URLS,
ThemeName,
CHANNEL,
CHANNEL_TOKEN
} from '@allianz/taly-core';
@Component({
selector: 'taly-showroom-header',
templateUrl: './showroom-header.component.html',
styleUrls: ['./showroom-header.component.scss'],
standalone: false,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ShowroomHeaderComponent implements OnInit {
@Input() debugToolsToggleVisible = true;
journeyDetailsExpanded = false;
presentationMode = false;
hasLocaleWarning = false;
protected debugToolsService = inject(DebugToolsService);
protected copyFormConfigIcon = 'duplicate';
private cdr = inject(ChangeDetectorRef);
protected isNdbx = inject(IS_NDBX);
protected isA1 = inject(IS_A1);
private readonly channel = inject(CHANNEL_TOKEN);
protected readonly isNdbxExpert = this.isNdbx && this.channel === CHANNEL.EXPERT;
protected themeConfig = inject(SHOWROOM_THEME_URLS);
protected readonly currentThemeName: ThemeName | '' = this.isA1
? THEME.A1
: this.isNdbx
? THEME.NDBX
: '';
protected readonly hasThemeSwitcher: boolean =
!!this.currentThemeName && Object.keys(this.themeConfig.themeUrls).length > 1;
private currentLocale = inject(LOCALE_ID);
private messageToastService = inject(NxMessageToastService);
private readonly defaultLocale = 'en-US';
ngOnInit() {
const url = new URL(windowUtils.getHref());
const searchParams = url.searchParams;
if (searchParams.get('presentation') === 'true') {
this.presentationMode = true;
this.journeyDetailsExpanded = false;
this.debugToolsService.debugToolsVisible.set(false);
}
this.hasLocaleWarning = this.currentLocale !== this.defaultLocale;
}
toggleDesignMode(enabled: boolean) {
this.debugToolsService.designModeEnabled.set(enabled);
}
enterPresentationMode() {
// For the HashOnlyLocationStrategy to preserve a query param
// we need to add it _before_ the hash. The Angular Router doesn't
// support this out of the box, so we need to do it manually.
const presentationUrl = new URL(windowUtils.getHref());
if (presentationUrl.searchParams.get('presentation') === 'true') {
return;
}
presentationUrl.searchParams.set('presentation', 'true');
const encodedDynamicFormConfig = this.debugToolsService.encodedDynamicFormConfig();
if (encodedDynamicFormConfig) {
presentationUrl.searchParams.delete('form');
presentationUrl.searchParams.append('form', encodedDynamicFormConfig);
windowUtils.open(presentationUrl.href, '_blank');
return;
}
windowUtils.replace(presentationUrl.href);
}
protected shareDynamicFormConfiguration() {
const encodedDynamicFormConfig = this.debugToolsService.encodedDynamicFormConfig();
const formURL = new URL(windowUtils.getHref());
formURL.searchParams.delete('form');
formURL.searchParams.append('form', encodedDynamicFormConfig);
const formConfigLink = formURL.toString();
navigator.clipboard.writeText(formConfigLink);
this.messageToastService.open('Form configuration link copied to clipboard', {
context: 'success',
duration: 4000
});
this.copyFormConfigIcon = 'check';
setTimeout(() => {
this.copyFormConfigIcon = 'duplicate';
this.cdr.markForCheck();
}, 4000);
}
protected switchTheme(themeName: ThemeName): void {
if (themeName === this.currentThemeName) return;
const themeUrl = this.themeConfig.themeUrls[themeName];
if (!themeUrl) return;
const currentUrl = new URL(windowUtils.getHref());
let targetUrl: URL;
try {
targetUrl = new URL(themeUrl);
} catch {
console.warn(`[SHOWROOM_THEME_URLS] Invalid URL for theme "${themeName}": "${themeUrl}"`);
return;
}
currentUrl.searchParams.forEach((value, key) => {
targetUrl.searchParams.set(key, value);
});
const encodedDynamicFormConfig = this.debugToolsService.encodedDynamicFormConfig();
if (encodedDynamicFormConfig) {
targetUrl.searchParams.delete('form');
targetUrl.searchParams.append('form', encodedDynamicFormConfig);
}
if (currentUrl.hash) {
targetUrl.hash = currentUrl.hash;
}
windowUtils.replace(targetUrl.href);
}
}
@if (hasLocaleWarning) {
<nx-message-banner
class="nx-margin-0"
context="warning"
closeButtonLabel="close non-english warning message banner button"
(close)="hasLocaleWarning = false"
data-testid="non-english-warning-banner"
>
This showroom is running in a non-english locale, which might lead to invalid example data being
used
</nx-message-banner>
} @if (!presentationMode) {
<header nx-header data-testid="header">
<nx-header-brand class="nx-margin-right-5xl">
<nx-link>
<a href="#">
<figure nxFigure>
<img
data-testid="logo"
height="32"
width="32"
[src]="'assets/logos/showroom_logo.svg' | talyNormalizeUrl"
i18n-alt="@@showroom-header.brand-logo.alt"
alt="Allianz Global Brand Logo"
role="none"
class="logo-image"
/>
</figure>
</a>
</nx-link>
<nx-header-app-title data-testid="nx-header-app-title" i18n>
Building Block Platform Showroom
</nx-header-app-title>
</nx-header-brand>
<nx-header-actions class="header-action">
@if (hasThemeSwitcher) {
<nx-formfield class="nx-margin-right-m theme-dropdown">
<nx-dropdown
[variant]="isNdbx && !isNdbxExpert ? 'negative' : ''"
[value]="currentThemeName"
(valueChange)="switchTheme($event)"
data-testid="theme-switcher"
>
@for (theme of themeConfig.themeUrls | keyvalue; track theme.key) {
<nx-dropdown-item [value]="theme.key">{{ theme.key | uppercase }}</nx-dropdown-item>
}
</nx-dropdown>
</nx-formfield>
}
<nx-switcher
[checked]="debugToolsService.designModeEnabled()"
(checkedChange)="toggleDesignMode($event)"
labelSize="small"
class="nx-margin-right-m"
data-testid="design-mode-switcher"
>Show Layout
</nx-switcher>
@if (debugToolsToggleVisible) {
<nx-switcher
[checked]="debugToolsService.debugToolsVisible()"
(checkedChange)="debugToolsService.debugToolsVisible.set($event)"
labelSize="small"
class="nx-margin-right-m"
data-testid="dev-tools-switcher"
>Dev Tools
</nx-switcher>
} @if (!debugToolsService.encodedDynamicFormConfig()){
<button
nxPlainButton
(click)="journeyDetailsExpanded = !journeyDetailsExpanded"
class="nx-margin-right-m"
data-testid="journey-details-button"
>
Journey Details
<nx-icon
[name]="journeyDetailsExpanded ? 'chevron-up' : 'chevron-down'"
aria-hidden="true"
nxIconPositionEnd
></nx-icon>
</button>
} @if (debugToolsService.encodedDynamicFormConfig()){
<button
nxPlainButton
(click)="shareDynamicFormConfiguration()"
class="nx-margin-right-m"
data-testid="share-df-config-button"
>
<nx-icon [name]="copyFormConfigIcon" aria-hidden="true" nxIconPositionEnd></nx-icon>
Share
</button>
}
<button nxPlainButton (click)="enterPresentationMode()" data-testid="present-button">
<nx-icon name="play" aria-hidden="true" nxIconPositionEnd></nx-icon>
Present
</button>
</nx-header-actions>
</header>
} @if (journeyDetailsExpanded) {
<div class="journey-details">
<taly-journey-details
[dynamicFormEditEnabled]="false"
[darkMode]="true"
data-testid="journey-details"
></taly-journey-details>
</div>
}
:host {
--header-background-color: #151c30;
background-color: var(--header-background-color);
header {
--text-01: #fbf9f9;
--header-border-color: #585459;
--azlogo-filter: brightness(0) invert(1);
--plain-button-color: var(--text-01);
--plain-button-hover-color: var(--hover-primary);
--plain-button-active-color: var(--active-primary);
--hover-primary: #ececec;
--active-primary: #ececec;
color: var(--text-01);
overflow-x: auto;
}
.logo-image {
display: block;
filter: var(--azlogo-filter);
}
.journey-details {
background-color: var(--header-background-color);
}
.theme-dropdown {
margin-bottom: 0;
align-self: center;
width: 130px;
--formfield-control-font-size: 16px;
--formfield-control-height: 36px;
--formfield-outline-control-height: 36px;
::ng-deep .nx-formfield__wrapper {
padding-bottom: 0;
padding-top: 0;
}
}
}
Legend
Html element with directive