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';
|
2018-10-09 10:56:59 +08:00
|
|
|
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';
|
2018-12-20 18:45:31 +08:00
|
|
|
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,
|
2019-02-27 14:14:28 +08:00
|
|
|
updateUsedRepoTags: PropTypes.func.isRequired,
|
2018-09-29 15:47:53 +08:00
|
|
|
};
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-11-27 14:47:19 +08: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;
|
2018-11-27 14:47:19 +08:00
|
|
|
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>
|
2019-02-26 10:37:14 +08:00
|
|
|
<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-20 18:45:31 +08:00
|
|
|
|
2018-12-21 12:33:31 +08:00
|
|
|
{this.state.isRepoTagDialogShow && (
|
2018-12-18 14:29:51 +08:00
|
|
|
<ModalPortal>
|
2018-12-20 18:45:31 +08:00
|
|
|
<Modal isOpen={true}>
|
|
|
|
{this.state.isListRepoTagShow && (
|
|
|
|
<ListTagDialog
|
|
|
|
repoID={repoID}
|
2018-12-21 12:33:31 +08:00
|
|
|
onListTagCancel={this.onCloseRepoTagDialog}
|
2018-12-20 18:45:31 +08:00
|
|
|
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}
|
2018-12-20 18:45:31 +08:00
|
|
|
toggleCancel={this.onCreateRepoTagToggle}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{this.state.isUpdateRepoTagShow && (
|
|
|
|
<UpdateTagDialog
|
|
|
|
repoID={repoID}
|
|
|
|
currentTag={this.state.currentTag}
|
2018-12-21 12:33:31 +08:00
|
|
|
onClose={this.onCloseRepoTagDialog}
|
2018-12-20 18:45:31 +08:00
|
|
|
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}
|
2018-12-20 18:45:31 +08:00
|
|
|
toggleCancel={this.onListTaggedFileToggle}
|
2019-02-27 14:14:28 +08:00
|
|
|
updateUsedRepoTags={this.props.updateUsedRepoTags}
|
2018-12-20 18:45:31 +08:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</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">
|
2019-02-26 10:37:14 +08:00
|
|
|
<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 18:32:53 +08:00
|
|
|
);
|
2018-09-29 15:47:53 +08:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2018-09-18 20:57:17 -05:00
|
|
|
}
|
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
DirTool.propTypes = propTypes;
|
2018-09-29 15:47:53 +08:00
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
export default DirTool;
|