blob: 4ba1f600c19a01299e02330be25427e1a82a733e [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/*
Steven Burrows2e0c9c02017-08-07 17:45:21 +010018 ONOS GUI -- Topo2 Hosts Panel
19 Module that builds the Hosts Panel for the selected Host
Steven Burrows86af4352016-11-16 18:19:12 -060020 */
21
22(function () {
23 'use strict';
24
25 // Injected Services
Steven Burrows2e0c9c02017-08-07 17:45:21 +010026 var panel, gs, flash, ls, ns;
Steven Burrows86af4352016-11-16 18:19:12 -060027
28 // Internal State
Steven Burrows2e0c9c02017-08-07 17:45:21 +010029 var hostPath = 'host',
30 hostPanel, hostData;
Steven Burrows86af4352016-11-16 18:19:12 -060031
32 function init() {
Steven Burrowsaf96a212016-12-28 12:57:02 +000033 hostPanel = panel();
Steven Burrows86af4352016-11-16 18:19:12 -060034 }
35
36 function formatHostData(data) {
Steven Burrows938bb8a2017-04-12 13:42:03 -070037 var format = {
Steven Burrows86af4352016-11-16 18:19:12 -060038 title: data.get('id'),
Steven Burrows938bb8a2017-04-12 13:42:03 -070039 propOrder: ['MAC', 'IP', 'VLAN'],
Steven Burrows86af4352016-11-16 18:19:12 -060040 props: {
41 '-': '',
42 'MAC': data.get('id'),
43 'IP': data.get('ips')[0],
Steven Burrows1c2a9682017-07-14 16:52:46 +010044 'VLAN': 'None', // TODO: VLAN is not currently in the data received from backend
45 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000046 };
Steven Burrows938bb8a2017-04-12 13:42:03 -070047
48 if (data.get('location')) {
49 format.propOrder.push('-', 'Latitude', 'Longitude');
50 format.props['Latitude'] = data.get('location').lat;
51 format.props['Longitude'] = data.get('location').lng;
52 }
53
54 return format;
Steven Burrowsaf96a212016-12-28 12:57:02 +000055 }
Steven Burrows86af4352016-11-16 18:19:12 -060056
57 function displayPanel(data) {
58 init();
59
60 hostData = formatHostData(data);
61 render();
62 }
63
64 function render() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070065 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060066 hostPanel.emptyRegions();
67
Steven Burrows2e0c9c02017-08-07 17:45:21 +010068 var navFn = function () {
69 ns.navTo(hostPath, { hostId: hostData.title });
70 };
71
Steven Burrows86af4352016-11-16 18:19:12 -060072 var svg = hostPanel.appendToHeader('div')
73 .classed('icon', true)
74 .append('svg'),
Steven Burrows2e0c9c02017-08-07 17:45:21 +010075 title = hostPanel.appendToHeader('h2')
76 .on('click', navFn)
77 .classed('clickable', true),
Steven Burrows86af4352016-11-16 18:19:12 -060078 table = hostPanel.appendToBody('table'),
79 tbody = table.append('tbody');
80
81 title.text(hostData.title);
82 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrowsaf96a212016-12-28 12:57:02 +000083 ls.listProps(tbody, hostData);
Steven Burrows86af4352016-11-16 18:19:12 -060084 }
85
86 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070087 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060088 }
89
90 function hide() {
91 hostPanel.el.hide();
92 }
93
94 function toggle() {
95 var on = hostPanel.el.toggle(),
96 verb = on ? 'Show' : 'Hide';
97 flash.flash(verb + ' host Panel');
98 }
99
100 function destroy() {
101 hostPanel.destroy();
102 }
103
104 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000105 .factory('Topo2HostsPanelService', [
106 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
Steven Burrows2e0c9c02017-08-07 17:45:21 +0100107 'NavService',
108 function (_ps_, _gs_, _flash_, _ls_, _ns_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600109
Steven Burrowsaf96a212016-12-28 12:57:02 +0000110 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600111 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600112 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000113 ls = _ls_;
Steven Burrows2e0c9c02017-08-07 17:45:21 +0100114 ns = _ns_;
Steven Burrows86af4352016-11-16 18:19:12 -0600115
116 return {
117 displayPanel: displayPanel,
118 init: init,
119 show: show,
120 hide: hide,
121 toggle: toggle,
122 destroy: destroy,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100123 isVisible: function () { return hostPanel.isVisible(); },
Steven Burrows86af4352016-11-16 18:19:12 -0600124 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100125 },
Steven Burrows86af4352016-11-16 18:19:12 -0600126 ]);
127
128})();