From 1939df5f33a724e268781633f633c78831b85285 Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Mon, 6 Mar 2017 21:55:51 +0100 Subject: [PATCH] Fix rest API, array-data-manager --- src/api/rest-api.js | 16 ++++++++-------- src/containers/home.js | 2 -- src/containers/visualization.js | 20 +++++++++++++++----- src/stores/array-store.js | 10 +++++----- src/stores/simulator-data-store.js | 8 ++++++++ src/styles/home.css | 8 -------- 6 files changed, 36 insertions(+), 28 deletions(-) delete mode 100644 src/styles/home.css diff --git a/src/api/rest-api.js b/src/api/rest-api.js index bc886bb..40329c2 100644 --- a/src/api/rest-api.js +++ b/src/api/rest-api.js @@ -21,8 +21,8 @@ class RestAPI { get(url) { return new Promise(function (resolve, reject) { request.get(makeURL(url)).end(function (error, res) { - if (res.status !== 200) { - reject(); + if (res == null || res.status !== 200) { + reject(error); } else { resolve(JSON.parse(res.text)); } @@ -33,8 +33,8 @@ class RestAPI { post(url, body) { return new Promise(function (resolve, reject) { request.post(makeURL(url)).send(body).end(function (error, res) { - if (res.status !== 200) { - reject(); + if (res == null || res.status !== 200) { + reject(error); } else { resolve(JSON.parse(res.text)); } @@ -45,8 +45,8 @@ class RestAPI { delete(url) { return new Promise(function (resolve, reject) { request.delete(makeURL(url)).end(function (error, res) { - if (res.status !== 200) { - reject(); + if (res == null || res.status !== 200) { + reject(error); } else { resolve(JSON.parse(res.text)); } @@ -57,8 +57,8 @@ class RestAPI { put(url, body) { return new Promise(function (resolve, reject) { request.put(makeURL(url)).send(body).end(function (error, res) { - if (res.status !== 200) { - reject(); + if (res == null || res.status !== 200) { + reject(error); } else { resolve(JSON.parse(res.text)); } diff --git a/src/containers/home.js b/src/containers/home.js index 81ead97..ae74541 100644 --- a/src/containers/home.js +++ b/src/containers/home.js @@ -13,8 +13,6 @@ import { Container } from 'flux/utils'; // import AppDispatcher from '../app-dispatcher'; import VillasStore from '../stores/villas-store'; -import '../styles/home.css'; - class Home extends Component { static getStores() { return [ VillasStore ]; diff --git a/src/containers/visualization.js b/src/containers/visualization.js index f2c33f2..9fd585f 100644 --- a/src/containers/visualization.js +++ b/src/containers/visualization.js @@ -23,11 +23,23 @@ class Visualization extends Component { return [ VisualizationStore ]; } - static calculateState() { + static calculateState(prevState) { + if (prevState) { + return { + visualizations: VisualizationStore.getState(), + + visualization: prevState.visualization, + editing: prevState.editing, + grid: prevState.grid + }; + } + return { visualizations: VisualizationStore.getState(), - visualization: {} + visualization: {}, + editing: false, + grid: false } } @@ -97,8 +109,6 @@ class Visualization extends Component { endpoint: 'localhost:5000', identifier: 'RTDS' }); - - this.setState({ editing: false }); } componentDidUpdate() { @@ -147,7 +157,7 @@ class Visualization extends Component { this.handleDrop(item)} editing={this.state.editing}> {this.state.visualization.widgets != null && this.state.visualization.widgets.map((widget, index) => ( - this.widgetChange(w, i)} editing={this.state.editing} index={index} /> + this.widgetChange(w, i)} editing={this.state.editing} index={index} grid={this.state.grid} /> ))} diff --git a/src/stores/array-store.js b/src/stores/array-store.js index 41123e8..8f2179d 100644 --- a/src/stores/array-store.js +++ b/src/stores/array-store.js @@ -43,11 +43,11 @@ class ArrayStore extends ReduceStore { return state; case this.type + '/added': - // state should always be immutable, thus make new copy - array = state.slice(); - array.push(action.data); + // signal array change since its not automatically detected + state.push(action.data); + this.__emitChange(); - return array; + return state; case this.type + '/add-error': // TODO: Add error message @@ -59,7 +59,7 @@ class ArrayStore extends ReduceStore { case this.type + '/removed': return state.filter((item) => { - return (item !== action.data); + return (item !== action.original); }); case this.type + '/remove-error': diff --git a/src/stores/simulator-data-store.js b/src/stores/simulator-data-store.js index 14b426b..38b69a3 100644 --- a/src/stores/simulator-data-store.js +++ b/src/stores/simulator-data-store.js @@ -12,6 +12,8 @@ import { ReduceStore } from 'flux/utils'; import AppDispatcher from '../app-dispatcher'; import SimulatorDataManager from '../data-managers/simulator-data-manager'; +const MAX_VALUES = 10000; + class SimulationDataStore extends ReduceStore { constructor() { super(AppDispatcher); @@ -43,6 +45,12 @@ class SimulationDataStore extends ReduceStore { // add data to simulator for (i = 0; i < state[action.identifier].signals; i++) { state[action.identifier].values[i].push({ x: action.data.timestamp, y: action.data.values[i] }); + + // erase old values + if (state[action.identifier].values[i].length > MAX_VALUES) { + const pos = state[action.identifier].values[i].length - MAX_VALUES; + state[action.identifier].values[i].splice(0, pos); + } } // update metadata diff --git a/src/styles/home.css b/src/styles/home.css deleted file mode 100644 index 5a74ef5..0000000 --- a/src/styles/home.css +++ /dev/null @@ -1,8 +0,0 @@ -/** - * File: home.css - * Author: Markus Grigull - * Date: 02.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. - **********************************************************************************/