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.
18 import Alt
from './skyquakeAltInstance.js';
19 import $ from 'jquery';
20 import SkyquakeContainerActions
from './skyquakeContainerActions'
22 let Utils
= require('utils/utils.js');
23 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
24 let HOST
= API_SERVER
;
25 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
26 let DEV_MODE
= require('utils/rw.js').getSearchParams(window
.location
).dev_mode
|| false;
27 let RW_REST_API_PORT
= require('utils/rw.js').getSearchParams(window
.location
).rw_rest_api_port
|| 8008;
30 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
37 return new Promise(function(resolve
, reject
) {
41 // beforeSend: Utils.addAuthorizationStub,
42 success: function(data
) {
43 Utils
.detectInactivity();
49 success
: SkyquakeContainerActions
.getSkyquakeNavSuccess
55 remote: function(state
, recordID
) {
56 return new Promise(function(resolve
, reject
) {
58 url
: '//' + window
.location
.hostname
+ ':' + window
.location
.port
+ '/api/operational/restconf-state/streams?api_server=' + API_SERVER
,
60 beforeSend
: Utils
.addAuthorizationStub
,
61 success: function(data
) {
64 }).fail(function(xhr
) {
65 //Authentication and the handling of fail states should be wrapped up into a connection class.
66 Utils
.checkAuthentication(xhr
.status
);
70 loading
: SkyquakeContainerActions
.getEventStreamsLoading
,
71 success
: SkyquakeContainerActions
.getEventStreamsSuccess
,
72 error
: SkyquakeContainerActions
.getEventStreamsError
76 openNotificationsSocket() {
78 remote: function(state
, location
, streamSource
) {
79 return new Promise((resolve
, reject
) => {
81 url
: '//' + window
.location
.hostname
+ ':' + window
.location
.port
+ '/socket-polling',
83 beforeSend
: Utils
.addAuthorizationStub
,
88 // var url = Utils.webSocketProtocol() + '//' + window.location.hostname + ':' + data.port + data.socketPath;
89 // var ws = new WebSocket(url);
92 // streamSource: streamSource
94 const checker
= () => {
95 if (!Utils
.isMultiplexerLoaded()) {
102 streamSource
: streamSource
112 loading
: SkyquakeContainerActions
.openNotificationsSocketLoading
,
113 success
: SkyquakeContainerActions
.openNotificationsSocketSuccess
,
114 error
: SkyquakeContainerActions
.openNotificationsSocketError
117 openProjectSocket() {
119 remote: function(state
) {
120 return new Promise(function(resolve
, reject
) {
121 //If socket connection already exists, eat the request.
123 return resolve(false);
126 url
: '/socket-polling',
128 beforeSend
: Utils
.addAuthorizationStub
,
130 url
: '/project?api_server=' + API_SERVER
132 success: function(data
, textStatus
, jqXHR
) {
133 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
137 //Authentication and the handling of fail states should be wrapped up into a connection class.
138 Utils
.checkAuthentication(xhr
.status
);
142 success
: SkyquakeContainerActions
.openProjectSocketSuccess
148 remote: function(state
, recordID
) {
149 return new Promise(function(resolve
, reject
) {
151 url
: '/user-profile?api_server=' + API_SERVER
,
153 beforeSend
: Utils
.addAuthorizationStub
,
154 success: function(data
) {
157 }).fail(function(xhr
) {
158 //Authentication and the handling of fail states should be wrapped up into a connection class.
159 Utils
.checkAuthentication(xhr
.status
);
163 loading
: Alt
.actions
.global
.showScreenLoader
,
164 success
: SkyquakeContainerActions
.getUserProfileSuccess
168 selectActiveProject() {
170 remote: function(state
, event
) {
173 projectId
= JSON
.parse(JSON
.parse(event
.currentTarget
.value
));
175 console
.log('Something went wrong in the selectActiveProject source function', e
);
178 return new Promise(function(resolve
, reject
) {
180 url
: `/session/${projectId}?api_server=${API_SERVER}`,
182 beforeSend
: Utils
.addAuthorizationStub
,
183 success: function(data
) {
186 }).fail(function(xhr
) {
187 //Authentication and the handling of fail states should be wrapped up into a connection class.
188 Utils
.checkAuthentication(xhr
.status
);
192 success
: SkyquakeContainerActions
.selectActiveProjectSuccess