2019-10-22 11:49:30 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-09 13:37:24 +00:00
|
|
|
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, FormGroup, Label, Input, Alert } from 'reactstrap';
|
2019-10-22 11:49:30 +00:00
|
|
|
import { gettext, siteRoot } from '../../../utils/constants';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
class LogsExportExcelDialog extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
startDateStr: '',
|
|
|
|
endDateStr: '',
|
|
|
|
errMsg: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadExcel = () => {
|
|
|
|
if (!this.isValidDateStr()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let { startDateStr, endDateStr } = this.state;
|
|
|
|
let url = siteRoot;
|
|
|
|
|
|
|
|
switch (this.props.logType) {
|
|
|
|
case 'login':
|
|
|
|
url += 'sys/loginadmin/export-excel/';
|
|
|
|
break;
|
|
|
|
case 'fileAccess':
|
|
|
|
url += 'sys/log/fileaudit/export-excel/';
|
|
|
|
break;
|
|
|
|
case 'fileUpdate':
|
|
|
|
url += 'sys/log/fileupdate/export-excel/';
|
|
|
|
break;
|
|
|
|
case 'sharePermission':
|
|
|
|
url += 'sys/log/permaudit/export-excel/';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
location.href = url + '?start=' + startDateStr + '&end=' + endDateStr;
|
|
|
|
this.props.toggle();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-22 11:49:30 +00:00
|
|
|
|
|
|
|
isValidDateStr = () => {
|
|
|
|
let { startDateStr, endDateStr } = this.state;
|
|
|
|
if (moment(startDateStr, 'YYYY-MM-DD', true).isValid() &&
|
|
|
|
moment(endDateStr, 'YYYY-MM-DD', true).isValid() &&
|
|
|
|
moment(startDateStr).isBefore(endDateStr)
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
errMsg: gettext('Date Invalid.')
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-22 11:49:30 +00:00
|
|
|
|
|
|
|
handleStartChange = (e) => {
|
|
|
|
const startDateStr = e.target.value.trim();
|
|
|
|
this.setState({
|
|
|
|
startDateStr: startDateStr,
|
|
|
|
errMsg: ''
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-22 11:49:30 +00:00
|
|
|
|
|
|
|
handleEndChange = (e) => {
|
|
|
|
const endDateStr = e.target.value.trim();
|
2020-11-02 05:56:35 +00:00
|
|
|
this.setState({
|
2019-10-22 11:49:30 +00:00
|
|
|
endDateStr: endDateStr,
|
|
|
|
errMsg: '',
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-10-22 11:49:30 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-12-24 02:41:34 +00:00
|
|
|
<Modal isOpen={true} toggle={this.props.toggle} autoFocus={false}>
|
2019-10-22 11:49:30 +00:00
|
|
|
<ModalHeader toggle={this.props.toggle}>{gettext('Choose date')}</ModalHeader>
|
|
|
|
<ModalBody>
|
2019-12-09 13:37:24 +00:00
|
|
|
<FormGroup>
|
|
|
|
<Label>{gettext('Start date')}</Label>
|
|
|
|
<Input
|
|
|
|
value={this.state.startDateStr}
|
|
|
|
onChange={this.handleStartChange}
|
|
|
|
placeholder='yyyy-mm-dd'
|
2022-12-24 02:41:34 +00:00
|
|
|
autoFocus={true}
|
2019-12-09 13:37:24 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Label>{gettext('End date')}</Label>
|
|
|
|
<Input
|
|
|
|
value={this.state.endDateStr}
|
|
|
|
onChange={this.handleEndChange}
|
|
|
|
placeholder='yyyy-mm-dd'
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2019-10-22 11:49:30 +00:00
|
|
|
{this.state.errMsg &&
|
|
|
|
<Alert className="mt-2" color="danger">
|
|
|
|
{gettext(this.state.errMsg)}
|
|
|
|
</Alert>
|
|
|
|
}
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
2019-12-09 13:37:24 +00:00
|
|
|
<Button color="secondary" onClick={this.props.toggle}>{gettext('Cancel')}</Button>
|
2019-10-22 11:49:30 +00:00
|
|
|
<Button color="primary" onClick={this.downloadExcel}>{gettext('Submit')}</Button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
toggle: PropTypes.func.isRequired,
|
|
|
|
logType: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
LogsExportExcelDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default LogsExportExcelDialog;
|