blob: eca6750a0a9a88c98ca2d03459caa1fdbe9aa488 [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 hostPanel, hostData;
30
31 function init() {
Steven Burrowsaf96a212016-12-28 12:57:02 +000032 hostPanel = panel();
Steven Burrows86af4352016-11-16 18:19:12 -060033 }
34
35 function formatHostData(data) {
36 return {
37 title: data.get('id'),
38 propOrder: ['MAC', 'IP', 'VLAN', '-', 'Latitude', 'Longitude'],
39 props: {
40 '-': '',
41 'MAC': data.get('id'),
42 'IP': data.get('ips')[0],
Steven Burrowsaf96a212016-12-28 12:57:02 +000043 'VLAN': 'None', // TODO: VLAN is not currently in the data received from backend
Steven Burrows86af4352016-11-16 18:19:12 -060044 'Latitude': data.get('location').lat,
Steven Burrowsaf96a212016-12-28 12:57:02 +000045 'Longitude': data.get('location').lng
Steven Burrows86af4352016-11-16 18:19:12 -060046 }
Steven Burrowsaf96a212016-12-28 12:57:02 +000047 };
48 }
Steven Burrows86af4352016-11-16 18:19:12 -060049
50 function displayPanel(data) {
51 init();
52
53 hostData = formatHostData(data);
54 render();
55 }
56
57 function render() {
58 hostPanel.el.show();
59 hostPanel.emptyRegions();
60
61 var svg = hostPanel.appendToHeader('div')
62 .classed('icon', true)
63 .append('svg'),
64 title = hostPanel.appendToHeader('h2'),
65 table = hostPanel.appendToBody('table'),
66 tbody = table.append('tbody');
67
68 title.text(hostData.title);
69 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000070 ls.listProps(tbody, hostData);
Steven Burrows86af4352016-11-16 18:19:12 -060071 }
72
73 function show() {
74 hostPanel.el.show();
75 }
76
77 function hide() {
78 hostPanel.el.hide();
79 }
80
81 function toggle() {
82 var on = hostPanel.el.toggle(),
83 verb = on ? 'Show' : 'Hide';
84 flash.flash(verb + ' host Panel');
85 }
86
87 function destroy() {
88 hostPanel.destroy();
89 }
90
91 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +000092 .factory('Topo2HostsPanelService', [
93 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
Steven Burrows3cc0c372017-02-10 15:15:24 +000094 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -060095
Steven Burrowsaf96a212016-12-28 12:57:02 +000096 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -060097 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -060098 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +000099 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -0600100
101 return {
102 displayPanel: displayPanel,
103 init: init,
104 show: show,
105 hide: hide,
106 toggle: toggle,
107 destroy: destroy,
108 isVisible: function () { return hostPanel.isVisible(); }
109 };
110 }
111 ]);
112
113})();