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

wip #210 frontend can now send url with query parameters to backend

This commit is contained in:
Laura Fuentes Grau 2019-11-10 18:59:24 +01:00
parent bfab0be2d9
commit a7124c3a24
2 changed files with 64 additions and 11 deletions

View file

@ -71,10 +71,10 @@ class ArrayStore extends ReduceStore {
if (Array.isArray(action.data)) {
action.data.forEach((id) => {
this.dataManager.load(id, action.token);
this.dataManager.load(id, action.token,action.param);
});
} else {
this.dataManager.load(action.data, action.token);
this.dataManager.load(action.data, action.token,action.param);
}
return state;
@ -99,7 +99,7 @@ class ArrayStore extends ReduceStore {
return super.reduce(state, action);
case this.type + '/start-add':
this.dataManager.add(action.data, action.token);
this.dataManager.add(action.data, action.token,action.param);
return state;
case this.type + '/added':
@ -111,7 +111,7 @@ class ArrayStore extends ReduceStore {
case this.type + '/start-remove':
this.dataManager.remove(action.data, action.token);
this.dataManager.remove(action.data, action.token,action.param);
return state;
case this.type + '/removed':
@ -133,11 +133,11 @@ class ArrayStore extends ReduceStore {
return super.reduce(state, action);
case this.type + '/start-edit':
this.dataManager.update(action.data, action.token);
this.dataManager.update(action.data, action.token,action.param);
return state;
case this.type + '/start-own-edit':
this.dataManager.update(action.data, action.token);
this.dataManager.update(action.data, action.token,action.param);
return state;
case this.type + '/edited':
@ -155,6 +155,11 @@ 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;
}

View file

@ -53,9 +53,53 @@ class RestDataManager {
}
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 => {
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), 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
});
});
}
}
else{
if (id != null) {
// load single object
RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => {
RestAPI.get(this.makeURL(this.url + '/' + id + '/' + param), token).then(response => {
const data = this.filterKeys(response[this.type]);
AppDispatcher.dispatch({
@ -74,7 +118,7 @@ class RestDataManager {
});
} else {
// load all objects
RestAPI.get(this.makeURL(this.url), token).then(response => {
RestAPI.get(this.makeURL(this.url) + '/' + param, token).then(response => {
const data = response[this.type + 's'].map(element => {
return this.filterKeys(element);
});
@ -94,6 +138,8 @@ class RestDataManager {
});
});
}
}
}
add(object, token = null, param = null) {
@ -115,7 +161,7 @@ class RestDataManager {
}
else{
console.log("else was called in add");
RestAPI.post(this.makeURL(this.url) + "?" + param, obj, token).then(response => {
RestAPI.post(this.makeURL(this.url) + "/" + param, obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/added',
data: response[this.type]
@ -145,7 +191,7 @@ class RestDataManager {
});
}
else{
RestAPI.delete(this.makeURL(this.url + '/' + object.id + '?' + param), token).then(response => {
RestAPI.delete(this.makeURL(this.url + '/' + object.id + '/' + param), token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/removed',
data: response[this.type],
@ -163,6 +209,7 @@ class RestDataManager {
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 => {
@ -178,7 +225,8 @@ class RestDataManager {
});
}
else{
RestAPI.put(this.makeURL(this.url + '/' + object.id + '?' + param), obj, token).then(response => {
console.log("here we have: " + this.url);
RestAPI.put(this.makeURL(this.url + '/' + object.id + '/' + param), obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/edited',
data: response[this.type]