Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 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 | /* |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 18 | ONOS GUI -- Topo2 Hosts Panel |
| 19 | Module that builds the Hosts Panel for the selected Host |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // Injected Services |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 26 | var panel, gs, flash, ls, ns; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 27 | |
| 28 | // Internal State |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 29 | var hostPath = 'host', |
| 30 | hostPanel, hostData; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 31 | |
| 32 | function init() { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 33 | hostPanel = panel(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | function formatHostData(data) { |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 37 | var format = { |
Steven Burrows | 22cb550 | 2018-02-06 11:28:33 +0000 | [diff] [blame] | 38 | 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 Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 47 | '-': '', |
| 48 | 'MAC': data.get('id'), |
| 49 | 'IP': data.get('ips')[0], |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 50 | 'VLAN': 'None', // TODO: VLAN is not currently in the data received from backend |
Steven Burrows | 22cb550 | 2018-02-06 11:28:33 +0000 | [diff] [blame] | 51 | 'Configured': data.get('configured'), |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 52 | }, |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 53 | }; |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 54 | |
| 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 62 | } |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 63 | |
| 64 | function displayPanel(data) { |
| 65 | init(); |
| 66 | |
| 67 | hostData = formatHostData(data); |
| 68 | render(); |
| 69 | } |
| 70 | |
| 71 | function render() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 72 | hostPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 73 | hostPanel.emptyRegions(); |
| 74 | |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 75 | var navFn = function () { |
| 76 | ns.navTo(hostPath, { hostId: hostData.title }); |
| 77 | }; |
| 78 | |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 79 | var svg = hostPanel.appendToHeader('div') |
| 80 | .classed('icon', true) |
| 81 | .append('svg'), |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 82 | title = hostPanel.appendToHeader('h2') |
| 83 | .on('click', navFn) |
| 84 | .classed('clickable', true), |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 85 | table = hostPanel.appendToBody('table'), |
| 86 | tbody = table.append('tbody'); |
| 87 | |
| 88 | title.text(hostData.title); |
| 89 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 90 | ls.listProps(tbody, hostData); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | function show() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 94 | hostPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | function hide() { |
| 98 | hostPanel.el.hide(); |
| 99 | } |
| 100 | |
| 101 | function toggle() { |
| 102 | var on = hostPanel.el.toggle(), |
| 103 | verb = on ? 'Show' : 'Hide'; |
| 104 | flash.flash(verb + ' host Panel'); |
| 105 | } |
| 106 | |
| 107 | function destroy() { |
| 108 | hostPanel.destroy(); |
| 109 | } |
| 110 | |
| 111 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 112 | .factory('Topo2HostsPanelService', [ |
| 113 | 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService', |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 114 | 'NavService', |
| 115 | function (_ps_, _gs_, _flash_, _ls_, _ns_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 116 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 117 | panel = _ps_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 118 | gs = _gs_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 119 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 120 | ls = _ls_; |
Steven Burrows | 2e0c9c0 | 2017-08-07 17:45:21 +0100 | [diff] [blame] | 121 | ns = _ns_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 122 | |
| 123 | return { |
| 124 | displayPanel: displayPanel, |
| 125 | init: init, |
| 126 | show: show, |
| 127 | hide: hide, |
| 128 | toggle: toggle, |
| 129 | destroy: destroy, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 130 | isVisible: function () { return hostPanel.isVisible(); }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 131 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 132 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 133 | ]); |
| 134 | |
| 135 | })(); |