blob: 987136fb890f80b8c23f594cf60861f2161ea77f [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 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) {
Steven Burrows938bb8a2017-04-12 13:42:03 -070036 var format = {
Steven Burrows86af4352016-11-16 18:19:12 -060037 title: data.get('id'),
Steven Burrows938bb8a2017-04-12 13:42:03 -070038 propOrder: ['MAC', 'IP', 'VLAN'],
Steven Burrows86af4352016-11-16 18:19:12 -060039 props: {
40 '-': '',
41 'MAC': data.get('id'),
42 'IP': data.get('ips')[0],
Simon Hunt5c3ed732017-07-20 19:03:28 +000043 'VLAN': 'None' // TODO: VLAN is not currently in the data received from backend
44 }
Steven Burrowsaf96a212016-12-28 12:57:02 +000045 };
Steven Burrows938bb8a2017-04-12 13:42:03 -070046
47 if (data.get('location')) {
48 format.propOrder.push('-', 'Latitude', 'Longitude');
49 format.props['Latitude'] = data.get('location').lat;
50 format.props['Longitude'] = data.get('location').lng;
51 }
52
53 return format;
Steven Burrowsaf96a212016-12-28 12:57:02 +000054 }
Steven Burrows86af4352016-11-16 18:19:12 -060055
56 function displayPanel(data) {
57 init();
58
59 hostData = formatHostData(data);
60 render();
61 }
62
63 function render() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070064 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060065 hostPanel.emptyRegions();
66
67 var svg = hostPanel.appendToHeader('div')
68 .classed('icon', true)
69 .append('svg'),
70 title = hostPanel.appendToHeader('h2'),
71 table = hostPanel.appendToBody('table'),
72 tbody = table.append('tbody');
73
74 title.text(hostData.title);
75 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000076 ls.listProps(tbody, hostData);
Steven Burrows86af4352016-11-16 18:19:12 -060077 }
78
79 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070080 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060081 }
82
83 function hide() {
84 hostPanel.el.hide();
85 }
86
87 function toggle() {
88 var on = hostPanel.el.toggle(),
89 verb = on ? 'Show' : 'Hide';
90 flash.flash(verb + ' host Panel');
91 }
92
93 function destroy() {
94 hostPanel.destroy();
95 }
96
97 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +000098 .factory('Topo2HostsPanelService', [
99 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
Steven Burrows3cc0c372017-02-10 15:15:24 +0000100 function (_ps_, _gs_, _flash_, _ls_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600101
Steven Burrowsaf96a212016-12-28 12:57:02 +0000102 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600103 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600104 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000105 ls = _ls_;
Steven Burrows86af4352016-11-16 18:19:12 -0600106
107 return {
108 displayPanel: displayPanel,
109 init: init,
110 show: show,
111 hide: hide,
112 toggle: toggle,
113 destroy: destroy,
Simon Hunt5c3ed732017-07-20 19:03:28 +0000114 isVisible: function () { return hostPanel.isVisible(); }
Steven Burrows86af4352016-11-16 18:19:12 -0600115 };
Simon Hunt5c3ed732017-07-20 19:03:28 +0000116 }
Steven Burrows86af4352016-11-16 18:19:12 -0600117 ]);
118
119})();