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

delete own user from scenario, closes #249

This commit is contained in:
irismarie 2020-09-15 19:10:17 +02:00
parent d644854e1f
commit 6a22d5387c
4 changed files with 55 additions and 21 deletions

View file

@ -110,10 +110,16 @@ class ArrayStore extends ReduceStore {
return state;
case this.type + '/removed':
return state.filter((item) => {
return (item !== action.original);
});
if (action.original) {
return state.filter((item) => {
return (item !== action.original);
});
} else {
return state.filter((item) => {
return (item.id !== action.data);
});
}
case this.type + '/remove-error':
if (action.error && !action.error.handled && action.error.response) {

View file

@ -37,7 +37,6 @@ class ScenarioStore extends ArrayStore{
})
this.__emitChange();
return state;
}
reduce(state, action) {
@ -85,7 +84,7 @@ class ScenarioStore extends ArrayStore{
return super.reduce(state, action);
case 'scenarios/remove-user':
this.dataManager.deleteUser(action.token, action.data, action.username)
this.dataManager.deleteUser(action.token, action.data, action.username, action.ownuser)
return super.reduce(state, action);
case 'scenarios/users-error':

View file

@ -43,11 +43,13 @@ import EditConfigDialog from "../componentconfig/edit-config";
import EditSignalMapping from "../signal/edit-signal-mapping";
import FileStore from "../file/file-store"
import WidgetStore from "../widget/widget-store";
import LoginStore from "../user/login-store"
import { Redirect } from 'react-router-dom';
class Scenario extends React.Component {
static getStores() {
return [ ScenarioStore, ConfigStore, DashboardStore, ICStore, SignalStore, FileStore, WidgetStore];
return [ ScenarioStore, ConfigStore, DashboardStore, ICStore, SignalStore, FileStore, WidgetStore, LoginStore];
}
static calculateState(prevState, props) {
@ -78,6 +80,7 @@ class Scenario extends React.Component {
let signals = SignalStore.getState();
let currentUser = LoginStore.getState().currentUser;
return {
scenario,
@ -85,6 +88,7 @@ class Scenario extends React.Component {
configs,
dashboards,
signals,
currentUser,
files,
ics: ICStore.getState(),
@ -109,6 +113,7 @@ class Scenario extends React.Component {
userToAdd: '',
deleteUserName: '',
deleteUserModal: false,
goToScenarios: false
}
}
@ -155,14 +160,26 @@ class Scenario extends React.Component {
}
closeDeleteUserModal() {
let scenarioID = this.state.scenario.id;
if (this.state.deleteUserName === this.state.currentUser.username) {
AppDispatcher.dispatch({
type: 'scenarios/remove-user',
data: scenarioID,
username: this.state.deleteUserName,
token: this.state.sessionToken,
ownuser: true
});
this.setState({ goToScenarios: true });
} else {
AppDispatcher.dispatch({
type: 'scenarios/remove-user',
data: scenarioID,
username: this.state.deleteUserName,
token: this.state.sessionToken,
ownuser: false
});
}
this.setState({ deleteUserModal: false });
AppDispatcher.dispatch({
type: 'scenarios/remove-user',
data: this.state.scenario.id,
username: this.state.deleteUserName,
token: this.state.sessionToken
});
}
/* ##############################################
@ -492,6 +509,10 @@ class Scenario extends React.Component {
############################################## */
render() {
if (this.state.goToScenarios) {
console.log("redirect to scenario overview")
return (<Redirect to="/scenarios" />);
}
const buttonStyle = {
marginLeft: '10px'

View file

@ -59,15 +59,23 @@ class ScenariosDataManager extends RestDataManager {
})
}
deleteUser(token, id, username) {
deleteUser(token, id, username, ownuser=false) {
let path = id + '/user';
RestAPI.delete(this.makeURL(this.url + '/' + path + '?username=' + username), token).then(response => {
AppDispatcher.dispatch({
type: 'scenarios/start-load-users',
data: id,
token: token
});
if (!ownuser) {
AppDispatcher.dispatch({
type: 'scenarios/start-load-users',
data: id,
token: token
});
} else {
// delete scenario from scenariostore
AppDispatcher.dispatch({
type: 'scenarios/removed',
data: id,
token: token
});
}
}).catch(error => {
AppDispatcher.dispatch({
type: 'scenarios/users-error',