1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 14:21:23 +00:00
Files
seahub/frontend/src/pages/wiki/main-panel.js

136 lines
4.7 KiB
JavaScript
Raw Normal View History

import React, { Component, Fragment } from 'react';
2018-10-16 18:19:51 +08:00
import PropTypes from 'prop-types';
2019-05-29 11:48:00 +08:00
import MediaQuery from 'react-responsive';
2019-01-28 16:48:03 +08:00
import { gettext, repoID, slug, siteRoot, username } from '../../utils/constants';
import CommonToolbar from '../../components/toolbar/common-toolbar';
2019-01-15 19:58:25 +08:00
import WikiMarkdownViewer from '../../components/wiki-markdown-viewer';
2019-01-28 16:48:03 +08:00
import WikiDirListView from '../../components/wiki-dir-list-view/wiki-dir-list-view';
import Loading from '../../components/loading';
2018-08-06 18:29:12 +08:00
2018-10-16 18:19:51 +08:00
const propTypes = {
2019-01-28 16:48:03 +08:00
path: PropTypes.string.isRequired,
pathExist: PropTypes.bool.isRequired,
isViewFile: PropTypes.bool.isRequired,
isDataLoading: PropTypes.bool.isRequired,
2018-10-16 18:19:51 +08:00
content: PropTypes.string,
2019-01-28 16:48:03 +08:00
permission: PropTypes.string,
2018-10-16 18:19:51 +08:00
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
2019-01-28 16:48:03 +08:00
direntList: PropTypes.array.isRequired,
2018-10-16 18:19:51 +08:00
onMenuClick: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
onMainNavBarClick: PropTypes.func.isRequired,
2019-01-28 16:48:03 +08:00
onDirentClick: PropTypes.func.isRequired,
2018-10-16 18:19:51 +08:00
onLinkClick: PropTypes.func.isRequired,
};
2018-08-06 18:29:12 +08:00
class MainPanel extends Component {
2018-08-10 17:05:29 +08:00
2018-08-06 18:29:12 +08:00
onMenuClick = () => {
this.props.onMenuClick();
}
onEditClick = (e) => {
e.preventDefault();
2019-01-29 11:03:43 +08:00
let url = siteRoot + 'lib/' + repoID + '/file' + this.props.path + '?mode=edit';
window.open(url);
2018-08-06 18:29:12 +08:00
}
2018-09-04 18:38:59 +08:00
onMainNavBarClick = (e) => {
this.props.onMainNavBarClick(e.target.dataset.path);
}
2019-01-28 16:48:03 +08:00
renderNavPath = () => {
let paths = this.props.path.split('/');
let nodePath = '';
2019-01-28 16:48:03 +08:00
let pathElem = paths.map((item, index) => {
if (item === '') {
2018-08-06 18:29:12 +08:00
return;
2018-09-04 18:38:59 +08:00
}
2019-01-28 16:48:03 +08:00
if (index === (paths.length - 1)) {
2018-08-06 18:29:12 +08:00
return (
<span key={index}><span className="path-split">/</span>{item}</span>
);
2018-09-04 18:38:59 +08:00
} else {
nodePath += '/' + item;
2018-09-04 18:38:59 +08:00
return (
2018-09-18 20:57:17 -05:00
<span key={index} >
<span className="path-split">/</span>
<a
className="path-link"
data-path={nodePath}
onClick={this.onMainNavBarClick}>
{item}
</a>
</span>
);
2018-08-06 18:29:12 +08:00
}
});
2019-01-28 16:48:03 +08:00
return pathElem;
}
2018-08-06 18:29:12 +08:00
2019-01-28 16:48:03 +08:00
render() {
2019-02-11 18:22:22 +08:00
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
2018-08-06 18:29:12 +08:00
return (
<div className="main-panel wiki-main-panel o-hidden">
2019-02-20 11:54:25 +08:00
<div className="main-panel-north panel-top border-left-show">
2019-01-28 16:48:03 +08:00
{username && (
<Fragment>
2019-02-20 11:54:25 +08:00
<div className="cur-view-toolbar">
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title="Side Nav Menu" onClick={this.onMenuClick}></span>
2019-05-29 11:48:00 +08:00
<MediaQuery query="(min-width: 768px)">
{this.props.permission === 'rw' &&
<button className="btn btn-secondary operation-item" title="Edit" onClick={this.onEditClick}>{gettext('Edit')}</button>}
</MediaQuery>
<MediaQuery query="(max-width: 767.8px)">
{this.props.permission === 'rw' &&
<button className="btn btn-secondary operation-item my-1" title="Edit" onClick={this.onEditClick}>{gettext('Edit')}</button>}
</MediaQuery>
</div>
<CommonToolbar
repoID={repoID}
onSearchedClick={this.props.onSearchedClick}
searchPlaceholder={gettext('Search files in this library')}
/>
</Fragment>
2019-01-28 16:48:03 +08:00
)}
2018-08-06 18:29:12 +08:00
</div>
2019-02-20 11:54:25 +08:00
<div className="main-panel-center">
2018-08-06 18:29:12 +08:00
<div className="cur-view-path">
<div className="path-containter">
<a href={siteRoot + 'published/' + slug} className="normal">{slug}</a>
2019-01-28 16:48:03 +08:00
{this.renderNavPath()}
2018-08-06 18:29:12 +08:00
</div>
</div>
2018-09-21 14:16:15 +08:00
<div className="cur-view-content">
2019-01-29 11:03:43 +08:00
{!this.props.pathExist && errMessage}
{this.props.pathExist && this.props.isDataLoading && <Loading />}
{(this.props.pathExist && !this.props.isDataLoading && this.props.isViewFile) && (
2019-01-15 19:58:25 +08:00
<WikiMarkdownViewer
2018-09-21 14:16:15 +08:00
markdownContent={this.props.content}
2019-01-28 16:48:03 +08:00
isFileLoading={this.props.isDataLoading}
2018-09-21 14:16:15 +08:00
lastModified = {this.props.lastModified}
2019-01-15 19:58:25 +08:00
latestContributor={this.props.latestContributor}
2018-09-21 14:16:15 +08:00
onLinkClick={this.props.onLinkClick}
2019-01-24 15:41:01 +08:00
isWiki={true}
2018-09-21 14:16:15 +08:00
/>
2019-01-28 16:48:03 +08:00
)}
{(!this.props.isDataLoading && !this.props.isViewFile) && (
<WikiDirListView
path={this.props.path}
direntList={this.props.direntList}
onDirentClick={this.props.onDirentClick}
/>
)}
2018-08-06 18:29:12 +08:00
</div>
</div>
</div>
);
2018-08-06 18:29:12 +08:00
}
}
2018-10-16 18:19:51 +08:00
MainPanel.propTypes = propTypes;
2018-08-06 18:29:12 +08:00
export default MainPanel;