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 {ComponentInstance} from "../../../componentsInstances/componentInstance";
22 import {CommonCINodeBase} from "../common-ci-node-base";
23 import {ICanvasImage, ImageCreatorService} from "app/directives/graphs-v2/image-creator/image-creator.service";
24 import {ImagesUrl, GraphUIObjects} from "app/utils";
25 import {AngularJSBridge} from "app/services";
27 export interface ICompositionCiNodeBase {
31 export abstract class CompositionCiNodeBase extends CommonCINodeBase implements ICompositionCiNodeBase {
33 public textPosition:string; //need to move to cp UCPE
34 public isUcpe:boolean;
35 public isInsideGroup:boolean;
36 public isUcpePart:boolean;
38 constructor(instance:ComponentInstance,
39 public imageCreator:ImageCreatorService) {
45 this.displayName = this.getDisplayName();
48 this.isUcpePart = false;
49 this.isInsideGroup = false;
53 public setUncertifiedImageBgStyle(node:Cy.Collection, nodeMinSize:number):string {
55 let uncertifiedIconWidth:number = GraphUIObjects.HANDLE_SIZE;
56 let nodeWidth:number = node.data('imgWidth') || node.width();
57 let uncertifiedCanvasWidth: number = nodeWidth;
59 if (nodeWidth < nodeMinSize) { //uncertified icon will overlap too much of the node, need to expand canvas.
60 uncertifiedCanvasWidth = nodeWidth + uncertifiedIconWidth/2; //expand canvas so that only half of the icon overlaps with the node
63 const x = uncertifiedCanvasWidth - nodeWidth, y = x, width = nodeWidth, height = width;
65 const canvasImages:ICanvasImage[] = [
66 { src: this.imagesPath + this.componentInstance.icon + '.png', x, y, width, height},
67 { src: this.imagesPath + 'uncertified.png', x: 0, y: 0, width: uncertifiedIconWidth, height: uncertifiedIconWidth}
71 //Create the image and update the node background styles
72 this.imageCreator.getMultiLayerBase64Image(canvasImages, uncertifiedCanvasWidth, uncertifiedCanvasWidth).then(img => this.updateNodeStyles(node,uncertifiedCanvasWidth,img));
73 return this.img; // Return the referance to the image (in Base64 format)
77 public setArchivedImageBgStyle(node:Cy.Collection, nodeMinSize:number):string {
78 let archivedIconWidth:number = GraphUIObjects.HANDLE_SIZE;
79 let nodeWidth:number = node.data('imgWidth') || node.width();
80 let archivedCanvasWidth: number = nodeWidth;
82 const x = archivedCanvasWidth - nodeWidth, y = x, width = nodeWidth, height = width;
83 const archiveImage = nodeWidth < 50? 'archive_small.png':'archive_big.png';
85 const canvasImages = [
86 { src: this.imagesPath + this.componentInstance.icon + '.png', x, y, width, height},
87 { src: AngularJSBridge.getAngularConfig().imagesPath + ImagesUrl.RESOURCE_ICONS + archiveImage, x, y, width, height}
90 //Create the image and update the node background styles
91 this.imageCreator.getMultiLayerBase64Image(canvasImages, archivedCanvasWidth, archivedCanvasWidth).then(img => this.updateNodeStyles(node, archivedCanvasWidth, img));
92 return this.img; // Return the default img
95 protected getDisplayName():string {
96 let graphResourceName = AngularJSBridge.getFilter('graphResourceName');
97 let resourceName = AngularJSBridge.getFilter('resourceName');
98 return graphResourceName(resourceName(this.componentInstance.name));
101 //TODO:: move to Base class ???
102 private updateNodeStyles(node,canvasWidth,imageBase64){
103 this.img = imageBase64;
105 'background-image': this.img,
106 'background-width': canvasWidth,
107 'background-height': canvasWidth,
108 'background-position-x':0,
109 'background-position-y':0