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';
|
2024-05-15 11:57:30 +08:00
|
|
|
import { gettext, repoID, siteRoot, username, isPro } from '../../utils/constants';
|
2023-12-26 14:35:44 +08:00
|
|
|
import SeafileMarkdownViewer from '../../components/seafile-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';
|
2019-07-08 16:47:04 +08:00
|
|
|
import Search from '../../components/search/search';
|
2019-12-31 16:58:45 +08:00
|
|
|
import Notification from '../../components/common/notification';
|
|
|
|
import Account from '../../components/common/account';
|
2023-12-28 15:00:26 +08:00
|
|
|
import SdocWikiPageViewer from '../../components/sdoc-wiki-page-viewer';
|
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();
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
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);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
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);
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
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 === '') {
|
2023-09-13 08:40:50 +08:00
|
|
|
return null;
|
2020-11-02 13:56:35 +08:00
|
|
|
}
|
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-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 (
|
2019-07-15 14:42:18 +08:00
|
|
|
<Fragment key={index} >
|
2018-09-18 20:57:17 -05:00
|
|
|
<span className="path-split">/</span>
|
2020-11-02 13:56:35 +08:00
|
|
|
<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-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;
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
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() {
|
2023-09-13 08:40:50 +08:00
|
|
|
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>);
|
2019-12-12 22:34:53 +08:00
|
|
|
const isViewingFile = this.props.pathExist && !this.props.isDataLoading && this.props.isViewFile;
|
2018-08-06 18:29:12 +08:00
|
|
|
return (
|
2024-05-15 11:57:30 +08:00
|
|
|
<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' : ''}`}>
|
2019-07-08 16:47:04 +08:00
|
|
|
{!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">
|
2020-03-06 18:24:53 +08:00
|
|
|
{isPro && (
|
2023-10-09 17:32:13 +08:00
|
|
|
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
|
2020-03-06 18:24:53 +08:00
|
|
|
)}
|
2019-07-08 16:47:04 +08:00
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
}
|
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-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> :
|
2024-06-28 08:39:44 +08:00
|
|
|
<span className="sf3-font sf3-font-rename mobile-toolbar-icon" title={gettext('Edit')} onClick={this.onEditClick}></span>
|
2019-08-22 20:23:08 +08:00
|
|
|
)}
|
2019-01-14 13:30:06 +08:00
|
|
|
</div>
|
2019-12-31 16:58:45 +08:00
|
|
|
<div className="common-toolbar">
|
2020-03-06 18:24:53 +08:00
|
|
|
{isPro && (
|
2023-10-09 17:32:13 +08:00
|
|
|
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
|
2020-03-06 18:24:53 +08:00
|
|
|
)}
|
|
|
|
<Notification />
|
2019-12-31 16:58:45 +08:00
|
|
|
<Account />
|
|
|
|
</div>
|
2019-01-14 13:30:06 +08:00
|
|
|
</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">
|
2019-12-12 22:34:53 +08:00
|
|
|
<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 />}
|
2023-12-28 15:00:26 +08:00
|
|
|
{isViewingFile && Utils.isMarkdownFile(this.props.path) && (
|
2023-12-26 14:35:44 +08:00
|
|
|
<SeafileMarkdownViewer
|
|
|
|
isWiki={true}
|
|
|
|
path={this.props.path}
|
|
|
|
repoID={repoID}
|
2024-11-01 10:37:16 +08:00
|
|
|
isTOCShow={false}
|
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-28 16:48:03 +08:00
|
|
|
)}
|
2023-12-28 15:00:26 +08:00
|
|
|
{isViewingFile && Utils.isSdocFile(this.props.path) && (
|
|
|
|
<SdocWikiPageViewer
|
|
|
|
isWiki={true}
|
|
|
|
path={this.props.path}
|
|
|
|
repoID={repoID}
|
|
|
|
markdownContent={this.props.content}
|
|
|
|
isFileLoading={this.props.isDataLoading}
|
|
|
|
lastModified = {this.props.lastModified}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
onLinkClick={this.props.onLinkClick}
|
|
|
|
/>
|
|
|
|
)}
|
2019-01-28 16:48:03 +08:00
|
|
|
{(!this.props.isDataLoading && !this.props.isViewFile) && (
|
|
|
|
<WikiDirListView
|
|
|
|
path={this.props.path}
|
|
|
|
direntList={this.props.direntList}
|
2020-11-02 13:56:35 +08:00
|
|
|
onDirentClick={this.props.onDirentClick}
|
2019-01-28 16:48:03 +08:00
|
|
|
/>
|
|
|
|
)}
|
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;
|