Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -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', '-', |
| 45 | 'B Type', 'B Id', 'B Label', 'B Port' |
| 46 | ], |
| 47 | props: { |
| 48 | '-': '', |
| 49 | 'Type': data.get('type'), |
| 50 | 'A Type': source.get('nodeType'), |
| 51 | 'A Id': source.get('id'), |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 52 | 'A Label': source.get('props').name, |
| 53 | 'A Port': data.get('portA') || 'N/A', |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 54 | 'B Type': target.get('nodeType'), |
| 55 | 'B Id': target.get('id'), |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 56 | 'B Label': target.get('props').name, |
| 57 | 'B Port': data.get('portB') || 'N/A' |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 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 displayLink(data) { |
| 63 | init(); |
| 64 | |
| 65 | linkData = formatLinkData(data); |
| 66 | render(); |
| 67 | } |
| 68 | |
| 69 | function render() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 70 | linkPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 71 | linkPanel.emptyRegions(); |
| 72 | |
| 73 | var svg = linkPanel.appendToHeader('div') |
| 74 | .classed('icon', true) |
| 75 | .append('svg'), |
| 76 | title = linkPanel.appendToHeader('h2'), |
| 77 | table = linkPanel.appendToBody('table'), |
| 78 | tbody = table.append('tbody'); |
| 79 | |
| 80 | title.text(linkData.title); |
| 81 | gs.addGlyph(svg, 'bird', 24, 0, [1, 1]); |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 82 | ls.listProps(tbody, linkData); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | function show() { |
Steven Burrows | c59481f | 2017-04-13 10:01:15 -0700 | [diff] [blame] | 86 | linkPanel.show(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | function hide() { |
| 90 | linkPanel.el.hide(); |
| 91 | } |
| 92 | |
| 93 | function toggle() { |
| 94 | var on = linkPanel.el.toggle(), |
| 95 | verb = on ? 'Show' : 'Hide'; |
| 96 | flash.flash(verb + ' Link Panel'); |
| 97 | } |
| 98 | |
| 99 | function destroy() { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 100 | linkPanel.destroy(); |
| 101 | } |
| 102 | |
| 103 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 104 | .factory('Topo2LinkPanelService', [ |
| 105 | 'Topo2DetailsPanelService', 'GlyphService', 'FlashService', 'ListService', |
| 106 | function (_ps_, _gs_, _flash_, _ls_) { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 107 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 108 | panel = _ps_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 109 | gs = _gs_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 110 | flash = _flash_; |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 111 | ls = _ls_; |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 112 | |
| 113 | return { |
| 114 | displayLink: displayLink, |
| 115 | init: init, |
| 116 | show: show, |
| 117 | hide: hide, |
| 118 | toggle: toggle, |
| 119 | destroy: destroy, |
| 120 | isVisible: function () { return linkPanel.isVisible(); } |
| 121 | }; |
| 122 | } |
| 123 | ]); |
| 124 | |
| 125 | })(); |