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 |
| 26 | var Panel, gs, wss, flash, listProps; |
| 27 | |
| 28 | // Internal State |
| 29 | var linkPanel, linkData; |
| 30 | |
| 31 | function init() { |
| 32 | linkPanel = Panel(); |
| 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'), |
| 52 | 'A Label': 'Label', |
| 53 | 'A Port': data.get('portA') || '', |
| 54 | 'B Type': target.get('nodeType'), |
| 55 | 'B Id': target.get('id'), |
| 56 | 'B Label': 'Label', |
| 57 | 'B Port': data.get('portB') || '', |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | function displayLink(data) { |
| 63 | init(); |
| 64 | |
| 65 | linkData = formatLinkData(data); |
| 66 | render(); |
| 67 | } |
| 68 | |
| 69 | function render() { |
| 70 | linkPanel.el.show(); |
| 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]); |
| 82 | listProps(tbody, linkData); |
| 83 | } |
| 84 | |
| 85 | function show() { |
| 86 | linkPanel.el.show(); |
| 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() { |
| 100 | wss.unbindHandlers(handlerMap); |
| 101 | linkPanel.destroy(); |
| 102 | } |
| 103 | |
| 104 | angular.module('ovTopo2') |
| 105 | .factory('Topo2LinkPanelService', |
| 106 | ['Topo2DetailsPanelService', 'GlyphService', 'WebSocketService', 'FlashService', 'ListService', |
| 107 | function (_ps_, _gs_, _wss_, _flash_, _listService_) { |
| 108 | |
| 109 | Panel = _ps_; |
| 110 | gs = _gs_; |
| 111 | wss = _wss_; |
| 112 | flash = _flash_; |
| 113 | listProps = _listService_; |
| 114 | |
| 115 | return { |
| 116 | displayLink: displayLink, |
| 117 | init: init, |
| 118 | show: show, |
| 119 | hide: hide, |
| 120 | toggle: toggle, |
| 121 | destroy: destroy, |
| 122 | isVisible: function () { return linkPanel.isVisible(); } |
| 123 | }; |
| 124 | } |
| 125 | ]); |
| 126 | |
| 127 | })(); |