Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 1 | /* |
| 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 |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 26 | var panel, gs, flash, ls; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 27 | |
| 28 | // Internal State |
| 29 | var hostPanel, hostData; |
| 30 | |
| 31 | function init() { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 32 | hostPanel = panel(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | function formatHostData(data) { |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 36 | var format = { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 37 | title: data.get('id'), |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 38 | propOrder: ['MAC', 'IP', 'VLAN'], |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 39 | props: { |
| 40 | '-': '', |
| 41 | 'MAC': data.get('id'), |
| 42 | 'IP': data.get('ips')[0], |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 43 | 'VLAN': 'None' // TODO: VLAN is not currently in the data received from backend |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 44 | } |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 45 | }; |
Steven Burrows | 938bb8a | 2017-04-12 13:42:03 -0700 | [diff] [blame] | 46 | |
| 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 54 | } |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 55 | |
| 56 | function displayPanel(data) { |
| 57 | init(); |
| 58 | |
| 59 | hostData = formatHostData(data); |
| 60 | render(); |
| 61 | } |
| 62 | |
| 63 | function render() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 64 | hostPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 65 | 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 76 | ls.listProps(tbody, hostData); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function show() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 80 | hostPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 81 | } |
| 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 Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 98 | .factory('Topo2HostsPanelService', [ |
| 99 | 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService', |
Steven Burrows | 3cc0c37 | 2017-02-10 15:15:24 +0000 | [diff] [blame] | 100 | function (_ps_, _gs_, _flash_, _ls_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 101 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 102 | panel = _ps_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 103 | gs = _gs_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 104 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 105 | ls = _ls_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 106 | |
| 107 | return { |
| 108 | displayPanel: displayPanel, |
| 109 | init: init, |
| 110 | show: show, |
| 111 | hide: hide, |
| 112 | toggle: toggle, |
| 113 | destroy: destroy, |
| 114 | isVisible: function () { return hostPanel.isVisible(); } |
| 115 | }; |
| 116 | } |
| 117 | ]); |
| 118 | |
| 119 | })(); |