blob: f8273b20ed5bfda0be55023fc35cfaa0f51f85f0 [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 Burrows22cb5502018-02-06 11:28:33 +000038 title: data.title(),
39 propOrder: ['MAC', 'IP', 'VLAN', 'Configured'],
40 propLabels: {
41 'MAC': 'MAC',
42 'Configured': 'Configured',
43 'IP': 'IP',
44 'VLAN': 'VLAN',
45 },
46 propValues: {
Steven Burrows86af4352016-11-16 18:19:12 -060047 '-': '',
48 'MAC': data.get('id'),
49 'IP': data.get('ips')[0],
Steven Burrows1c2a9682017-07-14 16:52:46 +010050 'VLAN': 'None', // TODO: VLAN is not currently in the data received from backend
Steven Burrows22cb5502018-02-06 11:28:33 +000051 'Configured': data.get('configured'),
Steven Burrows1c2a9682017-07-14 16:52:46 +010052 },
Steven Burrowsaf96a212016-12-28 12:57:02 +000053 };
Steven Burrows938bb8a2017-04-12 13:42:03 -070054
55 if (data.get('location')) {
56 format.propOrder.push('-', 'Latitude', 'Longitude');
57 format.props['Latitude'] = data.get('location').lat;
58 format.props['Longitude'] = data.get('location').lng;
59 }
60
61 return format;
Steven Burrowsaf96a212016-12-28 12:57:02 +000062 }
Steven Burrows86af4352016-11-16 18:19:12 -060063
64 function displayPanel(data) {
65 init();
66
67 hostData = formatHostData(data);
Steven Burrows22cb5502018-02-06 11:28:33 +000068 console.log(data);
Steven Burrows86af4352016-11-16 18:19:12 -060069 render();
70 }
71
72 function render() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070073 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060074 hostPanel.emptyRegions();
75
Steven Burrows2e0c9c02017-08-07 17:45:21 +010076 var navFn = function () {
77 ns.navTo(hostPath, { hostId: hostData.title });
78 };
79
Steven Burrows86af4352016-11-16 18:19:12 -060080 var svg = hostPanel.appendToHeader('div')
81 .classed('icon', true)
82 .append('svg'),
Steven Burrows2e0c9c02017-08-07 17:45:21 +010083 title = hostPanel.appendToHeader('h2')
84 .on('click', navFn)
85 .classed('clickable', true),
Steven Burrows86af4352016-11-16 18:19:12 -060086 table = hostPanel.appendToBody('table'),
87 tbody = table.append('tbody');
88
89 title.text(hostData.title);
90 gs.addGlyph(svg, 'bird', 24, 0, [1, 1]);
Steven Burrows22cb5502018-02-06 11:28:33 +000091 console.log()
Steven Burrowsaf96a212016-12-28 12:57:02 +000092 ls.listProps(tbody, hostData);
Steven Burrows86af4352016-11-16 18:19:12 -060093 }
94
95 function show() {
Steven Burrowsc59481f2017-04-13 10:01:15 -070096 hostPanel.show();
Steven Burrows86af4352016-11-16 18:19:12 -060097 }
98
99 function hide() {
100 hostPanel.el.hide();
101 }
102
103 function toggle() {
104 var on = hostPanel.el.toggle(),
105 verb = on ? 'Show' : 'Hide';
106 flash.flash(verb + ' host Panel');
107 }
108
109 function destroy() {
110 hostPanel.destroy();
111 }
112
113 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +0000114 .factory('Topo2HostsPanelService', [
115 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService',
Steven Burrows2e0c9c02017-08-07 17:45:21 +0100116 'NavService',
117 function (_ps_, _gs_, _flash_, _ls_, _ns_) {
Steven Burrows86af4352016-11-16 18:19:12 -0600118
Steven Burrowsaf96a212016-12-28 12:57:02 +0000119 panel = _ps_;
Steven Burrows86af4352016-11-16 18:19:12 -0600120 gs = _gs_;
Steven Burrows86af4352016-11-16 18:19:12 -0600121 flash = _flash_;
Steven Burrowsaf96a212016-12-28 12:57:02 +0000122 ls = _ls_;
Steven Burrows2e0c9c02017-08-07 17:45:21 +0100123 ns = _ns_;
Steven Burrows86af4352016-11-16 18:19:12 -0600124
125 return {
126 displayPanel: displayPanel,
127 init: init,
128 show: show,
129 hide: hide,
130 toggle: toggle,
131 destroy: destroy,
Steven Burrows1c2a9682017-07-14 16:52:46 +0100132 isVisible: function () { return hostPanel.isVisible(); },
Steven Burrows86af4352016-11-16 18:19:12 -0600133 };
Steven Burrows1c2a9682017-07-14 16:52:46 +0100134 },
Steven Burrows86af4352016-11-16 18:19:12 -0600135 ]);
136
137})();