1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00
Files
seahub/frontend/src/components/dirent-detail/detail-list-view.js

103 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-11-22 11:05:47 +08:00
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
2018-11-13 16:39:13 +08:00
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
const propTypes = {
repo: PropTypes.object.isRequired,
direntType: PropTypes.string.isRequired,
direntDetail: PropTypes.object.isRequired,
direntPath: PropTypes.string.isRequired,
2018-11-13 16:39:13 +08:00
fileTagList: PropTypes.array.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
};
class DetailListView extends React.Component {
2018-11-13 16:39:13 +08:00
constructor(props) {
super(props);
this.state = {
isEditFileTagShow: false,
};
}
getDirentPostion = () => {
let { repo, direntPath } = this.props;
let position = repo.repo_name + '/';
if (direntPath !== '/') {
let index = direntPath.lastIndexOf('/');
let path = direntPath.slice(0, index);
position = position + path;
}
return position;
}
2018-11-13 16:39:13 +08:00
onEditFileTagToggle = () => {
this.setState({
isEditFileTagShow: !this.state.isEditFileTagShow
});
}
render() {
2018-11-13 16:39:13 +08:00
let { direntType, direntDetail, fileTagList } = this.props;
let position = this.getDirentPostion();
if (direntType === 'dir') {
return (
2018-11-22 11:05:47 +08:00
<table>
<tbody>
<tr><th width="35%"></th><td width="65%"></td></tr>
<tr><th>{gettext('Folder')}</th><td>{direntDetail.dir_count}</td></tr>
<tr><th>{gettext('File')}</th><td>{direntDetail.file_count}</td></tr>
<tr><th>{gettext('Size')}</th><td>{Utils.bytesToSize(direntDetail.size)}</td></tr>
<tr><th>{gettext('Position')}</th><td>{position}</td></tr>
<tr><th>{gettext('Last Update')}</th><td>{moment(direntDetail.mtime).format('YYYY-MM-DD')}</td></tr>
</tbody>
</table>
);
} else {
return (
2018-11-22 11:05:47 +08:00
<Fragment>
<table>
<tbody>
<tr><th width="35%"></th><td width="65%"></td></tr>
<tr><th>{gettext('Size')}</th><td>{direntDetail.size}</td></tr>
<tr><th>{gettext('Position')}</th><td>{position}</td></tr>
<tr><th>{gettext('Last Update')}</th><td>{moment(direntDetail.mtime).format('YYYY-MM-DD')}</td></tr>
2018-11-13 16:39:13 +08:00
<tr className="file-tag-container"><th>{gettext('Tags')}</th>
<td>
<ul className="file-tag-list">
{fileTagList.map((fileTag) => {
return (
<li key={fileTag.id}>
<span className={`file-tag bg-${fileTag.color}`}></span>
<span className="tag-name">{fileTag.name}</span>
</li>
);
})}
</ul>
<i className='fa fa-pencil' onClick={this.onEditFileTagToggle}></i>
</td>
</tr>
</tbody>
</table>
2018-11-13 16:39:13 +08:00
{
this.state.isEditFileTagShow &&
<EditFileTagDialog
fileTagList={fileTagList}
filePath={this.props.direntPath}
toggleCancel={this.onEditFileTagToggle}
onFileTagChanged={this.props.onFileTagChanged}
/>
}
2018-11-22 11:05:47 +08:00
</Fragment>
);
}
}
}
DetailListView.propTypes = propTypes;
export default DetailListView;