2019-01-14 13:30:06 +08:00
|
|
|
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';
|
2018-09-19 21:19:11 -05:00
|
|
|
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';
|
2019-06-04 16:18:32 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
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) => {
|
2019-06-04 17:15:48 +08:00
|
|
|
let path = Utils.getEventData(e, 'path');
|
2019-06-04 16:18:32 +08:00
|
|
|
this.props.onMainNavBarClick(path);
|
2018-09-04 18:38:59 +08:00
|
|
|
}
|
|
|
|
|
2019-01-28 16:48:03 +08:00
|
|
|
renderNavPath = () => {
|
|
|
|
let paths = this.props.path.split('/');
|
2018-09-29 18:32:53 +08:00
|
|
|
let nodePath = '';
|
2019-01-28 16:48:03 +08:00
|
|
|
let pathElem = paths.map((item, index) => {
|
2018-09-29 18:32:53 +08:00
|
|
|
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-29 18:32:53 +08:00
|
|
|
);
|
2018-09-04 18:38:59 +08:00
|
|
|
} else {
|
2018-09-29 18:32:53 +08:00
|
|
|
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-09-29 18:32:53 +08:00
|
|
|
);
|
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 (
|
2018-09-25 09:13:06 +08:00
|
|
|
<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 && (
|
2019-01-14 13:30:06 +08:00
|
|
|
<Fragment>
|
2019-02-20 11:54:25 +08:00
|
|
|
<div className="cur-view-toolbar">
|
2019-01-14 13:30:06 +08:00
|
|
|
<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>
|
2019-01-14 13:30:06 +08:00
|
|
|
</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">
|
2019-04-24 08:40:23 +00:00
|
|
|
<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>
|
2018-09-29 18:32:53 +08:00
|
|
|
</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;
|