|
|
@ -29,6 +29,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
import {openprojectModule} from "../../angular-modules"; |
|
|
|
import {openprojectModule} from "../../angular-modules"; |
|
|
|
import WorkPackageResource from "../api/api-v3/hal-resources/work-package-resource.service"; |
|
|
|
import WorkPackageResource from "../api/api-v3/hal-resources/work-package-resource.service"; |
|
|
|
|
|
|
|
import {ApiWorkPackagesService} from "../api/api-work-packages/api-work-packages.service"; |
|
|
|
|
|
|
|
import IScope = angular.IScope; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class WorkPackageCacheService { |
|
|
|
export class WorkPackageCacheService { |
|
|
@ -38,11 +40,13 @@ export class WorkPackageCacheService { |
|
|
|
workPackagesSubject = new Rx.ReplaySubject<{[id: number]: WorkPackageResource}>(1); |
|
|
|
workPackagesSubject = new Rx.ReplaySubject<{[id: number]: WorkPackageResource}>(1); |
|
|
|
|
|
|
|
|
|
|
|
/*@ngInject*/ |
|
|
|
/*@ngInject*/ |
|
|
|
constructor(private $rootScope) { |
|
|
|
constructor(private $rootScope: IScope, private apiWorkPackages: ApiWorkPackagesService) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updateWorkPackage(wp: WorkPackageResource) { |
|
|
|
updateWorkPackage(wp: WorkPackageResource) { |
|
|
|
this.updateWorkPackageList([wp]); |
|
|
|
this.updateWorkPackageList([wp]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// romanroe: TODO Remove. Only required for 'old' API consumers.
|
|
|
|
this.$rootScope.$broadcast('workPackageRefreshRequired'); |
|
|
|
this.$rootScope.$broadcast('workPackageRefreshRequired'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -53,7 +57,13 @@ export class WorkPackageCacheService { |
|
|
|
this.workPackagesSubject.onNext(this.workPackageCache); |
|
|
|
this.workPackagesSubject.onNext(this.workPackageCache); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
loadWorkPackage(workPackageId: number): Rx.Observable<WorkPackageResource> { |
|
|
|
loadWorkPackage(workPackageId: number, forceUpdate = false): Rx.Observable<WorkPackageResource> { |
|
|
|
|
|
|
|
if (forceUpdate || this.workPackageCache[workPackageId] === undefined) { |
|
|
|
|
|
|
|
this.apiWorkPackages.loadWorkPackageById(workPackageId).then(wp => { |
|
|
|
|
|
|
|
this.updateWorkPackage(wp); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.workPackagesSubject |
|
|
|
return this.workPackagesSubject |
|
|
|
.map(cache => cache[workPackageId]) |
|
|
|
.map(cache => cache[workPackageId]) |
|
|
|
.filter(wp => wp !== undefined); |
|
|
|
.filter(wp => wp !== undefined); |
|
|
|