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;
+const MAX_STORED_EVENTS = 20;
class SkyquakeContainerStore {
constructor() {
this.currentPlugin = getCurrentPlugin();
this.nav = {};
- this.notifications = [];
+ let notificationList = null;
+ try {notificationList = JSON.parse(sessionStorage.getItem('notifications'));} catch (e) {}
+ this.notifications = notificationList || [];
this.socket = null;
+ this.projects = null;
+ this.user = {};
//Notification defaults
this.notificationMessage = '';
this.displayNotification = false;
ws.onmessage = (socket) => {
try {
var data = JSON.parse(socket.data);
+ if(data.hasOwnProperty('map')) {
+ data = [];
+ }
if (!data.notification) {
console.warn('No notification in the received payload: ', data);
} 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);
+ (self.notifications.length > MAX_STORED_EVENTS) && self.notifications.pop();
self.setState({
newNotificationEvent: true,
newNotificationMsg: data.notification,
notifications: self.notifications,
isLoading: false
});
+ sessionStorage.setItem('notifications', JSON.stringify(self.notifications));
}
}
} catch(e) {
console.log('Found streams: ', streams);
let self = this;
+ streams &&
streams['ietf-restconf-monitoring:streams'] &&
streams['ietf-restconf-monitoring:streams']['stream'] &&
streams['ietf-restconf-monitoring:streams']['stream'].map((stream) => {
})
}
- //Notifications
- showNotification = (data) => {
- let state = {
- displayNotification: true,
- notificationMessage: data,
- notificationType: 'error',
- displayScreenLoader: false
- }
- if(typeof(data) == 'string') {
-
- } else {
- state.notificationMessage = data.msg;
- if(data.type == 'success') {
- state.notificationType = 'success';
+ 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 (!data.project || !_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);
}
- }
- this.setState(state);
+ };
+ }
+ 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.href = window.location.origin;
+ }
+ //Notifications
+ handleServerReportedError = (result) => {
+ this.hideScreenLoader();
+ this.alt.actions.global.showNotification.defer(result);
+ }
+ showNotification = (notificationData) => {
+ this.setState({
+ notificationData,
+ displayNotification: true
+ })
}
hideNotification = () => {
this.setState({
if (k != currentPlugin) {
nav[k].routes.map(function(route, i) {
if (API_SERVER) {
- route.route = '/' + k + '/index.html?api_server=' + API_SERVER + '&upload_server=' + UPLOAD_SERVER + '#' + route.route;
+ route.route = '/' + k + '/index.html?api_server=' + API_SERVER + '#' + route.route;
} else {
route.route = '/' + k + '/#' + route.route;
}
}
}
-export default Alt.createStore(SkyquakeContainerStore);
+export default Alt.createStore(SkyquakeContainerStore, 'SkyquakeContainerStore');