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

cosmetic code cleanups

This commit is contained in:
Steffen Vogel 2021-03-08 17:40:07 +01:00
parent 74c16e3ae2
commit dccbc2e56c
6 changed files with 115 additions and 135 deletions

View file

@ -119,49 +119,47 @@ class CustomTable extends Component {
);
}
if (child.props.dataIndex) {
cell.push(index);
}
// add buttons
let showEditButton = true
if (child.props.showEditButton !== null)
{
showEditButton = child.props.showEditButton(index)
}
if(showEditButton){
if (child.props.editButton) {
cell.push(
<OverlayTrigger
key={0}
placement={'bottom'}
overlay={<Tooltip id={`tooltip-${"edit"}`}> Edit </Tooltip>}>
<Button
variant='table-control-button'
onClick={() => child.props.onEdit(index)}
disabled={child.props.onEdit == null} >
<Icon icon='edit' />
</Button>
</OverlayTrigger>);
}
}
let showEditButton = child.props.showEditButton !== null
? child.props.showEditButton(index)
: true;
if (child.props.editButton && showEditButton) {
cell.push(
<OverlayTrigger
key={0}
placement={'bottom'}
overlay={<Tooltip id={`tooltip-${"edit"}`}> Edit </Tooltip>}
>
<Button
variant='table-control-button'
onClick={() => child.props.onEdit(index)}
disabled={child.props.onEdit == null} >
<Icon icon='edit' />
</Button>
</OverlayTrigger>
);
}
if (child.props.checkbox) {
const checkboxKey = child.props.checkboxKey;
let isDisabled = false;
if (child.props.checkboxDisabled != null){
isDisabled = child.props.checkboxDisabled(index)
}
let isDisabled = child.props.checkboxDisabled != null
? child.props.checkboxDisabled(index)
: false;
cell.push(
<FormCheck
className="table-control-checkbox"
inline
disabled = {isDisabled}
disabled={isDisabled}
checked={checkboxKey ? data[checkboxKey] : null}
onChange={e => child.props.onChecked(data, e)}
/>);
/>
);
}
if (child.props.exportButton) {
@ -225,29 +223,28 @@ class CustomTable extends Component {
disabled={child.props.onDownloadAll == null}>
<Icon icon='file-download' />
</Button>
</OverlayTrigger>);
</OverlayTrigger>
);
}
let showDeleteButton = true;
if (child.props.showDeleteButton !== null){
showDeleteButton = child.props.showDeleteButton(index)
}
let showDeleteButton = child.props.showDeleteButton !== null
? child.props.showDeleteButton(index)
: true;
if (showDeleteButton){
if (child.props.deleteButton) {
cell.push(
<OverlayTrigger
key={5}
placement={'bottom'}
overlay={<Tooltip id={`tooltip-${"delete"}`}> Delete </Tooltip>} >
<Button
variant='table-control-button'
onClick={() => child.props.onDelete(index)}
disabled={child.props.onDelete == null}>
<Icon icon='trash' />
</Button>
</OverlayTrigger>);
}
if (child.props.deleteButton && showDeleteButton) {
cell.push(
<OverlayTrigger
key={5}
placement={'bottom'}
overlay={<Tooltip id={`tooltip-${"delete"}`}> Delete </Tooltip>} >
<Button
variant='table-control-button'
onClick={() => child.props.onDelete(index)}
disabled={child.props.onDelete == null}>
<Icon icon='trash' />
</Button>
</OverlayTrigger>
);
}
return cell;

View file

@ -63,6 +63,7 @@ class Scenario extends React.Component {
if (prevState == null) {
prevState = {};
}
// get selected scenario
const sessionToken = localStorage.getItem("token");

View file

@ -55,7 +55,7 @@ class EditOwnUserDialog extends React.Component {
let mail = true;
let pw = true;
let oldPassword = true;
let confirmpassword = true;
let confirmPassword = true;
if (this.state.username === '') {
username = false;
@ -73,12 +73,12 @@ class EditOwnUserDialog extends React.Component {
oldPassword = false;
}
if (this.state.confirmpassword === '') {
confirmpassword = false;
if (this.state.confirmPassword === '') {
confirmPassword = false;
}
// form is valid if the following condition is met
this.valid = username || mail || (oldPassword && pw && confirmpassword);
this.valid = username || mail || (oldPassword && pw && confirmPassword);
}
resetState() {
@ -86,7 +86,7 @@ class EditOwnUserDialog extends React.Component {
username: '',
mail: '',
oldPassword: '',
confirmpassword: '',
confirmPassword: '',
password: '',
id: this.props.user.id,
});

View file

@ -57,8 +57,8 @@ class EditUserDialog extends React.Component {
var mail = true;
var pw = true;
var active = true;
var confirmpassword = true;
var oldPW = true;
var confirmPassword = true;
var oldPassword = true;
if (this.state.username === '') {
username = false;
@ -68,29 +68,28 @@ class EditUserDialog extends React.Component {
role = false;
}
if(this.state.mail === ''){
if (this.state.mail === '') {
mail = false;
}
if(this.state.password === ''){
if (this.state.password === '') {
pw = false;
}
if(this.state.active === ''){
if (this.state.active === '') {
active = false;
}
if(this.state.confirmpassword === ''){
confirmpassword = false;
if (this.state.confirmPassword === '') {
confirmPassword = false;
}
if(this.state.oldPassword === ''){
oldPW = false;
if (this.state.oldPassword === '') {
oldPassword = false;
}
// form is valid if any of the fields contain somethig
this.valid = username || role || mail || pw || active || confirmpassword || oldPW;
this.valid = username || role || mail || pw || active || confirmPassword || oldPassword;
}
resetState() {

View file

@ -56,9 +56,7 @@ class User extends Component {
}
closeEditModal(data) {
this.setState({
editModal: false
});
this.setState({ editModal: false });
let updatedData = {}
updatedData.id = this.state.currentUser.id;
@ -66,52 +64,41 @@ class User extends Component {
let hasChanged = false;
let pwChanged = false;
if(data){
if (data.username !== ''){
hasChanged = true;
updatedData.username = data.username;
updatedUser.username = data.username
}
if (data.mail !== ''){
hasChanged = true;
updatedData.mail = data.mail;
updatedUser.mail = data.mail;
}
if (data.password !== '' && data.oldPassword !== '' && data.password === data.confirmpassword ){
pwChanged = true;
updatedData.password = data.password;
updatedData.oldPassword = data.oldPassword;
} else if (data.password !== '' && data.password !== data.confirmpassword) {
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_ERROR('New password not correctly confirmed'));
return
}
if (hasChanged || pwChanged) {
if (hasChanged){
this.setState({currentUser: updatedUser})
if (data) {
if (data.username !== '') {
hasChanged = true;
updatedData.username = data.username;
updatedUser.username = data.username
}
if (data.mail !== '') {
hasChanged = true;
updatedData.mail = data.mail;
updatedUser.mail = data.mail;
}
if (data.password !== '' && data.oldPassword !== '' && data.password === data.confirmPassword ) {
pwChanged = true;
updatedData.password = data.password;
updatedData.oldPassword = data.oldPassword;
} else if (data.password !== '' && data.password !== data.confirmPassword) {
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_ERROR('New password not correctly confirmed'));
return
}
AppDispatcher.dispatch({
type: 'users/start-edit',
data: updatedData,
token: this.state.token
});
} else {
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_WARNING('No update requested, no input data'));
if (hasChanged || pwChanged) {
if (hasChanged){
this.setState({ currentUser: updatedUser })
}
AppDispatcher.dispatch({
type: 'users/start-edit',
data: updatedData,
token: this.state.token
});
} else {
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_WARNING('No update requested, no input data'));
}
}
}
}
getHumanRoleName(role_key) {
const HUMAN_ROLE_NAMES = {
Admin: 'Administrator',
User: 'User',
Guest: 'Guest'
};
return HUMAN_ROLE_NAMES.hasOwnProperty(role_key)? HUMAN_ROLE_NAMES[role_key] : '';
}
render() {

View file

@ -38,7 +38,6 @@ class Users extends Component {
}
static calculateState(prevState, props) {
let token = localStorage.getItem("token");
// If there is a token available and this method was called as a result of loading users
@ -90,26 +89,19 @@ class Users extends Component {
this.setState({ editModal: false });
if (data) {
if(data.password === data.confirmpassword) {
if(data.password === data.confirmPassword) {
AppDispatcher.dispatch({
type: 'users/start-edit',
data: data,
token: this.state.token
});
} else{
} else {
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_ERROR("New password not correctly confirmed"))
}
}
}
getHumanRoleName(role_key) {
const HUMAN_ROLE_NAMES = {Admin: 'Administrator', User: 'User', Guest: 'Guest'};
return HUMAN_ROLE_NAMES.hasOwnProperty(role_key)? HUMAN_ROLE_NAMES[role_key] : '';
}
onModalKeyPress = (event) => {
if (event.key === 'Enter') {
event.preventDefault();
@ -118,14 +110,8 @@ class Users extends Component {
}
};
modifyActiveColumn(active){
if(active){
return <Icon icon='check' />
} else {
return <Icon icon='times' />
}
modifyActiveColumn(active) {
return <Icon icon={active ? 'check' : 'times'} />
}
render() {
@ -142,13 +128,24 @@ class Users extends Component {
<div>
<h1>Users
<span className='icon-button'>
<OverlayTrigger
key={1}
placement={'top'}
overlay={<Tooltip id={`tooltip-${"add"}`}> Add User </Tooltip>} >
<Button variant='light' style={buttonStyle} onClick={() => this.setState({ newModal: true })}><Icon icon='plus' classname='icon-color' style={iconStyle} /> </Button>
</OverlayTrigger>
</span>
<OverlayTrigger
key={1}
placement='top'
overlay={<Tooltip id={`tooltip-${"add"}`}> Add User </Tooltip>}
>
<Button
variant='light'
style={buttonStyle}
onClick={() => this.setState({ newModal: true })}
>
<Icon
icon='plus'
classname='icon-color'
style={iconStyle}
/>
</Button>
</OverlayTrigger>
</span>
</h1>
<Table data={this.state.users}>
@ -169,7 +166,6 @@ class Users extends Component {
<TableColumn
title='Role'
dataKey='role'
modifier={(role) => this.getHumanRoleName(role)}
/>
<TableColumn
title='Active'