Simon Hunt | 1ee0985 | 2015-09-29 12:28:14 -0700 | [diff] [blame^] | 1 | // sample topology overlay - client side |
| 2 | // |
| 3 | // This is the glue that binds our business logic (in sampleTopovDemo.js) |
| 4 | // to the overlay framework. |
| 5 | |
| 6 | (function () { |
| 7 | 'use strict'; |
| 8 | |
| 9 | // injected refs |
| 10 | var $log, tov, stds; |
| 11 | |
| 12 | // internal state should be kept in the service module (not here) |
| 13 | |
| 14 | // our overlay definition |
| 15 | var overlay = { |
| 16 | // NOTE: this must match the ID defined in AppUiTopoOverlay |
| 17 | overlayId: 'meowster-overlay', |
| 18 | glyphId: '*star4', |
| 19 | tooltip: 'Sample Meowster Topo Overlay', |
| 20 | |
| 21 | // These glyphs get installed using the overlayId as a prefix. |
| 22 | // e.g. 'star4' is installed as 'meowster-overlay-star4' |
| 23 | // They can be referenced (from this overlay) as '*star4' |
| 24 | // That is, the '*' prefix stands in for 'meowster-overlay-' |
| 25 | glyphs: { |
| 26 | star4: { |
| 27 | vb: '0 0 8 8', |
| 28 | d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z' |
| 29 | }, |
| 30 | banner: { |
| 31 | vb: '0 0 6 6', |
| 32 | d: 'M1,1v4l2,-2l2,2v-4z' |
| 33 | } |
| 34 | }, |
| 35 | |
| 36 | activate: function () { |
| 37 | $log.debug("Sample topology overlay ACTIVATED"); |
| 38 | }, |
| 39 | deactivate: function () { |
| 40 | stds.stopDisplay(); |
| 41 | $log.debug("Sample topology overlay DEACTIVATED"); |
| 42 | }, |
| 43 | |
| 44 | // detail panel button definitions |
| 45 | buttons: { |
| 46 | foo: { |
| 47 | gid: 'chain', |
| 48 | tt: 'A FOO action', |
| 49 | cb: function (data) { |
| 50 | $log.debug('FOO action invoked with data:', data); |
| 51 | } |
| 52 | }, |
| 53 | bar: { |
| 54 | gid: '*banner', |
| 55 | tt: 'A BAR action', |
| 56 | cb: function (data) { |
| 57 | $log.debug('BAR action invoked with data:', data); |
| 58 | } |
| 59 | } |
| 60 | }, |
| 61 | |
| 62 | // Key bindings for traffic overlay buttons |
| 63 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 64 | keyBindings: { |
| 65 | 0: { |
| 66 | cb: function () { stds.stopDisplay(); }, |
| 67 | tt: 'Cancel Display Mode', |
| 68 | gid: 'xMark' |
| 69 | }, |
| 70 | V: { |
| 71 | cb: function () { stds.startDisplay('mouse'); }, |
| 72 | tt: 'Start Mouse Mode', |
| 73 | gid: '*banner' |
| 74 | }, |
| 75 | F: { |
| 76 | cb: function () { stds.startDisplay('link'); }, |
| 77 | tt: 'Start Link Mode', |
| 78 | gid: 'chain' |
| 79 | }, |
| 80 | G: { |
| 81 | cb: buttonCallback, |
| 82 | tt: 'Uses the G key', |
| 83 | gid: 'crown' |
| 84 | }, |
| 85 | T: { |
| 86 | cb: buttonCallback, |
| 87 | tt: 'Uses the T key', |
| 88 | gid: 'switch' |
| 89 | }, |
| 90 | R: { |
| 91 | cb: buttonCallback, |
| 92 | tt: 'Uses the R key', |
| 93 | gid: 'endstation' |
| 94 | }, |
| 95 | |
| 96 | _keyOrder: [ |
| 97 | '0', 'V', 'F', 'G', 'T', 'R' |
| 98 | ] |
| 99 | |
| 100 | // NOTE: T and R should be rejected (not installed) |
| 101 | // T is reserved for 'toggle Theme' |
| 102 | // R is reserved for 'Reset pan and zoom' |
| 103 | }, |
| 104 | |
| 105 | hooks: { |
| 106 | // hook for handling escape key |
| 107 | // Must return true to consume ESC, false otherwise. |
| 108 | escape: function () { |
| 109 | // Must return true to consume ESC, false otherwise. |
| 110 | return stds.stopDisplay(); |
| 111 | }, |
| 112 | |
| 113 | // hooks for when the selection changes... |
| 114 | empty: function () { |
| 115 | selectionCallback('empty'); |
| 116 | }, |
| 117 | single: function (data) { |
| 118 | selectionCallback('single', data); |
| 119 | }, |
| 120 | multi: function (selectOrder) { |
| 121 | selectionCallback('multi', selectOrder); |
| 122 | tov.addDetailButton('foo'); |
| 123 | tov.addDetailButton('bar'); |
| 124 | }, |
| 125 | mouseover: function (m) { |
| 126 | // m has id, class, and type properties |
| 127 | $log.debug('mouseover:', m); |
| 128 | stds.updateDisplay(m); |
| 129 | }, |
| 130 | mouseout: function () { |
| 131 | $log.debug('mouseout'); |
| 132 | stds.updateDisplay(); |
| 133 | } |
| 134 | } |
| 135 | }; |
| 136 | |
| 137 | |
| 138 | function buttonCallback(x) { |
| 139 | $log.debug('Toolbar-button callback', x); |
| 140 | } |
| 141 | |
| 142 | function selectionCallback(x, d) { |
| 143 | $log.debug('Selection callback', x, d); |
| 144 | } |
| 145 | |
| 146 | // invoke code to register with the overlay service |
| 147 | angular.module('ovSampleTopov') |
| 148 | .run(['$log', 'TopoOverlayService', 'SampleTopovDemoService', |
| 149 | |
| 150 | function (_$log_, _tov_, _stds_) { |
| 151 | $log = _$log_; |
| 152 | tov = _tov_; |
| 153 | stds = _stds_; |
| 154 | tov.register(overlay); |
| 155 | }]); |
| 156 | |
| 157 | }()); |