2 * STANDARD_RIFT_IO_COPYRIGHT
4 import $ from 'jquery';
5 var Utils
= require('utils/utils.js');
6 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
8 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
9 let DEV_MODE
= require('utils/rw.js').getSearchParams(window
.location
).dev_mode
|| false;
12 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
17 module
.exports = function(Alt
) {
22 return new Promise(function(resolve
, reject
) {
24 url
: `config?api_server=${API_SERVER}`,
26 beforeSend
: Utils
.addAuthorizationStub
,
27 success: function(data
, textStatus
, jqXHR
) {
30 }).fail(function(xhr
){
31 //Authentication and the handling of fail states should be wrapped up into a connection class.
32 Utils
.checkAuthentication(xhr
.status
);
33 let msg
= xhr
.responseText
;
34 if(xhr
.errorMessage
) {
35 msg
= xhr
.errorMessage
41 interceptResponse
: interceptResponse({
42 'error': 'There was an error retrieving the redundancy config.'
44 success
: Alt
.actions
.global
.getRedundancySuccess
,
45 loading
: Alt
.actions
.global
.showScreenLoader
,
46 error
: Alt
.actions
.global
.handleServerReportedError
48 openRedundancyStateSocket
: {
49 remote: function(state
) {
50 return new Promise(function(resolve
, reject
) {
51 //If socket connection already exists, eat the request.
53 console
.log('connection already exists')
54 return resolve(false);
57 url
: '/socket-polling',
59 beforeSend
: Utils
.addAuthorizationStub
,
61 url
: 'redundancy/state?api_server=' + API_SERVER
63 success: function(data
, textStatus
, jqXHR
) {
64 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
66 }).fail(function(xhr
){
67 //Authentication and the handling of fail states should be wrapped up into a connection class.
68 Utils
.checkAuthentication(xhr
.status
);
69 reject(xhr
.responseText
|| 'An error occurred. Check your logs for more information');
73 loading
: Alt
.actions
.global
.showScreenLoader
,
74 success
: Alt
.actions
.global
.openRedundancyStateSocketSuccess
78 return new Promise(function(resolve
, reject
) {
80 url
: `site?api_server=${API_SERVER}`,
82 beforeSend
: Utils
.addAuthorizationStub
,
83 success: function(data
, textStatus
, jqXHR
) {
86 }).fail(function(xhr
){
87 //Authentication and the handling of fail states should be wrapped up into a connection class.
88 Utils
.checkAuthentication(xhr
.status
);
89 let msg
= xhr
.responseText
;
90 if(xhr
.errorMessage
) {
91 msg
= xhr
.errorMessage
97 interceptResponse
: interceptResponse({
98 'error': 'There was an error retrieving the redundancy sites.'
100 success
: Alt
.actions
.global
.getSitesSuccess
,
101 loading
: Alt
.actions
.global
.showScreenLoader
,
102 error
: Alt
.actions
.global
.handleServerReportedError
105 remote: function(state
, site
) {
106 return new Promise(function(resolve
, reject
) {
108 url
: `config?api_server=${API_SERVER}`,
111 beforeSend
: Utils
.addAuthorizationStub
,
112 success: function(data
, textStatus
, jqXHR
) {
115 }).fail(function(xhr
){
116 //Authentication and the handling of fail states should be wrapped up into a connection class.
117 Utils
.checkAuthentication(xhr
.status
);
118 let msg
= xhr
.responseText
;
119 if(xhr
.errorMessage
) {
120 msg
= xhr
.errorMessage
126 interceptResponse
: interceptResponse({
127 'error': 'There was an error updating the redundancy config.'
129 success
: Alt
.actions
.global
.updateConfigSuccess
,
130 loading
: Alt
.actions
.global
.showScreenLoader
,
131 error
: Alt
.actions
.global
.handleServerReportedError
134 remote: function(state
, site
) {
136 data
['rw-instances'].map(function(s
) {
137 if(s
.hasOwnProperty('isNew')) {
141 return new Promise(function(resolve
, reject
) {
143 url
: `site/${encodeURIComponent(site['site-name'])}?api_server=${API_SERVER}`,
146 beforeSend
: Utils
.addAuthorizationStub
,
147 success: function(data
, textStatus
, jqXHR
) {
150 }).fail(function(xhr
){
151 //Authentication and the handling of fail states should be wrapped up into a connection class.
152 Utils
.checkAuthentication(xhr
.status
);
153 let msg
= xhr
.responseText
;
154 if(xhr
.errorMessage
) {
155 msg
= xhr
.errorMessage
161 interceptResponse
: interceptResponse({
162 'error': 'There was an error updating the site.'
164 success
: Alt
.actions
.global
.updateSiteSuccess
,
165 loading
: Alt
.actions
.global
.showScreenLoader
,
166 error
: Alt
.actions
.global
.handleServerReportedError
169 remote: function(state
, site
) {
170 return new Promise(function(resolve
, reject
) {
172 url
: `site/${encodeURIComponent(site['site-name'])}?api_server=${API_SERVER}`,
174 beforeSend
: Utils
.addAuthorizationStub
,
175 success: function(data
, textStatus
, jqXHR
) {
178 }).fail(function(xhr
){
179 //Authentication and the handling of fail states should be wrapped up into a connection class.
180 Utils
.checkAuthentication(xhr
.status
);
181 let msg
= xhr
.responseText
;
182 if(xhr
.errorMessage
) {
183 msg
= xhr
.errorMessage
189 interceptResponse
: interceptResponse({
190 'error': 'There was an error deleting the site.'
192 success
: Alt
.actions
.global
.deleteSiteSuccess
,
193 loading
: Alt
.actions
.global
.showScreenLoader
,
194 error
: Alt
.actions
.global
.handleServerReportedError
197 remote: function(state
, site
) {
199 data
['rw-instances'].map(function(s
) {
200 if(s
.hasOwnProperty('isNew')) {
204 return new Promise(function(resolve
, reject
) {
206 url
: `site?api_server=${API_SERVER}`,
209 beforeSend
: Utils
.addAuthorizationStub
,
210 success: function(data
, textStatus
, jqXHR
) {
213 }).fail(function(xhr
){
214 //Authentication and the handling of fail states should be wrapped up into a connection class.
215 Utils
.checkAuthentication(xhr
.status
);
216 let msg
= xhr
.responseText
;
217 if(xhr
.errorMessage
) {
218 msg
= xhr
.errorMessage
224 interceptResponse
: interceptResponse({
225 'error': 'There was an error creating the site.'
227 success
: Alt
.actions
.global
.createSiteSuccess
,
228 loading
: Alt
.actions
.global
.showScreenLoader
,
229 error
: Alt
.actions
.global
.handleServerReportedError
234 function interceptResponse (responses
) {
235 return function(data
, action
, args
) {
236 if(responses
.hasOwnProperty(data
)) {