diff --git a/src/common/array-store.js b/src/common/array-store.js index 1d76845..710ff94 100644 --- a/src/common/array-store.js +++ b/src/common/array-store.js @@ -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': diff --git a/src/common/data-managers/rest-data-manager.js b/src/common/data-managers/rest-data-manager.js index b667ac0..7fc3c98 100644 --- a/src/common/data-managers/rest-data-manager.js +++ b/src/common/data-managers/rest-data-manager.js @@ -52,98 +52,134 @@ class RestDataManager { return object; } - load(id, token = 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); + requestURL(form, id, param, object = null){ + switch(form){ + case 'load/add': + if (param === null){ + if(id != null){ + return this.url + '/' + id; + } + else { + return this.makeURL(this.url); + } } + else{ + if(id != null){ + return this.url + '/' + id + '?' + param; + } + else { + return this.makeURL(this.url) + '?' + param + } + } + case 'remove/update': + if(param === null){ + return this.makeURL(this.url + '/' + object.id); + } + else{ + return this.makeURL(this.url + '/' + object.id + '?' + param); + } + default: + console.log("something went wrong"); + break; + } + } + + load(id, token = null,param = null) { + if (id != null) { + // load single object + RestAPI.get(this.requestURL('load/add',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.requestURL('load/add',id,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); + + RestAPI.post(this.requestURL('load/add',null,param), obj, token).then(response => { + AppDispatcher.dispatch({ + type: this.type + 's/added', + data: response[this.type] + }); }).catch(error => { AppDispatcher.dispatch({ - type: this.type + 's/load-error', + type: this.type + 's/add-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); - }); + } + remove(object, token = null, param = null) { + RestAPI.delete(this.requestURL('remove/update',null,param,object), token).then(response => { AppDispatcher.dispatch({ - type: this.type + 's/loaded', - data: data + type: this.type + 's/removed', + data: response[this.type], + original: object }); - - if (this.onLoad != null) { - this.onLoad(data); - } }).catch(error => { AppDispatcher.dispatch({ - type: this.type + 's/load-error', + type: this.type + 's/remove-error', error: error }); }); } - } - - add(object, token = null) { + + update(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] + RestAPI.put(this.requestURL('remove/update',null,param,object), 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/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 - }); - }).catch(error => { - AppDispatcher.dispatch({ - type: this.type + 's/remove-error', - error: error - }); - }); - } - - update(object, token = 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] - }); - }).catch(error => { - AppDispatcher.dispatch({ - type: this.type + 's/edit-error', - error: error - }); - }); - } }; export default RestDataManager; diff --git a/src/user/edit-user.js b/src/user/edit-user.js index 3427452..d60015b 100644 --- a/src/user/edit-user.js +++ b/src/user/edit-user.js @@ -121,8 +121,8 @@ class EditUserDialog extends React.Component { this.handleChange(e)} /> - Old Password - this.handleChange(e)} /> + Admin Password + this.handleChange(e)} /> Password diff --git a/src/user/user.js b/src/user/user.js index 692f8e4..1162e6d 100644 --- a/src/user/user.js +++ b/src/user/user.js @@ -73,7 +73,6 @@ class User extends Component { closeEditModal(data) { this.setState({ editModal: false }); - console.log(data); if (data) { if(data.password === data.confirmpassword){