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

151 lines
5.5 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';
import { gettext, repoID, siteRoot, username, isPro } from '../../utils/constants';
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';
import Search from '../../components/search/search';
import Notification from '../../components/common/notification';
import Account from '../../components/common/account';
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();
};
2018-08-06 18:29:12 +08:00
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('/');
let nodePath = '';
2019-01-28 16:48:03 +08:00
let pathElem = paths.map((item, index) => {
if (item === '') {
return null;
}
2019-01-28 16:48:03 +08:00
if (index === (paths.length - 1)) {
2018-08-06 18:29:12 +08:00
return (
2019-07-23 15:53:25 +08:00
<Fragment key={index}>
<span className="path-split">/</span>
<span className="path-file-name">{item}</span>
</Fragment>
);
2018-09-04 18:38:59 +08:00
} else {
nodePath += '/' + item;
2018-09-04 18:38:59 +08:00
return (
2019-07-15 14:42:18 +08:00
<Fragment key={index} >
2018-09-18 20:57:17 -05:00
<span className="path-split">/</span>
<a
className="path-link"
data-path={nodePath}
2018-09-18 20:57:17 -05:00
onClick={this.onMainNavBarClick}>
{item}
</a>
2019-07-15 14:42:18 +08:00
</Fragment>
);
2018-08-06 18:29:12 +08:00
}
});
2019-01-28 16:48:03 +08:00
return pathElem;
};
2019-01-28 16:48:03 +08:00
2018-08-06 18:29:12 +08:00
2019-01-28 16:48:03 +08:00
render() {
let { onSearchedClick } = this.props;
2019-02-11 18:22:22 +08:00
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
const isViewingFile = this.props.pathExist && !this.props.isDataLoading && this.props.isViewFile;
2018-08-06 18:29:12 +08:00
return (
<div className="main-panel wiki-main-panel">
2021-04-09 16:21:33 +08:00
<div className="main-panel-hide hide">{this.props.content}</div>
2019-09-02 10:54:01 +08:00
<div className={`main-panel-north panel-top ${this.props.permission === 'rw' ? 'border-left-show' : ''}`}>
{!username &&
<Fragment>
<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>
</div>
<div className="common-toolbar">
{isPro && (
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
)}
</div>
</Fragment>
}
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-08-22 20:23:08 +08:00
{this.props.permission == 'rw' && (
Utils.isDesktop() ?
<button className="btn btn-secondary operation-item" title={gettext('Edit')} onClick={this.onEditClick}>{gettext('Edit')}</button> :
<span className="fa fa-pencil-alt mobile-toolbar-icon" title={gettext('Edit')} onClick={this.onEditClick} style={{'fontSize': '1.1rem'}}></span>
2019-08-22 20:23:08 +08:00
)}
</div>
<div className="common-toolbar">
{isPro && (
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
)}
<Notification />
<Account />
</div>
</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">
<div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}>
2019-01-29 11:03:43 +08:00
{!this.props.pathExist && errMessage}
{this.props.pathExist && this.props.isDataLoading && <Loading />}
{isViewingFile && (
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}
2019-06-20 14:40:11 +08:00
path={this.props.path}
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}
2019-01-28 16:48:03 +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;