2020-09-07 04:03:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-11-06 12:12:39 +00:00
|
|
|
import { Button, ModalBody, ModalFooter, Form, FormGroup, Label, Input, Alert } from 'reactstrap';
|
|
|
|
import { gettext } from '../../../utils/constants';
|
|
|
|
import { seafileAPI } from '../../../utils/seafile-api';
|
|
|
|
import { Utils } from '../../../utils/utils';
|
|
|
|
import toaster from '../../toast';
|
2020-09-07 04:03:05 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
toggleDialog: PropTypes.func.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2024-11-06 12:12:39 +00:00
|
|
|
class LibOldFilesAutoDelSetting extends React.Component {
|
2020-09-07 04:03:05 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
autoDelDays: 0,
|
|
|
|
isAutoDel: false,
|
|
|
|
errorInfo: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
seafileAPI.getRepoOldFilesAutoDelDays(this.props.repoID).then(res => {
|
|
|
|
this.setState({
|
|
|
|
autoDelDays: res.data.auto_delete_days,
|
|
|
|
isAutoDel: res.data.auto_delete_days > 0,
|
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
submit = () => {
|
2021-10-09 07:21:37 +00:00
|
|
|
let daysNeedTobeSet;
|
2020-09-07 04:03:05 +00:00
|
|
|
|
2021-10-09 07:21:37 +00:00
|
|
|
if (this.state.isAutoDel) {
|
|
|
|
daysNeedTobeSet = this.state.autoDelDays;
|
2020-09-07 04:03:05 +00:00
|
|
|
|
2021-10-09 07:21:37 +00:00
|
|
|
let reg = /^-?\d+$/;
|
|
|
|
let isvalid_days = reg.test(daysNeedTobeSet);
|
|
|
|
if (!isvalid_days || daysNeedTobeSet <= 0) {
|
|
|
|
this.setState({
|
|
|
|
errorInfo: gettext('Please enter a positive integer'),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2024-07-18 03:58:42 +00:00
|
|
|
daysNeedTobeSet = 0; // if no auto del, give 0 to server
|
2020-09-07 04:03:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-09 07:21:37 +00:00
|
|
|
|
2020-09-07 04:03:05 +00:00
|
|
|
let repoID = this.props.repoID;
|
|
|
|
|
|
|
|
seafileAPI.setRepoOldFilesAutoDelDays(repoID, daysNeedTobeSet).then(res => {
|
|
|
|
this.props.toggleDialog();
|
2020-12-17 10:03:21 +00:00
|
|
|
toaster.success(gettext('Successfully set it.'));
|
2020-09-07 04:03:05 +00:00
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2020-09-07 04:03:05 +00:00
|
|
|
|
2023-11-14 12:25:25 +00:00
|
|
|
handleKeyDown = (e) => {
|
2020-09-07 04:03:05 +00:00
|
|
|
if (e.key === 'Enter') {
|
|
|
|
this.submit();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2020-09-07 04:03:05 +00:00
|
|
|
|
|
|
|
onChange = (e) => {
|
|
|
|
let days = e.target.value;
|
|
|
|
this.setState({
|
|
|
|
autoDelDays: days,
|
|
|
|
});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2020-09-07 04:03:05 +00:00
|
|
|
|
|
|
|
updateRadioCheck = (type) => {
|
|
|
|
if (type === 'noAutoDel') {
|
|
|
|
this.setState({
|
|
|
|
isAutoDel: false,
|
|
|
|
});
|
|
|
|
} else if (type === 'autoDel') {
|
|
|
|
this.setState({
|
|
|
|
isAutoDel: true,
|
|
|
|
});
|
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2020-09-07 04:03:05 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2024-11-06 12:12:39 +00:00
|
|
|
<>
|
2020-09-07 04:03:05 +00:00
|
|
|
<ModalBody>
|
|
|
|
<Form>
|
|
|
|
<FormGroup check>
|
2024-07-18 03:58:42 +00:00
|
|
|
<Input type="radio" name="radio1" checked={!this.state.isAutoDel} onChange={() => {this.updateRadioCheck('noAutoDel');}}/>{' '}
|
2020-09-07 04:03:05 +00:00
|
|
|
<Label>{gettext('Do not automatically delete files')}</Label>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup check>
|
2024-07-18 03:58:42 +00:00
|
|
|
<Input type="radio" name="radio1" checked={this.state.isAutoDel} onChange={() => {this.updateRadioCheck('autoDel');}}/>{' '}
|
2020-09-07 04:03:05 +00:00
|
|
|
<Label>{gettext('Automatically delete files that are not modified within certain days:')}</Label>
|
2020-11-02 05:56:35 +00:00
|
|
|
<Input
|
|
|
|
type="text"
|
|
|
|
className="expire-input"
|
2020-09-07 04:03:05 +00:00
|
|
|
value={this.state.autoDelDays}
|
2021-10-09 07:21:37 +00:00
|
|
|
disabled={!this.state.isAutoDel}
|
2020-11-02 05:56:35 +00:00
|
|
|
onChange={this.onChange}
|
2023-11-14 12:25:25 +00:00
|
|
|
onKeyDown={this.handleKeyDown}
|
2020-09-07 04:03:05 +00:00
|
|
|
/>{' '}
|
|
|
|
<Label><span>{gettext('days')}</span></Label>
|
|
|
|
</FormGroup>
|
|
|
|
{this.state.errorInfo && <Alert color="danger">{this.state.errorInfo}</Alert>}
|
|
|
|
</Form>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
|
|
|
|
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
|
|
|
|
</ModalFooter>
|
2024-11-06 12:12:39 +00:00
|
|
|
</>
|
2020-09-07 04:03:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-06 12:12:39 +00:00
|
|
|
LibOldFilesAutoDelSetting.propTypes = propTypes;
|
2020-09-07 04:03:05 +00:00
|
|
|
|
2024-11-06 12:12:39 +00:00
|
|
|
export default LibOldFilesAutoDelSetting;
|