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

Update new state name when route changes

Oliver Günthere9ebff678553
diff --git a/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.component.ts b/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.component.ts
index 4d2f2b4f2f1..9aaa15586bb 100644
--- a/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.component.ts
+++ b/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.component.ts
@@ -32,6 +32,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {CurrentProjectService} from "core-components/projects/current-project.service";
import {AuthorisationService} from "core-app/modules/common/model-auth/model-auth.service";
import {componentDestroyed} from "ng2-rx-componentdestroyed";
+import {Observable} from "rxjs";
@Component({
selector: 'wp-create-button',
@@ -40,7 +41,7 @@ import {componentDestroyed} from "ng2-rx-componentdestroyed";
})
export class WorkPackageCreateButtonComponent implements OnInit, OnDestroy {
@Input('allowed') allowedWhen:string[];
- @Input('stateName') stateName:string;
+ @Input('stateName$') stateName$:Observable<string>;
allowed:boolean;
disabled:boolean
@@ -88,10 +89,6 @@ export class WorkPackageCreateButtonComponent implements OnInit, OnDestroy {
this.transitionUnregisterFn();
}
- createWorkPackage() {
- this.$state.go(this.stateName, {projectPath: this.projectIdentifier});
- }
-
private updateDisabledState() {
this.disabled = !this.allowed || this.$state.includes('**.new');
this.cdRef.detectChanges();
diff --git a/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.html b/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.html
index 5bc00757609..4d5ea36b766 100644
--- a/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.html
+++ b/frontend/src/app/components/wp-buttons/wp-create-button/wp-create-button.html
@@ -4,7 +4,7 @@
[attr.aria-label]="text.explanation"
opTypesCreateDropdown
[projectIdentifier]="projectIdentifier"
- [stateName]="stateName"
+ [stateName]="stateName$ | async"
[dropdownActive]="allowed">
<op-icon icon-classes="button--icon icon-add"></op-icon>
<span class="button--text"
diff --git a/frontend/src/app/modules/ifc_models/pages/viewer/ifc-viewer-page.component.ts b/frontend/src/app/modules/ifc_models/pages/viewer/ifc-viewer-page.component.ts
index 73f6d89064e..cffc6c89eac 100644
--- a/frontend/src/app/modules/ifc_models/pages/viewer/ifc-viewer-page.component.ts
+++ b/frontend/src/app/modules/ifc_models/pages/viewer/ifc-viewer-page.component.ts
@@ -20,7 +20,8 @@ import {QueryParamListenerService} from "core-components/wp-query/query-param-li
import {QueryResource} from "core-app/modules/hal/resources/query-resource";
import {BimManageIfcModelsButtonComponent} from "core-app/modules/ifc_models/toolbar/manage-ifc-models-button/bim-manage-ifc-models-button.component";
import {WorkPackageCreateButtonComponent} from "core-components/wp-buttons/wp-create-button/wp-create-button.component";
-import {StateService} from "@uirouter/core";
+import {StateService, TransitionService} from "@uirouter/core";
+import {BehaviorSubject, Subject} from "rxjs";
@Component({
templateUrl: '/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',
@@ -42,11 +43,14 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
areYouSure: this.I18n.t('js.text_are_you_sure')
};
+ newRoute$ = new BehaviorSubject<string>(this.state.current.data.newRoute);
+ transitionUnsubscribeFn:Function;
+
toolbarButtonComponents:ToolbarButtonComponentDefinition[] = [
{
component: WorkPackageCreateButtonComponent,
inputs: {
- stateName: this.state.current.data.newRoute || 'bim.partitioned.split.new',
+ stateName$: this.newRoute$,
allowed: ['work_packages.createWorkPackage', 'work_package.copy']
}
},
@@ -79,6 +83,7 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
constructor(readonly ifcData:IfcModelsDataService,
readonly state:StateService,
readonly bimView:BimViewService,
+ readonly transition:TransitionService,
readonly gon:GonService,
readonly injector:Injector) {
super(injector);
@@ -93,6 +98,17 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
.subscribe((view) => {
this.filterAllowed = view !== bimViewerViewIdentifier;
});
+
+ // Keep the new route up to date depending on where we move to
+ this.transitionUnsubscribeFn = this.transition.onSuccess({}, () => {
+ this.newRoute$.next(this.state.current.data.newRoute);
+ });
+ }
+
+ ngOnDestroy():void {
+ super.ngOnDestroy();
+
+
}
/**
diff --git a/frontend/src/app/modules/work_packages/routing/wp-view-page/wp-view-page.component.ts b/frontend/src/app/modules/work_packages/routing/wp-view-page/wp-view-page.component.ts
index 547dec901eb..48e220b6c22 100644
--- a/frontend/src/app/modules/work_packages/routing/wp-view-page/wp-view-page.component.ts
+++ b/frontend/src/app/modules/work_packages/routing/wp-view-page/wp-view-page.component.ts
@@ -46,6 +46,7 @@ import {BcfImportButtonComponent} from "core-app/modules/bcf/bcf-buttons/bcf-imp
import {BcfExportButtonComponent} from "core-app/modules/bcf/bcf-buttons/bcf-export-button.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 {Observable, of} from "rxjs";
@Component({
selector: 'wp-view-page',
@@ -66,7 +67,7 @@ export class WorkPackageViewPageComponent extends PartitionedQuerySpacePageCompo
{
component: WorkPackageCreateButtonComponent,
inputs: {
- stateName: "work-packages.partitioned.list.new",
+ stateName$: of("work-packages.partitioned.list.new"),
allowed: ['work_packages.createWorkPackage']
}
},