1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-25 12:13:17 +00:00
seahub/frontend/src/components/dirent-list-view/dirent-list-view.js

213 lines
6.4 KiB
JavaScript
Raw Normal View History

2018-11-22 03:05:47 +00:00
import React, { Fragment } from 'react';
2018-10-13 09:07:54 +00:00
import PropTypes from 'prop-types';
import { gettext, repoID } from '../../utils/constants';
import URLDecorator from '../../utils/url-decorator';
import editorUtilities from '../../utils/editor-utilties';
import Loading from '../loading';
2018-10-13 09:07:54 +00:00
import DirentListItem from './dirent-list-item';
import ZipDownloadDialog from '../dialog/zip-download-dialog';
import MoveDirentDialog from '../dialog/move-dirent-dialog';
import CopyDirentDialog from '../dialog/copy-dirent-dialog';
2018-10-13 09:07:54 +00:00
const propTypes = {
2018-11-22 03:26:00 +00:00
path: PropTypes.string.isRequired,
2018-10-13 09:07:54 +00:00
direntList: PropTypes.array.isRequired,
onItemDelete: PropTypes.func.isRequired,
onItemRename: PropTypes.func.isRequired,
2018-10-13 09:07:54 +00:00
onItemClick: PropTypes.func.isRequired,
onItemMove: PropTypes.func.isRequired,
onItemCopy: PropTypes.func.isRequired,
onItemDetails: PropTypes.func.isRequired,
2018-11-22 03:26:00 +00:00
updateDirent: PropTypes.func.isRequired,
isDirentListLoading: PropTypes.bool.isRequired,
2018-11-01 10:40:18 +00:00
isRepoOwner: PropTypes.bool,
currentRepo: PropTypes.object,
2018-10-13 09:07:54 +00:00
};
class DirentListView extends React.Component {
constructor(props) {
super(props);
this.state = {
progress: 0,
2018-10-13 09:07:54 +00:00
isItemFreezed: false,
isProgressDialogShow: false,
isMoveDialogShow: false,
isCopyDialogShow: false,
currentDirent: false,
direntPath: '',
2018-10-13 09:07:54 +00:00
};
}
onFreezedItem = () => {
2018-10-13 09:07:54 +00:00
this.setState({isItemFreezed: true});
}
2018-11-22 03:26:00 +00:00
onUnfreezedItem = () => {
2018-10-13 09:07:54 +00:00
this.setState({isItemFreezed: false});
}
onRenameMenuItemClick = () => {
this.onFreezedItem();
2018-10-13 09:07:54 +00:00
}
onDirentItemMove = (dirent, direntPath) => {
this.setState({
isMoveDialogShow: true,
currentDirent: dirent,
direntPath: direntPath
});
2018-10-13 09:07:54 +00:00
}
onDirentItemCopy = (dirent, direntPath) => {
this.setState({
isCopyDialogShow: true,
currentDirent: dirent,
direntPath: direntPath
});
2018-10-13 09:07:54 +00:00
}
onItemMove = (repo, direntPath, moveToDirentPath) => {
this.props.onItemMove(repo, direntPath, moveToDirentPath);
}
2018-11-22 03:26:00 +00:00
onCancelMove = () => {
this.setState({isMoveDialogShow: false});
}
2018-11-22 03:26:00 +00:00
onItemCopy = (repo, direntPath, copyToDirentPath) => {
this.props.onItemCopy(repo, direntPath, copyToDirentPath);
}
2018-11-22 03:26:00 +00:00
onCancelCopy = () => {
this.setState({isCopyDialogShow: false});
}
onItemDetails = (dirent, direntPath) => {
this.props.onItemDetails(dirent, direntPath);
}
onItemDownload = (dirent, direntPath) => {
2018-10-13 09:07:54 +00:00
if (dirent.type === 'dir') {
this.setState({isProgressDialogShow: true, progress: 0});
2018-11-22 03:26:00 +00:00
editorUtilities.zipDownload(this.props.path, dirent.name).then(res => {
2018-10-13 09:07:54 +00:00
this.zip_token = res.data['zip_token'];
this.addDownloadAnimation();
this.interval = setInterval(this.addDownloadAnimation, 1000);
});
} else {
let url = URLDecorator.getUrl({type: 'download_file_url', repoID: repoID, filePath: direntPath});
2018-10-13 09:07:54 +00:00
location.href = url;
}
}
addDownloadAnimation = () => {
let _this = this;
let token = this.zip_token;
editorUtilities.queryZipProgress(token).then(res => {
let data = res.data;
let progress = data.total === 0 ? 100 : (data.zipped / data.total * 100).toFixed(0);
this.setState({progress: parseInt(progress)});
2018-10-13 09:07:54 +00:00
if (data['total'] === data['zipped']) {
this.setState({
progress: 100
2018-10-13 09:07:54 +00:00
});
clearInterval(this.interval);
location.href = URLDecorator.getUrl({type: 'download_dir_zip_url', token: token});
setTimeout(function() {
_this.setState({isProgressDialogShow: false});
}, 500);
}
});
}
onCancelDownload = () => {
let zip_token = this.zip_token;
editorUtilities.cancelZipTask(zip_token).then(res => {
this.setState({
isProgressDialogShow: false,
});
});
}
render() {
const { direntList } = this.props;
if (this.props.isDirentListLoading) {
return (<Loading />);
}
2018-10-13 09:07:54 +00:00
return (
2018-11-22 03:05:47 +00:00
<Fragment>
2018-10-13 09:07:54 +00:00
<table>
<thead>
<tr>
<th width="3%" className="select"><input type="checkbox" className="vam" /></th>
<th width="3%"></th>
<th width="5%"></th>
2018-11-13 08:39:13 +00:00
<th width="35%">{gettext('Name')}</th>
<th width="10%"></th>
2018-10-13 09:07:54 +00:00
<th width="20%"></th>
<th width="11%">{gettext('Size')}</th>
<th width="13%">{gettext('Last Update')}</th>
</tr>
</thead>
<tbody>
{
direntList.length !== 0 && direntList.map((dirent, index) => {
return (
<DirentListItem
key={index}
dirent={dirent}
2018-11-22 03:26:00 +00:00
path={this.props.path}
2018-11-01 10:40:18 +00:00
currentRepo={this.props.currentRepo}
isRepoOwner={this.props.isRepoOwner}
onItemClick={this.props.onItemClick}
onRenameMenuItemClick={this.onRenameMenuItemClick}
onItemDelete={this.props.onItemDelete}
onItemRename={this.props.onItemRename}
2018-10-13 09:07:54 +00:00
isItemFreezed={this.state.isItemFreezed}
onFreezedItem={this.onFreezedItem}
onUnfreezedItem={this.onUnfreezedItem}
2018-10-13 09:07:54 +00:00
onItemDownload={this.onItemDownload}
onDirentItemMove={this.onDirentItemMove}
onDirentItemCopy={this.onDirentItemCopy}
onItemDetails={this.onItemDetails}
2018-11-22 03:26:00 +00:00
updateDirent={this.props.updateDirent}
2018-10-13 09:07:54 +00:00
/>
);
})
}
</tbody>
</table>
2018-11-22 03:26:00 +00:00
{this.state.isProgressDialogShow &&
<ZipDownloadDialog progress={this.state.progress} onCancelDownload={this.onCancelDownload}
/>
}
{this.state.isMoveDialogShow &&
2018-11-22 03:26:00 +00:00
<MoveDirentDialog
dirent={this.state.currentDirent}
direntPath={this.state.direntPath}
onItemMove={this.props.onItemMove}
onCancelMove={this.onCancelMove}
/>
}
{this.state.isCopyDialogShow &&
2018-11-22 03:26:00 +00:00
<CopyDirentDialog
dirent={this.state.currentDirent}
direntPath={this.state.direntPath}
onItemCopy={this.props.onItemCopy}
2018-11-22 03:26:00 +00:00
onCancelCopy={this.onCancelCopy}
/>
2018-10-13 09:07:54 +00:00
}
2018-11-22 03:05:47 +00:00
</Fragment>
2018-10-13 09:07:54 +00:00
);
}
}
DirentListView.propTypes = propTypes;
export default DirentListView;