This commit is contained in:
2019-08-22 23:15:22 -04:00
parent 88cfd67184
commit 1ef1b252d7
4 changed files with 54 additions and 31 deletions

View File

@ -1,15 +1,34 @@
<mat-toolbar>
<mat-toolbar id="toolbar">
<button mat-icon-button routerLink="/">
<img src="/assets/images/logo.png" height="35px" width="auto">
</button>
<small class="ml-1 text-muted">{{version}}</small>
<div class="ml-auto">
<div *ngFor="let section of menu" class="d-inline ml-4">
<ng-container *ngFor="let item of section">
<button *ngIf="!item.hidden" mat-icon-button [ngClass]="{'selected': item.enabled}" class="ml-1" (click)="clickWrapper(item)">
<mat-icon>{{item.icon}}</mat-icon>
</button>
<div *ngFor="let item of menuItems; let i = index" class="d-inline mx-1">
<ng-container *ngIf="i <= maxMenuItems">
<ng-container *ngTemplateOutlet="menuItem; context: {$implicit: item}"></ng-container>
</ng-container>
</div>
<button *ngIf="menuItems.length > maxMenuItems" mat-icon-button [matMenuTriggerFor]="menu">
<mat-icon>menu</mat-icon>
</button>
<mat-menu #menu="matMenu">
<ng-container *ngFor="let item of menuItems; let i = index">
<ng-container *ngIf="i > maxMenuItems">
<button mat-menu-item>
<mat-icon>{{item.icon}}</mat-icon>
{{item.name}}
</button>
</ng-container>
</ng-container>
</mat-menu>
</div>
</mat-toolbar>
<ng-template #menuItem let-item>
<ng-container>
<button mat-icon-button [ngClass]="{'selected': item?.enabled}" class="ml-1" (click)="clickWrapper(item)">
<mat-icon>{{item?.icon}}</mat-icon>
</button>
</ng-container>
</ng-template>

View File

@ -1,4 +1,4 @@
import {Component, EventEmitter, Input, Output} from "@angular/core";
import {AfterViewInit, Component, EventEmitter, HostListener, Input, Output,} from "@angular/core";
import {ToolbarItem} from "./toolbarItem";
import {version} from '../../../../package.json';
@ -7,26 +7,33 @@ import {version} from '../../../../package.json';
templateUrl: 'toolbar.component.html',
styleUrls: ['toolbar.component.scss']
})
export class ToolbarComponent {
@Input() menu: ToolbarItem[][];
export class ToolbarComponent implements AfterViewInit {
@Input() menuItems: ToolbarItem[];
@Output() menuChange = new EventEmitter<ToolbarItem[][]>();
@Output() menuItemsChange = new EventEmitter<ToolbarItem[]>();
private maxMenuItems;
readonly version = version;
constructor() { }
@HostListener('window:resize', ['$event'])
ngAfterViewInit() {
setTimeout(() => this.maxMenuItems = Math.floor((document.getElementById('toolbar').offsetWidth - 200) / 75), 1);
}
clickWrapper(item: ToolbarItem) {
if(item.toggle) {
if (item.individualToggle) {
this.menu.forEach(menu => menu.filter(i2 => item.name != i2.name && i2.individualToggle).forEach(item => {
this.menuItems.filter(i2 => item.name != i2.name && i2.individualToggle).forEach(item => {
item.enabled = false;
if (item.onDisabled) item.onDisabled();
}));
});
}
item.enabled = !item.enabled;
this.menuChange.emit(this.menu);
this.menuItemsChange.emit(this.menuItems);
if(item.enabled) {
if(item.onEnabled) item.onEnabled();