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

107 lines
3.8 KiB
JavaScript
Raw Normal View History

2018-11-02 15:34:34 +08:00
import React, { Fragment } from 'react';
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 = {
currentPath: PropTypes.string.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 = {
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() {
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) {
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 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;