diff --git a/src/app/components/context-menu/animations.ts b/src/app/components/context-menu/animations.ts
deleted file mode 100644
index b8d69501f..000000000
--- a/src/app/components/context-menu/animations.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-/*!
- * @license
- * Alfresco Example Content Application
- *
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
- *
- * This file is part of the Alfresco Example Content Application.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * The Alfresco Example Content Application is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * The Alfresco Example Content Application is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-
-import {
- state,
- style,
- animate,
- transition,
- query,
- group,
- sequence
-} from '@angular/animations';
-
-export const contextMenuAnimation = [
- state(
- 'void',
- style({
- opacity: 0,
- transform: 'scale(0.01, 0.01)'
- })
- ),
- transition(
- 'void => *',
- sequence([
- query('.mat-menu-content', style({ opacity: 0 })),
- animate(
- '100ms linear',
- style({ opacity: 1, transform: 'scale(1, 0.5)' })
- ),
- group([
- query(
- '.mat-menu-content',
- animate(
- '400ms cubic-bezier(0.55, 0, 0.55, 0.2)',
- style({ opacity: 1 })
- )
- ),
- animate(
- '300ms cubic-bezier(0.25, 0.8, 0.25, 1)',
- style({ transform: 'scale(1, 1)' })
- )
- ])
- ])
- ),
- transition('* => void', animate('150ms 50ms linear', style({ opacity: 0 })))
-];
diff --git a/src/app/components/context-menu/context-menu-item.component.html b/src/app/components/context-menu/context-menu-item.component.html
new file mode 100644
index 000000000..cf3b25f0c
--- /dev/null
+++ b/src/app/components/context-menu/context-menu-item.component.html
@@ -0,0 +1,39 @@
+
\ No newline at end of file
diff --git a/src/app/components/context-menu/context-menu-item.component.spec.ts b/src/app/components/context-menu/context-menu-item.component.spec.ts
new file mode 100644
index 000000000..adb4567b8
--- /dev/null
+++ b/src/app/components/context-menu/context-menu-item.component.spec.ts
@@ -0,0 +1,107 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ *
+ * This file is part of the Alfresco Example Content Application.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * The Alfresco Example Content Application is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The Alfresco Example Content Application is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+
+import { TestBed, ComponentFixture } from '@angular/core/testing';
+import { AppTestingModule } from '../../testing/app-testing.module';
+import { AppExtensionService } from '../../extensions/extension.service';
+import { ContextMenuItemComponent } from './context-menu-item.component';
+import { ContextMenuModule } from './context-menu.module';
+import {
+ TranslateModule,
+ TranslateLoader,
+ TranslateFakeLoader
+} from '@ngx-translate/core';
+
+describe('ContextMenuComponent', () => {
+ let fixture: ComponentFixture;
+ let component: ContextMenuItemComponent;
+ let extensionsService;
+ let contextItem;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [
+ AppTestingModule,
+ ContextMenuModule,
+ TranslateModule.forRoot({
+ loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
+ })
+ ],
+ providers: [AppExtensionService]
+ });
+
+ fixture = TestBed.createComponent(ContextMenuItemComponent);
+ component = fixture.componentInstance;
+ extensionsService = TestBed.get(AppExtensionService);
+
+ contextItem = {
+ type: 'button',
+ id: 'action-button',
+ title: 'Test Button',
+ actions: {
+ click: 'TEST_EVENT'
+ }
+ };
+ });
+
+ afterEach(() => {
+ fixture.destroy();
+ });
+
+ it('should render defined menu actions items', () => {
+ component.actionRef = contextItem;
+ fixture.detectChanges();
+
+ const buttonElement = fixture.nativeElement.querySelector('button');
+ expect(buttonElement.innerText.trim()).toBe(contextItem.title);
+ });
+
+ it('should not run action when entry has no click attribute defined', () => {
+ spyOn(extensionsService, 'runActionById');
+ contextItem.actions = {};
+ component.actionRef = contextItem;
+ fixture.detectChanges();
+
+ fixture.nativeElement
+ .querySelector('#action-button')
+ .dispatchEvent(new MouseEvent('click'));
+
+ expect(extensionsService.runActionById).not.toHaveBeenCalled();
+ });
+
+ it('should run action with provided action id', () => {
+ spyOn(extensionsService, 'runActionById');
+ component.actionRef = contextItem;
+ fixture.detectChanges();
+
+ fixture.nativeElement
+ .querySelector('#action-button')
+ .dispatchEvent(new MouseEvent('click'));
+
+ expect(extensionsService.runActionById).toHaveBeenCalledWith(
+ contextItem.actions.click
+ );
+ });
+});
diff --git a/src/app/components/context-menu/context-menu-item.directive.ts b/src/app/components/context-menu/context-menu-item.component.ts
similarity index 55%
rename from src/app/components/context-menu/context-menu-item.directive.ts
rename to src/app/components/context-menu/context-menu-item.component.ts
index bc4827505..ac2a17f6f 100644
--- a/src/app/components/context-menu/context-menu-item.directive.ts
+++ b/src/app/components/context-menu/context-menu-item.component.ts
@@ -23,29 +23,36 @@
* along with Alfresco. If not, see .
*/
-import { Directive, ElementRef, OnDestroy } from '@angular/core';
-import { FocusableOption, FocusMonitor, FocusOrigin } from '@angular/cdk/a11y';
+import { Component, Input, ViewEncapsulation } from '@angular/core';
+import { ContentActionRef } from '@alfresco/adf-extensions';
+import { AppExtensionService } from '../../extensions/extension.service';
-@Directive({
- selector: '[acaContextMenuItem]'
+@Component({
+ selector: 'app-context-menu-item',
+ templateUrl: 'context-menu-item.component.html',
+ encapsulation: ViewEncapsulation.None,
+ host: { class: 'app-context-menu-item' }
})
-export class ContextMenuItemDirective implements OnDestroy, FocusableOption {
- constructor(
- private elementRef: ElementRef,
- private focusMonitor: FocusMonitor
- ) {
- focusMonitor.monitor(this.getHostElement(), false);
+export class ContextMenuItemComponent {
+ @Input()
+ actionRef: ContentActionRef;
+
+ constructor(private extensions: AppExtensionService) {}
+
+ runAction() {
+ if (this.hasClickAction(this.actionRef)) {
+ this.extensions.runActionById(this.actionRef.actions.click);
+ }
}
- ngOnDestroy() {
- this.focusMonitor.stopMonitoring(this.getHostElement());
+ private hasClickAction(actionRef: ContentActionRef): boolean {
+ if (actionRef && actionRef.actions && actionRef.actions.click) {
+ return true;
+ }
+ return false;
}
- focus(origin: FocusOrigin = 'keyboard'): void {
- this.focusMonitor.focusVia(this.getHostElement(), origin);
- }
-
- private getHostElement(): HTMLElement {
- return this.elementRef.nativeElement;
+ trackById(index: number, obj: { id: string }) {
+ return obj.id;
}
}
diff --git a/src/app/components/context-menu/context-menu-item.directive.spec.ts b/src/app/components/context-menu/context-menu-item.directive.spec.ts
deleted file mode 100644
index 8b2b5c92e..000000000
--- a/src/app/components/context-menu/context-menu-item.directive.spec.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/*!
- * @license
- * Alfresco Example Content Application
- *
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
- *
- * This file is part of the Alfresco Example Content Application.
- * If the software was purchased under a paid Alfresco license, the terms of
- * the paid license agreement will prevail. Otherwise, the software is
- * provided under the following open source license terms:
- *
- * The Alfresco Example Content Application is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * The Alfresco Example Content Application is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-
-import { ContextMenuItemDirective } from './context-menu-item.directive';
-
-describe('ContextMenuItemDirective', () => {
- it('should be defined', () => {
- expect(ContextMenuItemDirective).toBeDefined();
- });
-});
diff --git a/src/app/components/context-menu/context-menu.component.html b/src/app/components/context-menu/context-menu.component.html
index 944503960..27964c349 100644
--- a/src/app/components/context-menu/context-menu.component.html
+++ b/src/app/components/context-menu/context-menu.component.html
@@ -1,48 +1,41 @@
-