From 7a7b9a71ca26ba0b8708d5fc66e18568bb5ba70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 11 Jul 2016 08:34:24 +0200 Subject: [PATCH] Avoid early observing of work package before constructor has completed --- .../routing/wp-details/wp-details.controller.ts | 1 + .../routing/wp-show/wp-show.controller.ts | 2 +- .../wp-view-base/wp-view-base.controller.ts | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frontend/app/components/routing/wp-details/wp-details.controller.ts b/frontend/app/components/routing/wp-details/wp-details.controller.ts index 945b491e6b..b54d89d17c 100644 --- a/frontend/app/components/routing/wp-details/wp-details.controller.ts +++ b/frontend/app/components/routing/wp-details/wp-details.controller.ts @@ -35,6 +35,7 @@ export class WorkPackageDetailsController extends WorkPackageViewController { public $scope, public $state) { super($injector, $scope, $state.params['workPackageId']); + this.observeWorkPackage(); } public onWorkPackageSave() { diff --git a/frontend/app/components/routing/wp-show/wp-show.controller.ts b/frontend/app/components/routing/wp-show/wp-show.controller.ts index e0131eac7b..dbbe797f3d 100644 --- a/frontend/app/components/routing/wp-show/wp-show.controller.ts +++ b/frontend/app/components/routing/wp-show/wp-show.controller.ts @@ -26,7 +26,6 @@ // See doc/COPYRIGHT.rdoc for more details. // ++ -import {WorkPackageEditModeStateService} from "../../wp-edit/wp-edit-mode-state.service"; import {wpControllersModule} from '../../../angular-modules'; import {WorkPackageViewController} from '../wp-view-base/wp-view-base.controller'; import {WorkPackageResourceInterface} from '../../api/api-v3/hal-resources/work-package-resource.service'; @@ -60,6 +59,7 @@ export class WorkPackageShowController extends WorkPackageViewController { public WorkPackageAuthorization, public PERMITTED_MORE_MENU_ACTIONS) { super($injector, $scope, $state.params['workPackageId']); + this.observeWorkPackage(); } protected init() { diff --git a/frontend/app/components/routing/wp-view-base/wp-view-base.controller.ts b/frontend/app/components/routing/wp-view-base/wp-view-base.controller.ts index a091807f2e..50c345893d 100644 --- a/frontend/app/components/routing/wp-view-base/wp-view-base.controller.ts +++ b/frontend/app/components/routing/wp-view-base/wp-view-base.controller.ts @@ -47,7 +47,7 @@ export class WorkPackageViewController { // Helper promise to detect when the controller has been initialized // (when a WP has loaded). - public initialized:ng.IPromise; + public initialized:ng.IDeferred; // Static texts public text:any = {}; @@ -63,15 +63,20 @@ export class WorkPackageViewController { this.$inject('$q', '$state', 'keepTab', 'wpCacheService', 'WorkPackageService', 'wpEditModeState', 'PathHelper', 'I18n'); - var deferred = this.$q.defer(); - this.initialized = deferred.promise; + this.initialized = this.$q.defer(); this.initializeTexts(); + } - scopedObservable($scope, this.wpCacheService.loadWorkPackage(workPackageId)) + /** + * Observe changes of work package and re-run initialization. + * Needs to be run explicitly by descendants. + */ + protected observeWorkPackage() { + scopedObservable(this.$scope, this.wpCacheService.loadWorkPackage(this.workPackageId)) .subscribe((wp:WorkPackageResourceInterface) => { this.workPackage = wp; this.init(); - deferred.resolve(); + this.initialized.resolve(); }); }