From 4af41a03506f128ad208f746f9d96dda0cf2885f Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Mon, 20 Jun 2016 15:23:11 +0200 Subject: [PATCH] Load relations on directive initialisation This fixes an issue, where the relations of a work package wouldn't be loaded and thus not shown. --- .../hal-resources/collection-resource.service.ts | 9 ++++++++- .../work-package-resource.service.ts | 9 +++++---- .../relations-panel/relations-panel.directive.ts | 15 ++++----------- .../wp-relation-group.service.ts | 5 +++-- .../wp-relations/wp-relations.directive.ts | 6 +++--- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/collection-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/collection-resource.service.ts index 969d0bd2c6..4b4caa12ad 100644 --- a/frontend/app/components/api/api-v3/hal-resources/collection-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/collection-resource.service.ts @@ -27,7 +27,11 @@ //++ import {HalResource} from './hal-resource.service'; -import {opApiModule} from "../../../../angular-modules"; +import {opApiModule} from '../../../../angular-modules'; + +interface CollectionResourceEmbedded { + elements: HalResource[] & any; +} export class CollectionResource extends HalResource { public getElements() { @@ -35,6 +39,9 @@ export class CollectionResource extends HalResource { } } +export interface CollectionResourceInterface extends CollectionResourceEmbedded, CollectionResource { +} + function collectionResource() { return CollectionResource; } diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index 730733de88..18a6255cf1 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -27,10 +27,11 @@ //++ import {HalResource} from './hal-resource.service'; -import {opApiModule} from "../../../../angular-modules"; -import {WorkPackageCacheService} from "../../../work-packages/work-package-cache.service"; -import {ApiWorkPackagesService} from "../../api-work-packages/api-work-packages.service"; +import {opApiModule} from '../../../../angular-modules'; +import {WorkPackageCacheService} from '../../../work-packages/work-package-cache.service'; +import {ApiWorkPackagesService} from '../../api-work-packages/api-work-packages.service'; import IQService = angular.IQService; +import {CollectionResourceInterface} from './collection-resource.service'; interface WorkPackageResourceEmbedded { activities:HalResource|any; @@ -43,7 +44,7 @@ interface WorkPackageResourceEmbedded { parent:HalResource|any; priority:HalResource|any; project:HalResource|any; - relations:HalResource[]|any[] + relations:CollectionResourceInterface; responsible:HalResource|any; schema:HalResource|any; status:HalResource|any; diff --git a/frontend/app/components/wp-panels/relations-panel/relations-panel.directive.ts b/frontend/app/components/wp-panels/relations-panel/relations-panel.directive.ts index 3c903c7a20..6586f1945d 100644 --- a/frontend/app/components/wp-panels/relations-panel/relations-panel.directive.ts +++ b/frontend/app/components/wp-panels/relations-panel/relations-panel.directive.ts @@ -36,8 +36,7 @@ export class RelationsPanelController { public relationTitles; public relationGroups; - constructor($scope, - I18n: op.I18n, + constructor(I18n: op.I18n, wpRelations:WorkPackageRelationsService) { this.relationTitles = { @@ -52,15 +51,9 @@ export class RelationsPanelController { follows: I18n.t('js.relation_buttons.add_follows') }; - this.relationGroups = wpRelations.getWpRelationGroups(this.workPackage); - - // $scope.wpChildren = new ChildRelationsHandler(this.workPackage); - // - // - // if (this.workPackage.children) { - // $scope.wpChildren = new ChildRelationsHandler(this.workPackage, this.workPackage.children); - // } - // + this.workPackage.relations.$load().then(() => { + this.relationGroups = wpRelations.getWpRelationGroups(this.workPackage); + }); } } diff --git a/frontend/app/components/wp-relations/wp-relation-group/wp-relation-group.service.ts b/frontend/app/components/wp-relations/wp-relation-group/wp-relation-group.service.ts index de21a0abcb..a4d19ad76e 100644 --- a/frontend/app/components/wp-relations/wp-relation-group/wp-relation-group.service.ts +++ b/frontend/app/components/wp-relations/wp-relation-group/wp-relation-group.service.ts @@ -118,9 +118,10 @@ export class WorkPackageRelationGroup { } protected init() { - if (Array.isArray(this.workPackage.relations)) { + const elements = this.workPackage.relations.elements; + if (Array.isArray(elements)) { this.relations.push( - ...this.workPackage.relations.filter(relation => relation._type === this.type)); + ...elements.filter(relation => relation._type === this.type)); } } } diff --git a/frontend/app/components/wp-relations/wp-relations.directive.ts b/frontend/app/components/wp-relations/wp-relations.directive.ts index cbab8f064e..009334bd6d 100644 --- a/frontend/app/components/wp-relations/wp-relations.directive.ts +++ b/frontend/app/components/wp-relations/wp-relations.directive.ts @@ -26,8 +26,8 @@ // See doc/COPYRIGHT.rdoc for more details. //++ -import {wpTabsModule} from "../../angular-modules"; -import {WorkPackageRelationGroup} from "./wp-relation-group/wp-relation-group.service"; +import {wpTabsModule} from '../../angular-modules'; +import {WorkPackageRelationGroup} from './wp-relation-group/wp-relation-group.service'; const iconArrowClasses = ['icon-arrow-up1', 'icon-arrow-down1']; @@ -48,7 +48,7 @@ export class WorkPackageRelationsController { } public get groupExpanded() { - if (angular.isUndefined(this._initialExpand)) { + if (angular.isUndefined(this._initialExpand) && !this.relationGroup.isEmpty) { this._initialExpand = this.expand = !this.relationGroup.isEmpty; } return this.expand;