71e3d7d5dda7f491e8573f727d89782b8ec6e0bb
3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
20 let HOST
= API_SERVER
;
21 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| 8000;
22 let DEV_MODE
= require('utils/rw.js').getSearchParams(window
.location
).dev_mode
|| false;
25 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
28 var isSocketOff
= true;
29 var FleetActions
= require('./launchpadFleetActions.js');
30 var Utils
= require('utils/utils.js');
31 import $ from 'jquery';
34 module
.exports = function(Alt
) {
38 remote: function(state
, method
, url
, value
) {
39 return new Promise(function(resolve
, reject
) {
41 // console.log(method + 'ing: "' + value + '" to "' + url + '"');
42 resolve(method
+ 'ing: "' + value
+ '" to "' + url
+ '"')
45 success
: FleetActions
.nsrControlSuccess
,
46 error
: FleetActions
.nsrControlError
50 return new Promise(function(resolve
, reject
) {
52 url
: 'api/nsr?api_server=' + API_SERVER
,
54 beforeSend
: Utils
.addAuthorizationStub
,
55 success: function(data
) {
61 success
: FleetActions
.getNsrInstancesSuccess
,
62 error
: FleetActions
.getNsrInstancesError
65 remote: function(d
, id
) {
67 return new Promise(function(resolve
, reject
) {
69 url
: 'api/nsr/' + id
+ '?api_server=' + API_SERVER
,
71 beforeSend
: Utils
.addAuthorizationStub
,
72 success: function(data
) {
78 success
: FleetActions
.deleteNsrInstanceSuccess
,
79 error
: FleetActions
.deleteNsrInstancesError
82 remote: function(state
) {
83 return new Promise(function(resolve
, reject
) {
84 //If socket connection already exists, eat the request.
86 return resolve(false);
89 url
: '/socket-polling?api_server=' + API_SERVER
,
91 beforeSend
: Utils
.addAuthorizationStub
,
93 url
: 'launchpad/api/nsr?api_server=' + API_SERVER
95 success: function(data
, textStatus
, jqXHR
) {
96 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
98 }).fail(function(xhr
){
99 //Authentication and the handling of fail states should be wrapped up into a connection class.
100 Utils
.checkAuthentication(xhr
.status
);
104 loading
: Alt
.actions
.global
.openNSRSocketLoading
,
105 success
: FleetActions
.openNSRSocketSuccess
,
106 error
: FleetActions
.openNSRError
109 remote: function(state
, id
, status
) {
110 return new Promise(function(resolve
, reject
) {
112 url
: 'api/nsr/' + id
+ '/admin-status?api_server=' + API_SERVER
,
114 beforeSend
: Utils
.addAuthorizationStub
,
118 success: function(data
, textStatus
, jqXHR
) {
124 success
: FleetActions
.setNSRStatusSuccess
,
125 error
: FleetActions
.setNSRStatusError
130 Object
.size = function(obj
) {
134 if (obj
.hasOwnProperty(key
)) size
++;