blob: b131729cd887b9a4c452e9ca68217490867471f6 [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
26 var Panel, gs, wss, flash, listProps;
27
28 // Internal State
29 var hostPanel, hostData;
30
31 function init() {
32 hostPanel = Panel();
33 }
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],
43 'VLAN': 'None', // TODO
44 'Latitude': data.get('location').lat,
45 'Longitude': data.get('location').lng,
46 }
47 }
48 };
49
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]);
70 listProps(tbody, hostData);
71 }
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')
92 .factory('Topo2HostsPanelService',
93 ['Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService',
94 function (_ps_, _gs_, _wss_, _flash_, _listService_) {
95
96 Panel = _ps_;
97 gs = _gs_;
98 wss = _wss_;
99 flash = _flash_;
100 listProps = _listService_;
101
102 return {
103 displayPanel: displayPanel,
104 init: init,
105 show: show,
106 hide: hide,
107 toggle: toggle,
108 destroy: destroy,
109 isVisible: function () { return hostPanel.isVisible(); }
110 };
111 }
112 ]);
113
114})();