[27764] Fix plugin actions

https://community.openproject.com/wp/27764
pull/6337/head
Oliver Günther 7 years ago
parent e5db8fd8c9
commit 99b2bec54a
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 8
      frontend/app/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts
  2. 12
      frontend/app/components/op-context-menu/wp-context-menu/wp-static-context-menu-actions.ts
  3. 31
      frontend/app/components/work-packages/work-package-authorization.service.ts
  4. 1
      frontend/app/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts

@ -14,6 +14,7 @@ import {AuthorisationService} from "core-components/common/model-auth/model-auth
import {StateService} from "@uirouter/core"; import {StateService} from "@uirouter/core";
import {OpModalService} from "core-components/op-modals/op-modal.service"; import {OpModalService} from "core-components/op-modals/op-modal.service";
import {WpDestroyModal} from "core-components/modals/wp-destroy-modal/wp-destroy.modal"; import {WpDestroyModal} from "core-components/modals/wp-destroy-modal/wp-destroy.modal";
import {PathHelperService} from "core-components/common/path-helper/path-helper.service";
@Directive({ @Directive({
selector: '[wpSingleContextMenu]' selector: '[wpSingleContextMenu]'
@ -23,6 +24,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
constructor(@Inject(HookServiceToken) readonly HookService:any, constructor(@Inject(HookServiceToken) readonly HookService:any,
@Inject($stateToken) readonly $state:StateService, @Inject($stateToken) readonly $state:StateService,
readonly PathHelper:PathHelperService,
readonly elementRef:ElementRef, readonly elementRef:ElementRef,
readonly opModalService:OpModalService, readonly opModalService:OpModalService,
readonly opContextMenuService:OPContextMenuService, readonly opContextMenuService:OPContextMenuService,
@ -34,7 +36,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
this.workPackage.project.$load().then(() => { this.workPackage.project.$load().then(() => {
this.authorisationService.initModelAuth('work_package', this.workPackage.$links); this.authorisationService.initModelAuth('work_package', this.workPackage.$links);
var authorization = new WorkPackageAuthorization(this.workPackage); var authorization = new WorkPackageAuthorization(this.workPackage, this.PathHelper, this.$state);
const permittedActions = angular.extend(this.getPermittedActions(authorization), const permittedActions = angular.extend(this.getPermittedActions(authorization),
this.getPermittedPluginActions(authorization)); this.getPermittedPluginActions(authorization));
@ -88,12 +90,12 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger
protected buildItems(permittedActions:WorkPackageAction[]) { protected buildItems(permittedActions:WorkPackageAction[]) {
this.items = permittedActions.map((action:WorkPackageAction) => { this.items = permittedActions.map((action:WorkPackageAction) => {
const key = action.icon!; const key = action.key;
return { return {
disabled: false, disabled: false,
linkText: I18n.t('js.button_' + key), linkText: I18n.t('js.button_' + key),
href: action.link, href: action.link,
icon: `icon-${key}`, icon: action.icon || `icon-${key}`,
onClick: ($event:JQueryEventObject) => { onClick: ($event:JQueryEventObject) => {
if (action.link && LinkHandling.isClickedWithModifier($event)) { if (action.link && LinkHandling.isClickedWithModifier($event)) {
return false; return false;

@ -1,31 +1,31 @@
export const PERMITTED_CONTEXT_MENU_ACTIONS = [ export const PERMITTED_CONTEXT_MENU_ACTIONS = [
{ {
icon: 'log_time', key: 'log_time',
link: 'logTime', link: 'logTime',
resource: 'workPackage' resource: 'workPackage'
}, },
{ {
icon: 'move', key: 'move',
link: 'move', link: 'move',
resource: 'workPackage' resource: 'workPackage'
}, },
{ {
icon: 'copy', key: 'copy',
link: 'copy', link: 'copy',
resource: 'workPackage' resource: 'workPackage'
}, },
{ {
icon: 'delete', key: 'delete',
link: 'delete', link: 'delete',
resource: 'workPackage' resource: 'workPackage'
}, },
{ {
icon: 'export-pdf', key: 'export-pdf',
link: 'pdf', link: 'pdf',
resource: 'workPackage' resource: 'workPackage'
}, },
{ {
icon: 'export-atom', key: 'export-atom',
link: 'atom', link: 'atom',
resource: 'workPackage' resource: 'workPackage'
} }

@ -30,15 +30,15 @@
import {opWorkPackagesModule} from '../../angular-modules'; import {opWorkPackagesModule} from '../../angular-modules';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource'; import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {StateService} from '@uirouter/core'; import {StateService} from '@uirouter/core';
import {PathHelperService} from "core-components/common/path-helper/path-helper.service";
var $state:StateService;
var PathHelper:any;
export class WorkPackageAuthorization { export class WorkPackageAuthorization {
public project:any; public project:any;
constructor(public workPackage:WorkPackageResource) { constructor(public workPackage:WorkPackageResource,
readonly PathHelper:PathHelperService,
readonly $state:StateService) {
this.project = workPackage.project; this.project = workPackage.project;
} }
@ -50,12 +50,11 @@ export class WorkPackageAuthorization {
} }
public copyLink() { public copyLink() {
const stateName = $state.current.name as string; const stateName = this.$state.current.name as string;
if (stateName.indexOf('work-packages.show') === 0) { if (stateName.indexOf('work-packages.list.details') === 0) {
return PathHelper.workPackageCopyPath(this.workPackage.id); return this.PathHelper.workPackageDetailsCopyPath(this.project.identifier, this.workPackage.id);
} } else {
else if (stateName.indexOf('work-packages.list.details') === 0) { return this.PathHelper.workPackageCopyPath(this.workPackage.id);
return PathHelper.workPackageDetailsCopyPath(this.project.identifier, this.workPackage.id);
} }
} }
@ -91,15 +90,3 @@ export class WorkPackageAuthorization {
return allowed; return allowed;
} }
} }
function wpAuthorizationService(...args:any[]) {
[$state, PathHelper] = args;
return WorkPackageAuthorization;
}
wpAuthorizationService.$inject = [
'$state',
'PathHelper'
];
opWorkPackagesModule.factory('WorkPackageAuthorization', wpAuthorizationService);

@ -34,6 +34,7 @@ import {UrlParamsHelperService} from 'core-components/wp-query/url-params-helper
export type WorkPackageAction = { export type WorkPackageAction = {
text:string; text:string;
key:string;
icon?:string; icon?:string;
link:string; link:string;
href?:string; href?:string;

Loading…
Cancel
Save