blob: 1fedd6d299604faf471ca7dd76610f9d6834a2f4 [file] [log] [blame]
Thomas Vachuska88716912015-11-13 08:15:01 -08001/*
2 * Copyright 2014-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, tss, tds;
27
28 // constants
29 var dataRequest = 'byonFetchNetworksRequest',
30 dataResponse = 'byonFetchNetworksResponse';
31
32 // internal state
33 var networks,
34 handlers = {};
35
36
37 // === ---------------------------
38 // === Helper functions
39
40 function sendDisplayStop() {
41 wss.sendEvent(displayStop);
42 }
43
44 function createListContent() {
45 var content = tds.createDiv('my-content-class'),
46 items;
47 items = content.append('div');
48 networks.forEach(function (d) {
49 items.append('p').text(d.name + ' (' + d.hostCount + ')');
50 });
51 return content;
52 }
53
54 function dClose() {
Simon Hunta06c85b2016-02-05 09:44:31 -080055 $log.debug('Dialog Close button clicked (or Esc pressed)');
Thomas Vachuska88716912015-11-13 08:15:01 -080056 }
57
58 function processResponse(data) {
59 networks = data.networks;
60 tds.openDialog()
61 .setTitle('Virtual Networks')
62 .addContent(createListContent())
Simon Hunta06c85b2016-02-05 09:44:31 -080063 .addCancel(dClose, 'Close')
Simon Huntffb98482016-02-04 13:51:31 -080064 .bindKeys();
Thomas Vachuska88716912015-11-13 08:15:01 -080065 }
66
67 function registerHandlers() {
68 handlers[dataResponse] = processResponse;
69 wss.bindHandlers(handlers);
70 }
71
72 function unregisterHandlers() {
73 wss.unbindHandlers(handlers);
74 }
75
76 // === ---------------------------
77 // === Main API functions
78
79 // this example dialog invoked from the toolbar
80 function start() {
81 $log.debug('BYON start');
82 registerHandlers();
83 openNetworkList();
84 }
85
86 // this example dialog invoked from the toolbar
87 function stop() {
88 $log.debug('BYON stop');
89 unregisterHandlers();
90 }
91
92 function openNetworkList() {
93 wss.sendEvent(dataRequest);
94 }
95
96 function handleEscape() {
Simon Hunta06c85b2016-02-05 09:44:31 -080097 // Placeholder.
98 // If you consume an Escape key (to cancel something), return true.
Thomas Vachuska88716912015-11-13 08:15:01 -080099 $log.debug("BYON escape");
100 return false;
101 }
102
103 // === ---------------------------
104 // === Module Factory Definition
105
106 angular.module('ovByonTopov', [])
107 .factory('ByonTopovService',
108 ['$log', 'FnService', 'FlashService', 'WebSocketService',
109 'TopoSelectService', 'TopoDialogService',
110
111 function (_$log_, _fs_, _flash_, _wss_, _tss_, _tds_) {
112 $log = _$log_;
113 fs = _fs_;
114 flash = _flash_;
115 wss = _wss_;
116 tss = _tss_;
117 tds = _tds_;
118
119 return {
120 start: start,
121 stop: stop,
122 openNetworkList: openNetworkList,
123 handleEscape: handleEscape
124 };
125 }]);
126}());