1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00
Files
seahub/frontend/src/components/cur-dir-path/dir-tool.js

160 lines
5.7 KiB
JavaScript
Raw Normal View History

2018-11-02 15:34:34 +08:00
import React, { Fragment } from 'react';
2018-11-28 12:41:49 +08:00
import { gettext, siteRoot } from '../../utils/constants';
import { Utils } from '../../utils/utils';
2018-09-29 15:47:53 +08:00
import PropTypes from 'prop-types';
2018-12-18 14:29:51 +08:00
import ModalPortal from '../modal-portal';
import { Modal } from 'reactstrap';
2018-11-02 15:34:34 +08:00
import ListTagDialog from '../dialog/list-tag-dialog';
import CreateTagDialog from '../dialog/create-tag-dialog';
import UpdateTagDialog from '../dialog/update-tag-dialog';
2018-11-19 17:44:59 +08:00
import ListTaggedFilesDialog from '../dialog/list-taggedfiles-dialog';
2018-09-18 20:57:17 -05:00
2018-09-29 15:47:53 +08:00
const propTypes = {
2018-11-28 12:41:49 +08:00
repoID: PropTypes.string.isRequired,
repoName: PropTypes.string.isRequired,
permission: PropTypes.bool.isRequired,
currentPath: PropTypes.string.isRequired,
updateUsedRepoTags: PropTypes.func.isRequired,
onDeleteRepoTag: PropTypes.func.isRequired,
2018-09-29 15:47:53 +08:00
};
2018-09-18 20:57:17 -05:00
class DirTool extends React.Component {
2018-09-18 20:57:17 -05:00
2018-11-02 15:34:34 +08:00
constructor(props) {
super(props);
this.state = {
2018-12-21 12:33:31 +08:00
isRepoTagDialogShow: false,
2018-11-02 15:34:34 +08:00
currentTag: null,
isListRepoTagShow: false,
isUpdateRepoTagShow: false,
isCreateRepoTagShow: false,
2018-11-19 17:44:59 +08:00
isListTaggedFileShow: false,
2018-11-02 15:34:34 +08:00
};
}
2018-12-21 12:33:31 +08:00
onShowListRepoTag = () => {
this.setState({
isRepoTagDialogShow: true,
isListRepoTagShow: true,
isUpdateRepoTagShow: false,
isCreateRepoTagShow: false,
isListTaggedFileShow: false
});
}
onCloseRepoTagDialog = () => {
this.setState({
isRepoTagDialogShow: false,
isListRepoTagShow: false,
isUpdateRepoTagShow: false,
isCreateRepoTagShow: false,
isListTaggedFileShow: false
});
}
2018-11-02 15:34:34 +08:00
onCreateRepoTagToggle = () => {
this.setState({
isCreateRepoTagShow: !this.state.isCreateRepoTagShow,
isListRepoTagShow: !this.state.isListRepoTagShow,
});
}
onUpdateRepoTagToggle = (currentTag) => {
this.setState({
currentTag: currentTag,
isListRepoTagShow: !this.state.isListRepoTagShow,
isUpdateRepoTagShow: !this.state.isUpdateRepoTagShow,
});
}
2018-11-19 17:44:59 +08:00
onListTaggedFileToggle = (currentTag) => {
this.setState({
currentTag: currentTag,
isListRepoTagShow: !this.state.isListRepoTagShow,
isListTaggedFileShow: !this.state.isListTaggedFileShow,
});
}
2018-09-29 15:47:53 +08:00
isMarkdownFile(filePath) {
2018-11-22 11:26:00 +08:00
let name = Utils.getFileName(filePath);
2018-09-29 15:47:53 +08:00
return name.indexOf('.md') > -1 ? true : false;
}
2018-11-22 11:26:00 +08:00
2018-09-29 15:47:53 +08:00
render() {
2018-11-28 12:41:49 +08:00
let { repoID, repoName, permission, currentPath } = this.props;
let isFile = this.isMarkdownFile(currentPath);
let name = Utils.getFileName(currentPath);
let trashUrl = siteRoot + 'repo/' + repoID + '/trash/';
let historyUrl = siteRoot + 'repo/history/' + repoID + '/';
2019-05-29 18:44:38 +08:00
if (permission) {
if (!isFile) {
2019-05-29 18:44:38 +08:00
if (name) { // name not '' is not root path
trashUrl = siteRoot + 'repo/' + repoID + '/trash/?path=' + encodeURIComponent(currentPath);
2019-05-29 18:44:38 +08:00
return (
<ul className="path-toolbar">
<li className="toolbar-item"><a className="op-link sf2-icon-recycle" href={trashUrl} title={gettext('Trash')} aria-label={gettext('Trash')}></a></li>
</ul>
);
} else { // currentPath === '/' is root path
return (
<Fragment>
<ul className="path-toolbar">
<li className="toolbar-item"><a className="op-link sf2-icon-tag" onClick={this.onShowListRepoTag} title={gettext('Tags')} aria-label={gettext('Tags')}></a></li>
<li className="toolbar-item"><a className="op-link sf2-icon-recycle" href={trashUrl} title={gettext('Trash')} aria-label={gettext('Trash')}></a></li>
<li className="toolbar-item"><a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a></li>
</ul>
{this.state.isRepoTagDialogShow && (
<ModalPortal>
<Modal isOpen={true}>
{this.state.isListRepoTagShow && (
<ListTagDialog
repoID={repoID}
onListTagCancel={this.onCloseRepoTagDialog}
onCreateRepoTag={this.onCreateRepoTagToggle}
onUpdateRepoTag={this.onUpdateRepoTagToggle}
onListTaggedFiles={this.onListTaggedFileToggle}
/>
)}
{this.state.isCreateRepoTagShow && (
<CreateTagDialog
repoID={repoID}
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onCreateRepoTagToggle}
/>
)}
{this.state.isUpdateRepoTagShow && (
<UpdateTagDialog
repoID={repoID}
currentTag={this.state.currentTag}
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onUpdateRepoTagToggle}
onDeleteRepoTag={this.props.onDeleteRepoTag}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
)}
{this.state.isListTaggedFileShow && (
<ListTaggedFilesDialog
repoID={this.props.repoID}
currentTag={this.state.currentTag}
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onListTaggedFileToggle}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
)}
</Modal>
</ModalPortal>
)}
</Fragment>
);
}
}
2018-09-29 15:47:53 +08:00
}
return '';
}
2018-09-18 20:57:17 -05:00
}
DirTool.propTypes = propTypes;
2018-09-29 15:47:53 +08:00
export default DirTool;