blob: 523142e4b17ba2bf8b99a8bb4ff5ac06b4958eed [file] [log] [blame]
Thomas Vachuskab4d3ff72015-12-01 09:53:51 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 Sample Demo module. This contains the "business logic" for the topology
19 overlay that we are implementing.
20 */
21
22(function () {
23 'use strict';
24
25 // injected refs
26 var $log, fs, flash, wss;
27
28 // constants
29 var srcMessage = 'ppTopovSetSrc',
30 dstMessage = 'ppTopovSetDst',
31 modeMessage = 'ppTopovSetMode',
32 nextPathMessage = 'ppTopovNextPath',
33 prevPathMessage = 'ppTopovPrevPath';
34
35 // internal state
36 var currentMode = null;
37
38
39 // === ---------------------------
40 // === Helper functions
41
42
43 // === ---------------------------
44 // === Main API functions
45
46
47 function setSrc(node) {
48 wss.sendEvent(srcMessage, {
49 id: node.id
50 });
51 flash.flash('Source node: ' + node.id);
52 }
53
54 function setDst(node) {
55 wss.sendEvent(dstMessage, {
56 id: node.id
57 });
58 flash.flash('Destination node: ' + node.id);
59 }
60
61 function nextPath(node) {
62 wss.sendEvent(nextPathMessage);
63 }
64
65 function prevPath(node) {
66 wss.sendEvent(prevPathMessage);
67 }
68
69
70 function setMode(mode) {
71 if (currentMode === mode) {
72 $log.debug('(in mode', mode, 'already)');
73 } else {
74 currentMode = mode;
75 wss.sendEvent(modeMessage, {
76 mode: mode
77 });
78 flash.flash('Path mode: ' + mode);
79 }
80 }
81
82 // === ---------------------------
83 // === Module Factory Definition
84
85 angular.module('ovPpTopov', [])
86 .factory('PathPainterTopovService',
87 ['$log', 'FnService', 'FlashService', 'WebSocketService',
88
89 function (_$log_, _fs_, _flash_, _wss_) {
90 $log = _$log_;
91 fs = _fs_;
92 flash = _flash_;
93 wss = _wss_;
94
95 return {
96 setSrc: setSrc,
97 setDst: setDst,
98 setMode: setMode,
99 nextPath: nextPath,
100 prevPath: prevPath
101 };
102 }]);
103}());