1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-29 04:01:24 +00:00
seahub/frontend/src/components/dirent-detail/detail-list-view.js

118 lines
3.8 KiB
JavaScript
Raw Normal View History

2018-11-22 03:05:47 +00: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 08:39:13 +00:00
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
const propTypes = {
2018-12-18 09:21:01 +00:00
repoInfo: PropTypes.object.isRequired,
2018-11-28 04:41:49 +00:00
repoID: PropTypes.string.isRequired,
dirent: PropTypes.object.isRequired,
direntType: PropTypes.string.isRequired,
direntDetail: PropTypes.object.isRequired,
2018-11-29 09:55:14 +00:00
path: PropTypes.string.isRequired,
2018-11-13 08:39:13 +00:00
fileTagList: PropTypes.array.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
};
class DetailListView extends React.Component {
2018-11-13 08:39:13 +00:00
constructor(props) {
super(props);
this.state = {
isEditFileTagShow: false,
};
}
getDirentPostion = () => {
2018-12-18 09:21:01 +00:00
let { repoInfo } = this.props;
2018-11-29 09:55:14 +00:00
let direntPath = this.getDirentPath();
2018-12-18 09:21:01 +00:00
let position = repoInfo.repo_name;
if (direntPath !== '/') {
let index = direntPath.lastIndexOf('/');
let path = direntPath.slice(0, index);
position = position + path;
}
return position;
}
2018-11-13 08:39:13 +00:00
onEditFileTagToggle = () => {
this.setState({
isEditFileTagShow: !this.state.isEditFileTagShow
});
}
2018-11-22 03:26:00 +00:00
onFileTagChanged = () => {
2018-11-29 09:55:14 +00:00
let direntPath = this.getDirentPath();
this.props.onFileTagChanged(this.props.dirent, direntPath);
}
getDirentPath = () => {
let { dirent, path } = this.props;
return Utils.joinPath(path, dirent.name);
2018-11-22 03:26:00 +00:00
}
render() {
2018-11-13 08:39:13 +00:00
let { direntType, direntDetail, fileTagList } = this.props;
let position = this.getDirentPostion();
2018-11-29 09:55:14 +00:00
let direntPath = this.getDirentPath();
if (direntType === 'dir') {
return (
2018-11-22 03:05:47 +00: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 03:05:47 +00: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>
2018-11-22 03:26:00 +00:00
<tr><th>{gettext('Last Update')}</th><td>{moment(direntDetail.last_modified).fromNow()}</td></tr>
2018-11-13 08:39:13 +00:00
<tr className="file-tag-container"><th>{gettext('Tags')}</th>
<td>
<ul className="file-tag-list">
{fileTagList.map((fileTag) => {
return (
2018-12-17 08:52:04 +00:00
<li key={fileTag.id} className="file-tag-item">
2018-11-13 08:39:13 +00:00
<span className={`file-tag bg-${fileTag.color}`}></span>
2018-12-17 08:52:04 +00:00
<span className="tag-name" title={fileTag.name}>{fileTag.name}</span>
2018-11-13 08:39:13 +00:00
</li>
);
})}
</ul>
2018-12-17 08:52:04 +00:00
<i className='fa fa-pencil tag-edit-icon' onClick={this.onEditFileTagToggle}></i>
2018-11-13 08:39:13 +00:00
</td>
</tr>
</tbody>
</table>
2018-11-13 08:39:13 +00:00
{
this.state.isEditFileTagShow &&
<EditFileTagDialog
2018-11-28 04:41:49 +00:00
repoID={this.props.repoID}
2018-11-13 08:39:13 +00:00
fileTagList={fileTagList}
2018-11-29 09:55:14 +00:00
filePath={direntPath}
2018-11-13 08:39:13 +00:00
toggleCancel={this.onEditFileTagToggle}
2018-11-22 03:26:00 +00:00
onFileTagChanged={this.onFileTagChanged}
2018-11-13 08:39:13 +00:00
/>
}
2018-11-22 03:05:47 +00:00
</Fragment>
);
}
}
}
DetailListView.propTypes = propTypes;
export default DetailListView;