4 * Copyright 2016 RIFT.IO Inc
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 let getSearchParams
= require('utils/rw.js').getSearchParams
;
21 var API_SERVER
= getSearchParams(window
.location
).api_server
;
22 let HOST
= API_SERVER
;
23 let NODE_PORT
= getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
24 let DEV_MODE
= getSearchParams(window
.location
).dev_mode
|| false;
25 var TopologyL2Actions
= require('./topologyL2Actions.js');
26 var Utils
= require('utils/utils.js');
27 import $ from 'jquery';
30 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
34 openTopologyApiSocket: function() {
36 remote: function(state
, id
) {
37 // TODO: add topology type to the parameter
38 return new Promise(function(resolve
, reject
) {
39 //If socket connection already exists, eat the request.
41 return resolve(false);
44 url
: '/socket-polling?api_server=' + API_SERVER
,
46 beforeSend
: Utils
.addAuthorizationStub
,
48 url
: '/launchpad/api/network-topology?api_server=' + API_SERVER
50 success: function(data
, textStatus
, jqXHR
) {
51 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
53 }).fail(function(xhr
){
54 //Authentication and the handling of fail states should be wrapped up into a connection class.
55 Utils
.checkAuthentication(xhr
.status
);
59 loading
: TopologyL2Actions
.openTopologyApiSocketLoading
,
60 success
: TopologyL2Actions
.openTopologyApiSocketSuccess
,
61 error
: TopologyL2Actions
.openTopologyApiSocketError
67 return new Promise(function (resolve
, reject
) {
69 url
: '/launchpad/api/network-topology?api_server=' + API_SERVER
,
71 beforeSend
: Utils
.addAuthorizationStub
,
72 contentType
: "application/json",
73 success: function(data
) {
76 error: function(error
) {
77 console
.log("There was an error getting the network topology data", error
);
86 success
: TopologyL2Actions
.getTopologyApiSuccess
,
87 error
: TopologyL2Actions
.getTopologyApiError
,
88 loading
: TopologyL2Actions
.getTopologyApiLoading