blob: 3a91674471f444168f8f6f9f0fdc097f4d2ab095 [file] [log] [blame]
Simon Huntb9c495e2015-11-05 15:08:06 -08001// UI Reference App - topology overlay - client side
2//
3// This is the glue that binds our business logic (in uiRefTopovDemo.js)
4// to the overlay framework.
5
6(function () {
7 'use strict';
8
9 // injected refs
Simon Hunt97f2dbb2015-11-06 13:39:58 -080010 var $log, tov, demo;
Simon Huntb9c495e2015-11-05 15:08:06 -080011
12 // internal state should be kept in the service module (not here)
13
Simon Huntdf8a6402016-02-04 10:58:54 -080014 var smiley = "M97,20.3A9.3,9.3,0,0,0,87.7,11H24.3A9.3,9.3,0,0,0,15,20.3" +
15 "V64.7A9.3,9.3,0,0,0,24.3,74H87.7A9.3,9.3,0,0,0,97,64.7V20.3Z" +
16 "M54.5,19.1A24.3,24.3,0,1,1,30.2,43.3,24.3,24.3,0,0,1,54.5,19.1Z" +
17 "M104.7,94.9L97.6,82.8c-0.9-1.6-3.7-2.8-6.1-2.8H18.9" +
18 "c-2.5,0-5.2,1.3-6.1,2.8L5.6,94.9C4.3,97.1,5.7,99,8.9,99h92.6" +
19 "C104.6,99,106.1,97.1,104.7,94.9ZM54.5,56.5" +
20 "c-7.3,0-17.2-8.6-13.3-7.4,13,3.9,13.7,3.9,26.5,0" +
21 "C71.7,48,61.9,56.6,54.5,56.6Z" +
22 "M38,33.9C38,32,40.2,31,42.1,31h7.3" +
23 "a3.2,3.2,0,0,1,3.1,1.7,13.1,13.1,0,0,1,2.1-.3,12.9,12.9,0,0,1,2.1.4" +
24 "A3.3,3.3,0,0,1,59.7,31H67c1.9,0,4,1,4,2.9v3.2A4.4,4.4,0,0,1,67,41" +
25 "H59.7A4,4,0,0,1,56,37.1V33.9h0a4.4,4.4,0,0,0-1.6-.2l-1.5.2H53v3.2" +
26 "A4,4,0,0,1,49.4,41H42.1A4.4,4.4,0,0,1,38,37.1V33.9Z";
27
Simon Huntb9c495e2015-11-05 15:08:06 -080028 // our overlay definition
29 var overlay = {
30 // NOTE: this must match the ID defined in UiRefTopoOverlay
31 overlayId: 'ui-ref-overlay',
Simon Huntdf8a6402016-02-04 10:58:54 -080032 glyphId: '*smiley',
Simon Huntb9c495e2015-11-05 15:08:06 -080033 tooltip: 'UI Reference Overlay',
34
35 // These glyphs get installed using the overlayId as a prefix.
36 // e.g. 'star4' is installed as 'ui-ref-overlay-star4'
37 // They can be referenced (from this overlay) as '*star4'
38 // That is, the '*' prefix stands in for 'ui-ref-overlay-'
39 glyphs: {
Simon Huntdf8a6402016-02-04 10:58:54 -080040 smiley: {
41 vb: '0 0 110 110',
42 d: smiley
43 },
Simon Huntb9c495e2015-11-05 15:08:06 -080044 star4: {
45 vb: '0 0 8 8',
46 d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
47 },
48 banner: {
49 vb: '0 0 6 6',
50 d: 'M1,1v4l2,-2l2,2v-4z'
51 }
52 },
53
54 activate: function () {
55 $log.debug("UI Ref topology overlay ACTIVATED");
Simon Hunt92042c82016-05-27 19:52:39 -070056 demo.overlayActive(true);
Simon Huntb9c495e2015-11-05 15:08:06 -080057 },
58 deactivate: function () {
Simon Hunt92042c82016-05-27 19:52:39 -070059 demo.overlayActive(false);
Simon Huntb9c495e2015-11-05 15:08:06 -080060 $log.debug("UI Ref topology overlay DEACTIVATED");
61 },
62
Simon Hunt92042c82016-05-27 19:52:39 -070063 // Detail panel button definitions
64 // NOTE: the callbacks needs to be wrapped in anonymous functions
65 // to defer the dereferencing of 'demo' to after injection
66 // of the business logic service API.
Simon Huntb9c495e2015-11-05 15:08:06 -080067 buttons: {
Simon Hunt92042c82016-05-27 19:52:39 -070068 simpleDialog: {
Simon Huntb9c495e2015-11-05 15:08:06 -080069 gid: '*banner',
Simon Hunt92042c82016-05-27 19:52:39 -070070 tt: 'Simple dialog example',
71 cb: function() { demo.simpleDialog(); }
72 },
73 chainDialog: {
74 gid: 'chain',
75 tt: 'Chained dialogs example',
76 cb: function () { demo.chainedDialogs(); }
Simon Huntb9c495e2015-11-05 15:08:06 -080077 }
78 },
79
Simon Hunt92042c82016-05-27 19:52:39 -070080 // Key bindings for topology overlay buttons
Simon Huntb9c495e2015-11-05 15:08:06 -080081 // NOTE: fully qual. button ID is derived from overlay-id and key-name
82 keyBindings: {
83 0: {
Simon Hunt97f2dbb2015-11-06 13:39:58 -080084 cb: function () { demo.stopDisplay(); },
Simon Huntb9c495e2015-11-05 15:08:06 -080085 tt: 'Cancel Display Mode',
86 gid: 'xMark'
87 },
88 V: {
Simon Hunt97f2dbb2015-11-06 13:39:58 -080089 cb: function () { demo.startDisplay('mouse'); },
Simon Huntb9c495e2015-11-05 15:08:06 -080090 tt: 'Start Mouse Mode',
91 gid: '*banner'
92 },
93 F: {
Simon Hunt97f2dbb2015-11-06 13:39:58 -080094 cb: function () { demo.startDisplay('link'); },
Simon Huntb9c495e2015-11-05 15:08:06 -080095 tt: 'Start Link Mode',
96 gid: 'chain'
97 },
Simon Hunt92042c82016-05-27 19:52:39 -070098 A: {
Simon Huntfb658672015-11-09 13:05:54 -080099 cb: function () { demo.listDialog(); },
Simon Hunt92042c82016-05-27 19:52:39 -0700100 tt: 'List Dialog',
Simon Huntb9c495e2015-11-05 15:08:06 -0800101 gid: 'crown'
102 },
103
Simon Hunt92042c82016-05-27 19:52:39 -0700104 // defines the order in which the buttons appear on the toolbar
Simon Huntb9c495e2015-11-05 15:08:06 -0800105 _keyOrder: [
Simon Hunt92042c82016-05-27 19:52:39 -0700106 '0', 'V', 'F', 'A'
Simon Huntb9c495e2015-11-05 15:08:06 -0800107 ]
108 },
109
110 hooks: {
Simon Hunt92042c82016-05-27 19:52:39 -0700111 // hook for handling escape key...
Simon Huntb9c495e2015-11-05 15:08:06 -0800112 escape: function () {
113 // Must return true to consume ESC, false otherwise.
Simon Hunt97f2dbb2015-11-06 13:39:58 -0800114 return demo.stopDisplay();
Simon Huntb9c495e2015-11-05 15:08:06 -0800115 },
116
117 // hooks for when the selection changes...
118 empty: function () {
Simon Hunt92042c82016-05-27 19:52:39 -0700119 // selection changed to the empty set
Simon Huntb9c495e2015-11-05 15:08:06 -0800120 selectionCallback('empty');
121 },
122 single: function (data) {
Simon Hunt92042c82016-05-27 19:52:39 -0700123 // selection changed to a single node
Simon Huntb9c495e2015-11-05 15:08:06 -0800124 selectionCallback('single', data);
Simon Hunt92042c82016-05-27 19:52:39 -0700125 // NOTE: the detail buttons to show on the dialog are included
126 // in the detail data response from the server
Simon Huntb9c495e2015-11-05 15:08:06 -0800127 },
128 multi: function (selectOrder) {
Simon Hunt92042c82016-05-27 19:52:39 -0700129 // selection changed to more than one node
Simon Huntb9c495e2015-11-05 15:08:06 -0800130 selectionCallback('multi', selectOrder);
Simon Hunt92042c82016-05-27 19:52:39 -0700131 // NOTE: we have to manually add detail button(s) for a
132 // multi-selection
133 tov.addDetailButton('simpleDialog');
Simon Huntb9c495e2015-11-05 15:08:06 -0800134 },
Simon Hunt92042c82016-05-27 19:52:39 -0700135
136 // hooks for mouse movement over nodes (devices/hosts)...
Simon Huntb9c495e2015-11-05 15:08:06 -0800137 mouseover: function (m) {
138 // m has id, class, and type properties
139 $log.debug('mouseover:', m);
Simon Hunt97f2dbb2015-11-06 13:39:58 -0800140 demo.updateDisplay(m);
Simon Huntb9c495e2015-11-05 15:08:06 -0800141 },
142 mouseout: function () {
143 $log.debug('mouseout');
Simon Hunt97f2dbb2015-11-06 13:39:58 -0800144 demo.updateDisplay();
Simon Huntb9c495e2015-11-05 15:08:06 -0800145 }
146 }
147 };
148
Simon Hunt92042c82016-05-27 19:52:39 -0700149 // just an example callback to log the selection to the console.
150 // usually you would do something more useful.
Simon Huntb9c495e2015-11-05 15:08:06 -0800151 function selectionCallback(x, d) {
152 $log.debug('Selection callback', x, d);
153 }
154
155 // invoke code to register with the overlay service
156 angular.module('ovUiRefTopov')
157 .run(['$log', 'TopoOverlayService', 'UiRefTopovDemoService',
158
Simon Hunt97f2dbb2015-11-06 13:39:58 -0800159 function (_$log_, _tov_, _demo_) {
Simon Huntb9c495e2015-11-05 15:08:06 -0800160 $log = _$log_;
161 tov = _tov_;
Simon Hunt97f2dbb2015-11-06 13:39:58 -0800162 demo = _demo_;
Simon Huntb9c495e2015-11-05 15:08:06 -0800163 tov.register(overlay);
164 }]);
165
166}());