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

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

@ -30,15 +30,15 @@
import {opWorkPackagesModule} from '../../angular-modules';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {StateService} from '@uirouter/core';
var $state:StateService;
var PathHelper:any;
import {PathHelperService} from "core-components/common/path-helper/path-helper.service";
export class WorkPackageAuthorization {
public project:any;
constructor(public workPackage:WorkPackageResource) {
constructor(public workPackage:WorkPackageResource,
readonly PathHelper:PathHelperService,
readonly $state:StateService) {
this.project = workPackage.project;
}
@ -50,12 +50,11 @@ export class WorkPackageAuthorization {
}
public copyLink() {
const stateName = $state.current.name as string;
if (stateName.indexOf('work-packages.show') === 0) {
return PathHelper.workPackageCopyPath(this.workPackage.id);
}
else if (stateName.indexOf('work-packages.list.details') === 0) {
return PathHelper.workPackageDetailsCopyPath(this.project.identifier, this.workPackage.id);
const stateName = this.$state.current.name as string;
if (stateName.indexOf('work-packages.list.details') === 0) {
return this.PathHelper.workPackageDetailsCopyPath(this.project.identifier, this.workPackage.id);
} else {
return this.PathHelper.workPackageCopyPath(this.workPackage.id);
}
}
@ -91,15 +90,3 @@ export class WorkPackageAuthorization {
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 = {
text:string;
key:string;
icon?:string;
link:string;
href?:string;

Loading…
Cancel
Save