X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_container%2FskyquakeContainerStore.js;h=4f270945abffa8a7671253f92404337fbd3c8d74;hp=aa4e7448f9d7b52018e4e145e8613d7540f8f5b0;hb=54e4cde9338a0c798477422905cdd3b194d33a42;hpb=3130c3b976dc11f641bce038fcfa1c101d156f12 diff --git a/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js b/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js index aa4e7448f..4f270945a 100644 --- a/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js +++ b/skyquake/framework/widgets/skyquake_container/skyquakeContainerStore.js @@ -20,6 +20,7 @@ import Alt from './skyquakeAltInstance.js'; import SkyquakeContainerSource from './skyquakeContainerSource.js'; import SkyquakeContainerActions from './skyquakeContainerActions'; +let Utils = require('utils/utils.js'); import _ from 'lodash'; //Temporary, until api server is on same port as webserver var rw = require('utils/rw.js'); @@ -32,6 +33,8 @@ class SkyquakeContainerStore { this.nav = {}; this.notifications = []; this.socket = null; + this.projects = []; + this.user = {}; //Notification defaults this.notificationMessage = ''; this.displayNotification = false; @@ -161,6 +164,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,9 +212,10 @@ class SkyquakeContainerStore { if(typeof(data) == 'string') { } else { - state.notificationMessage = data.msg; - if(data.type == 'success') { - state.notificationType = 'success'; + 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; } } this.setState(state);