diff --git a/package.json b/package.json index 00dba54..0116f0a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "es6-promise": "^4.0.5", "flux": "^3.1.2", "immutable": "^3.8.1", + "rd3": "^0.7.4", "react": "^15.4.2", "react-bootstrap": "^0.30.7", "react-contextmenu": "^2.3.0", @@ -15,10 +16,10 @@ "react-dnd": "^2.2.4", "react-dnd-html5-backend": "^2.2.4", "react-dom": "^15.4.2", + "react-notification-system": "^0.2.13", "react-rnd": "^4.2.2", "react-router": "^3.0.2", - "superagent": "^3.5.0", - "rd3": "^0.7.4" + "superagent": "^3.5.0" }, "devDependencies": { "react-scripts": "0.9.3" diff --git a/src/containers/app.js b/src/containers/app.js index 8b3e7aa..34c7b07 100644 --- a/src/containers/app.js +++ b/src/containers/app.js @@ -11,11 +11,13 @@ import React, { Component } from 'react'; import { Container } from 'flux/utils'; import { DragDropContext } from 'react-dnd'; import HTML5Backend from 'react-dnd-html5-backend'; +import NotificationSystem from 'react-notification-system'; import AppDispatcher from '../app-dispatcher'; import SimulationStore from '../stores/simulation-store'; import SimulatorStore from '../stores/simulator-store'; import UserStore from '../stores/user-store'; +import NotificationsDataManager from '../data-managers/notifications-data-manager'; import Header from '../components/header'; import Footer from '../components/footer'; @@ -95,6 +97,10 @@ class App extends Component { }); } + componentDidMount() { + NotificationsDataManager.setSystem(this.refs.notificationSystem); + } + componentWillUpdate(nextProps, nextState) { // check if user is still logged in if (nextState.token == null) { @@ -160,6 +166,8 @@ class App extends Component { return (
+ +
diff --git a/src/data-managers/notifications-data-manager.js b/src/data-managers/notifications-data-manager.js new file mode 100644 index 0000000..b5798bb --- /dev/null +++ b/src/data-managers/notifications-data-manager.js @@ -0,0 +1,22 @@ +/** + * File: notifications-data-manager.js + * Author: Markus Grigull + * Date: 21.03.2017 + * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + +class NotificationsDataManager { + _notificationSystem = null; + + setSystem(notificationSystem) { + this._notificationSystem = notificationSystem; + } + + addNotification(notification) { + this._notificationSystem.addNotification(notification); + } +} + +export default new NotificationsDataManager(); diff --git a/src/stores/simulator-store.js b/src/stores/simulator-store.js index c2ac8e9..1e7d48b 100644 --- a/src/stores/simulator-store.js +++ b/src/stores/simulator-store.js @@ -9,6 +9,7 @@ import ArrayStore from './array-store'; import SimulatorsDataManager from '../data-managers/simulators-data-manager'; +import NotificationsDataManager from '../data-managers/notifications-data-manager'; class SimulatorStore extends ArrayStore { constructor() { @@ -51,6 +52,12 @@ class SimulatorStore extends ArrayStore { return element._id === action.identifier; }); + NotificationsDataManager.addNotification({ + title: 'Simulator online', + message: 'Simulator \'' + simulator.name + '\' went online.', + level: 'info' + }); + // restart requesting again SimulatorsDataManager.stopRunningDetection(simulator); @@ -65,6 +72,12 @@ class SimulatorStore extends ArrayStore { // update running state simulator.running = false; + NotificationsDataManager.addNotification({ + title: 'Simulator offline', + message: 'Simulator \'' + simulator.name + '\' went offline.', + level: 'info' + }); + // restart requesting again SimulatorsDataManager.startRunningDetection(simulator);