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