2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * Created by ob0695 on 5/9/2017.
25 * Created by ob0695 on 5/9/2017.
28 * Created by obarda on 1/8/2017.
31 import {RequirementsGroup, Component, Relationship, RelationshipModel} from "app/models";
33 export interface IRequirementsListScope extends ng.IScope {
35 requirements:RequirementsGroup;
36 currentComponent: Component;
40 export class RequirementsListDirective implements ng.IDirective {
42 constructor(private $filter: ng.IFilterService) {
53 template = ():string => {
54 return require('./requirements-list-view.html');
57 link = (scope:IRequirementsListScope) => {
59 scope.isInstanceSelected = () : boolean => {
60 return scope.component && scope.component.selectedInstance != undefined && scope.component.selectedInstance != null;
63 scope.getRelation = (requirement:any):any => {
64 if (scope.isInstanceSelected() && scope.component.componentInstancesRelations) {
65 let relationItem:Array<RelationshipModel> = _.filter((<Component>scope.component).componentInstancesRelations, (relation:RelationshipModel) => {
66 return relation.fromNode === scope.component.selectedInstance.uniqueId &&
67 _.filter(relation.relationships, (relationship:Relationship) => {
68 return relationship.relation.requirement == requirement.name && relationship.relation.requirementOwnerId == requirement.ownerId;
72 if (relationItem && relationItem.length) {
74 type: requirement.relationship.split('.').pop(),
75 requirementName: this.$filter('resourceName')(scope.component.componentInstances[_.map
76 (scope.component.componentInstances, "uniqueId").indexOf(relationItem[0].toNode)].name)
85 public static factory = ($filter: ng.IFilterService)=> {
86 return new RequirementsListDirective($filter);
90 RequirementsListDirective.factory.$inject = ['$filter'];