blob: ea096b791aa82d2442cc4bbc64f6010400b258f3 [file] [log] [blame]
Steven Burrows86af4352016-11-16 18:19:12 -06001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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', '-',
45 'B Type', 'B Id', 'B Label', 'B Port'
46 ],
47 props: {
48 '-': '',
49 'Type': data.get('type'),
50 'A Type': source.get('nodeType'),
51 'A Id': source.get('id'),
Steven Burrowsaf96a212016-12-28 12:57:02 +000052 'A Label': source.get('props').name,
53 'A Port': data.get('portA') || 'N/A',
Steven Burrows86af4352016-11-16 18:19:12 -060054 'B Type': target.get('nodeType'),
55 'B Id': target.get('id'),
Steven Burrowsaf96a212016-12-28 12:57:02 +000056 'B Label': target.get('props').name,
57 'B Port': data.get('portB') || 'N/A'
Steven Burrows86af4352016-11-16 18:19:12 -060058 }
Steven Burrowsaf96a212016-12-28 12:57:02 +000059 };
60 }
Steven Burrows86af4352016-11-16 18:19:12 -060061
62 function displayLink(data) {
63 init();
64
65 linkData = formatLinkData(data);
66 render();
67 }
68
69 function render() {
70 linkPanel.el.show();
71 linkPanel.emptyRegions();
72
73 var svg = linkPanel.appendToHeader('div')
74 .classed('icon', true)
75 .append('svg'),
76 title = linkPanel.appendToHeader('h2'),
77 table = linkPanel.appendToBody('table'),
78 tbody = table.append('tbody');
79
80 title.text(linkData.title);
81 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000082 ls.listProps(tbody, linkData);
Steven Burrows86af4352016-11-16 18:19:12 -060083 }
84
85 function show() {
86 linkPanel.el.show();
87 }
88
89 function hide() {
90 linkPanel.el.hide();
91 }
92
93 function toggle() {
94 var on = linkPanel.el.toggle(),
95 verb = on ? 'Show' : 'Hide';
96 flash.flash(verb + ' Link Panel');
97 }
98
99 function destroy() {
Steven Burrows86af4352016-11-16 18:19:12 -0600100 linkPanel.destroy();
101 }
102
103 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000104 .factory('Topo2LinkPanelService', [
105 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
106 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600107
Steven Burrowsaf96a212016-12-28 12:57:02 +0000108 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600109 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600110 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000111 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -0600112
113 return {
114 displayLink: displayLink,
115 init: init,
116 show: show,
117 hide: hide,
118 toggle: toggle,
119 destroy: destroy,
120 isVisible: function () { return linkPanel.isVisible(); }
121 };
122 }
123 ]);
124
125})();