2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 import React from 'react';
28 import IconFactory from './IconFactory.js';
29 import NodeVisualElementConstants from './NodeVisualElementConstants.js';
31 class NodeVisualElementFactory {
34 this.visualElementMeta = {};
36 this.setVisualElementMeta = this.setVisualElementMeta.bind(this);
37 this.buildVisualElement = this.buildVisualElement.bind(this);
38 this.createSvgCircle = this.createSvgCircle.bind(this);
39 this.createSvgLine = this.createSvgLine.bind(this);
40 this.createTextElement = this.createTextElement.bind(this);
41 this.createImageElement = this.createImageElement.bind(this);
42 this.createObjectElement = this.createObjectElement.bind(this);
43 this.createButtonElement = this.createButtonElement.bind(this);
44 this.applySvgAttributes = this.applySvgAttributes.bind(this);
45 this.applyTransform = this.applyTransform.bind(this);
48 setVisualElementMeta(metaObject) {
49 this.visualElementMeta = metaObject;
52 buildVisualElement(nodeProps, elementType, elementProps, index) {
53 let elementKey = nodeProps.id + index.toString();
54 switch (elementType) {
55 case NodeVisualElementConstants.SVG_CIRCLE:
56 return this.createSvgCircle(elementProps, elementKey);
58 case NodeVisualElementConstants.SVG_LINE:
59 return this.createSvgLine(elementProps, elementKey);
61 case NodeVisualElementConstants.TEXT:
62 return this.createTextElement(nodeProps, elementProps, elementKey);
64 case NodeVisualElementConstants.IMAGE:
65 return this.createImageElement(elementProps, elementKey);
67 case NodeVisualElementConstants.OBJECT:
68 return this.createObjectElement(elementProps, elementKey);
70 case NodeVisualElementConstants.BUTTON:
71 return this.createButtonElement(elementProps, elementKey);
73 case NodeVisualElementConstants.ICON:
74 return this.createButtonElement(elementProps, elementKey, nodeProps);
79 createSvgCircle(circleProps, elementKey) {
81 finalProps[NodeVisualElementConstants.CSS_CLASS] = circleProps.class;
83 finalProps = this.applyTransform(finalProps, circleProps.shapeAttributes);
84 finalProps = this.applySvgAttributes(finalProps, circleProps.svgAttributes);
91 return React.createElement(NodeVisualElementConstants.SVG_CIRCLE,
95 createSvgLine(lineProps, elementKey) {
97 /* Keep this commented code. Will be used again when
98 proper link construction is added
100 finalProps[NodeVisualElementConstants.CSS_CLASS] = lineProps.class;
101 finalProps = this.applySvgAttributes(finalProps, lineProps.svgAttributes);
102 finalProps = this.applyTransform(finalProps, lineProps.shapeAttributes);
110 return React.createElement(NodeVisualElementConstants.SVG_LINE, finalProps);
113 createTextElement(nodeProps, textProps, elementKey) {
115 finalProps[NodeVisualElementConstants.CSS_CLASS] = textProps.class;
117 finalProps = this.applySvgAttributes(finalProps, textProps.svgAttributes);
118 finalProps = this.applyTransform(finalProps, textProps.shapeAttributes);
125 return React.createElement(NodeVisualElementConstants.TEXT, finalProps,
126 nodeProps[textProps.displayKey]);
129 createImageElement(imageProps, elementKey) {
131 finalProps[NodeVisualElementConstants.CSS_CLASS] = imageProps.class;
133 finalProps = this.applyTransform(finalProps, imageProps.shapeAttributes);
134 finalProps = this.applySvgAttributes(finalProps, imageProps.svgAttributes);
141 return React.createElement(NodeVisualElementConstants.IMAGE, finalProps);
144 createObjectElement(objectProps, elementKey) {
146 finalProps[NodeVisualElementConstants.CSS_CLASS] = objectProps.class;
148 finalProps = this.applyTransform(finalProps, objectProps.shapeAttributes);
149 finalProps = this.applySvgAttributes(finalProps, objectProps.svgAttributes);
156 return React.createElement(NodeVisualElementConstants.OBJECT, finalProps);
159 createButtonElement(buttonProps, elementKey, nodeMeta) {
160 return IconFactory.createIcon(buttonProps.name, buttonProps, elementKey,
164 applySvgAttributes(elementProps, svgAttributes) {
174 applyTransform(elementProps, shapeAttributes) {
175 if (shapeAttributes) {
176 if (shapeAttributes.offset) {
179 transform: `translate(
180 ${shapeAttributes.offset.x},
181 ${shapeAttributes.offset.y})`
189 export default NodeVisualElementFactory;