blob: 79d27a32ff5ecb5a5e311edbb1a3b987e2689c9c [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Steven Burrows86af4352016-11-16 18:19:12 -06003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Topology Layout Module.
19 Module that contains the d3.force.layout logic
20 */
21
22(function () {
23 'use strict';
24
25 // Injected Services
Steven Burrowsaf96a212016-12-28 12:57:02 +000026 var panel, gs, flash, ls;
Steven Burrows86af4352016-11-16 18:19:12 -060027
28 // Internal State
29 var linkPanel, linkData;
30
31 function init() {
Steven Burrowsaf96a212016-12-28 12:57:02 +000032 linkPanel = panel();
Steven Burrows86af4352016-11-16 18:19:12 -060033 }
34
35 function formatLinkData(data) {
36
37 var source = data.get('source'),
38 target = data.get('target');
39
40 return {
41 title: 'Link',
42 propOrder: [
43 'Type', '-',
44 'A Type', 'A Id', 'A Label', 'A Port', '-',
Steven Burrows1c2a9682017-07-14 16:52:46 +010045 'B Type', 'B Id', 'B Label', 'B Port',
Steven Burrows86af4352016-11-16 18:19:12 -060046 ],
Steven Burrows4260dd52017-10-09 16:05:06 +010047 propLabels: {
48 'Type': 'Type',
49 'A Type': 'A Type',
50 'A Id': 'A Id',
51 'A Label': 'A Label',
52 'A Port': 'A Port',
53 'B Type': 'B Type',
54 'B Id': 'B Id',
55 'B Label': 'B Label',
56 'B Port': 'B Port',
57 },
58 propValues: {
Steven Burrows86af4352016-11-16 18:19:12 -060059 '-': '',
60 'Type': data.get('type'),
61 'A Type': source.get('nodeType'),
62 'A Id': source.get('id'),
Steven Burrowsaf96a212016-12-28 12:57:02 +000063 'A Label': source.get('props').name,
64 'A Port': data.get('portA') || 'N/A',
Steven Burrows86af4352016-11-16 18:19:12 -060065 'B Type': target.get('nodeType'),
66 'B Id': target.get('id'),
Steven Burrowsaf96a212016-12-28 12:57:02 +000067 'B Label': target.get('props').name,
Steven Burrows1c2a9682017-07-14 16:52:46 +010068 'B Port': data.get('portB') || 'N/A',
69 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000070 };
71 }
Steven Burrows86af4352016-11-16 18:19:12 -060072
73 function displayLink(data) {
74 init();
75
76 linkData = formatLinkData(data);
77 render();
78 }
79
80 function render() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070081 linkPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060082 linkPanel.emptyRegions();
83
84 var svg = linkPanel.appendToHeader('div')
85 .classed('icon', true)
86 .append('svg'),
87 title = linkPanel.appendToHeader('h2'),
88 table = linkPanel.appendToBody('table'),
89 tbody = table.append('tbody');
90
91 title.text(linkData.title);
92 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000093 ls.listProps(tbody, linkData);
Steven Burrows86af4352016-11-16 18:19:12 -060094 }
95
96 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070097 linkPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060098 }
99
100 function hide() {
101 linkPanel.el.hide();
102 }
103
104 function toggle() {
105 var on = linkPanel.el.toggle(),
106 verb = on ? 'Show' : 'Hide';
107 flash.flash(verb + ' Link Panel');
108 }
109
110 function destroy() {
Steven Burrows86af4352016-11-16 18:19:12 -0600111 linkPanel.destroy();
112 }
113
114 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000115 .factory('Topo2LinkPanelService', [
116 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
117 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600118
Steven Burrowsaf96a212016-12-28 12:57:02 +0000119 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600120 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600121 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000122 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -0600123
124 return {
125 displayLink: displayLink,
126 init: init,
127 show: show,
128 hide: hide,
129 toggle: toggle,
130 destroy: destroy,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100131 isVisible: function () { return linkPanel.isVisible(); },
Steven Burrows86af4352016-11-16 18:19:12 -0600132 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100133 },
Steven Burrows86af4352016-11-16 18:19:12 -0600134 ]);
135
136})();