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.3 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';
2018-11-29 17:55:14 +08:00
import { gettext, repoID, slug, siteRoot } 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';
2018-09-04 18:38:59 +08:00
import TreeDirView from '../../components/tree-dir-view/tree-dir-view';
2018-08-06 18:29:12 +08:00
2019-01-11 12:41:30 +08:00
let loginUser = window.app.pageOptions.username;
2018-10-16 18:19:51 +08:00
const propTypes = {
content: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
permission: PropTypes.string,
filePath: PropTypes.string.isRequired,
isFileLoading: PropTypes.bool.isRequired,
isViewFileState: PropTypes.bool.isRequired,
changedNode: PropTypes.object,
onMenuClick: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
onMainNavBarClick: PropTypes.func.isRequired,
onMainNodeClick: PropTypes.func.isRequired,
onLinkClick: PropTypes.func.isRequired,
onDeleteNode: PropTypes.func.isRequired,
onRenameNode: PropTypes.func.isRequired,
};
2018-08-06 18:29:12 +08:00
class MainPanel extends Component {
2018-08-10 17:05:29 +08:00
2018-09-29 15:47:53 +08:00
constructor(props) {
super(props);
this.state = {
needOperationGroup: false
2018-09-29 15:47:53 +08:00
};
}
2018-08-06 18:29:12 +08:00
onMenuClick = () => {
this.props.onMenuClick();
}
onEditClick = (e) => {
// const w=window.open('about:blank')
e.preventDefault();
2018-11-29 17:55:14 +08:00
window.location.href= siteRoot + 'lib/' + repoID + '/file' + this.props.filePath + '?mode=edit';
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);
}
2018-12-12 11:52:50 +08:00
2018-08-06 18:29:12 +08:00
render() {
2018-09-04 18:38:59 +08:00
let filePathList = this.props.filePath.split('/');
let nodePath = '';
2018-09-04 18:38:59 +08:00
let pathElem = filePathList.map((item, index) => {
if (item === '') {
2018-08-06 18:29:12 +08:00
return;
2018-09-04 18:38:59 +08:00
}
if (index === (filePathList.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
}
});
return (
<div className="main-panel wiki-main-panel o-hidden">
2018-08-06 18:29:12 +08:00
<div className="main-panel-top panel-top">
2019-01-11 12:41:30 +08:00
{loginUser &&
<Fragment>
<div className="cur-view-toolbar border-left-show">
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title="Side Nav Menu" onClick={this.onMenuClick}></span>
{
this.props.permission === 'rw' &&
<button className="btn btn-secondary operation-item" title="Edit File" onClick={this.onEditClick}>{gettext('Edit Page')}</button>
}
</div>
<CommonToolbar
repoID={repoID}
onSearchedClick={this.props.onSearchedClick}
searchPlaceholder={gettext('Search files in this library')}
/>
</Fragment>
2019-01-11 12:41:30 +08:00
}
2018-08-06 18:29:12 +08:00
</div>
2018-09-21 14:16:15 +08:00
<div className="cur-view-container">
2018-08-06 18:29:12 +08:00
<div className="cur-view-path">
<div className="path-containter">
{loginUser &&
<Fragment>
<a href={siteRoot + 'wikis/'} className="normal">{gettext('Wikis')}</a>
<span className="path-split">/</span>
</Fragment>
}
2018-08-06 18:29:12 +08:00
<a href={siteRoot + 'wikis/' + slug} className="normal">{slug}</a>
{pathElem}
</div>
</div>
2018-09-21 14:16:15 +08:00
<div className="cur-view-content">
2019-01-15 19:58:25 +08:00
{this.props.isViewFileState &&
<WikiMarkdownViewer
2018-09-21 14:16:15 +08:00
markdownContent={this.props.content}
2019-01-15 19:58:25 +08:00
isFileLoading={this.props.isFileLoading}
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-15 19:58:25 +08:00
{!this.props.isViewFileState &&
<TreeDirView node={this.props.changedNode} onMainNodeClick={this.props.onMainNodeClick} />
2018-09-04 18:38:59 +08:00
}
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;