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