|
|
@@ -1,6 +1,7 @@
|
|
|
import React, { Fragment } from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
+import { format } from 'date-fns';
|
|
|
|
|
|
import { createSubscribedElement } from '../../UnstatedUtils';
|
|
|
import AppContainer from '../../../services/AppContainer';
|
|
|
@@ -15,7 +16,8 @@ class ExportPage extends React.Component {
|
|
|
files: {},
|
|
|
};
|
|
|
|
|
|
- this.createZipFile = this.createZipFile.bind(this);
|
|
|
+ this.toggleCheckbox = this.toggleCheckbox.bind(this);
|
|
|
+ this.exportSingle = this.exportSingle.bind(this);
|
|
|
this.deleteZipFile = this.deleteZipFile.bind(this);
|
|
|
}
|
|
|
|
|
|
@@ -25,9 +27,18 @@ class ExportPage extends React.Component {
|
|
|
this.setState({ files: res.files });
|
|
|
}
|
|
|
|
|
|
- async createZipFile() {
|
|
|
+ toggleCheckbox(e) {
|
|
|
+ const { target } = e;
|
|
|
+ const { name, checked } = target;
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ [name]: checked,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async exportSingle(collection) {
|
|
|
// TODO use appContainer.apiv3.post
|
|
|
- const res = await this.props.appContainer.apiPost('/v3/export/pages', {});
|
|
|
+ const res = await this.props.appContainer.apiPost(`/v3/export/${collection}`, {});
|
|
|
// TODO toastSuccess, toastError
|
|
|
this.setState((prevState) => {
|
|
|
return {
|
|
|
@@ -52,27 +63,31 @@ class ExportPage extends React.Component {
|
|
|
<h2>Export Data as Zip</h2>
|
|
|
<form className="my-5">
|
|
|
{Object.keys(this.state.files).map((file) => {
|
|
|
- const disabled = file !== 'pages';
|
|
|
+ const disabled = !(file === 'pages' || file === 'revisions');
|
|
|
+ const stat = this.state.files[file] || {};
|
|
|
return (
|
|
|
- <div className="form-check" key={file}>
|
|
|
+ <div className="checkbox checkbox-info" key={file}>
|
|
|
<input
|
|
|
- type="radio"
|
|
|
+ type="checkbox"
|
|
|
id={file}
|
|
|
- name="collection"
|
|
|
+ name={file}
|
|
|
className="form-check-input"
|
|
|
value={file}
|
|
|
disabled={disabled}
|
|
|
- checked={!disabled}
|
|
|
- onChange={() => {}}
|
|
|
+ checked={this.state[file]}
|
|
|
+ onChange={this.toggleCheckbox}
|
|
|
/>
|
|
|
<label className={`form-check-label ml-3 ${disabled ? 'text-muted' : ''}`} htmlFor={file}>
|
|
|
- {file} ({this.state.files[file] || 'not found'})
|
|
|
+ {file} ({stat.name || 'not found'}) ({stat.mtime ? format(new Date(stat.mtime), 'yyyy/MM/dd HH:mm:ss') : ''})
|
|
|
</label>
|
|
|
+ <button type="button" className="btn btn-sm btn-primary" onClick={() => this.exportSingle(file)} disabled={disabled}>
|
|
|
+ Create zip file
|
|
|
+ </button>
|
|
|
</div>
|
|
|
);
|
|
|
})}
|
|
|
</form>
|
|
|
- <button type="button" className="btn btn-sm btn-default" onClick={this.createZipFile}>Generate</button>
|
|
|
+ <button type="button" className="btn btn-sm btn-default" onClick={this.exportSingle}>Generate</button>
|
|
|
<a href="/_api/v3/export/pages">
|
|
|
<button type="button" className="btn btn-sm btn-primary ml-2">Download</button>
|
|
|
</a>
|