Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / launchpad / src / topologyL2View / topologyL2Source.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 getSearchParams = require('utils/rw.js').getSearchParams;
20
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';
28
29 if (DEV_MODE) {
30 HOST = window.location.protocol + '//' + window.location.hostname;
31 }
32
33 export default {
34 openTopologyApiSocket: function() {
35 return {
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.
40 if(state.socket) {
41 return resolve(false);
42 }
43 $.ajax({
44 url: '/socket-polling?api_server=' + API_SERVER ,
45 type: 'POST',
46 beforeSend: Utils.addAuthorizationStub,
47 data: {
48 url: '/launchpad/api/network-topology?api_server=' + API_SERVER
49 },
50 success: function(data, textStatus, jqXHR) {
51 Utils.checkAndResolveSocketRequest(data, resolve, reject);
52 }
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);
56 });;
57 });
58 },
59 loading: TopologyL2Actions.openTopologyApiSocketLoading,
60 success: TopologyL2Actions.openTopologyApiSocketSuccess,
61 error: TopologyL2Actions.openTopologyApiSocketError
62 };
63 },
64 fetchTopology() {
65 return {
66 remote() {
67 return new Promise(function (resolve, reject) {
68 $.ajax({
69 url: '/launchpad/api/network-topology?api_server=' + API_SERVER,
70 type: 'GET',
71 beforeSend: Utils.addAuthorizationStub,
72 contentType: "application/json",
73 success: function(data) {
74 resolve(data);
75 },
76 error: function(error) {
77 console.log("There was an error getting the network topology data", error);
78 reject(error);
79 }
80 });
81 })
82 },
83 local() {
84 return null;
85 },
86 success: TopologyL2Actions.getTopologyApiSuccess,
87 error: TopologyL2Actions.getTopologyApiError,
88 loading: TopologyL2Actions.getTopologyApiLoading
89 }
90 }
91 }