Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [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 layer filtering Module. |
| 19 | Provides functionality to visually differentiate between the packet and |
| 20 | optical layers of the topology. |
| 21 | */ |
| 22 | |
| 23 | (function () { |
| 24 | 'use strict'; |
| 25 | |
| 26 | // injected refs |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 27 | var flash; |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 28 | |
| 29 | // api to topoForce |
| 30 | var api; |
| 31 | /* |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 32 | node() // get ref to D3 selection of nodes |
| 33 | link() // get ref to D3 selection of links |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 34 | */ |
| 35 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 36 | // function to be replaced by the localization bundle function |
| 37 | var topoLion = function (x) { |
| 38 | return '#tfltr#' + x + '#'; |
| 39 | }; |
| 40 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 41 | var smax = 'suppressedmax'; |
| 42 | |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 43 | // which "layer" a particular item "belongs to" |
| 44 | var layerLookup = { |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 45 | host: { |
| 46 | endstation: 'pkt', // default, if host event does not define type |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 47 | router: 'pkt', |
| 48 | bgpSpeaker: 'pkt', |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 49 | }, |
| 50 | device: { |
| 51 | switch: 'pkt', |
Michele Santuari | 54f420d | 2016-08-18 09:02:18 +0200 | [diff] [blame] | 52 | router: 'pkt', |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 53 | roadm: 'opt', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 54 | otn: 'opt', |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 55 | }, |
| 56 | link: { |
| 57 | hostLink: 'pkt', |
| 58 | direct: 'pkt', |
| 59 | indirect: '', |
| 60 | tunnel: '', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 61 | optical: 'opt', |
| 62 | }, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 63 | }, |
| 64 | // order of layer cycling in button |
| 65 | dispatch = [ |
| 66 | { |
| 67 | type: 'all', |
| 68 | action: function () { suppressLayers(false); }, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 69 | }, |
| 70 | { |
| 71 | type: 'pkt', |
| 72 | action: function () { showLayer('pkt'); }, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 73 | }, |
| 74 | { |
| 75 | type: 'opt', |
| 76 | action: function () { showLayer('opt'); }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 77 | }, |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 78 | ], |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 79 | layer = 0, |
| 80 | layerType, |
| 81 | lionKey; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 82 | |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 83 | function clickAction() { |
| 84 | layer = (layer + 1) % dispatch.length; |
| 85 | dispatch[layer].action(); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 86 | layerType = dispatch[layer].type; |
| 87 | lionKey = 'fl_layer_' + layerType; |
| 88 | flash.flash(topoLion(lionKey)); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | function selected() { |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 92 | return dispatch[layer].type; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 95 | function inLayer(d, layer) { |
| 96 | var type = d.class === 'link' ? d.type() : d.type, |
| 97 | look = layerLookup[d.class], |
| 98 | lyr = look && look[type]; |
| 99 | return lyr === layer; |
| 100 | } |
| 101 | |
| 102 | function unsuppressLayer(which) { |
| 103 | api.node().each(function (d) { |
| 104 | var node = d.el; |
| 105 | if (inLayer(d, which)) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 106 | node.classed(smax, false); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 107 | } |
| 108 | }); |
| 109 | |
| 110 | api.link().each(function (d) { |
| 111 | var link = d.el; |
| 112 | if (inLayer(d, which)) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 113 | link.classed(smax, false); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 114 | } |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | function suppressLayers(b) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 119 | api.node().classed(smax, b); |
| 120 | api.link().classed(smax, b); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | function showLayer(which) { |
| 124 | suppressLayers(true); |
| 125 | unsuppressLayer(which); |
| 126 | } |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 127 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 128 | // invoked after the localization bundle has been received from the server |
| 129 | function setLionBundle(bundle) { |
| 130 | topoLion = bundle; |
| 131 | } |
| 132 | |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 133 | // === ----------------------------------------------------- |
| 134 | // === MODULE DEFINITION === |
| 135 | |
| 136 | angular.module('ovTopo') |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 137 | .factory('TopoFilterService', ['FlashService', |
| 138 | function (_flash_) { |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 139 | flash = _flash_; |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 140 | |
Bri Prebilic Cole | b5f2b15 | 2015-04-07 14:58:09 -0700 | [diff] [blame] | 141 | function initFilter(_api_) { |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 142 | api = _api_; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 143 | } |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 144 | |
| 145 | return { |
| 146 | initFilter: initFilter, |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 147 | |
| 148 | clickAction: clickAction, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 149 | selected: selected, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 150 | inLayer: inLayer, |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 151 | setLionBundle: setLionBundle, |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 152 | }; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 153 | }, |
| 154 | ]); |
Simon Hunt | 99ee1e2 | 2015-02-13 09:24:43 -0800 | [diff] [blame] | 155 | }()); |