Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 1 | // UI Reference App - topology overlay - client side |
| 2 | // |
| 3 | // This is the glue that binds our business logic (in uiRefTopovDemo.js) |
| 4 | // to the overlay framework. |
| 5 | |
| 6 | (function () { |
| 7 | 'use strict'; |
| 8 | |
| 9 | // injected refs |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 10 | var $log, tov, demo; |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 11 | |
| 12 | // internal state should be kept in the service module (not here) |
| 13 | |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame] | 14 | var smiley = "M97,20.3A9.3,9.3,0,0,0,87.7,11H24.3A9.3,9.3,0,0,0,15,20.3" + |
| 15 | "V64.7A9.3,9.3,0,0,0,24.3,74H87.7A9.3,9.3,0,0,0,97,64.7V20.3Z" + |
| 16 | "M54.5,19.1A24.3,24.3,0,1,1,30.2,43.3,24.3,24.3,0,0,1,54.5,19.1Z" + |
| 17 | "M104.7,94.9L97.6,82.8c-0.9-1.6-3.7-2.8-6.1-2.8H18.9" + |
| 18 | "c-2.5,0-5.2,1.3-6.1,2.8L5.6,94.9C4.3,97.1,5.7,99,8.9,99h92.6" + |
| 19 | "C104.6,99,106.1,97.1,104.7,94.9ZM54.5,56.5" + |
| 20 | "c-7.3,0-17.2-8.6-13.3-7.4,13,3.9,13.7,3.9,26.5,0" + |
| 21 | "C71.7,48,61.9,56.6,54.5,56.6Z" + |
| 22 | "M38,33.9C38,32,40.2,31,42.1,31h7.3" + |
| 23 | "a3.2,3.2,0,0,1,3.1,1.7,13.1,13.1,0,0,1,2.1-.3,12.9,12.9,0,0,1,2.1.4" + |
| 24 | "A3.3,3.3,0,0,1,59.7,31H67c1.9,0,4,1,4,2.9v3.2A4.4,4.4,0,0,1,67,41" + |
| 25 | "H59.7A4,4,0,0,1,56,37.1V33.9h0a4.4,4.4,0,0,0-1.6-.2l-1.5.2H53v3.2" + |
| 26 | "A4,4,0,0,1,49.4,41H42.1A4.4,4.4,0,0,1,38,37.1V33.9Z"; |
| 27 | |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 28 | // our overlay definition |
| 29 | var overlay = { |
| 30 | // NOTE: this must match the ID defined in UiRefTopoOverlay |
| 31 | overlayId: 'ui-ref-overlay', |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame] | 32 | glyphId: '*smiley', |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 33 | tooltip: 'UI Reference Overlay', |
| 34 | |
| 35 | // These glyphs get installed using the overlayId as a prefix. |
| 36 | // e.g. 'star4' is installed as 'ui-ref-overlay-star4' |
| 37 | // They can be referenced (from this overlay) as '*star4' |
| 38 | // That is, the '*' prefix stands in for 'ui-ref-overlay-' |
| 39 | glyphs: { |
Simon Hunt | df8a640 | 2016-02-04 10:58:54 -0800 | [diff] [blame] | 40 | smiley: { |
| 41 | vb: '0 0 110 110', |
| 42 | d: smiley |
| 43 | }, |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 44 | star4: { |
| 45 | vb: '0 0 8 8', |
| 46 | d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z' |
| 47 | }, |
| 48 | banner: { |
| 49 | vb: '0 0 6 6', |
| 50 | d: 'M1,1v4l2,-2l2,2v-4z' |
| 51 | } |
| 52 | }, |
| 53 | |
| 54 | activate: function () { |
| 55 | $log.debug("UI Ref topology overlay ACTIVATED"); |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 56 | demo.overlayActive(true); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 57 | }, |
| 58 | deactivate: function () { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 59 | demo.overlayActive(false); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 60 | $log.debug("UI Ref topology overlay DEACTIVATED"); |
| 61 | }, |
| 62 | |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 63 | // Detail panel button definitions |
| 64 | // NOTE: the callbacks needs to be wrapped in anonymous functions |
| 65 | // to defer the dereferencing of 'demo' to after injection |
| 66 | // of the business logic service API. |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 67 | buttons: { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 68 | simpleDialog: { |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 69 | gid: '*banner', |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 70 | tt: 'Simple dialog example', |
| 71 | cb: function() { demo.simpleDialog(); } |
| 72 | }, |
| 73 | chainDialog: { |
| 74 | gid: 'chain', |
| 75 | tt: 'Chained dialogs example', |
| 76 | cb: function () { demo.chainedDialogs(); } |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 77 | } |
| 78 | }, |
| 79 | |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 80 | // Key bindings for topology overlay buttons |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 81 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 82 | keyBindings: { |
| 83 | 0: { |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 84 | cb: function () { demo.stopDisplay(); }, |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 85 | tt: 'Cancel Display Mode', |
| 86 | gid: 'xMark' |
| 87 | }, |
| 88 | V: { |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 89 | cb: function () { demo.startDisplay('mouse'); }, |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 90 | tt: 'Start Mouse Mode', |
| 91 | gid: '*banner' |
| 92 | }, |
| 93 | F: { |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 94 | cb: function () { demo.startDisplay('link'); }, |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 95 | tt: 'Start Link Mode', |
| 96 | gid: 'chain' |
| 97 | }, |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 98 | A: { |
Simon Hunt | fb65867 | 2015-11-09 13:05:54 -0800 | [diff] [blame] | 99 | cb: function () { demo.listDialog(); }, |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 100 | tt: 'List Dialog', |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 101 | gid: 'crown' |
| 102 | }, |
| 103 | |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 104 | // defines the order in which the buttons appear on the toolbar |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 105 | _keyOrder: [ |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 106 | '0', 'V', 'F', 'A' |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 107 | ] |
| 108 | }, |
| 109 | |
| 110 | hooks: { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 111 | // hook for handling escape key... |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 112 | escape: function () { |
| 113 | // Must return true to consume ESC, false otherwise. |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 114 | return demo.stopDisplay(); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 115 | }, |
| 116 | |
| 117 | // hooks for when the selection changes... |
| 118 | empty: function () { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 119 | // selection changed to the empty set |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 120 | selectionCallback('empty'); |
| 121 | }, |
| 122 | single: function (data) { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 123 | // selection changed to a single node |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 124 | selectionCallback('single', data); |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 125 | // NOTE: the detail buttons to show on the dialog are included |
| 126 | // in the detail data response from the server |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 127 | }, |
| 128 | multi: function (selectOrder) { |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 129 | // selection changed to more than one node |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 130 | selectionCallback('multi', selectOrder); |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 131 | // NOTE: we have to manually add detail button(s) for a |
| 132 | // multi-selection |
| 133 | tov.addDetailButton('simpleDialog'); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 134 | }, |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 135 | |
| 136 | // hooks for mouse movement over nodes (devices/hosts)... |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 137 | mouseover: function (m) { |
| 138 | // m has id, class, and type properties |
| 139 | $log.debug('mouseover:', m); |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 140 | demo.updateDisplay(m); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 141 | }, |
| 142 | mouseout: function () { |
| 143 | $log.debug('mouseout'); |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 144 | demo.updateDisplay(); |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | }; |
| 148 | |
Simon Hunt | 92042c8 | 2016-05-27 19:52:39 -0700 | [diff] [blame] | 149 | // just an example callback to log the selection to the console. |
| 150 | // usually you would do something more useful. |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 151 | function selectionCallback(x, d) { |
| 152 | $log.debug('Selection callback', x, d); |
| 153 | } |
| 154 | |
| 155 | // invoke code to register with the overlay service |
| 156 | angular.module('ovUiRefTopov') |
| 157 | .run(['$log', 'TopoOverlayService', 'UiRefTopovDemoService', |
| 158 | |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 159 | function (_$log_, _tov_, _demo_) { |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 160 | $log = _$log_; |
| 161 | tov = _tov_; |
Simon Hunt | 97f2dbb | 2015-11-06 13:39:58 -0800 | [diff] [blame] | 162 | demo = _demo_; |
Simon Hunt | b9c495e | 2015-11-05 15:08:06 -0800 | [diff] [blame] | 163 | tov.register(overlay); |
| 164 | }]); |
| 165 | |
| 166 | }()); |