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=========================================================
21 import * as _ from "lodash";
22 import {Match, ConnectRelationModel} from "app/models";
23 import {Component} from "../../../models/components/component";
25 export interface IRelationMenuScope extends ng.IScope {
26 relationMenuDirectiveObj:ConnectRelationModel;
27 createRelation:Function;
28 isLinkMenuOpen:boolean;
29 hideRelationMatch:Function;
33 showMatch(arr1:Array<Match>, arr2:Array<Match>):boolean;
34 hasMatchesToShow(matchesObj:Match, selectedMatch:Array<Match>);
35 updateSelectionText():void;
40 export class RelationMenuDirective implements ng.IDirective {
42 constructor(private $filter:ng.IFilterService) {
46 relationMenuDirectiveObj: '=',
54 template = ():string => {
55 return require('./relation-menu.html');
58 link = (scope:IRelationMenuScope, element:JQuery, $attr:ng.IAttributes) => {
60 scope.saveRelation = ():void=> {
61 let chosenMatches:Array<any> = _.intersection(scope.relationMenuDirectiveObj.rightSideLink.selectedMatch, scope.relationMenuDirectiveObj.leftSideLink.selectedMatch);
62 let chosenMatch:Match = chosenMatches[0];
63 scope.createRelation()(chosenMatch);
67 scope.hideRelationMatch = () => {
68 scope.isLinkMenuOpen = false;
72 //to show options in link menu
73 scope.showMatch = (arr1:Array<Match>, arr2:Array<Match>):boolean => {
74 return !arr1 || !arr2 || _.intersection(arr1, arr2).length > 0;
77 //to show requirements/capabilities title
78 scope.hasMatchesToShow = (matchesObj:Match, selectedMatch:Array<Match>):boolean => {
79 let result:boolean = false;
80 _.forEach(matchesObj, (matchesArr:Array<Match>) => {
82 result = scope.showMatch(matchesArr, selectedMatch);
89 scope.updateSelectionText = ():void => {
90 let left:string = scope.relationMenuDirectiveObj.leftSideLink.selectedMatch ? this.$filter('resourceName')(scope.relationMenuDirectiveObj.leftSideLink.selectedMatch[0].getDisplayText('left')) : '';
91 let both:string = scope.relationMenuDirectiveObj.leftSideLink.selectedMatch && scope.relationMenuDirectiveObj.rightSideLink.selectedMatch ? ' - ' +
92 this.$filter('resourceName')(scope.relationMenuDirectiveObj.leftSideLink.selectedMatch[0].requirement.relationship) + ' - ' : '';
93 let right:string = scope.relationMenuDirectiveObj.rightSideLink.selectedMatch ? this.$filter('resourceName')(scope.relationMenuDirectiveObj.rightSideLink.selectedMatch[0].getDisplayText('right')) : '';
94 scope.relationMenuDirectiveObj.selectionText = left + both + right;
99 public static factory = ($filter:ng.IFilterService)=> {
100 return new RelationMenuDirective($filter);
104 RelationMenuDirective.factory.$inject = ['$filter'];