mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACS-3700] Pass mat menu items from external components to mat menu (#2720)
* [ACS-3700] Pass mat menu items from external components to mat menu * [ACS-3700] Linter fixes
This commit is contained in:
parent
2b12fa983c
commit
eee6feca1a
@ -23,9 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, Input, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, Input, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { ContentActionRef } from '@alfresco/adf-extensions';
|
||||
import { AppExtensionService } from '../../../services/app.extension.service';
|
||||
import { MatMenuItem } from '@angular/material/menu';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toolbar-menu-item',
|
||||
@ -44,6 +45,9 @@ export class ToolbarMenuItemComponent {
|
||||
@Input()
|
||||
actionRef: ContentActionRef;
|
||||
|
||||
@ViewChild(MatMenuItem)
|
||||
menuItem: MatMenuItem;
|
||||
|
||||
constructor(private extensions: AppExtensionService) {}
|
||||
|
||||
runAction() {
|
||||
|
@ -23,10 +23,11 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, Input, ViewEncapsulation, HostListener, ViewChild } from '@angular/core';
|
||||
import { Component, Input, ViewEncapsulation, HostListener, ViewChild, ViewChildren, QueryList, AfterViewInit } from '@angular/core';
|
||||
import { ContentActionRef } from '@alfresco/adf-extensions';
|
||||
import { MatMenuTrigger } from '@angular/material/menu';
|
||||
import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu';
|
||||
import { ThemePalette } from '@angular/material/core';
|
||||
import { ToolbarMenuItemComponent } from '../toolbar-menu-item/toolbar-menu-item.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toolbar-menu',
|
||||
@ -34,7 +35,7 @@ import { ThemePalette } from '@angular/material/core';
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'app-toolbar-menu' }
|
||||
})
|
||||
export class ToolbarMenuComponent {
|
||||
export class ToolbarMenuComponent implements AfterViewInit {
|
||||
@Input()
|
||||
actionRef: ContentActionRef;
|
||||
|
||||
@ -44,11 +45,30 @@ export class ToolbarMenuComponent {
|
||||
@ViewChild('matTrigger')
|
||||
matTrigger: MatMenuTrigger;
|
||||
|
||||
@ViewChild(MatMenu)
|
||||
menu: MatMenu;
|
||||
|
||||
@ViewChildren(ToolbarMenuItemComponent)
|
||||
toolbarMenuItems: QueryList<ToolbarMenuItemComponent>;
|
||||
|
||||
@HostListener('document:keydown.Escape')
|
||||
handleKeydownEscape() {
|
||||
this.matTrigger.closeMenu();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const menuItems: MatMenuItem[] = [];
|
||||
this.toolbarMenuItems.forEach((toolbarMenuItem: ToolbarMenuItemComponent) => {
|
||||
if (toolbarMenuItem.menuItem !== undefined) {
|
||||
menuItems.push(toolbarMenuItem.menuItem);
|
||||
}
|
||||
});
|
||||
const menuItemsQueryList: QueryList<MatMenuItem> = new QueryList<MatMenuItem>();
|
||||
menuItemsQueryList.reset(menuItems);
|
||||
this.menu._allItems = menuItemsQueryList;
|
||||
this.menu.ngAfterContentInit();
|
||||
}
|
||||
|
||||
trackByActionId(_: number, obj: ContentActionRef): string {
|
||||
return obj.id;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user