Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [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 | // 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: { |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 50 | jp: { |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 51 | vb: '0 0 110 110', |
| 52 | d: 'M84.3,89.3L58.9,64.2l-1.4,1.4L83,90.7L84.3,89.3z M27,7.6H7.4v19.2H27V7.6z' + |
| 53 | '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' |
| 54 | }, |
| 55 | }, |
| 56 | |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 57 | // Key bindings for PCE web overlay buttons |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 58 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 59 | keyBindings: { |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 60 | 1: { |
| 61 | cb: function () { |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 62 | pps.setMode(selection); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 63 | }, |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 64 | tt: 'Setup path', |
| 65 | gid: 'plus' |
| 66 | }, |
| 67 | 2: { |
| 68 | cb: function () { |
| 69 | pps.updatePath(selection); |
| 70 | }, |
| 71 | tt: 'Update path', |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 72 | gid: '*jp' |
| 73 | }, |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 74 | 3: { |
| 75 | cb: function () { |
| 76 | pps.remPath(selection); |
| 77 | }, |
| 78 | tt: 'Remove path', |
| 79 | gid: 'minus' |
| 80 | }, |
| 81 | 4: { |
| 82 | cb: function () { |
| 83 | pps.queryTunnelDisplay(); |
| 84 | }, |
| 85 | tt: 'Show Tunnels', |
| 86 | gid: 'checkMark' |
| 87 | }, |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 88 | |
| 89 | _keyOrder: [ |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 90 | '1', '2', '3', '4' |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 91 | ] |
| 92 | }, |
| 93 | hooks: { |
| 94 | // hook for handling escape key |
| 95 | // Must return true to consume ESC, false otherwise. |
| 96 | escape: function () { |
| 97 | selectionCallback(); |
| 98 | pps.setSrc(); |
| 99 | pps.setDst(); |
| 100 | return true; |
| 101 | }, |
| 102 | |
| 103 | // hooks for when the selection changes... |
| 104 | empty: function () { |
| 105 | selectionCallback(); |
| 106 | }, |
| 107 | single: function (data) { |
| 108 | selectionCallback(data); |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 109 | }, |
| 110 | multi: function (selectOrder) { |
| 111 | selectionCallback(selectOrder); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame] | 112 | }, |
| 113 | modifylinkdata: function (data, extra) { |
| 114 | $log.debug("Modify link data", data, extra); |
| 115 | |
| 116 | function sep() { |
| 117 | data.propOrder.push('-'); |
| 118 | } |
| 119 | |
| 120 | function add(key) { |
| 121 | var val = extra[key]; |
| 122 | if (val !== undefined) { |
| 123 | data.propOrder.push(key); |
| 124 | data.props[key] = val; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | sep(); |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 129 | add('Src Address'); |
| 130 | add('Dst Address'); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame] | 131 | add('Te metric'); |
| 132 | add('Bandwidth'); |
| 133 | |
| 134 | return data; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | function selectionCallback(d) { |
| 140 | $log.debug('Selection callback', d); |
| 141 | selection = d; |
| 142 | } |
| 143 | |
| 144 | // invoke code to register with the overlay service |
| 145 | angular.module('ovPcewebTopov') |
| 146 | .run(['$log', 'TopoOverlayService', 'PcewebTopovDemoService', |
| 147 | |
| 148 | function (_$log_, _tov_, _pps_) { |
| 149 | $log = _$log_; |
| 150 | tov = _tov_; |
| 151 | pps = _pps_; |
| 152 | tov.register(overlay); |
| 153 | }]); |
| 154 | |
| 155 | }()); |