login redirect to last page. if no last page redirect to launchpad if lcm role in...
[osm/UI.git] / skyquake / plugins / launchpad / src / launchpad_card / launchpad-card.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 require('./launchpad-fleet-card-params.html');
20 var React = require('react');
21 var LaunchpadCard = require('./launchpadCard.jsx');
22 // var LaunchpadCard = require('../../components/dashboard_card/dashboard_card.jsx');
23 angular.module('launchpad')
24 .directive('fleetCard', function($state, $stateParams) {
25 return {
26 restrict: 'AE',
27 replace: true,
28 template: '<div></div>',
29 scope: {
30 fleet: '=data',
31 $index: '=',
32 metric: '=?',
33 slaParam: '=?',
34 nfviMetric: '=?'
35 },
36
37 bindToController: true,
38 controllerAs: 'card',
39 link: function(scope, element, attributes) {
40
41 },
42 controller: function($timeout, $interval, $scope, $rootScope, $element) {
43 var self = this;
44
45 console.log(self.fleet)
46 $scope.$watch(function() {
47 return self.fleet}, reactRender)
48 function reactRender() {
49 console.log('rendering', self.fleet)
50 React.render(
51 React.createElement(LaunchpadCard, {className:'launchpadCard'}
52 ),
53 $element[0]
54 );
55 }
56 //FOR WAG ONLY
57 // self.isOn = false;
58
59 // //END WAG ONLY
60 // //Remove for testing only
61 // $scope.$watch(function() {
62 // return self.fleet;
63 // }, function() {});
64
65 // // var fleetChannel = $rw.radio.channel('fleetChannel');
66 // var FleetStore = require('../launchpadFleetStore.js');
67 // self.valueFormat = {
68 // "int": 1,
69 // "dec": 0
70 // };
71 // self.federationID = $stateParams.id;
72 // //if this is true, set gauges to start
73 // if (require('utils/rw.js').getSearchParams(window.location).api_server) {
74 // self.fleet.started = true;
75 // }
76 // self.apiServer = require('utils/rw.js').getSearchParams(window.location).api_server;
77 // self.isNoisy = false;
78 // var rateChanged = function(rate) {
79 // self.rate = rate;
80 // fleetChannel.command('fleet:change:rate', rate)
81 // }
82 // var packetSizeChanged = function(packetSize) {
83 // self.packetSize = packetSize
84 // fleetChannel.command('fleet:change:packetSize', packetSize)
85 // };
86 // self.openFleet = function(index) {
87 // var params = require('utils/rw.js').getSearchParams(window.location);
88 // if (params.api_server) {
89 // if (params.api_server == "http://10.0.201.25:5000") {
90 // var newLoc = window.location.origin + window.location.pathname + '?config=' + params.config + '&api_server=' + 'http://10.0.201.25:5050' + '#/wag';
91 // window.open(newLoc);
92 // return;
93 // }
94 // if (self.fleet.api == "10.0.117.22") self.fleet.api = "10.0.117.17";
95 // var newLoc = window.location.origin + window.location.pathname + '?config=' + params.config + '&api_server=' + 'http://' + self.fleet.api + ':5050' + '&name=' + self.fleet.name + '&env_id=' + self.fleet.id + '#/dashboard/' + $stateParams.id + '/' + index;;
96 // console.log('Opening new window at: %s', newLoc)
97 // window.open(newLoc);
98 // } else {
99 // if (self.fleet.id == 'wag-fleet') {
100 // var newLoc = window.location.origin + window.location.pathname + '?config=' + params.config + '#/wag';
101 // window.open(newLoc);
102 // }
103 // window.open('#/dashboard/' + $stateParams.id + '/' + index);
104 // }
105 // };
106 // self.openConsole = function(index) {
107 // console.log(self);
108 // var params = require('utils/rw.js').getSearchParams(window.location);
109 // if (params.api_server) {
110 // if (self.fleet.api == "10.0.117.22") self.fleet.api = "10.0.117.17";
111 // var newLoc = self.apiServer + '/api/environments/' + self.fleet.id + '/console';
112 // window.open(newLoc);
113 // } else {
114 // window.open('#/dashboard/' + $stateParams.id + '/' + index);
115 // }
116 // };
117
118
119 // self.noisyToggle = function() {
120 // var action;
121 // if (self.isNoisy) {
122 // action = 'stop';
123 // self.isNoisy = false;
124 // } else {
125 // action = 'start';
126 // self.isNoisy = true;
127 // }
128 // $.ajax({
129 // url: "http://" + self.fleet.api + ':5050/api/operations/' + action + '-stream',
130 // type: "POST",
131 // headers: {
132 // "Content-Type": "application/vnd.yang.operation+json"
133 // },
134 // dataType: "json",
135 // data: JSON.stringify({
136 // "input": {
137 // "now": ""
138 // }
139 // })
140 // });
141 // };
142
143 // self.toggleStatus = function() {
144 // var state;
145 // var status = self.fleet.status;
146 // console.log(self.fleet)
147 // if (status == "starting" || status == "stopping") {
148 // return;
149 // }
150 // if (status == "active") {
151 // state = "inactive";
152 // } else {
153 // state = "active";
154 // }
155 // self.fleet.status = state;
156 // FleetStore.setFleetState(self.fleet.id, state);
157 // };
158 // //CAT + NOISY NEIGHBOR ONLY
159
160 // self.catStarted = false;
161 // self.catToggle = function() {
162 // var action;
163 // if (self.catStarted) {
164 // action = 'stop';
165 // self.catStarted = false;
166 // } else {
167 // action = 'start';
168 // self.catStarted = true;
169 // }
170 // $.ajax({
171 // url: "http://" + self.fleet.api + ':5050/api/operations/' + action + '-cat',
172 // type: "POST",
173 // headers: {
174 // "Content-Type": "application/vnd.yang.operation+json"
175 // },
176 // dataType: "json",
177 // data: JSON.stringify({
178 // "input": {
179 // "now": ""
180 // }
181 // })
182 // });
183 // };
184
185 // self.deleteFleet = function() {
186 // if (confirm("Do you really want to delete this fleet?")) {
187 // // if (confirm("Seriously, you REALLY want to delete this?")) {
188 // // fleetChannel.request('fleet:delete', self.fleet);
189 // FleetStore.deleteFleet(self.fleet.id)
190 // // }
191 // }
192 // };
193
194
195 // /**
196 // * WAG Code Start
197 // **/
198 // // var wagChannel = $rw.radio.channel('wag');
199
200 // //If Wag page Offline
201 // if (!self.apiServer && self.fleet.id == 'wag-fleet') {
202 // self.offline = setInterval(function() {
203 // if (self.fleet.started) {
204 // self.fleet.wagpage.clientsim['traffic-gen']['rx-pps'] = 100 * (Math.random() - .5) + 200;
205 // self.fleet.wagpage.clientsim['traffic-gen']['tx-pps'] = 100 * (Math.random() - .5) + 200;
206 // }
207 // }, 2000);
208 // }
209
210 // // If Wag page Online
211 // if (self.fleet.template_name == 'Wireless Access Gateway') {
212 // wagChannel.command('wag-poll');
213 // wagChannel.on('wag-update', function(data) {
214 // $timeout(function() {
215 // self.fleet.wagpage = {};
216 // self.fleet.wagpage.clientsim = data.clientsim
217 // // self.data.clientsim['traffic-sink']['rx-pps'] / 1000000;
218 // self.isOn = data.clientsim['traffic-gen-status'].running;
219 // });
220 // });
221 // }
222
223 // $rootScope.$on('$stateChangeStart', function() {
224 // wagChannel.command('wag-poll:kill');
225 // });
226
227 // /**
228 // * WAG Code End
229 // **/
230
231
232 }
233 };
234 })
235
236 .directive('launchpadFleetCardParams', function() {
237 return {
238 restrict: 'AE',
239 replace: true,
240 templateUrl: '/modules/launchpad/launchpad_card/launchpad-fleet-card-params.html',
241 controllerAs: 'params',
242 scope: {
243 $index: "=",
244 cardData: '=',
245 slaParam: '=?',
246 nfviMetric: '=?'
247 },
248 bindToController: true,
249 controller: function($scope, $stateParams, $timeout, $interval, $rootScope) {
250 //remove watch
251 $scope.$watch(function() {
252 return self.cardData;
253 }, function() {})
254 var self = this;
255 var apiServer = require('utils/rw.js').getSearchParams(window.location).api_server;
256 self.apiServer = apiServer;
257 // self.refs = refsDB;
258
259
260 // var LaunchpadFleetActions = require('../launchpadFleetActions.js');
261 // var LaunchpadFleetStore = require('../launchpadFleetStore.js');
262 //var LaunchpadFleetActions = require('./launchpadFleetActions.js');
263
264 self.rate = 40;
265 self.packetSize = 256;
266 self.refParam = $rw.refParams;
267 var currentNFVIRef;
268
269 this.visible = 'default';
270 if (self.cardData.id == "wag-fleet") {
271 self.cardData.started = self.cardData.wagpage.clientsim['traffic-gen-status'].running;
272 }
273
274
275 self.selectedNFVI = 0;
276 self.selectedSLAParam = {};
277 self.refPools = $rw.refPools;
278
279 // Event Listeners
280 // View Actions
281 self.load = function(panel) {
282 self.visible = panel;
283 };
284 self.filterSLA = function(ref) {
285 // fleetChannel.command('filter:SLAParams', ref);
286 FleetActions.filterSLAParams(ref);
287 };
288 self.filterNFVI = function(ref) {
289 FleetActions.filterNfviMetrics(ref)
290 // fleetChannel.command('filter:NFVIMetrics', ref);
291 };
292 self.serviceToggle = function(fleet, control) {
293 if (apiServer) {
294 var vnfrChannel = $rw.radio.channel('vnfr');
295 switch (control.ref) {
296 case "trafgen":
297 var action = (control.started) ? 'stop' : 'start';
298 vnfrChannel.command("vnf:command", action, control.data.api, "http://" + fleet.api + ':5050');
299 break;
300 case "iot_army":
301 var action = (control.started) ? 'stop' : 'start';
302 vnfrChannel.command("vnf:command", action, control.data.api, "http://" + fleet.api + ':5050');
303 break;
304 }
305 } else {
306 fleetChannel.command('fleet:start', $stateParams.id, self.$index);
307 if ($stateParams.id == 'wag-federation') {
308 if (!self.cardData.wagpage.clientsim['traffic-gen-status']) {
309 self.cardData.wagpage.clientsim['traffic-gen-status'] = {};
310 }
311 self.cardData.wagpage.clientsim['traffic-gen-status'].running = !self.cardData.wagpage.clientsim['traffic-gen-status'].running;
312 }
313 }
314
315 };
316 // Init Params
317
318
319 //WAG ONLY
320 if (self.apiServer == "http://10.0.201.25:5000") {
321 self.isWag = true;
322 }
323 self.toggleOn = function(e) {
324 // self.setPacket(e, self.packetSize);
325 // self.setRate(e, self.rate);
326 // self.setSubscribers(e, self.subscribers);
327 // self.setAP(e, self.ap);
328 var wagServer = ""
329 if (self.apiServer) {
330 if (self.isOn) {
331 $.ajax({
332 type: "POST",
333 url: "http://10.0.201.25:5050/api/running/stop-device-group/",
334 success: (function() {
335 console.log('stahp post sent')
336 })
337 });
338 $.ajax({
339 type: "POST",
340 url: "http://10.0.201.25:5050/api/running/stop-sink-server/",
341 success: (function() {
342 console.log('stahp post sent')
343 })
344 });
345 } else {
346 $.ajax({
347 type: "POST",
348 url: "http://10.0.201.25:5050/api/running/start-sink-server/",
349 success: (function() {
350 console.log('start post sent')
351 })
352 });
353 $.ajax({
354 type: "POST",
355 url: "http://10.0.201.25:5050/api/running/start-device-group/",
356 success: (function() {
357 console.log('start post sent')
358 })
359 });
360 }
361 }
362 self.isOn = !self.isOn;
363 }
364
365 //END WAG ONLY
366
367 },
368 link: function(s, e, a) {}
369 }
370 });