1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-28 11:41:18 +00:00
seahub/frontend/src/components/dirent-detail/detail-list-view.js
2018-12-18 17:21:00 +08:00

118 lines
3.8 KiB
JavaScript

import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
const propTypes = {
repoInfo: PropTypes.object.isRequired,
repoID: PropTypes.string.isRequired,
dirent: PropTypes.object.isRequired,
direntType: PropTypes.string.isRequired,
direntDetail: PropTypes.object.isRequired,
path: PropTypes.string.isRequired,
fileTagList: PropTypes.array.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
};
class DetailListView extends React.Component {
constructor(props) {
super(props);
this.state = {
isEditFileTagShow: false,
};
}
getDirentPostion = () => {
let { repoInfo } = this.props;
let direntPath = this.getDirentPath();
let position = repoInfo.repo_name;
if (direntPath !== '/') {
let index = direntPath.lastIndexOf('/');
let path = direntPath.slice(0, index);
position = position + path;
}
return position;
}
onEditFileTagToggle = () => {
this.setState({
isEditFileTagShow: !this.state.isEditFileTagShow
});
}
onFileTagChanged = () => {
let direntPath = this.getDirentPath();
this.props.onFileTagChanged(this.props.dirent, direntPath);
}
getDirentPath = () => {
let { dirent, path } = this.props;
return Utils.joinPath(path, dirent.name);
}
render() {
let { direntType, direntDetail, fileTagList } = this.props;
let position = this.getDirentPostion();
let direntPath = this.getDirentPath();
if (direntType === 'dir') {
return (
<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 (
<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.last_modified).fromNow()}</td></tr>
<tr className="file-tag-container"><th>{gettext('Tags')}</th>
<td>
<ul className="file-tag-list">
{fileTagList.map((fileTag) => {
return (
<li key={fileTag.id} className="file-tag-item">
<span className={`file-tag bg-${fileTag.color}`}></span>
<span className="tag-name" title={fileTag.name}>{fileTag.name}</span>
</li>
);
})}
</ul>
<i className='fa fa-pencil tag-edit-icon' onClick={this.onEditFileTagToggle}></i>
</td>
</tr>
</tbody>
</table>
{
this.state.isEditFileTagShow &&
<EditFileTagDialog
repoID={this.props.repoID}
fileTagList={fileTagList}
filePath={direntPath}
toggleCancel={this.onEditFileTagToggle}
onFileTagChanged={this.onFileTagChanged}
/>
}
</Fragment>
);
}
}
}
DetailListView.propTypes = propTypes;
export default DetailListView;