blob: 415928720f4a7261ac319c75adf9ced1f12fa4aa [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001// path painter topology overlay - client side
2//
3// This is the glue that binds our business logic (in ppTopovDemo.js)
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 Campanella0c17a0a2015-12-01 09:53:51 -080019 glyphId: 'topo',
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080020 tooltip: 'Path Painter Topo Overlay',
21
22 // These glyphs get installed using the overlayId as a prefix.
23 // e.g. 'star4' is installed as 'meowster-overlay-star4'
24 // They can be referenced (from this overlay) as '*star4'
25 // That is, the '*' prefix stands in for 'meowster-overlay-'
26 glyphs: {
27 star4: {
28 vb: '0 0 8 8',
29 d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
30 },
31 banner: {
32 vb: '0 0 6 6',
33 d: 'M1,1v4l2,-2l2,2v-4z'
34 }
35 },
36
37 activate: function () {
38 $log.debug("Path painter topology overlay ACTIVATED");
39 },
40 deactivate: function () {
41 $log.debug("Path painter topology overlay DEACTIVATED");
42 },
43
44 // detail panel button definitions
45 // FIXME: new icons for src/dst
46 buttons: {
47 src: {
48 gid: 'triangleUp',
49 tt: 'Set source node',
50 cb: function (data) {
51 $log.debug('Set src action invoked with data:', data);
52 pps.setSrc(selection);
53 }
54 },
55 dst: {
56 gid: 'triangleDown',
57 tt: 'Set destination node',
58 cb: function (data) {
59 $log.debug('Set dst action invoked with data:', data);
60 pps.setDst(selection);
61 }
62 }
63 },
64
65 // Key bindings for traffic overlay buttons
66 // NOTE: fully qual. button ID is derived from overlay-id and key-name
67 // FIXME: use into [ and ] instead of 1 and 2
68 // FIXME: new icons for src/dst
69 // TODO: add keys for shortest paths & disjoint paths modes
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080070 keyBindings: {
71 1: {
72 cb: function () { pps.setSrc(selection); },
73 tt: 'Set source node',
74 gid: 'triangleUp'
75 },
76 2: {
77 cb: function () { pps.setDst(selection); },
78 tt: 'Set destination node',
79 gid: 'triangleDown'
80 },
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080081 3: {
82 cb: function () { pps.swapSrcDst(); },
83 tt: 'Swap source and destination nodes',
84 gid: 'refresh'
85 },
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080086 leftArrow: {
87 cb: function () { pps.prevPath(); },
88 tt: 'Highlight previous path',
89 gid: 'prevIntent'
90 },
91 rightArrow: {
92 cb: function () { pps.nextPath(); },
93 tt: 'Highlight next path',
94 gid: 'nextIntent'
95 },
96
97 _keyOrder: [
Andrea Campanella0c17a0a2015-12-01 09:53:51 -080098 '1', '2', '3', 'leftArrow', 'rightArrow'
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -080099 ]
100 },
101
102 hooks: {
103 // hook for handling escape key
104 // Must return true to consume ESC, false otherwise.
105 escape: function () {
106 selectionCallback();
107 pps.setSrc();
108 pps.setDst();
109 },
110
111 // hooks for when the selection changes...
112 empty: function () {
113 selectionCallback();
114 },
115 single: function (data) {
116 selectionCallback(data);
117 }
118 }
119 };
120
121
122 function buttonCallback(x) {
123 $log.debug('Toolbar-button callback', x);
124 }
125
126 function selectionCallback(d) {
127 $log.debug('Selection callback', d);
128 selection = d;
129 }
130
131 // invoke code to register with the overlay service
132 angular.module('ovPpTopov')
133 .run(['$log', 'TopoOverlayService', 'PathPainterTopovService',
134
135 function (_$log_, _tov_, _pps_) {
136 $log = _$log_;
137 tov = _tov_;
138 pps = _pps_;
139 tov.register(overlay);
140 }]);
141
142}());