1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 17:02:47 +00:00
Files
seahub/frontend/src/components/toolbar/path-toolbar.js

52 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-09-18 20:57:17 -05:00
import React from 'react';
2018-09-29 15:47:53 +08:00
import { gettext, repoID, slug, permission, siteRoot } from '../constants';
import { encodePath } from '../utils';
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) {
historyUrl = siteRoot + 'repo/file_revisions/' + repoID + '/?p=' + encodePath(this.props.filePath) + '&referer=' + encodeURIComponent(location.href);
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>
)
}
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;