2018-11-02 15:34:34 +08:00
|
|
|
import React, { Fragment } from 'react';
|
2018-10-09 10:56:59 +08:00
|
|
|
import { gettext, repoID, slug, permission, siteRoot } from '../../utils/constants';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2018-09-29 15:47:53 +08:00
|
|
|
import PropTypes from 'prop-types';
|
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-09-18 20:57:17 -05:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
const propTypes = {
|
2018-11-27 14:47:19 +08:00
|
|
|
currentPath: PropTypes.string.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 = {
|
|
|
|
currentTag: null,
|
|
|
|
isListRepoTagShow: false,
|
|
|
|
isUpdateRepoTagShow: false,
|
|
|
|
isCreateRepoTagShow: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onListRepoTagToggle = () => {
|
|
|
|
this.setState({isListRepoTagShow: !this.state.isListRepoTagShow});
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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-27 14:47:19 +08:00
|
|
|
let { 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);
|
|
|
|
if ( (name === slug || name === '') && !isFile && permission) {
|
|
|
|
return (
|
2018-11-02 15:34:34 +08:00
|
|
|
<Fragment>
|
|
|
|
<ul className="path-toolbar">
|
2018-11-13 16:39:13 +08:00
|
|
|
<li className="toolbar-item"><a className="op-link sf2-icon-tag" onClick={this.onListRepoTagToggle} title={gettext('Tags')} aria-label={gettext('Tags')}></a></li>
|
2018-11-02 15:34:34 +08:00
|
|
|
<li className="toolbar-item"><a className="op-link sf2-icon-trash" 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>
|
|
|
|
{
|
2018-11-22 11:26:00 +08:00
|
|
|
this.state.isListRepoTagShow &&
|
|
|
|
<ListTagDialog
|
2018-11-02 15:34:34 +08:00
|
|
|
onListTagCancel={this.onListRepoTagToggle}
|
|
|
|
onCreateRepoTag={this.onCreateRepoTagToggle}
|
|
|
|
onUpdateRepoTag={this.onUpdateRepoTagToggle}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.isCreateRepoTagShow &&
|
2018-11-22 11:26:00 +08:00
|
|
|
<CreateTagDialog
|
2018-11-02 15:34:34 +08:00
|
|
|
toggleCancel={this.onCreateRepoTagToggle}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.isUpdateRepoTagShow &&
|
2018-11-22 11:26:00 +08:00
|
|
|
<UpdateTagDialog
|
|
|
|
currentTag={this.state.currentTag}
|
2018-11-02 15:34:34 +08:00
|
|
|
toggleCancel={this.onUpdateRepoTagToggle}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</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-trash" href={trashUrl} title={gettext('Trash')} aria-label={gettext('Trash')}></a></li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
} else if (permission) {
|
2018-11-27 14:47:19 +08:00
|
|
|
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(currentPath) + '&referer=' + encodeURIComponent(location.href);
|
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;
|