1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

Wiki optimized third (#2406)

This commit is contained in:
shanshuirenjia
2018-09-29 15:47:53 +08:00
committed by Daniel Pan
parent 5cffd4cb69
commit 3ab4cbff4f
22 changed files with 612 additions and 107 deletions

View File

@@ -1,29 +1,51 @@
import React from 'react';
import { gettext, repoID, permission, siteRoot, initialFilePath } from '../constants';
import { gettext, repoID, slug, permission, siteRoot } from '../constants';
import { encodePath } from '../utils';
import PropTypes from 'prop-types';
function PathToolbar() {
const propTypes = {
filePath: PropTypes.string.isRequired
};
let trashUrl = '';
let historyUrl = '';
if (initialFilePath === '/' && permission) {
trashUrl = siteRoot + 'repo/recycle/' + repoID + '/?referer=' + encodeURIComponent(location.href);
historyUrl = siteRoot + 'repo/history/' + repoID + '/?referer=' + encodeURIComponent(location.href);
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 (permission) {
trashUrl = siteRoot + 'dir/recycle/' + repoID + '/?dir_path=' + encodeURIComponent(initialFilePath);
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>
);
class PathToolbar extends React.Component {
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 '';
}
return '';
}
PathToolbar.propTypes = propTypes;
export default PathToolbar;