X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_container%2FskyquakeContainerStore.js;h=87651e59c6de46cc94d4b7ebe1b6c748f4bcd779;hb=2da8b7a246ba17396c5bc218a0b7f1685fb8d304;hp=f69014ebfac65312dbf6b260175001163c98854c;hpb=efcca9816240e4cd87e524776885551ed534aa9d;p=osm%2FUI.git diff --git a/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js b/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js index f69014ebf..87651e59c 100644 --- a/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js +++ b/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js @@ -20,9 +20,12 @@ import Alt from './skyquakeAltInstance.js'; import SkyquakeContainerSource from './skyquakeContainerSource.js'; import SkyquakeContainerActions from './skyquakeContainerActions'; -import _ from 'lodash'; +let Utils = require('utils/utils.js'); +import _indexOf from 'lodash/indexOf'; +import _isEqual from 'lodash/isEqual'; //Temporary, until api server is on same port as webserver -var rw = require('utils/rw.js'); +import rw from 'utils/rw.js'; + var API_SERVER = rw.getSearchParams(window.location).api_server; var UPLOAD_SERVER = rw.getSearchParams(window.location).upload_server; @@ -32,6 +35,8 @@ class SkyquakeContainerStore { this.nav = {}; this.notifications = []; this.socket = null; + this.projects = []; + this.user = {}; //Notification defaults this.notificationMessage = ''; this.displayNotification = false; @@ -100,7 +105,7 @@ class SkyquakeContainerStore { } else { // Temp to test before adding multi-sources data.notification.source = streamSource; - if (_.indexOf(self.notifications, data.notification) == -1) { + if (_indexOf(self.notifications, data.notification) == -1) { // newly appreared event. // Add to the notifications list and setState self.notifications.unshift(data.notification); @@ -161,6 +166,43 @@ class SkyquakeContainerStore { }) } + openProjectSocketSuccess = (connection) => { + var self = this; + var ws = window.multiplexer.channel(connection); + if (!connection) return; + self.setState({ + socket: ws.ws, + channelId: connection + }); + ws.onmessage = function(socket) { + try { + var data = JSON.parse(socket.data); + Utils.checkAuthentication(data.statusCode, function() { + self.closeSocket(); + }); + if (!_isEqual(data.project, self.projects)) { + let user = self.user; + user.projects = data.project; + self.setState({ + user: user, + projects: data.project + }); + } + } catch(e) { + console.log('HIT an exception in openProjectSocketSuccess', e); + } + }; + } + getUserProfileSuccess = (user) => { + this.alt.actions.global.hideScreenLoader.defer(); + this.setState({user}) + } + selectActiveProjectSuccess = (projectId) => { + let user = this.user; + user.projectId = projectId; + this.setState({user}); + window.location.reload(true); + } //Notifications showNotification = (data) => { let state = { @@ -172,7 +214,8 @@ class SkyquakeContainerStore { if(typeof(data) == 'string') { } else { - state.notificationMessage = data.msg; + if(!data) data = {}; + state.notificationMessage = data.msg || 'Something wrong occurred. Check the network tab and console logs for more information.'; if(data.type) { state.notificationType = data.type; }