2018-09-18 20:57:17 -05:00
|
|
|
import React 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-09-18 20:57:17 -05:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
const propTypes = {
|
|
|
|
filePath: PropTypes.string.isRequired
|
|
|
|
};
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
class PathToolbar extends React.Component {
|
2018-09-18 20:57:17 -05:00
|
|
|
|
2018-09-29 15:47:53 +08:00
|
|
|
isMarkdownFile(filePath) {
|
|
|
|
let lastIndex = filePath.lastIndexOf('/');
|
|
|
|
let name = filePath.slice(lastIndex + 1);
|
|
|
|
return name.indexOf('.md') > -1 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let isFile = this.isMarkdownFile(this.props.filePath);
|
|
|
|
let index = this.props.filePath.lastIndexOf('/');
|
|
|
|
let name = this.props.filePath.slice(index + 1);
|
|
|
|
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 (
|
|
|
|
<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>
|
|
|
|
<li className="toolbar-item"><a className="op-link sf2-icon-history" href={historyUrl} title={gettext('History')} aria-label={gettext('History')}></a></li>
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
} else if ( !isFile && permission) {
|
|
|
|
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-10-09 10:56:59 +08:00
|
|
|
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + Utils.encodePath(this.props.filePath) + '&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-09-29 15:47:53 +08:00
|
|
|
PathToolbar.propTypes = propTypes;
|
|
|
|
|
2018-09-18 20:57:17 -05:00
|
|
|
export default PathToolbar;
|