Bug 209
[osm/UI.git] / skyquake / plugins / launchpad / src / vnfr / vnfrSource.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 let alt = require('../alt');
20 import VnfrActions from './vnfrActions.js';
21 let Utils = require('utils/utils.js');
22 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
23 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
24 let isSocketOff = true;
25 import $ from 'jquery';
26
27 export default {
28 openVnfrSocket: function() {
29 return {
30 remote: function(state) {
31 let nsrRegEx = new RegExp("([0-9a-zA-Z-]+)\/vnfr$");
32 let nsr_id;
33 try {
34 console.log('NSR ID in url is', window.location.hash.match(nsrRegEx)[1]);
35 nsr_id = window.location.hash.match(nsrRegEx)[1];
36 } catch (e) {
37
38 }
39 return new Promise(function(resolve, reject) {
40 if (state.socket) {
41 resolve(false);
42 }
43 console.log(nsr_id)
44 $.ajax({
45 url: '//' + window.location.hostname + ':' + window.location.port + '/socket-polling?api_server=' + API_SERVER,
46 type: 'POST',
47 beforeSend: Utils.addAuthorizationStub,
48 data: {
49 url: API_SERVER + ':' + NODE_PORT + '/launchpad/nsr/' + nsr_id + '/vnfr?api_server=' + API_SERVER,
50 },
51 success: function(data) {
52 Utils.checkAndResolveSocketRequest(data, resolve, reject);
53 }
54 });
55 })
56 },
57 loading: VnfrActions.openVnfrSocketLoading,
58 success: VnfrActions.openVnfrSocketSuccess,
59 error: VnfrActions.openVnfrSocketError,
60 }
61 }
62 }