Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Extract back button into separate component to make it reusable

Henriette Dinger65a6728a6441
diff --git a/frontend/src/app/modules/boards/board/board.component.html b/frontend/src/app/modules/boards/board/board.component.html
index 2a37dabfebe..cdad782a58d 100644
--- a/frontend/src/app/modules/boards/board/board.component.html
+++ b/frontend/src/app/modules/boards/board/board.component.html
@@ -6,12 +6,10 @@
<div class="toolbar-container -editable">
<div id="toolbar">
<div class="title-container board--header-container">
- <div class="wp-show--back-button hide-when-print">
- <accessible-by-keyboard (execute)="goBack()"
- linkClass="board--back-button button">
- <op-icon icon-classes="button--icon icon-back-up"></op-icon>
- </accessible-by-keyboard>
- </div>
+
+ <back-button linkClass="board--back-button"
+ [customBackMethod]="goBack.bind(this)">
+ </back-button>
<editable-toolbar-title [title]="board.name"
[inFlight]="inFlight"
diff --git a/frontend/src/app/modules/common/back-routing/back-button.component.ts b/frontend/src/app/modules/common/back-routing/back-button.component.ts
new file mode 100644
index 00000000000..cecb7c61dd3
--- /dev/null
+++ b/frontend/src/app/modules/common/back-routing/back-button.component.ts
@@ -0,0 +1,66 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2020 the OpenProject GmbH
+//
+// 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 docs/COPYRIGHT.rdoc for more details.
+// ++
+
+import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
+import {BackRoutingService} from "core-app/modules/common/back-routing/back-routing.service";
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+
+@Component({
+ template: `
+ <div class="wp-show--back-button hide-when-print">
+ <accessible-by-keyboard (execute)="goBack()"
+ [linkClass]="linkClass + ' button'"
+ [linkAriaLabel]="text.goBack"
+ [linkTitle]="text.goBack">
+ <op-icon icon-classes="button--icon icon-back-up"></op-icon>
+ </accessible-by-keyboard>
+ </div>
+ `,
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ selector: 'back-button',
+})
+export class BackButtonComponent {
+ @Input() public linkClass:string;
+ @Input() public customBackMethod:Function;
+
+ public text = {
+ goBack: this.I18n.t('js.button_back')
+ };
+
+ constructor(readonly backRoutingService:BackRoutingService,
+ readonly I18n:I18nService,) {
+ }
+
+ public goBack() {
+ if (this.customBackMethod) {
+ this.customBackMethod();
+ } else {
+ this.backRoutingService.goBack();
+ }
+ }
+}
diff --git a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts
index 089bda861fd..05b36e7d4d8 100644
--- a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts
@@ -166,9 +166,8 @@ import {TimeEntryChangeset} from 'core-app/components/time-entries/time-entry-ch
import {WorkPackageListViewComponent} from "core-app/modules/work_packages/routing/wp-list-view/wp-list-view.component";
import {PartitionedQuerySpacePageComponent} from "core-app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component";
import {WorkPackageViewPageComponent} from "core-app/modules/work_packages/routing/wp-view-page/wp-view-page.component";
-import {ZenModeButtonComponent} from "core-components/wp-buttons/zen-mode-toggle-button/zen-mode-toggle-button.component";
import {WorkPackageSettingsButtonComponent} from "core-components/wp-buttons/wp-settings-button/wp-settings-button.component";
-import {WorkPackageCreateComponent} from "core-components/wp-new/wp-create.component";
+import {BackButtonComponent} from "core-app/modules/common/back-routing/back-button.component";
@NgModule({
@@ -312,6 +311,7 @@ import {WorkPackageCreateComponent} from "core-components/wp-new/wp-create.compo
WorkPackageChildrenQueryComponent,
WorkPackageRelationQueryComponent,
WorkPackageFormAttributeGroupComponent,
+ BackButtonComponent,
// Activity Tab
NewestActivityOnOverviewComponent,
@@ -393,11 +393,6 @@ import {WorkPackageCreateComponent} from "core-components/wp-new/wp-create.compo
WorkPackageIsolatedGraphQuerySpaceDirective,
QueryFiltersComponent,
- // Needed so that e.g. IFC can access it.
- WorkPackageCreateButtonComponent,
- WorkPackageTypeStatusComponent,
- WorkPackageEditActionsBarComponent,
- WorkPackageSingleViewComponent,
WpResizerDirective,
WorkPackageBreadcrumbComponent,
WorkPackageBreadcrumbParentComponent,
@@ -416,7 +411,8 @@ import {WorkPackageCreateComponent} from "core-components/wp-new/wp-create.compo
WorkPackageTypeStatusComponent,
WorkPackageEditActionsBarComponent,
WorkPackageSingleViewComponent,
- WorkPackageSplitViewComponent
+ WorkPackageSplitViewComponent,
+ BackButtonComponent
]
})
export class OpenprojectWorkPackagesModule {
diff --git a/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.component.ts
index 5b3bcfae8a2..5d547e986ff 100644
--- a/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.component.ts
+++ b/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.component.ts
@@ -31,7 +31,6 @@ import {StateService} from '@uirouter/core';
import {Component, Injector, OnInit} from '@angular/core';
import {WorkPackageViewSelectionService} from 'core-app/modules/work_packages/routing/wp-view-base/view-services/wp-view-selection.service';
import {WorkPackageSingleViewBase} from "core-app/modules/work_packages/routing/wp-view-base/work-package-single-view.base";
-import {BackRoutingService} from "core-app/modules/common/back-routing/back-routing.service";
import {of} from "rxjs";
@Component({
@@ -55,7 +54,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
constructor(public injector:Injector,
public wpTableSelection:WorkPackageViewSelectionService,
- public backRoutingService:BackRoutingService,
readonly $state:StateService) {
super(injector, $state.params['workPackageId']);
}
@@ -79,12 +77,8 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.wpTableFocus.updateFocus(this.workPackage.id!);
this.setWorkPackageScopeProperties(this.workPackage);
- this.text.goBack = this.I18n.t('js.button_back');
}
- public goBack() {
- this.backRoutingService.goBack();
- }
private setWorkPackageScopeProperties(wp:WorkPackageResource) {
this.isWatched = wp.hasOwnProperty('unwatch');
this.displayWatchButton = wp.hasOwnProperty('unwatch') || wp.hasOwnProperty('watch');
diff --git a/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.html b/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.html
index 36c596aaa01..906a131fcc0 100644
--- a/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.html
+++ b/frontend/src/app/modules/work_packages/routing/wp-full-view/wp-full-view.html
@@ -8,14 +8,9 @@
<div class="toolbar-container">
<div id="toolbar">
<div class="wp-show--header-container">
- <div class="wp-show--back-button hide-when-print">
- <accessible-by-keyboard (execute)="goBack()"
- linkClass="work-packages-back-button button"
- [linkAriaLabel]="text.goBack"
- [linkTitle]="text.goBack">
- <op-icon icon-classes="button--icon icon-back-up"></op-icon>
- </accessible-by-keyboard>
- </div>
+
+ <back-button linkClass="work-packages-back-button"></back-button>
+
<ul class="subject-header">
<li class="subject-header-inner">
<wp-subject></wp-subject>