From 32bbbca2bf92d1ebcd277c025ec6ca5870d91083 Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 12 Jun 2019 08:19:45 +0200 Subject: [PATCH] extract wp table config menu trigger into own component --- frontend/src/app/angular4-modules.ts | 3 + .../config-menu/config-menu.component.ts | 30 ++++++ .../config-menu/config-menu.template.html | 7 ++ .../wp-table/wp-table.directive.html | 10 +- .../components/wp-table/wp-table.directive.ts | 8 -- .../board-list/board-list-menu.component.html | 5 + .../board-list/board-list-menu.component.ts | 94 +++++++++++++++++++ .../board-list/board-list.component.html | 9 +- .../board-list/board-list.component.sass | 4 - .../board/board-list/board-list.component.ts | 10 +- .../boards/openproject-boards.module.ts | 6 +- ...icon-triggered-context-menu.component.html | 3 + ...icon-triggered-context-menu.component.sass | 5 + .../icon-triggered-context-menu.component.ts} | 39 +++----- .../openproject-context-menu.module.ts | 52 ++++++++++ .../widgets/wp-table/wp-table.component.html | 36 +++---- .../widgets/wp-table/wp-table.component.ts | 4 +- .../openproject-work-packages.module.ts | 3 + lib/api/helpers/attachment_renderer.rb | 1 - 19 files changed, 252 insertions(+), 77 deletions(-) create mode 100644 frontend/src/app/components/wp-table/config-menu/config-menu.component.ts create mode 100644 frontend/src/app/components/wp-table/config-menu/config-menu.template.html create mode 100644 frontend/src/app/modules/boards/board/board-list/board-list-menu.component.html create mode 100644 frontend/src/app/modules/boards/board/board-list/board-list-menu.component.ts create mode 100644 frontend/src/app/modules/context-menu/icon-triggered-context-menu.component.html create mode 100644 frontend/src/app/modules/context-menu/icon-triggered-context-menu.component.sass rename frontend/src/app/modules/{boards/board/board-list/board-list-dropdown.directive.ts => context-menu/icon-triggered-context-menu.component.ts} (74%) create mode 100644 frontend/src/app/modules/context-menu/openproject-context-menu.module.ts diff --git a/frontend/src/app/angular4-modules.ts b/frontend/src/app/angular4-modules.ts index 2a4392646a6..0714c818ac1 100644 --- a/frontend/src/app/angular4-modules.ts +++ b/frontend/src/app/angular4-modules.ts @@ -86,6 +86,7 @@ import {MainMenuNavigationService} from "core-components/main-menu/main-menu-nav import {StatusCacheService} from "core-components/statuses/status-cache.service"; import {VersionCacheService} from "core-components/versions/version-cache.service"; import {FormsCacheService} from "core-components/forms/forms-cache.service"; +import {OpenprojectContextMenuModule} from "core-app/modules/context-menu/openproject-context-menu.module"; @NgModule({ imports: [ @@ -93,6 +94,8 @@ import {FormsCacheService} from "core-components/forms/forms-cache.service"; BrowserModule, // Commons OpenprojectCommonModule, + // ContextMenus + OpenprojectContextMenuModule, // Router module OpenprojectRouterModule, // Hal Module diff --git a/frontend/src/app/components/wp-table/config-menu/config-menu.component.ts b/frontend/src/app/components/wp-table/config-menu/config-menu.component.ts new file mode 100644 index 00000000000..8079db3a1e8 --- /dev/null +++ b/frontend/src/app/components/wp-table/config-menu/config-menu.component.ts @@ -0,0 +1,30 @@ +import {I18nService} from "core-app/modules/common/i18n/i18n.service"; +import {Component, OnInit, Injector} from '@angular/core'; +import {OpModalService} from "core-components/op-modals/op-modal.service"; +import {OPContextMenuService} from "core-components/op-context-menu/op-context-menu.service"; +import {WpTableConfigurationModalComponent} from "core-components/wp-table/configuration-modal/wp-table-configuration.modal"; + +@Component({ + templateUrl: './config-menu.template.html', + selector: 'wp-table-config-menu', +}) +export class WorkPackagesTableConfigMenu implements OnInit { + public text:any; + + constructor(readonly I18n:I18nService, + readonly injector:Injector, + readonly opModalService:OpModalService, + readonly opContextMenu:OPContextMenuService) { + } + + ngOnInit():void { + this.text = { + configureTable: I18n.t('js.toolbar.settings.configure_view') + }; + } + + public openTableConfigurationModal() { + this.opContextMenu.close(); + this.opModalService.show(WpTableConfigurationModalComponent, this.injector); + } +} diff --git a/frontend/src/app/components/wp-table/config-menu/config-menu.template.html b/frontend/src/app/components/wp-table/config-menu/config-menu.template.html new file mode 100644 index 00000000000..5e33ee5f13b --- /dev/null +++ b/frontend/src/app/components/wp-table/config-menu/config-menu.template.html @@ -0,0 +1,7 @@ + + + diff --git a/frontend/src/app/components/wp-table/wp-table.directive.html b/frontend/src/app/components/wp-table/wp-table.directive.html index ba3cc98fa48..c048fdad115 100644 --- a/frontend/src/app/components/wp-table/wp-table.directive.html +++ b/frontend/src/app/components/wp-table/wp-table.directive.html @@ -32,14 +32,8 @@
- - - + +
diff --git a/frontend/src/app/components/wp-table/wp-table.directive.ts b/frontend/src/app/components/wp-table/wp-table.directive.ts index 0f797e6f542..361434e6be5 100644 --- a/frontend/src/app/components/wp-table/wp-table.directive.ts +++ b/frontend/src/app/components/wp-table/wp-table.directive.ts @@ -112,8 +112,6 @@ export class WorkPackagesTableController implements OnInit, OnDestroy { readonly injector:Injector, readonly states:States, readonly querySpace:IsolatedQuerySpace, - readonly opModalService:OpModalService, - readonly opContextMenu:OPContextMenuService, readonly I18n:I18nService, readonly cdRef:ChangeDetectorRef, readonly wpTableGroupBy:WorkPackageTableGroupByService, @@ -138,7 +136,6 @@ export class WorkPackagesTableController implements OnInit, OnDestroy { title: I18n.t('js.work_packages.no_results.title'), description: I18n.t('js.work_packages.no_results.description') }, - configureTable: I18n.t('js.toolbar.settings.configure_view'), tableSummary: I18n.t('js.work_packages.table.summary'), tableSummaryHints: [ I18n.t('js.work_packages.table.text_inline_edit'), @@ -200,11 +197,6 @@ export class WorkPackagesTableController implements OnInit, OnDestroy { this.cdRef.detectChanges(); } - public openTableConfigurationModal() { - this.opContextMenu.close(); - this.opModalService.show(WpTableConfigurationModalComponent, this.injector); - } - public get isEmbedded() { return this.configuration.isEmbedded; } diff --git a/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.html b/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.html new file mode 100644 index 00000000000..251b91c2133 --- /dev/null +++ b/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.html @@ -0,0 +1,5 @@ + + + + diff --git a/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.ts b/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.ts new file mode 100644 index 00000000000..5c658dd9ff7 --- /dev/null +++ b/frontend/src/app/modules/boards/board/board-list/board-list-menu.component.ts @@ -0,0 +1,94 @@ +//-- copyright +// OpenProject is a project management system. +// Copyright (C) 2012-2015 the OpenProject Foundation (OPF) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +// Copyright (C) 2006-2013 Jean-Philippe Lang +// Copyright (C) 2010-2013 the ChiliProject Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See doc/COPYRIGHT.rdoc for more details. +//++ + +import {Component, Output, EventEmitter, Input} from '@angular/core'; +import {I18nService} from 'core-app/modules/common/i18n/i18n.service'; +import {AuthorisationService} from 'core-app/modules/common/model-auth/model-auth.service'; +import {OpModalService} from "core-components/op-modals/op-modal.service"; +import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space"; +import {Board} from "core-app/modules/boards/board/board"; +import {BoardActionsRegistryService} from "core-app/modules/boards/board/board-actions/board-actions-registry.service"; +import {OpContextMenuItem} from "core-components/op-context-menu/op-context-menu.types"; +import {BoardService} from "core-app/modules/boards/board/board.service"; +import {BoardActionService} from "core-app/modules/boards/board/board-actions/board-action.service"; + +@Component({ + selector: 'board-list-menu', + templateUrl: './board-list-menu.component.html', +}) +export class BoardListMenuComponent { + @Input() board:Board; + @Output() onRemove = new EventEmitter(); + + constructor(readonly opModalService:OpModalService, + readonly authorisationService:AuthorisationService, + private readonly querySpace:IsolatedQuerySpace, + private readonly boardService:BoardService, + private readonly boardActionRegistry:BoardActionsRegistryService, + readonly I18n:I18nService) { + } + + public get menuItems() { + return async () => { + let items:OpContextMenuItem[] = [ + { + disabled: !this.canDelete, + linkText: this.I18n.t('js.boards.lists.delete'), + onClick: () => { + this.onRemove.emit(); + return true; + } + } + ]; + + // Add action specific menu entries + if (this.board.isAction) { + const additional = await this.actionService.getAdditionalListMenuItems(this.query); + return items.concat(additional); + } + + return items; + }; + } + + private get actionService():BoardActionService { + return this.boardActionRegistry.get(this.board.actionAttribute!); + } + + private get canManage() { + return this.boardService.canManage(this.board); + } + + public canDelete() { + return this.canManage && !!this.query.delete; + } + + private get query() { + return this.querySpace.query.value!; + } +} diff --git a/frontend/src/app/modules/boards/board/board-list/board-list.component.html b/frontend/src/app/modules/boards/board/board-list/board-list.component.html index da126a9e0ca..2cb53728388 100644 --- a/frontend/src/app/modules/boards/board/board-list/board-list.component.html +++ b/frontend/src/app/modules/boards/board/board-list/board-list.component.html @@ -24,11 +24,10 @@ class="-small"> -
- - - -
+ +