X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_container%2FskyquakeContainerSource.js;h=f02e7bac918b36967fbb8bee22245cbe924773eb;hp=da7080f0adac07038d444e73880080ac7af60ad7;hb=refs%2Fchanges%2F79%2F5479%2F2;hpb=f2dc2462571800e62cba969964de621dca09299c diff --git a/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js b/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js index da7080f0a..f02e7bac9 100644 --- a/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js +++ b/skyquake/framework/widgets/skyquake_container/skyquakeContainerSource.js @@ -79,7 +79,7 @@ export default { remote: function(state, location, streamSource) { return new Promise((resolve, reject) => { $.ajax({ - url: '//' + window.location.hostname + ':' + window.location.port + '/socket-polling?api_server=' + API_SERVER, + url: '//' + window.location.hostname + ':' + window.location.port + '/socket-polling', type: 'POST', beforeSend: Utils.addAuthorizationStub, data: { @@ -114,6 +114,79 @@ export default { success: SkyquakeContainerActions.openNotificationsSocketSuccess, error: SkyquakeContainerActions.openNotificationsSocketError } + }, + openProjectSocket() { + return { + remote: function(state) { + return new Promise(function(resolve, reject) { + //If socket connection already exists, eat the request. + if(state.socket) { + return resolve(false); + } + $.ajax({ + url: '/socket-polling', + type: 'POST', + beforeSend: Utils.addAuthorizationStub, + data: { + url: '/project?api_server=' + API_SERVER + }, + success: function(data, textStatus, jqXHR) { + Utils.checkAndResolveSocketRequest(data, resolve, reject); + } + }) + .fail(function(xhr){ + //Authentication and the handling of fail states should be wrapped up into a connection class. + Utils.checkAuthentication(xhr.status); + });; + }); + }, + success: SkyquakeContainerActions.openProjectSocketSuccess + } + }, + + getUserProfile() { + return { + remote: function(state, recordID) { + return new Promise(function(resolve, reject) { + $.ajax({ + url: '/user-profile?api_server=' + API_SERVER, + type: 'GET', + beforeSend: Utils.addAuthorizationStub, + success: function(data) { + resolve(data); + } + }).fail(function(xhr) { + //Authentication and the handling of fail states should be wrapped up into a connection class. + Utils.checkAuthentication(xhr.status); + });; + }); + }, + loading: Alt.actions.global.showScreenLoader, + success: SkyquakeContainerActions.getUserProfileSuccess + } + }, + + selectActiveProject() { + return { + remote: function(state, projectId) { + const {currentPlugin} = state; + const encodedProjectId = encodeURIComponent(projectId); + return new Promise(function(resolve, reject) { + $.ajax({ + url: `/session/${encodedProjectId}?api_server=${API_SERVER}&app=${currentPlugin}`, + type: 'PUT', + beforeSend: Utils.addAuthorizationStub, + success: function(data) { + resolve(projectId); + } + }).fail(function(xhr) { + //Authentication and the handling of fail states should be wrapped up into a connection class. + Utils.checkAuthentication(xhr.status); + });; + }); + }, + success: SkyquakeContainerActions.selectActiveProjectSuccess + } } }