Commit 700c64fc authored by Laura Fuentes Grau's avatar Laura Fuentes Grau

wip #210 fixed query parameters, added an example dashboard file for testing

parent a7124c3a
......@@ -51,6 +51,7 @@ import Scenario from './scenario/scenario';
import SimulationModel from './simulationmodel/simulation-model';
import Users from './user/users';
import User from './user/user';
import ExDashboard from './dashboard/exdashboard';
import './styles/app.css';
......@@ -152,6 +153,7 @@ class App extends React.Component {
<Route path="/simulators" component={Simulators} />
<Route path="/user" component={User} />
<Route path="/users" component={Users} />
<Route path="/exdashboard" component={ExDashboard} />
</div>
</div>
......
......@@ -155,11 +155,6 @@ class ArrayStore extends ReduceStore {
case this.type + '/edit-error':
return state;
case 'exdashboard/querytest' :
console.log("querytest wurde aufgerufen");
this.dataManager.update(action.data, action.token,action.param);
return state;
default:
return state;
}
......
......@@ -52,11 +52,57 @@ class RestDataManager {
return object;
}
sendRequest(form, id, token, param, object = null, obj = null) {
switch (form) {
case 'load':
if (param === null) {
if (id != null) {
// load single object
return RestAPI.get(this.makeURL(this.url + '/' + id), token);
} else {
// load all objects
return RestAPI.get(this.makeURL(this.url), token);
}
}
else {
if (id != null) {
// load single object
return RestAPI.get(this.makeURL(this.url + '/' + id + '?' + param), token)
} else {
// load all objects
return RestAPI.get(this.makeURL(this.url) + '?' + param, token)
}
}
case 'add':
if (param === null) {
return RestAPI.post(this.makeURL(this.url), obj, token);
} else {
return RestAPI.post(this.makeURL(this.url) + "?" + param, obj, token);
}
case 'remove':
if (param === null) {
return RestAPI.delete(this.makeURL(this.url + '/' + object.id), token)
}
else {
return RestAPI.delete(this.makeURL(this.url + '/' + object.id + '?' + param))
}
case 'update':
if (param === null) {
return RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token);
}
else {
return RestAPI.put(this.makeURL(this.url + '/' + object.id + '?' + param), obj, token);
}
default:
console.log("something went wrong");
break;
}
}
load(id, token = null,param = null) {
if (param === null) {
if (id != null) {
// load single object
RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => {
this.sendRequest('load',id,token,param).then(response => {
const data = this.filterKeys(response[this.type]);
AppDispatcher.dispatch({
......@@ -75,7 +121,7 @@ class RestDataManager {
});
} else {
// load all objects
RestAPI.get(this.makeURL(this.url), token).then(response => {
this.sendRequest('load',id,token,param).then(response => {
const data = response[this.type + 's'].map(element => {
return this.filterKeys(element);
});
......@@ -96,72 +142,13 @@ class RestDataManager {
});
}
}
else{
if (id != null) {
// load single object
RestAPI.get(this.makeURL(this.url + '/' + id + '/' + param), token).then(response => {
const data = this.filterKeys(response[this.type]);
AppDispatcher.dispatch({
type: this.type + 's/loaded',
data: data
});
if (this.onLoad != null) {
this.onLoad(data);
}
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/load-error',
error: error
});
});
} else {
// load all objects
RestAPI.get(this.makeURL(this.url) + '/' + param, token).then(response => {
const data = response[this.type + 's'].map(element => {
return this.filterKeys(element);
});
AppDispatcher.dispatch({
type: this.type + 's/loaded',
data: data
});
if (this.onLoad != null) {
this.onLoad(data);
}
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/load-error',
error: error
});
});
}
}
}
add(object, token = null, param = null) {
var obj = {};
obj[this.type] = this.filterKeys(object);
if (param === null) {
RestAPI.post(this.makeURL(this.url), obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/added',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/add-error',
error: error
});
});
}
else{
console.log("else was called in add");
RestAPI.post(this.makeURL(this.url) + "/" + param, obj, token).then(response => {
this.sendRequest('add',null,token,param,null,obj).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/added',
data: response[this.type]
......@@ -172,12 +159,10 @@ class RestDataManager {
error: error
});
});
}
}
remove(object, token = null, param = null) {
if (param === null) {
RestAPI.delete(this.makeURL(this.url + '/' + object.id), token).then(response => {
this.sendRequest('remove',null,token,param,object).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/removed',
data: response[this.type],
......@@ -190,43 +175,12 @@ class RestDataManager {
});
});
}
else{
RestAPI.delete(this.makeURL(this.url + '/' + object.id + '/' + param), token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/removed',
data: response[this.type],
original: object
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/remove-error',
error: error
});
});
}
}
update(object, token = null, param = null) {
var obj = {};
obj[this.type] = this.filterKeys(object);
console.log("wir haben den rdm erreicht!");
if(param === null) {
RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/edited',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/edit-error',
error: error
});
});
}
else{
console.log("here we have: " + this.url);
RestAPI.put(this.makeURL(this.url + '/' + object.id + '/' + param), obj, token).then(response => {
this.sendRequest('update',null,token,param,object,obj).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/edited',
data: response[this.type]
......@@ -238,7 +192,8 @@ class RestDataManager {
});
});
}
}
};
......
......@@ -35,6 +35,7 @@ class SidebarMenu extends React.Component {
<li><NavLink to="/home" activeClassName="active" title="Home">Home</NavLink></li>
<li><NavLink to="/scenarios" activeClassName="active" title="Scenarios">Scenarios</NavLink></li>
<li><NavLink to="/simulators" activeClassName="active" title="Simulators">Simulators</NavLink></li>
<li><NavLink to="/exdashboard" activeClassName="active" title="Example Dashboard">Example Dashboard</NavLink></li>
{ this.props.currentRole === 'Admin' ?
<li><NavLink to="/users" activeClassName="active" title="User Management">User Management</NavLink></li> : ''
}
......
import React, { Component } from 'react';
import { Container } from 'flux/utils';
import DashboardStore from './dashboard-store';
import AppDispatcher from '../common/app-dispatcher';
import Table from '../common/table';
import TableColumn from '../common/table-column';
import UserStore from '../user/user-store'
class ExDashboard extends Component {
static getStores() {
return [ DashboardStore ];
}
static calculateState(prevState, props) {
prevState = prevState || {};
console.log("calculateState has been called");
const dashboards = DashboardStore.getState();
let tokenState = UserStore.getState().token;
console.log(dashboards);
return{
dashboards,
tokenState
}
}
componentDidMount() {
AppDispatcher.dispatch({
type: 'dashboards/start-load',
token: this.state.tokenState,
param: 'scenarioID=1'
});
}
render() {
return (
<div className='section'>
<h1>Dashboards</h1>
<Table data={this.state.dashboards}>
<TableColumn title='Name' dataKey='name' link='/exdashboard/' linkKey='id' />
<TableColumn title='Grid' dataKey='grid' link='/exdashboard/' linkKey='id' />
<TableColumn title='ScenarioID' dataKey='scenarioID' link='/exdashboard/' linkKey='id' />
</Table>
</div>
);
}
}
let fluxContainerConverter = require('../common/FluxContainerConverter');
export default Container.create(fluxContainerConverter.convert(ExDashboard));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment