blob: 338c1d5d4f1874180fec525961f9cf8e6fce2d64 [file] [log] [blame]
Simon Huntb9c495e2015-11-05 15:08:06 -08001/*
2 Sample Demo module. This contains the "business logic" for the topology
3 overlay that we are implementing.
4 */
5
6(function () {
7 'use strict';
8
9 // injected refs
10 var $log, fs, flash, wss;
11
12 // constants
13 var displayStart = 'uiRefTopovDisplayStart',
14 displayUpdate = 'uiRefTopovDisplayUpdate',
15 displayStop = 'uiRefTopovDisplayStop';
16
17 // internal state
18 var currentMode = null;
19
20
21 // === ---------------------------
22 // === Helper functions
23
24 function sendDisplayStart(mode) {
25 wss.sendEvent(displayStart, {
26 mode: mode
27 });
28 }
29
30 function sendDisplayUpdate(what) {
31 wss.sendEvent(displayUpdate, {
32 id: what ? what.id : ''
33 });
34 }
35
36 function sendDisplayStop() {
37 wss.sendEvent(displayStop);
38 }
39
40 // === ---------------------------
41 // === Main API functions
42
43 function startDisplay(mode) {
44 if (currentMode === mode) {
45 $log.debug('(in mode', mode, 'already)');
46 } else {
47 currentMode = mode;
48 sendDisplayStart(mode);
49 flash.flash('Starting display mode: ' + mode);
50 }
51 }
52
53 function updateDisplay(m) {
54 if (currentMode) {
55 sendDisplayUpdate(m);
56 }
57 }
58
59 function stopDisplay() {
60 if (currentMode) {
61 currentMode = null;
62 sendDisplayStop();
63 flash.flash('Canceling display mode');
64 return true;
65 }
66 return false;
67 }
68
69 // === ---------------------------
70 // === Module Factory Definition
71
72 angular.module('ovUiRefTopov', [])
73 .factory('UiRefTopovDemoService',
74 ['$log', 'FnService', 'FlashService', 'WebSocketService',
75
76 function (_$log_, _fs_, _flash_, _wss_) {
77 $log = _$log_;
78 fs = _fs_;
79 flash = _flash_;
80 wss = _wss_;
81
82 return {
83 startDisplay: startDisplay,
84 updateDisplay: updateDisplay,
85 stopDisplay: stopDisplay
86 };
87 }]);
88}());