mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
wip #210 added query parameter 'param'
This commit is contained in:
parent
b801a50901
commit
bfab0be2d9
3 changed files with 84 additions and 35 deletions
|
@ -73,6 +73,7 @@ class RestAPI {
|
|||
}
|
||||
|
||||
post(url, body, token) {
|
||||
console.log(url);
|
||||
return new Promise(function (resolve, reject) {
|
||||
var req = request.post(url).send(body).timeout({ response: 5000 }); // Simple response start timeout (3s)
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class RestDataManager {
|
|||
return object;
|
||||
}
|
||||
|
||||
load(id, token = null) {
|
||||
load(id, token = null,param = null) {
|
||||
if (id != null) {
|
||||
// load single object
|
||||
RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => {
|
||||
|
@ -96,54 +96,102 @@ class RestDataManager {
|
|||
}
|
||||
}
|
||||
|
||||
add(object, token = null) {
|
||||
add(object, token = null, param = null) {
|
||||
var obj = {};
|
||||
obj[this.type] = this.filterKeys(object);
|
||||
|
||||
RestAPI.post(this.makeURL(this.url), obj, token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/added',
|
||||
data: response[this.type]
|
||||
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
|
||||
});
|
||||
});
|
||||
}).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 => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/added',
|
||||
data: response[this.type]
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/add-error',
|
||||
error: error
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
remove(object, token = null) {
|
||||
RestAPI.delete(this.makeURL(this.url + '/' + object.id), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/removed',
|
||||
data: response[this.type],
|
||||
original: object
|
||||
remove(object, token = null, param = null) {
|
||||
if (param === null) {
|
||||
RestAPI.delete(this.makeURL(this.url + '/' + object.id), 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
|
||||
});
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/remove-error',
|
||||
error: error
|
||||
}
|
||||
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) {
|
||||
update(object, token = null, param = null) {
|
||||
var obj = {};
|
||||
obj[this.type] = this.filterKeys(object);
|
||||
|
||||
RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/edited',
|
||||
data: response[this.type]
|
||||
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
|
||||
});
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: this.type + 's/edit-error',
|
||||
error: error
|
||||
}
|
||||
else{
|
||||
RestAPI.put(this.makeURL(this.url + '/' + object.id + '?' + param), 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
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default RestDataManager;
|
||||
|
|
|
@ -121,8 +121,8 @@ class EditUserDialog extends React.Component {
|
|||
<FormControl type="text" placeholder="Enter e-mail" value={this.state.mail} onChange={(e) => this.handleChange(e)} />
|
||||
</FormGroup>
|
||||
<FormGroup as={Col} controlId="oldPassword">
|
||||
<FormLabel>Old Password</FormLabel>
|
||||
<FormControl type="password" placeholder="Enter current password" value={this.state.oldPassword} onChange={(e) => this.handleChange(e)} />
|
||||
<FormLabel>Admin Password</FormLabel>
|
||||
<FormControl type="password" placeholder="Enter admin password" value={this.state.oldPassword} onChange={(e) => this.handleChange(e)} />
|
||||
</FormGroup>
|
||||
<FormGroup as={Col} controlId="password">
|
||||
<FormLabel>Password</FormLabel>
|
||||
|
|
Loading…
Add table
Reference in a new issue