src/app/core/common-components/view-title/view-title.component.ts
Building block for views, providing a consistent layout to a title section for both dialog and routed views.
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | app-view-title |
| standalone | true |
| imports |
MatButtonModule
MatTooltipModule
FontAwesomeModule
|
| styleUrls | ./view-title.component.scss |
| templateUrl | ./view-title.component.html |
AdminAiAgentComponent
AdminConfigCleanupComponent
AdminDashboardComponent
AdminEntityComponent
AdminEntityDetailsComponent
AdminEntityListComponent
AdminEntityPublicFormsComponent
AdminEntityTypesComponent
AdminMatchingEntitiesComponent
AdminMenuComponent
AdminPrimaryActionComponent
AdminRoleDetailsComponent
AdminRolesListComponent
AdvancedFeaturesComponent
AttendanceManagerComponent
BulkLinkExternalProfilesComponent
ConflictResolutionListComponent
DataPrivacyComponent
EntityDetailsComponent
EntityListComponent
NoteDetailsComponent
ReportingComponent
ReviewDuplicatesComponent
RollCallComponent
RollCallSetupComponent
SetupWizardComponent
SubscriptionInfoComponent
UserListComponent
MatButtonModule
MatTooltipModule
FontAwesomeModule
NgTemplateOutlet
AfterViewInit
Properties |
|
Methods |
|
Inputs |
HostBindings |
| disableBackButton | |
Type : boolean
|
|
Default value : false
|
|
|
(Optional) do not show button to navigate back to the parent page |
|
| displayInPlace | |
Type : boolean
|
|
Default value : false
|
|
| navigateToParentBehaviour | |
Type : boolean
|
|
Default value : false
|
|
|
whether instead of a basic back to previous page navigation the back button should navigate to logical parent page |
|
| title | |
Type : string
|
|
|
The page title to be displayed |
|
| class |
Type : string
|
Default value : "mat-title"
|
| Async navigateBack |
navigateBack()
|
|
Returns :
any
|
| extraClasses |
Type : string
|
Default value : "mat-title"
|
Decorators :
@HostBinding('class')
|
| Protected Readonly isBackButtonDisabled |
Type : unknown
|
Default value : computed(
() => this.disableBackButton() || !!this.viewContext?.isDialog,
)
|
| Readonly parentUrl |
Type : unknown
|
Default value : computed(() => this.findParentUrl())
|
| template |
Type : TemplateRef<any>
|
Decorators :
@ViewChild('template')
|
| Protected viewContext |
Type : unknown
|
Default value : inject(ViewComponentContext, { optional: true })
|
import {
AfterViewInit,
Component,
computed,
HostBinding,
input,
TemplateRef,
ViewChild,
inject,
ChangeDetectionStrategy,
} from "@angular/core";
import { getUrlWithoutParams } from "../../../utils/utils";
import { Router } from "@angular/router";
import { Location, NgTemplateOutlet } from "@angular/common";
import { MatButtonModule } from "@angular/material/button";
import { MatTooltipModule } from "@angular/material/tooltip";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { ViewComponentContext } from "../../ui/abstract-view/view-component-context";
/**
* Building block for views, providing a consistent layout to a title section
* for both dialog and routed views.
*/
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-view-title",
templateUrl: "./view-title.component.html",
styleUrls: ["./view-title.component.scss"],
imports: [
MatButtonModule,
MatTooltipModule,
FontAwesomeModule,
NgTemplateOutlet,
],
})
export class ViewTitleComponent implements AfterViewInit {
private router = inject(Router);
private location = inject(Location);
protected viewContext = inject(ViewComponentContext, { optional: true });
@ViewChild("template") template: TemplateRef<any>;
/** The page title to be displayed */
title = input<string>();
/** (Optional) do not show button to navigate back to the parent page */
disableBackButton = input<boolean>(false);
/**
* whether instead of a basic back to previous page navigation the back button should navigate to logical parent page
*/
navigateToParentBehaviour = input<boolean>(false);
readonly parentUrl = computed(() => this.findParentUrl());
protected readonly isBackButtonDisabled = computed(
() => this.disableBackButton() || !!this.viewContext?.isDialog,
);
displayInPlace = input<boolean>(false);
ngAfterViewInit(): void {
if (this.viewContext && !this.displayInPlace()) {
setTimeout(() => this.viewContext.setTitle(this));
}
}
private findParentUrl(): string {
const currentUrl = getUrlWithoutParams(this.router);
const lastUrlSegmentStart = currentUrl.lastIndexOf("/");
if (lastUrlSegmentStart < 1) {
// do not navigate to root
return null;
}
return currentUrl.substring(0, lastUrlSegmentStart);
}
async navigateBack() {
const parentUrl = this.parentUrl();
if (this.navigateToParentBehaviour() && parentUrl) {
await this.router.navigate([parentUrl]);
} else {
this.location.back();
}
}
@HostBinding("class") extraClasses = "mat-title";
}
<ng-template #template>
<div class="container flex-row">
@if (
(parentUrl() || !navigateToParentBehaviour()) && !isBackButtonDisabled()
) {
<button
mat-icon-button
(click)="navigateBack()"
i18n-matTooltip="Generic back button"
matTooltip="Back"
>
<fa-icon icon="arrow-left"></fa-icon>
</button>
}
<h1 class="remove-margin-bottom flex-grow">
<ng-content></ng-content>
</h1>
</div>
</ng-template>
@if (!viewContext || displayInPlace()) {
<ng-container *ngTemplateOutlet="template"></ng-container>
}
./view-title.component.scss
.container {
align-items: center;
margin-bottom: 0 !important;
}
.back-button {
position: relative;
left: -12px;
}