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=========================================================
20 /// <reference path="../../../../../../references"/>>
21 module Sdc.ViewModels {
24 interface IRelationsViewModelScope extends ICompositionViewModelScope {
26 $parent: ICompositionViewModelScope;
27 getRelation(requirement:any): any;
30 export class RelationsViewModel {
37 constructor(private $scope:IRelationsViewModelScope,
38 private $filter:ng.IFilterService) {
43 private updateRC = ():void =>{
44 if(this.$scope.currentComponent) {
45 this.$scope.currentComponent.updateRequirementsCapabilities();
49 private initScope = ():void => {
51 this.$scope.isLoading = this.$scope.$parent.isLoading;
53 this.$scope.getRelation = (requirement:any):any => {
55 if(this.$scope.isComponentInstanceSelected() && this.$scope.currentComponent.componentInstancesRelations ) {
56 let relationItem = _.filter(this.$scope.currentComponent.componentInstancesRelations, (relation:any) => {
57 return relation.fromNode === this.$scope.currentComponent.selectedInstance.uniqueId &&
58 _.some(relation.relationships, {'requirement': requirement.name,
59 'requirementOwnerId': requirement.ownerId});
62 if (relationItem && relationItem.length) {
64 type: requirement.relationship.split('.').pop(),
65 requirementName: this.$filter('resourceName')(this.$scope.currentComponent.componentInstances[_.map
66 (this.$scope.currentComponent.componentInstances, "uniqueId").indexOf(relationItem[0].toNode)].name)
73 if(!this.$scope.isComponentInstanceSelected()) {
74 this.$scope.$watch('currentComponent.componentInstances + currentComponent.componentInstancesRelations', ():void => {