12875e1f6a0dd6f017b0d7042529202dceb815c8
[onosfw.git] /
1 // sample topology overlay - client side
2 //
3 // This is the glue that binds our business logic (in sampleTopovDemo.js)
4 // to the overlay framework.
5
6 (function () {
7     'use strict';
8
9     // injected refs
10     var $log, tov, stds;
11
12     // internal state should be kept in the service module (not here)
13
14     // our overlay definition
15     var overlay = {
16         // NOTE: this must match the ID defined in AppUiTopoOverlay
17         overlayId: 'meowster-overlay',
18         glyphId: '*star4',
19         tooltip: 'Sample Meowster Topo Overlay',
20
21         // These glyphs get installed using the overlayId as a prefix.
22         // e.g. 'star4' is installed as 'meowster-overlay-star4'
23         // They can be referenced (from this overlay) as '*star4'
24         // That is, the '*' prefix stands in for 'meowster-overlay-'
25         glyphs: {
26             star4: {
27                 vb: '0 0 8 8',
28                 d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
29             },
30             banner: {
31                 vb: '0 0 6 6',
32                 d: 'M1,1v4l2,-2l2,2v-4z'
33             }
34         },
35
36         activate: function () {
37             $log.debug("Sample topology overlay ACTIVATED");
38         },
39         deactivate: function () {
40             stds.stopDisplay();
41             $log.debug("Sample topology overlay DEACTIVATED");
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             0: {
66                 cb: function () { stds.stopDisplay(); },
67                 tt: 'Cancel Display Mode',
68                 gid: 'xMark'
69             },
70             V: {
71                 cb: function () { stds.startDisplay('mouse'); },
72                 tt: 'Start Mouse Mode',
73                 gid: '*banner'
74             },
75             F: {
76                 cb: function () { stds.startDisplay('link'); },
77                 tt: 'Start Link Mode',
78                 gid: 'chain'
79             },
80             G: {
81                 cb: buttonCallback,
82                 tt: 'Uses the G key',
83                 gid: 'crown'
84             },
85
86             _keyOrder: [
87                 '0', 'V', 'F', 'G'
88             ]
89         },
90
91         hooks: {
92             // hook for handling escape key
93             // Must return true to consume ESC, false otherwise.
94             escape: function () {
95                 // Must return true to consume ESC, false otherwise.
96                 return stds.stopDisplay();
97             },
98
99             // hooks for when the selection changes...
100             empty: function () {
101                 selectionCallback('empty');
102             },
103             single: function (data) {
104                 selectionCallback('single', data);
105             },
106             multi: function (selectOrder) {
107                 selectionCallback('multi', selectOrder);
108                 tov.addDetailButton('foo');
109                 tov.addDetailButton('bar');
110             },
111             mouseover: function (m) {
112                 // m has id, class, and type properties
113                 $log.debug('mouseover:', m);
114                 stds.updateDisplay(m);
115             },
116             mouseout: function () {
117                 $log.debug('mouseout');
118                 stds.updateDisplay();
119             }
120         }
121     };
122
123
124     function buttonCallback(x) {
125         $log.debug('Toolbar-button callback', x);
126     }
127
128     function selectionCallback(x, d) {
129         $log.debug('Selection callback', x, d);
130     }
131
132     // invoke code to register with the overlay service
133     angular.module('ovSampleTopov')
134         .run(['$log', 'TopoOverlayService', 'SampleTopovDemoService',
135
136         function (_$log_, _tov_, _stds_) {
137             $log = _$log_;
138             tov = _tov_;
139             stds = _stds_;
140             tov.register(overlay);
141         }]);
142
143 }());