Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 1 | // path painter topology overlay - client side |
| 2 | // |
Andrea Campanella | a4ef01d | 2017-02-02 09:34:26 -0800 | [diff] [blame] | 3 | // This is the glue that binds our business logic (in ppTopov.js) |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 4 | // to the overlay framework. |
| 5 | |
| 6 | (function () { |
| 7 | 'use strict'; |
| 8 | |
| 9 | // injected refs |
| 10 | var $log, tov, pps; |
| 11 | |
| 12 | // internal state should be kept in the service module (not here) |
| 13 | var selection; |
| 14 | |
| 15 | // our overlay definition |
| 16 | var overlay = { |
| 17 | // NOTE: this must match the ID defined in AppUiTopovOverlay |
| 18 | overlayId: 'pp-overlay', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 19 | glyphId: 'm_topo', |
Simon Hunt | fc5c584 | 2017-02-01 23:32:18 -0800 | [diff] [blame] | 20 | tooltip: 'Path Painter Overlay', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 21 | |
Andrea Campanella | 48c674c | 2015-12-04 14:48:04 -0800 | [diff] [blame] | 22 | activate: function () { |
| 23 | $log.debug("Path painter topology overlay ACTIVATED"); |
| 24 | }, |
| 25 | deactivate: function () { |
| 26 | pps.clear(); |
| 27 | $log.debug("Path painter topology overlay DEACTIVATED"); |
| 28 | }, |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 29 | |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 30 | |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 31 | // detail panel button definitions |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 32 | buttons: { |
| 33 | src: { |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 34 | gid: 'm_source', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 35 | tt: 'Set source node', |
| 36 | cb: function (data) { |
| 37 | $log.debug('Set src action invoked with data:', data); |
| 38 | pps.setSrc(selection); |
| 39 | } |
| 40 | }, |
| 41 | dst: { |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 42 | gid: 'm_destination', |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 43 | tt: 'Set destination node', |
| 44 | cb: function (data) { |
| 45 | $log.debug('Set dst action invoked with data:', data); |
| 46 | pps.setDst(selection); |
| 47 | } |
| 48 | } |
| 49 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 50 | // Key bindings for traffic overlay buttons |
| 51 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 52 | // FIXME: find better keys for shortest paths & disjoint paths modes |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 53 | keyBindings: { |
Andrea Campanella | 6f065b7 | 2016-01-25 13:08:46 -0800 | [diff] [blame] | 54 | openBracket: { |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 55 | cb: function () { |
| 56 | pps.setSrc(selection); |
| 57 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 58 | tt: 'Set source node', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 59 | gid: 'm_source' |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 60 | }, |
Andrea Campanella | 6f065b7 | 2016-01-25 13:08:46 -0800 | [diff] [blame] | 61 | closeBracket: { |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 62 | cb: function () { |
| 63 | pps.setDst(selection); |
| 64 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 65 | tt: 'Set destination node', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 66 | gid: 'm_destination' |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 67 | }, |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 68 | 3: { |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 69 | cb: function () { |
| 70 | pps.swapSrcDst(); |
| 71 | }, |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 72 | tt: 'Swap source and destination nodes', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 73 | gid: 'm_swap' |
Andrea Campanella | 0c17a0a | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 74 | }, |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 75 | 4: { |
| 76 | cb: function () { |
| 77 | pps.setMode("shortest"); |
| 78 | }, |
| 79 | tt: 'Set shortest paths mode', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 80 | gid: 'm_shortestPath' |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 81 | }, |
| 82 | 5: { |
| 83 | cb: function () { |
| 84 | pps.setMode("disjoint"); |
| 85 | }, |
| 86 | tt: 'Set disjoint paths mode', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 87 | gid: 'm_disjointPaths' |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 88 | }, |
Andrea Campanella | c87fba7 | 2015-12-04 11:30:59 -0800 | [diff] [blame] | 89 | 6: { |
| 90 | cb: function () { |
| 91 | pps.setMode("geodata"); |
| 92 | }, |
| 93 | tt: 'Set geodata path weight mode', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 94 | gid: 'm_shortestGeoPath' |
Andrea Campanella | c87fba7 | 2015-12-04 11:30:59 -0800 | [diff] [blame] | 95 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 96 | leftArrow: { |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 97 | cb: function () { |
| 98 | pps.prevPath(); |
| 99 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 100 | tt: 'Highlight previous path', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 101 | gid: 'm_prev' |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 102 | }, |
| 103 | rightArrow: { |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 104 | cb: function () { |
| 105 | pps.nextPath(); |
| 106 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 107 | tt: 'Highlight next path', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 108 | gid: 'm_next' |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 109 | }, |
Andrea Campanella | dffc7d6 | 2016-03-07 12:01:14 -0800 | [diff] [blame] | 110 | 0: { |
| 111 | cb: function () { |
| 112 | pps.clear(); |
| 113 | }, |
| 114 | tt: 'Clear source and destination', |
Andrea Campanella | 1937e29 | 2016-11-18 16:02:45 +0100 | [diff] [blame] | 115 | gid: 'm_xMark' |
Andrea Campanella | dffc7d6 | 2016-03-07 12:01:14 -0800 | [diff] [blame] | 116 | }, |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 117 | |
| 118 | _keyOrder: [ |
Andrea Campanella | dffc7d6 | 2016-03-07 12:01:14 -0800 | [diff] [blame] | 119 | 'openBracket', 'closeBracket', '3', '4', '5', '6', 'leftArrow', 'rightArrow', '0' |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 120 | ] |
| 121 | }, |
| 122 | |
| 123 | hooks: { |
| 124 | // hook for handling escape key |
Andrea Campanella | a4ef01d | 2017-02-02 09:34:26 -0800 | [diff] [blame] | 125 | // Must return true to consume ESC, false otherwise. |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 126 | escape: function () { |
| 127 | selectionCallback(); |
Andrea Campanella | a4ef01d | 2017-02-02 09:34:26 -0800 | [diff] [blame] | 128 | return pps.clear(); |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 129 | }, |
| 130 | |
| 131 | // hooks for when the selection changes... |
| 132 | empty: function () { |
| 133 | selectionCallback(); |
| 134 | }, |
| 135 | single: function (data) { |
| 136 | selectionCallback(data); |
| 137 | } |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | |
| 142 | function buttonCallback(x) { |
| 143 | $log.debug('Toolbar-button callback', x); |
| 144 | } |
| 145 | |
| 146 | function selectionCallback(d) { |
| 147 | $log.debug('Selection callback', d); |
| 148 | selection = d; |
| 149 | } |
| 150 | |
| 151 | // invoke code to register with the overlay service |
| 152 | angular.module('ovPpTopov') |
| 153 | .run(['$log', 'TopoOverlayService', 'PathPainterTopovService', |
| 154 | |
Andrea Campanella | 8583e6b | 2015-12-01 21:24:45 -0800 | [diff] [blame] | 155 | function (_$log_, _tov_, _pps_) { |
| 156 | $log = _$log_; |
| 157 | tov = _tov_; |
| 158 | pps = _pps_; |
| 159 | tov.register(overlay); |
| 160 | }]); |
Thomas Vachuska | b4d3ff7 | 2015-12-01 09:53:51 -0800 | [diff] [blame] | 161 | |
| 162 | }()); |