UI: Menu improvements.
This commit is contained in:
parent
e97e57a38f
commit
c4a129a0bf
@ -49,6 +49,7 @@ import { PageLink } from '@shared/models/page/page-link';
|
|||||||
import { Direction } from '@shared/models/page/sort-order';
|
import { Direction } from '@shared/models/page/sort-order';
|
||||||
import { emptyPageData, PageData } from '@shared/models/page/page-data';
|
import { emptyPageData, PageData } from '@shared/models/page/page-data';
|
||||||
import { deepClone } from '@core/utils';
|
import { deepClone } from '@core/utils';
|
||||||
|
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-quick-link',
|
selector: 'tb-quick-link',
|
||||||
@ -114,6 +115,7 @@ export class QuickLinkComponent extends PageComponent implements OnInit, Control
|
|||||||
private fb: UntypedFormBuilder,
|
private fb: UntypedFormBuilder,
|
||||||
private menuService: MenuService,
|
private menuService: MenuService,
|
||||||
public translate: TranslateService,
|
public translate: TranslateService,
|
||||||
|
private customTranslate: CustomTranslatePipe,
|
||||||
@SkipSelf() private errorStateMatcher: ErrorStateMatcher) {
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher) {
|
||||||
super(store);
|
super(store);
|
||||||
}
|
}
|
||||||
@ -135,7 +137,7 @@ export class QuickLinkComponent extends PageComponent implements OnInit, Control
|
|||||||
this.updateView(modelValue);
|
this.updateView(modelValue);
|
||||||
}),
|
}),
|
||||||
map(value => value ? (typeof value === 'string' ? value :
|
map(value => value ? (typeof value === 'string' ? value :
|
||||||
((value as any).translated ? value.name : this.translate.instant(value.name))) : ''),
|
((value as any).translated ? value.name : this.customTranslate.transform(value.name))) : ''),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
switchMap(name => this.fetchLinks(name) ),
|
switchMap(name => this.fetchLinks(name) ),
|
||||||
share()
|
share()
|
||||||
@ -202,7 +204,7 @@ export class QuickLinkComponent extends PageComponent implements OnInit, Control
|
|||||||
}
|
}
|
||||||
|
|
||||||
displayLinkFn = (link?: MenuSection): string | undefined =>
|
displayLinkFn = (link?: MenuSection): string | undefined =>
|
||||||
link ? ((link as any).translated ? link.name : this.translate.instant(link.fullName || link.name)) : undefined;
|
link ? ((link as any).translated ? link.name : this.customTranslate.transform(link.fullName || link.name)) : undefined;
|
||||||
|
|
||||||
fetchLinks(searchText?: string): Observable<Array<MenuSection>> {
|
fetchLinks(searchText?: string): Observable<Array<MenuSection>> {
|
||||||
this.searchText = searchText;
|
this.searchText = searchText;
|
||||||
@ -228,7 +230,7 @@ export class QuickLinkComponent extends PageComponent implements OnInit, Control
|
|||||||
map((links) => {
|
map((links) => {
|
||||||
const result = deepClone(links);
|
const result = deepClone(links);
|
||||||
for (const link of result) {
|
for (const link of result) {
|
||||||
link.name = this.translate.instant(link.fullName || link.name);
|
link.name = this.customTranslate.transform(link.fullName || link.name);
|
||||||
(link as any).translated = true;
|
(link as any).translated = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -17,5 +17,5 @@
|
|||||||
-->
|
-->
|
||||||
<a mat-button routerLinkActive="tb-active" [routerLinkActiveOptions]="{paths: 'subset', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored'}" routerLink="{{section.path}}">
|
<a mat-button routerLinkActive="tb-active" [routerLinkActiveOptions]="{paths: 'subset', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored'}" routerLink="{{section.path}}">
|
||||||
<tb-icon matButtonIcon *ngIf="section.icon !== null">{{section.icon}}</tb-icon>
|
<tb-icon matButtonIcon *ngIf="section.icon !== null">{{section.icon}}</tb-icon>
|
||||||
<span>{{section.name | translate}}</span>
|
<span>{{section.name | customTranslate}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
-->
|
-->
|
||||||
<a mat-button class="tb-button-toggle" (click)="toggleSection($event)">
|
<a mat-button class="tb-button-toggle" (click)="toggleSection($event)">
|
||||||
<tb-icon matButtonIcon *ngIf="section.icon !== null">{{section.icon}}</tb-icon>
|
<tb-icon matButtonIcon *ngIf="section.icon !== null">{{section.icon}}</tb-icon>
|
||||||
<span>{{section.name | translate}}</span>
|
<span>{{section.name | customTranslate}}</span>
|
||||||
<span class=" pull-right fa fa-chevron-down tb-toggle-icon"
|
<span class=" pull-right fa fa-chevron-down tb-toggle-icon"
|
||||||
[ngClass]="{'tb-toggled' : section.opened}"></span>
|
[ngClass]="{'tb-toggled' : section.opened}"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -17,9 +17,7 @@
|
|||||||
-->
|
-->
|
||||||
<div fxFlex class="tb-breadcrumb" fxLayout="row">
|
<div fxFlex class="tb-breadcrumb" fxLayout="row">
|
||||||
<h1 fxFlex fxHide.gt-sm *ngIf="lastBreadcrumb$ | async; let breadcrumb">
|
<h1 fxFlex fxHide.gt-sm *ngIf="lastBreadcrumb$ | async; let breadcrumb">
|
||||||
{{ breadcrumb.ignoreTranslate
|
{{ breadcrumb.labelFunction ? breadcrumb.labelFunction() : (breadcrumb.label | customTranslate) }}
|
||||||
? (breadcrumb.labelFunction ? breadcrumb.labelFunction() : (breadcrumb.label | customTranslate))
|
|
||||||
: (breadcrumb.label | translate) }}
|
|
||||||
</h1>
|
</h1>
|
||||||
<span fxHide.lt-md fxLayout="row" *ngFor="let breadcrumb of breadcrumbs$ | async; trackBy: trackByBreadcrumbs; last as isLast;" [ngSwitch]="isLast">
|
<span fxHide.lt-md fxLayout="row" *ngFor="let breadcrumb of breadcrumbs$ | async; trackBy: trackByBreadcrumbs; last as isLast;" [ngSwitch]="isLast">
|
||||||
<a *ngSwitchCase="false" [routerLink]="breadcrumb.link" [queryParams]="breadcrumb.queryParams">
|
<a *ngSwitchCase="false" [routerLink]="breadcrumb.link" [queryParams]="breadcrumb.queryParams">
|
||||||
@ -40,7 +38,5 @@
|
|||||||
<tb-icon *ngIf="!breadcrumb.iconUrl">
|
<tb-icon *ngIf="!breadcrumb.iconUrl">
|
||||||
{{ breadcrumb.icon }}
|
{{ breadcrumb.icon }}
|
||||||
</tb-icon>
|
</tb-icon>
|
||||||
{{ breadcrumb.ignoreTranslate
|
{{ breadcrumb.labelFunction ? breadcrumb.labelFunction() : (breadcrumb.label | customTranslate) }}
|
||||||
? (breadcrumb.labelFunction ? breadcrumb.labelFunction() : (breadcrumb.label | customTranslate))
|
|
||||||
: (breadcrumb.label | translate) }}
|
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|||||||
@ -113,16 +113,12 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
const breadcrumbConfig = route.routeConfig.data.breadcrumb as BreadCrumbConfig<any>;
|
const breadcrumbConfig = route.routeConfig.data.breadcrumb as BreadCrumbConfig<any>;
|
||||||
if (breadcrumbConfig && !breadcrumbConfig.skip) {
|
if (breadcrumbConfig && !breadcrumbConfig.skip) {
|
||||||
let labelFunction: () => string;
|
let labelFunction: () => string;
|
||||||
let ignoreTranslate: boolean;
|
|
||||||
const section: MenuSection = breadcrumbConfig.menuId ?
|
const section: MenuSection = breadcrumbConfig.menuId ?
|
||||||
availableMenuSections.find(menu => menu.id === breadcrumbConfig.menuId) : null;
|
availableMenuSections.find(menu => menu.id === breadcrumbConfig.menuId) : null;
|
||||||
const label = section?.name || breadcrumbConfig.label || 'home.home';
|
const label = section?.name || breadcrumbConfig.label || 'home.home';
|
||||||
if (breadcrumbConfig.labelFunction) {
|
if (breadcrumbConfig.labelFunction) {
|
||||||
labelFunction = () => this.activeComponentValue ?
|
labelFunction = () => this.activeComponentValue ?
|
||||||
breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue, lastChild.data) : label;
|
breadcrumbConfig.labelFunction(route, this.translate, this.activeComponentValue, lastChild.data) : label;
|
||||||
ignoreTranslate = true;
|
|
||||||
} else {
|
|
||||||
ignoreTranslate = false;
|
|
||||||
}
|
}
|
||||||
const icon = section?.icon || breadcrumbConfig.icon || 'home';
|
const icon = section?.icon || breadcrumbConfig.icon || 'home';
|
||||||
const link = [ route.pathFromRoot.map(v => v.url.map(segment => segment.toString()).join('/')).join('/') ];
|
const link = [ route.pathFromRoot.map(v => v.url.map(segment => segment.toString()).join('/')).join('/') ];
|
||||||
@ -130,7 +126,6 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
id: guid(),
|
id: guid(),
|
||||||
label,
|
label,
|
||||||
labelFunction,
|
labelFunction,
|
||||||
ignoreTranslate,
|
|
||||||
icon,
|
icon,
|
||||||
link,
|
link,
|
||||||
queryParams: null
|
queryParams: null
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import { MenuId } from '@core/services/menu.models';
|
|||||||
export interface BreadCrumb extends HasUUID{
|
export interface BreadCrumb extends HasUUID{
|
||||||
label: string;
|
label: string;
|
||||||
labelFunction?: () => string;
|
labelFunction?: () => string;
|
||||||
ignoreTranslate: boolean;
|
|
||||||
icon: string;
|
icon: string;
|
||||||
link: any[];
|
link: any[];
|
||||||
queryParams: Params;
|
queryParams: Params;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user