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;
this.nav = {};
this.notifications = [];
this.socket = null;
+ this.projects = [];
+ this.user = {};
//Notification defaults
this.notificationMessage = '';
this.displayNotification = false;
} 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);
})
}
+ 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 = {
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);
}
}
-export default Alt.createStore(SkyquakeContainerStore);
+export default Alt.createStore(SkyquakeContainerStore, 'SkyquakeContainerStore');