1 define(['next-ui'], function () {
5 * Service to handle next directive
7 function NextTopologyService() {
9 * Create base nx topology object
11 * @returns {nx.graphic.Topology}
13 this.getNxTopClass = function (topoColors) {
14 return new nx.graphic.Topology({
19 //iconType: 'model.icon',
21 color: function (node, model) {
22 return topoColors.getItem('forwarding-box');
26 // connected to hosts links have different colors
27 width: function (model, link) {
28 return (model._data.gLinks && model._data.gLinks.length > 2) ? 5 : 3;
32 tooltipManagerConfig: {
33 nodeTooltipContentClass: 'ExtendedTooltip',
34 showLinkTooltip: false
36 dataProcessor: 'force',
40 enableSmartNode: false,
41 linkInstanceClass: 'ExtendedLink',
42 nodeInstanceClass: 'ExtendedNode'
47 * Method for getting right link's color based on status
52 this.getLinkColor = function (status, topoColors) {
56 // all links are operational
57 if ( status.operational === status.configured ) {
58 color = topoColors.getItem('operational');
60 // operational less than configured
61 if (status.operational < status.configured && status.operational) {
62 color = topoColors.getItem('operational-mixed');
64 // if operational and something else presented
65 if (!status.operational && status.configured) {
66 // if the link is between forwarding boxes, it's considered down
67 /*if ( model.source()._data.type === 'forwarding-box' && model.target()._data.type === 'forwarding-box' ) {
68 color = topoColors.getItem('down');
70 // otherwise just configured connection
71 color = topoColors.getItem('configured');
74 color = topoColors.getItem('down');
77 color = topoColors.getItem('default');
83 color = topoColors.getItem('default');
90 * Service for reading topo nodes data from local storage
93 this.readTopologyDataFromLS = function(){
97 data = JSON.parse(localStorage.getItem("verizonTopologyData"));
99 console.info('Local Storage read parse error:', e);
106 * Set loaded nodes data from local storage
111 this.setTopologyDataFromLS = function (data, topo, nodesDict) {
112 if ( data && data.nodes ) {
114 data.nodes.forEach(function(node, index){
115 var nodeInst = topo.getNode(nodesDict.getItem(node.nodeName));
116 if(nodeInst !== undefined)
117 nodeInst.position({'x': node.x, 'y': node.y});
123 * Prepare and save data to local storage
126 this.saveTopologyDataToLS = function (topo) {
127 var data = {'nodes': []},
128 nodesLayer = topo.getLayer('nodes');
130 // prepare data for writing
131 nodesLayer.eachNode(function(node){
135 'nodeName': node.model()._data['node-id']
139 // save to local storage
141 localStorage.setItem("verizonTopologyData", JSON.stringify(data));
143 console.info('Local Storage save error:', e);
148 * Service for fade out all topo layers
151 this.fadeOutAllLayers = function(topo){
152 nx.each(topo.layers(), function(layer) {
158 * Service for fade in all topo layers
161 this.fadeInAllLayers = function(topo){
162 //fade out all layers
163 var linksLayerHighlightElements = topo.getLayer('links').highlightedElements(),
164 nodeLayerHighlightElements = topo.getLayer('nodes').highlightedElements();
167 nodeLayerHighlightElements.clear();
168 linksLayerHighlightElements.clear();
170 nx.each(topo.layers(), function(layer) {
176 * Service for highlighting node with(without) links
181 this.highlightNode = function (topo, targetId, noLinks) {
182 var nodeLayer = topo.getLayer('nodes'),
183 linksLayer = topo.getLayer('links'),
184 linksLayerHighlightElements = linksLayer.highlightedElements(),
185 nodeLayerHighlightElements = nodeLayer.highlightedElements();
188 nodeLayerHighlightElements.clear();
189 linksLayerHighlightElements.clear();
192 nodeLayerHighlightElements.add(topo.getNode(targetId));
195 linksLayerHighlightElements.addRange(nx.util.values(topo.getNode(targetId).links()));
198 linksLayer.fadeOut(true);
203 * Service for highlighting link
207 this.highlightLink = function(topo, linkId) {
208 var nodeLayer = topo.getLayer('nodes'),
209 linksLayer = topo.getLayer('links'),
210 linksLayerHighlightElements = linksLayer.highlightedElements(),
211 nodeLayerHighlightElements = nodeLayer.highlightedElements(),
212 link = topo.getLink(linkId);
215 nodeLayerHighlightElements.clear();
216 linksLayerHighlightElements.clear();
219 linksLayerHighlightElements.add(link);
220 //highlight connected nodes
221 nodeLayerHighlightElements.addRange(nx.util.values({source: topo.getNode(link.model().sourceID()), target: topo.getNode(link.model().targetID())}));
225 * Service for highlighting selected links path
227 * @param links - array of nx links obj
229 this.highlightPath = function(topo, links){
230 // clear the path layer and get its instance
231 var pathLayer = this.clearPathLayer(topo),
233 path = new nx.graphic.Topology.Path({
240 pathLayer.addPath(path);
244 * Completely clear all paths from path layer
246 * @returns {*} path instance
248 this.clearPathLayer = function(topo){
249 var pathLayer = topo.getLayer("paths");
255 * Service for returning nx tooltip skeleton
256 * @returns {{content: *[]}}
258 this.getTooltipContent = function () {
264 class: "n-topology-tooltip-header"
270 class: "n-topology-tooltip-header-text"
272 content: '{#node.model.label}'
279 class: "n-topology-tooltip-content n-list"
285 class: "n-list-wrap",
286 style: "font-size: 0.8em"
292 class: "n-list-item-i",
300 style: "display: block; margin-top: 10px;"
305 content: "{#node.model.status}"
312 class: "n-list-item-i",
318 content: "DataPath ID",
320 style: "display: block; margin-top: 10px;"
325 content: "{#node.model.datapath-id}"
332 class: "n-list-item-i",
340 style: "display: block; margin-top: 10px;"
345 content: "{#node.model.data.type}"
358 NextTopologyService.$inject=[];
360 return NextTopologyService;