blob: 068c30c5974b68dce2318fb4e989b88c458df5c1 [file] [log] [blame]
Simon Hunt72e44bf2015-07-21 21:34:20 -07001// sample topology overlay - client side
2(function () {
3 'use strict';
4
5 // injected refs
Simon Hunt8d22c4b2015-08-06 16:24:43 -07006 var $log, tov;
7
8 // internal state
9 var someStateValue = true;
Simon Hunt72e44bf2015-07-21 21:34:20 -070010
11 // our overlay definition
12 var overlay = {
Simon Huntfb940112015-07-29 18:36:35 -070013 // NOTE: this must match the ID defined in AppUiTopoOverlay
14 overlayId: 'meowster-overlay',
15 glyphId: '*star4',
16 tooltip: 'Sample Meowster Topo Overlay',
Simon Hunt72e44bf2015-07-21 21:34:20 -070017
Simon Huntfb940112015-07-29 18:36:35 -070018 // These glyphs get installed using the overlayId as a prefix.
19 // e.g. 'star4' is installed as 'meowster-overlay-star4'
20 // They can be referenced (from this overlay) as '*star4'
21 // That is, the '*' prefix stands in for 'meowster-overlay-'
22 glyphs: {
23 star4: {
24 vb: '0 0 8 8',
25 d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
26 },
27 banner: {
28 vb: '0 0 6 6',
29 d: 'M1,1v4l2,-2l2,2v-4z'
30 }
Simon Hunt72e44bf2015-07-21 21:34:20 -070031 },
Simon Hunt72e44bf2015-07-21 21:34:20 -070032
Simon Hunt8d22c4b2015-08-06 16:24:43 -070033 activate: function () {
34 $log.debug("sample topology overlay ACTIVATED");
35 },
36 deactivate: function () {
37 $log.debug("sample topology overlay DEACTIVATED");
38 },
Simon Huntfb940112015-07-29 18:36:35 -070039
Simon Hunt8d22c4b2015-08-06 16:24:43 -070040
41
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 V: {
66 cb: buttonCallback,
67 tt: 'Uses the V key',
68 gid: '*banner'
69 },
70 F: {
71 cb: buttonCallback,
72 tt: 'Uses the F key',
73 gid: 'chain'
74 },
75 G: {
76 cb: buttonCallback,
77 tt: 'Uses the G key',
78 gid: 'crown'
79 },
80
81 T: {
82 cb: buttonCallback,
83 tt: 'Uses the T key',
84 gid: 'switch'
85 },
86
87 R: {
88 cb: buttonCallback,
89 tt: 'Uses the R key',
90 gid: 'endstation'
91 },
92
93 0: {
94 cb: buttonCallback,
95 tt: 'Uses the ZERO key',
96 gid: 'xMark'
97 },
98
99 _keyOrder: [
100 '0', 'V', 'F', 'G', 'T', 'R'
101 ]
102
103 // NOTE: T and R should be rejected (not installed)
104 // T is reserved for 'toggle Theme'
105 // R is reserved for 'Reset pan and zoom'
106 },
107
108 hooks: {
109 // hook for handling escape key
110 // Must return true to consume ESC, false otherwise.
111 escape: cancelState,
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 }
Simon Huntfb940112015-07-29 18:36:35 -0700125 }
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700126
Simon Hunt72e44bf2015-07-21 21:34:20 -0700127 };
128
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700129 // invoked when the escape key is pressed
130 function cancelState() {
131 if (someStateValue) {
132 someStateValue = false;
133 // we consumed the ESC event
134 return true;
135 }
136 return false;
Simon Huntfb940112015-07-29 18:36:35 -0700137 }
138
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700139 function buttonCallback(x) {
140 $log.debug('Toolbar-button callback', x);
Simon Huntfb940112015-07-29 18:36:35 -0700141 }
142
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700143 function selectionCallback(x, d) {
144 $log.debug('Selection callback', x, d);
Simon Hunt72e44bf2015-07-21 21:34:20 -0700145 }
146
Simon Hunt72e44bf2015-07-21 21:34:20 -0700147 // invoke code to register with the overlay service
148 angular.module('ovSample')
149 .run(['$log', 'TopoOverlayService',
150
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700151 function (_$log_, _tov_) {
Simon Hunt72e44bf2015-07-21 21:34:20 -0700152 $log = _$log_;
Simon Hunt8d22c4b2015-08-06 16:24:43 -0700153 tov = _tov_;
Simon Hunt72e44bf2015-07-21 21:34:20 -0700154 tov.register(overlay);
155 }]);
156
157}());