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 | /* |
| 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 subRegionPanel, subRegionData; |
| 30 | |
| 31 | function init() { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 32 | subRegionPanel = panel(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | function formatSubRegionData(data) { |
| 36 | return { |
| 37 | title: data.get('name'), |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 38 | propLabels: { |
| 39 | '-': '-', |
| 40 | 'id': 'Id', |
| 41 | 'nodeType': 'Type', |
| 42 | 'nDevs': '# Devices', |
| 43 | 'nHosts': '# Hosts', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 44 | }, |
Simon Hunt | 3d875ec | 2017-09-07 16:52:59 -0700 | [diff] [blame] | 45 | propValues: { |
| 46 | '-': '-', |
| 47 | 'id': data.get('id'), |
| 48 | 'nodeType': data.get('nodeType'), |
| 49 | 'nDevs': data.get('nDevs'), |
| 50 | 'nHosts': data.get('nHosts'), |
| 51 | }, |
| 52 | propOrder: [ |
| 53 | 'id', |
| 54 | 'nodeType', |
| 55 | '-', |
| 56 | 'nDevs', |
| 57 | 'nHosts', |
| 58 | ], |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 59 | }; |
| 60 | } |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 61 | |
| 62 | function displayPanel(data) { |
| 63 | init(); |
| 64 | subRegionData = formatSubRegionData(data); |
| 65 | render(); |
| 66 | } |
| 67 | |
| 68 | function render() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 69 | subRegionPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 70 | subRegionPanel.emptyRegions(); |
| 71 | |
| 72 | var svg = subRegionPanel.appendToHeader('div') |
| 73 | .classed('icon', true) |
| 74 | .append('svg'), |
| 75 | title = subRegionPanel.appendToHeader('h2'), |
| 76 | table = subRegionPanel.appendToBody('table'), |
| 77 | tbody = table.append('tbody'); |
| 78 | |
| 79 | title.text(subRegionData.title); |
| 80 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 81 | ls.listProps(tbody, subRegionData); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | function show() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 85 | subRegionPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | function hide() { |
| 89 | subRegionPanel.el.hide(); |
| 90 | } |
| 91 | |
| 92 | function toggle() { |
| 93 | var on = subRegionPanel.el.toggle(), |
| 94 | verb = on ? 'Show' : 'Hide'; |
| 95 | flash.flash(verb + ' subRegion Panel'); |
| 96 | } |
| 97 | |
| 98 | function destroy() { |
| 99 | subRegionPanel.destroy(); |
| 100 | } |
| 101 | |
| 102 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 103 | .factory('Topo2SubRegionPanelService', [ |
| 104 | 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService', |
| 105 | function (_ps_, _gs_, _flash_, _ls_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 106 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 107 | panel = _ps_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 108 | gs = _gs_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 109 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 110 | ls = _ls_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 111 | |
| 112 | return { |
| 113 | displayPanel: displayPanel, |
| 114 | init: init, |
| 115 | show: show, |
| 116 | hide: hide, |
| 117 | toggle: toggle, |
| 118 | destroy: destroy, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 119 | isVisible: function () { return subRegionPanel.isVisible(); }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 120 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 121 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 122 | ]); |
| 123 | |
| 124 | })(); |