1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 08:28:11 +00:00
Files
seahub/frontend/src/components/cur-dir-path/dir-tool.js

162 lines
5.6 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,
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);
2018-09-29 15:47:53 +08:00
let trashUrl = siteRoot + 'repo/recycle/' + repoID + '/?referer=' + encodeURIComponent(location.href);
let historyUrl = siteRoot + 'repo/history/' + repoID + '/?referer=' + encodeURIComponent(location.href);
2018-11-28 12:41:49 +08:00
if ( (name === repoName || name === '') && !isFile && permission) {
2018-09-29 15:47:53 +08:00
return (
2018-11-02 15:34:34 +08:00
<Fragment>
<ul className="path-toolbar">
2018-12-21 12:33:31 +08:00
<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>
2018-11-02 15:34:34 +08:00
<li className="toolbar-item"><a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a></li>
</ul>
2018-12-21 12:33:31 +08:00
{this.state.isRepoTagDialogShow && (
2018-12-18 14:29:51 +08:00
<ModalPortal>
<Modal isOpen={true}>
{this.state.isListRepoTagShow && (
<ListTagDialog
repoID={repoID}
2018-12-21 12:33:31 +08:00
onListTagCancel={this.onCloseRepoTagDialog}
onCreateRepoTag={this.onCreateRepoTagToggle}
onUpdateRepoTag={this.onUpdateRepoTagToggle}
onListTaggedFiles={this.onListTaggedFileToggle}
/>
)}
{this.state.isCreateRepoTagShow && (
<CreateTagDialog
repoID={repoID}
2018-12-21 12:33:31 +08:00
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onCreateRepoTagToggle}
/>
)}
{this.state.isUpdateRepoTagShow && (
<UpdateTagDialog
repoID={repoID}
currentTag={this.state.currentTag}
2018-12-21 12:33:31 +08:00
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onUpdateRepoTagToggle}
/>
)}
{this.state.isListTaggedFileShow && (
<ListTaggedFilesDialog
repoID={this.props.repoID}
currentTag={this.state.currentTag}
2018-12-21 12:33:31 +08:00
onClose={this.onCloseRepoTagDialog}
toggleCancel={this.onListTaggedFileToggle}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
)}
</Modal>
2018-12-18 14:29:51 +08:00
</ModalPortal>
)}
2018-11-02 15:34:34 +08:00
</Fragment>
2018-09-29 15:47:53 +08:00
);
2018-11-22 11:26:00 +08:00
} else if (!isFile && permission) {
2018-09-29 15:47:53 +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>
2018-09-29 15:47:53 +08:00
</ul>
);
} else if (permission) {
2019-03-05 10:37:27 +08:00
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(currentPath);
2018-09-29 15:47:53 +08:00
return (
<ul className="path-toolbar">
<li className="toolbar-item"><a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a></li>
</ul>
);
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;