diff --git a/src/user/users-to-scenario.js b/src/user/users-to-scenario.js new file mode 100644 index 0000000..81e4a19 --- /dev/null +++ b/src/user/users-to-scenario.js @@ -0,0 +1,71 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import { Table } from 'react-bootstrap'; + +import Dialog from '../common/dialogs/dialog'; + +class UsersToScenarioDialog extends React.Component { + valid = true; + + onClose() { + if (this.props.onClose != null) { + this.props.onClose(); + } + }; + + renderRow(value, key) { + return ( + {key} + {value} + ); + } + + renderData() { + let arr = []; + this.props.users.forEach((value, key) => { + arr.push(this.renderRow(value,key)) + }) + return arr; + } + + render() { + return this.onClose()} + valid={true} + > + + + + + + + + + { this.renderData() } + +
IDName
+
; + } +} + +export default UsersToScenarioDialog; diff --git a/src/user/users.js b/src/user/users.js index d4cd584..ef56cfe 100644 --- a/src/user/users.js +++ b/src/user/users.js @@ -20,13 +20,16 @@ import { Container } from 'flux/utils'; import AppDispatcher from '../common/app-dispatcher'; import UsersStore from './users-store'; +import ScenarioStore from '../scenario/scenario-store'; import Icon from '../common/icon'; import IconButton from '../common/icon-button'; +import { Dropdown, DropdownButton } from 'react-bootstrap'; import Table from '../common/table'; import TableColumn from '../common/table-column'; import NewUserDialog from './new-user'; import EditUserDialog from './edit-user'; +import UsersToScenarioDialog from './users-to-scenario'; import DeleteDialog from '../common/dialogs/delete-dialog'; import NotificationsDataManager from "../common/data-managers/notifications-data-manager"; @@ -34,7 +37,7 @@ import NotificationsFactory from "../common/data-managers/notifications-factory" class Users extends Component { static getStores() { - return [ UsersStore ]; + return [UsersStore, ScenarioStore]; } static calculateState(prevState, props) { @@ -48,11 +51,20 @@ class Users extends Component { }); } + if (prevState == null) { + prevState = {}; + } + return { token: token, users: UsersStore.getState(), + scenarios: ScenarioStore.getState(), + usersToAdd: prevState.usersToAdd || new Map(), + selectedScenarioID: prevState.selectedScenarioID || null, + selectedScenario: prevState.selectedScenario || '', newModal: false, + addUsersModal: false, editModal: false, deleteModal: false, modalData: {}, @@ -110,6 +122,35 @@ class Users extends Component { } }; + onUserChecked(user) { + let temp = this.state.usersToAdd; + const found = temp.get(user.id); + if (!found) { + temp.set(user.id, user.username); + } else { + temp.delete(user.id) + } + this.setState({ usersToAdd: temp }); + } + + setScenario(ID) { + let scenario = this.state.scenarios.find(s => s.id == ID); + this.setState({ selectedScenarioID: scenario.id, selectedScenario: scenario.name, addUsersModal: true }) + }; + + closeAddUsersModal() { + this.state.usersToAdd.forEach((value, key) => { + AppDispatcher.dispatch({ + type: 'scenarios/add-user', + data: this.state.selectedScenarioID, + username: value, + token: this.state.token + }); + }) + + this.setState({ addUsersModal: false, selectedScenarioID: null }) + } + modifyActiveColumn(active) { return } @@ -125,65 +166,91 @@ class Users extends Component { } return
-

Users +

Users - this.setState({ newModal: true })} - icon='plus' - buttonStyle={buttonStyle} - iconStyle={iconStyle} - /> - -

+ this.setState({ newModal: true })} + icon='plus' + buttonStyle={buttonStyle} + iconStyle={iconStyle} + /> + + - - {this.state.currentUser.role === "Admin" ? - - : <> - } +
+ {this.state.currentUser.role === "Admin" ? + : <> + } + {this.state.currentUser.role === "Admin" ? this.onUserChecked(index, event)} + checkboxKey='checked' + width='30' /> - - this.modifyActiveColumn(active)} - /> - this.setState({ - editModal: true, - modalData: this.state.users[index] - })} - onDelete={index => this.setState({ - deleteModal: true, - modalData: this.state.users[index] - })} - /> -
+ : <> + } + + + + this.modifyActiveColumn(active)} + /> + this.setState({ + editModal: true, + modalData: this.state.users[index] + })} + onDelete={index => this.setState({ + deleteModal: true, + modalData: this.state.users[index] + })} + /> + + + this.setScenario(id)} + > + {this.state.scenarios.map(scenario => ( + {scenario.name} + ))} + + - this.closeNewModal(data)} /> - this.closeEditModal(data)} user={this.state.modalData} /> - this.closeDeleteModal(e)} /> -
; + this.closeAddUsersModal()} + /> + this.closeNewModal(data)} /> + this.closeEditModal(data)} user={this.state.modalData} /> + this.closeDeleteModal(e)} /> + ; } }