1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Fix rest API, array-data-manager

This commit is contained in:
Markus Grigull 2017-03-06 21:55:51 +01:00
parent 5441bd46f6
commit 1939df5f33
6 changed files with 36 additions and 28 deletions

View file

@ -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));
}

View file

@ -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 ];

View file

@ -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 {
<Dropzone onDrop={item => this.handleDrop(item)} editing={this.state.editing}>
{this.state.visualization.widgets != null &&
this.state.visualization.widgets.map((widget, index) => (
<Widget key={index} data={widget} onWidgetChange={(w, i) => this.widgetChange(w, i)} editing={this.state.editing} index={index} />
<Widget key={index} data={widget} onWidgetChange={(w, i) => this.widgetChange(w, i)} editing={this.state.editing} index={index} grid={this.state.grid} />
))}
</Dropzone>

View file

@ -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':

View file

@ -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

View file

@ -1,8 +0,0 @@
/**
* File: home.css
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* 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.
**********************************************************************************/