From e265af85f93e756f4c90d9d5ae0832a3f3e4a9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 1 Nov 2016 17:46:26 +0100 Subject: [PATCH] Normalize the relation type depending on direction The frontend needs to normalize the relationType retrieved from the API to either that, or reverseType when the shown work package is the `to` link. This PR also extends the relations spec to test exactly that. --- .../relation-resource.service.ts | 9 ++++ .../wp-relation-row.directive.ts | 14 ++++- .../wp-relation-row.template.html | 9 ++-- .../dynamic-relation-types.template.html | 4 +- .../wp-relations-group.template.html | 3 +- .../details/details_relations_spec.rb | 52 ++++++++++++++++++- 6 files changed, 84 insertions(+), 7 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/relation-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/relation-resource.service.ts index 4f7c90b6b6..016c848807 100644 --- a/frontend/app/components/api/api-v3/hal-resources/relation-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/relation-resource.service.ts @@ -65,12 +65,21 @@ export class RelationResource extends HalResource { public description:string|null; public name:string; public type:string; + public reverseType:string; // Links public $links: RelationResourceLinks; public to:WorkPackageResource; public from:WorkPackageResource; + public normalizedType(workPackage:WorkPackageResource) { + if (this.to.href === workPackage.href) { + return this.reverseType; + } + + return this.type; + } + public updateDescription(description) { return this.$links.updateImmediately({ description: description }); } diff --git a/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.directive.ts b/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.directive.ts index 6a419dfd6c..6129fd6e02 100644 --- a/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.directive.ts +++ b/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.directive.ts @@ -2,6 +2,7 @@ import {wpDirectivesModule} from '../../../angular-modules'; import {RelatedWorkPackage} from '../wp-relations.interfaces'; import {WorkPackageCacheService} from '../../work-packages/work-package-cache.service'; import {WorkPackageNotificationService} from '../../wp-edit/wp-notification.service'; +import {WorkPackageResourceInterface} from '../../api/api-v3/hal-resources/work-package-resource.service'; import {WorkPackageRelationsService} from '../wp-relations.service'; import { RelationResourceInterface, @@ -9,6 +10,7 @@ import { } from '../../api/api-v3/hal-resources/relation-resource.service'; class WpRelationRowDirectiveController { + public workPackage: WorkPackageResourceInterface; public relatedWorkPackage: RelatedWorkPackage; public relationType: string; public showRelationInfo:boolean = false; @@ -42,6 +44,15 @@ class WpRelationRowDirectiveController { this.selectedRelationType = _.find(this.availableRelationTypes, {'name': this.relation.type}); }; + /** + * Return the normalized relation type for the work package we're viewing. + * That is, normalize `precedes` where the work package is the `to` link. + */ + public get normalizedRelationType() { + var type = this.relation.normalizedType(this.workPackage); + return this.I18n.t('js.relation_labels.' + type); + } + public get relationReady() { return this.relatedWorkPackage && this.relatedWorkPackage.$loaded; } @@ -90,7 +101,8 @@ function WpRelationRowDirective() { restrict:'E', templateUrl:'/components/wp-relations/wp-relation-row/wp-relation-row.template.html', scope:{ - relatedWorkPackage:'=' + workPackage: '=', + relatedWorkPackage: '=' }, controller:WpRelationRowDirectiveController, controllerAs:'$ctrl', diff --git a/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.template.html b/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.template.html index 17f712b7a9..11962971f5 100644 --- a/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.template.html +++ b/frontend/app/components/wp-relations/wp-relation-row/wp-relation-row.template.html @@ -1,12 +1,14 @@