1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 01:41:39 +00:00
Files
seahub/frontend/src/components/file-uploader/upload-list-item.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-11-14 10:55:11 +08:00
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
const propTypes = {
item: PropTypes.object.isRequired,
onUploadCancel: PropTypes.func.isRequired,
};
class UploadListItem extends React.Component {
2018-11-30 11:52:19 +08:00
onUploadCancel = (e) => {
e.preventDefault();
2018-11-14 10:55:11 +08:00
let item = this.props.item;
item.resumableFile.cancel();
this.props.onUploadCancel(item);
}
formatFileSize = (size) => {
if (typeof size !== 'number') {
return '';
}
if (size >= 1000 * 1000 * 1000) {
return (size / (1000 * 1000 * 1000)).toFixed(1) + ' G';
}
if (size >= 1000 * 1000) {
return (size / (1000 * 1000)).toFixed(1) + ' M';
}
if (size >= 1000) {
return (size / 1000).toFixed(1) + ' K';
}
return size.toFixed(1) + ' B';
}
render() {
let { item } = this.props;
let progress = Math.round(item.resumableFile.progress() * 100);
return (
<tr className="file-upload-item">
<td width="50%" className="upload-name ellipsis">{item.resumableFile.relativePath}</td>
<td width="30%" className="upload-progress upload-size">
{
progress === 100 ? this.formatFileSize(item.resumableFile.size) : progress + '%'
}
</td>
<td width="20%" className="upload-operation">
{ progress !== 100 ?
2018-11-30 11:52:19 +08:00
<a href="#" onClick={this.onUploadCancel}>{gettext(('cancel'))}</a> :
2018-11-14 10:55:11 +08:00
<span>{gettext('uploaded')}</span>
}
</td>
</tr>
);
}
}
UploadListItem.propTypes = propTypes;
export default UploadListItem;