Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [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 | // PCE web topology overlay - client side |
| 18 | // |
| 19 | // This is the glue that binds our business logic (in pcewebTopovDemo.js) |
| 20 | // to the overlay framework. |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
| 26 | var $log, tov, pps; |
| 27 | |
| 28 | // internal state should be kept in the service module (not here) |
| 29 | var selection; |
| 30 | // our overlay definition |
| 31 | var overlay = { |
| 32 | // NOTE: this must match the ID defined in AppUiTopovOverlay |
| 33 | overlayId: 'PCE-web-overlay', |
| 34 | glyphId: 'topo', |
| 35 | tooltip: 'PCE web Topo Overlay', |
| 36 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 37 | activate: function () { |
| 38 | $log.debug("PCE web topology overlay ACTIVATED"); |
| 39 | }, |
| 40 | deactivate: function () { |
| 41 | pps.clear(); |
| 42 | $log.debug("PCE web topology overlay DEACTIVATED"); |
| 43 | }, |
| 44 | |
| 45 | // These glyphs get installed using the overlayId as a prefix. |
| 46 | // e.g. 'src' is installed as 'PCE-web-overlay-src' |
| 47 | // They can be referenced (from this overlay) as '*src' |
| 48 | // That is, the '*' prefix stands in for 'PCE-web-overlay-' |
| 49 | glyphs: { |
| 50 | src: { |
| 51 | vb: '0 0 110 110', |
| 52 | d: 'M28.7,59.3 M14.9,53 M8.7,39 M32.4,92.5H25l-0.2-3.6' + |
| 53 | 'c-0.5-9-5.4-23.9-12.9-33.5c-5.2-6.6-7-12.8-7-16.3c0-13.3,10.7-24,23.8-24c13.1,0,23.8,10.8,23.8,24c0,3.5-1.8,9.7-7,16.3' + |
| 54 | 'C38,65,33.1,80,32.6,88.9L32.4,92.5z M27.9,89.5h1.7l0-0.7c0.5-9.4,5.7-25.2,13.5-35.2c4.7-6,6.4-11.4,6.4-14.5' + |
| 55 | 'c0-11.6-9.3-21-20.8-21C17.3,18,7.9,27.5,7.9,39c0,3,1.7,8.4,6.4,14.5c7.9,10.1,13.1,25.8,13.5,35.2L27.9,89.5z M28.7,83.2' + |
| 56 | 'M28.6,29.8c-4.7,0-8.5,3.8-8.5,8.5c0,4.7,3.8,8.5,8.5,8.5s8.5-3.8,8.5-8.5C37.1,33.6,33.3,29.8,28.6,29.8z M89.6,47 M89.6,29.5' + |
| 57 | 'c-0.1,3.1-0.1,12.8,0,17c0.1,4.2,14.1-5.5,13.9-8.5C103.4,35.1,89.6,25.6,89.6,29.5z M51,38.1L89.5,38 M89.5,39.5l0-3L51,36.5l0,3' + |
| 58 | 'L89.5,39.5z' |
| 59 | }, |
| 60 | dst: { |
| 61 | vb: '0 0 110 110', |
| 62 | d: 'M80.3,59.8 M85.8,92.5h-7.2L78.4,89c-0.4-8.8-5.2-23.6-12.3-33' + |
| 63 | 'c-4.9-6.5-6.7-12.5-6.7-16c0-13,10.2-23.7,22.7-23.7c12.5,0,22.7,10.6,22.7,23.7c0,3.5-1.8,9.5-6.7,16C91.2,65.4,86.4,80.1,86,89' + |
| 64 | 'L85.8,92.5z M81.4,89.5H83l0-0.7c0.5-9.3,5.4-24.8,12.9-34.7c4.5-5.9,6.1-11.2,6.1-14.2c0-11.4-8.9-20.7-19.8-20.7' + |
| 65 | 'c-10.9,0-19.8,9.3-19.8,20.7c0,3,1.6,8.3,6.1,14.2C76,64,80.9,79.5,81.4,88.8L81.4,89.5z M82.1,30.8c-4.5,0-8.1,3.7-8.1,8.4' + |
| 66 | 's3.6,8.4,8.1,8.4c4.5,0,8.1-3.7,8.1-8.4S86.6,30.8,82.1,30.8z M47.2,47.5 M45.2,30.8c-0.1,3.1-0.1,12.6,0,16.7' + |
| 67 | 'c0.1,4.1,13.4-5.4,13.3-8.4C58.4,36.2,45.2,26.9,45.2,30.8z M45.2,39.1L6.7,39.2 M45.2,40.6l0-3L6.7,37.7l0,3L45.2,40.6z' |
| 68 | }, |
| 69 | jp: { |
| 70 | vb: '0 0 110 110', |
| 71 | d: 'M84.3,89.3L58.9,64.2l-1.4,1.4L83,90.7L84.3,89.3z M27,7.6H7.4v19.2H27V7.6z' + |
| 72 | 'M59.3,47.1H39.8v19.2h19.5V47.1z M102.1,79.5H82.6v19.2h19.5V79.5z M41.7,47.6L19,25.1l-1.2,1.2l22.7,22.5L41.7,47.6z' |
| 73 | }, |
| 74 | }, |
| 75 | |
| 76 | // detail panel button definitions |
| 77 | buttons: { |
| 78 | src: { |
| 79 | gid: '*src', |
| 80 | tt: 'Set source node', |
| 81 | cb: function (data) { |
| 82 | $log.debug('Set src action invoked with data:', data); |
| 83 | pps.setSrc(selection); |
| 84 | } |
| 85 | }, |
| 86 | dst: { |
| 87 | gid: '*dst', |
| 88 | tt: 'Set destination node', |
| 89 | cb: function (data) { |
| 90 | $log.debug('Set dst action invoked with data:', data); |
| 91 | pps.setDst(selection); |
| 92 | } |
| 93 | } |
| 94 | }, |
| 95 | // Key bindings for PCE web overlay buttons |
| 96 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 97 | keyBindings: { |
| 98 | openBracket: { |
| 99 | cb: function () { |
| 100 | pps.setSrc(selection); |
| 101 | }, |
| 102 | tt: 'Set source node', |
| 103 | gid: '*src' |
| 104 | }, |
| 105 | closeBracket: { |
| 106 | cb: function () { |
| 107 | pps.setDst(selection); |
| 108 | }, |
| 109 | tt: 'Set destination node', |
| 110 | gid: '*dst' |
| 111 | }, |
| 112 | 1: { |
| 113 | cb: function () { |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 114 | pps.setMode(); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 115 | }, |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 116 | tt: 'Setup path', |
| 117 | gid: 'plus' |
| 118 | }, |
| 119 | 2: { |
| 120 | cb: function () { |
| 121 | pps.updatePath(selection); |
| 122 | }, |
| 123 | tt: 'Update path', |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 124 | gid: '*jp' |
| 125 | }, |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 126 | 3: { |
| 127 | cb: function () { |
| 128 | pps.remPath(selection); |
| 129 | }, |
| 130 | tt: 'Remove path', |
| 131 | gid: 'minus' |
| 132 | }, |
| 133 | 4: { |
| 134 | cb: function () { |
| 135 | pps.queryTunnelDisplay(); |
| 136 | }, |
| 137 | tt: 'Show Tunnels', |
| 138 | gid: 'checkMark' |
| 139 | }, |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 140 | 0: { |
| 141 | cb: function () { |
| 142 | pps.clear(); |
| 143 | }, |
| 144 | tt: 'Clear source and destination', |
| 145 | gid: 'xMark' |
| 146 | }, |
| 147 | |
| 148 | _keyOrder: [ |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 149 | 'openBracket', 'closeBracket', '1', '2', '3', '4', '0' |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 150 | ] |
| 151 | }, |
| 152 | hooks: { |
| 153 | // hook for handling escape key |
| 154 | // Must return true to consume ESC, false otherwise. |
| 155 | escape: function () { |
| 156 | selectionCallback(); |
| 157 | pps.setSrc(); |
| 158 | pps.setDst(); |
| 159 | return true; |
| 160 | }, |
| 161 | |
| 162 | // hooks for when the selection changes... |
| 163 | empty: function () { |
| 164 | selectionCallback(); |
| 165 | }, |
| 166 | single: function (data) { |
| 167 | selectionCallback(data); |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 168 | }, |
| 169 | multi: function (selectOrder) { |
| 170 | selectionCallback(selectOrder); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 171 | }, |
| 172 | modifylinkdata: function (data, extra) { |
| 173 | $log.debug("Modify link data", data, extra); |
| 174 | |
| 175 | function sep() { |
| 176 | data.propOrder.push('-'); |
| 177 | } |
| 178 | |
| 179 | function add(key) { |
| 180 | var val = extra[key]; |
| 181 | if (val !== undefined) { |
| 182 | data.propOrder.push(key); |
| 183 | data.props[key] = val; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | sep(); |
| 188 | add('Src port'); |
| 189 | add('Dst port'); |
| 190 | add('Te metric'); |
| 191 | add('Bandwidth'); |
| 192 | |
| 193 | return data; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | }; |
| 197 | |
| 198 | function selectionCallback(d) { |
| 199 | $log.debug('Selection callback', d); |
| 200 | selection = d; |
| 201 | } |
| 202 | |
| 203 | // invoke code to register with the overlay service |
| 204 | angular.module('ovPcewebTopov') |
| 205 | .run(['$log', 'TopoOverlayService', 'PcewebTopovDemoService', |
| 206 | |
| 207 | function (_$log_, _tov_, _pps_) { |
| 208 | $log = _$log_; |
| 209 | tov = _tov_; |
| 210 | pps = _pps_; |
| 211 | tov.register(overlay); |
| 212 | }]); |
| 213 | |
| 214 | }()); |