blob: b2f38b4d3a49cc8aa68147194db81e103720d4da [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001// path painter topology overlay - client side
2//
Andrea Campanellaa4ef01d2017-02-02 09:34:26 -08003// This is the glue that binds our business logic (in ppTopov.js)
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08004// 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 Campanella1937e292016-11-18 16:02:45 +010019 glyphId: 'm_topo',
Simon Huntfc5c5842017-02-01 23:32:18 -080020 tooltip: 'Path Painter Overlay',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080021
Andrea Campanella48c674c2015-12-04 14:48:04 -080022 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 Campanella8583e6b2015-12-01 21:24:45 -080029
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080030
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080031 // detail panel button definitions
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080032 buttons: {
33 src: {
Andrea Campanella1937e292016-11-18 16:02:45 +010034 gid: 'm_source',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080035 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 Campanella1937e292016-11-18 16:02:45 +010042 gid: 'm_destination',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080043 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 Vachuskab4d3ff72015-12-01 09:53:51 -080050 // Key bindings for traffic overlay buttons
51 // NOTE: fully qual. button ID is derived from overlay-id and key-name
Andrea Campanella8583e6b2015-12-01 21:24:45 -080052 // FIXME: find better keys for shortest paths & disjoint paths modes
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080053 keyBindings: {
Andrea Campanella6f065b72016-01-25 13:08:46 -080054 openBracket: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080055 cb: function () {
56 pps.setSrc(selection);
57 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080058 tt: 'Set source node',
Andrea Campanella1937e292016-11-18 16:02:45 +010059 gid: 'm_source'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080060 },
Andrea Campanella6f065b72016-01-25 13:08:46 -080061 closeBracket: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080062 cb: function () {
63 pps.setDst(selection);
64 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080065 tt: 'Set destination node',
Andrea Campanella1937e292016-11-18 16:02:45 +010066 gid: 'm_destination'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080067 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080068 3: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080069 cb: function () {
70 pps.swapSrcDst();
71 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080072 tt: 'Swap source and destination nodes',
Andrea Campanella1937e292016-11-18 16:02:45 +010073 gid: 'm_swap'
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080074 },
Andrea Campanella8583e6b2015-12-01 21:24:45 -080075 4: {
76 cb: function () {
77 pps.setMode("shortest");
78 },
79 tt: 'Set shortest paths mode',
Andrea Campanella1937e292016-11-18 16:02:45 +010080 gid: 'm_shortestPath'
Andrea Campanella8583e6b2015-12-01 21:24:45 -080081 },
82 5: {
83 cb: function () {
84 pps.setMode("disjoint");
85 },
86 tt: 'Set disjoint paths mode',
Andrea Campanella1937e292016-11-18 16:02:45 +010087 gid: 'm_disjointPaths'
Andrea Campanella8583e6b2015-12-01 21:24:45 -080088 },
Andrea Campanellac87fba72015-12-04 11:30:59 -080089 6: {
90 cb: function () {
91 pps.setMode("geodata");
92 },
93 tt: 'Set geodata path weight mode',
Andrea Campanella1937e292016-11-18 16:02:45 +010094 gid: 'm_shortestGeoPath'
Andrea Campanellac87fba72015-12-04 11:30:59 -080095 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080096 leftArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -080097 cb: function () {
98 pps.prevPath();
99 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800100 tt: 'Highlight previous path',
Andrea Campanella1937e292016-11-18 16:02:45 +0100101 gid: 'm_prev'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800102 },
103 rightArrow: {
Andrea Campanella8583e6b2015-12-01 21:24:45 -0800104 cb: function () {
105 pps.nextPath();
106 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800107 tt: 'Highlight next path',
Andrea Campanella1937e292016-11-18 16:02:45 +0100108 gid: 'm_next'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800109 },
Andrea Campanelladffc7d62016-03-07 12:01:14 -0800110 0: {
111 cb: function () {
112 pps.clear();
113 },
114 tt: 'Clear source and destination',
Andrea Campanella1937e292016-11-18 16:02:45 +0100115 gid: 'm_xMark'
Andrea Campanelladffc7d62016-03-07 12:01:14 -0800116 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800117
118 _keyOrder: [
Andrea Campanelladffc7d62016-03-07 12:01:14 -0800119 'openBracket', 'closeBracket', '3', '4', '5', '6', 'leftArrow', 'rightArrow', '0'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800120 ]
121 },
122
123 hooks: {
124 // hook for handling escape key
Andrea Campanellaa4ef01d2017-02-02 09:34:26 -0800125 // Must return true to consume ESC, false otherwise.
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800126 escape: function () {
127 selectionCallback();
Andrea Campanellaa4ef01d2017-02-02 09:34:26 -0800128 return pps.clear();
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800129 },
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 Campanella8583e6b2015-12-01 21:24:45 -0800155 function (_$log_, _tov_, _pps_) {
156 $log = _$log_;
157 tov = _tov_;
158 pps = _pps_;
159 tov.register(overlay);
160 }]);
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -0800161
162}());