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/>.
|
* 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 { ContentActionRef } from '@alfresco/adf-extensions';
|
||||||
import { AppExtensionService } from '../../../services/app.extension.service';
|
import { AppExtensionService } from '../../../services/app.extension.service';
|
||||||
|
import { MatMenuItem } from '@angular/material/menu';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-toolbar-menu-item',
|
selector: 'app-toolbar-menu-item',
|
||||||
@ -44,6 +45,9 @@ export class ToolbarMenuItemComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
actionRef: ContentActionRef;
|
actionRef: ContentActionRef;
|
||||||
|
|
||||||
|
@ViewChild(MatMenuItem)
|
||||||
|
menuItem: MatMenuItem;
|
||||||
|
|
||||||
constructor(private extensions: AppExtensionService) {}
|
constructor(private extensions: AppExtensionService) {}
|
||||||
|
|
||||||
runAction() {
|
runAction() {
|
||||||
|
@ -23,10 +23,11 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* 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 { 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 { ThemePalette } from '@angular/material/core';
|
||||||
|
import { ToolbarMenuItemComponent } from '../toolbar-menu-item/toolbar-menu-item.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-toolbar-menu',
|
selector: 'app-toolbar-menu',
|
||||||
@ -34,7 +35,7 @@ import { ThemePalette } from '@angular/material/core';
|
|||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
host: { class: 'app-toolbar-menu' }
|
host: { class: 'app-toolbar-menu' }
|
||||||
})
|
})
|
||||||
export class ToolbarMenuComponent {
|
export class ToolbarMenuComponent implements AfterViewInit {
|
||||||
@Input()
|
@Input()
|
||||||
actionRef: ContentActionRef;
|
actionRef: ContentActionRef;
|
||||||
|
|
||||||
@ -44,11 +45,30 @@ export class ToolbarMenuComponent {
|
|||||||
@ViewChild('matTrigger')
|
@ViewChild('matTrigger')
|
||||||
matTrigger: MatMenuTrigger;
|
matTrigger: MatMenuTrigger;
|
||||||
|
|
||||||
|
@ViewChild(MatMenu)
|
||||||
|
menu: MatMenu;
|
||||||
|
|
||||||
|
@ViewChildren(ToolbarMenuItemComponent)
|
||||||
|
toolbarMenuItems: QueryList<ToolbarMenuItemComponent>;
|
||||||
|
|
||||||
@HostListener('document:keydown.Escape')
|
@HostListener('document:keydown.Escape')
|
||||||
handleKeydownEscape() {
|
handleKeydownEscape() {
|
||||||
this.matTrigger.closeMenu();
|
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 {
|
trackByActionId(_: number, obj: ContentActionRef): string {
|
||||||
return obj.id;
|
return obj.id;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user