2024-05-15 11:57:30 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-05-21 10:13:54 +08:00
|
|
|
import { SdocWikiViewer } from '@seafile/sdoc-editor';
|
2024-05-15 14:57:18 +08:00
|
|
|
import { gettext, repoID, siteRoot, username, isEditWiki } from '../../utils/constants';
|
2024-05-15 11:57:30 +08:00
|
|
|
import SeafileMarkdownViewer from '../../components/seafile-markdown-viewer';
|
|
|
|
import Loading from '../../components/loading';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2024-05-15 14:57:18 +08:00
|
|
|
// import Search from '../../components/search/search';
|
2024-05-15 11:57:30 +08:00
|
|
|
import Notification from '../../components/common/notification';
|
|
|
|
import Account from '../../components/common/account';
|
2024-05-21 10:13:54 +08:00
|
|
|
|
|
|
|
import './wiki.css';
|
2024-05-15 11:57:30 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
pathExist: PropTypes.bool.isRequired,
|
|
|
|
isViewFile: PropTypes.bool.isRequired,
|
|
|
|
isDataLoading: PropTypes.bool.isRequired,
|
|
|
|
content: PropTypes.string,
|
|
|
|
permission: PropTypes.string,
|
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
onMenuClick: PropTypes.func.isRequired,
|
|
|
|
onSearchedClick: PropTypes.func.isRequired,
|
|
|
|
onMainNavBarClick: PropTypes.func.isRequired,
|
|
|
|
onLinkClick: PropTypes.func.isRequired,
|
2024-05-17 15:09:41 +08:00
|
|
|
can_edit_file: PropTypes.bool,
|
|
|
|
seadoc_access_token: PropTypes.string,
|
2024-05-17 16:46:12 +08:00
|
|
|
assets_url: PropTypes.string,
|
2024-05-15 11:57:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MainPanel extends Component {
|
|
|
|
|
2024-05-17 15:09:41 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
docUuid: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-15 11:57:30 +08:00
|
|
|
onMenuClick = () => {
|
|
|
|
this.props.onMenuClick();
|
|
|
|
};
|
|
|
|
|
|
|
|
onEditClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let url = siteRoot + 'lib/' + repoID + '/file' + this.props.path + '?mode=edit';
|
|
|
|
window.open(url);
|
|
|
|
};
|
|
|
|
|
|
|
|
onMainNavBarClick = (e) => {
|
|
|
|
let path = Utils.getEventData(e, 'path');
|
|
|
|
this.props.onMainNavBarClick(path);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderNavPath = () => {
|
|
|
|
let paths = this.props.path.split('/');
|
|
|
|
let nodePath = '';
|
|
|
|
let pathElem = paths.map((item, index) => {
|
|
|
|
if (item === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (index === (paths.length - 1)) {
|
|
|
|
return (
|
|
|
|
<Fragment key={index}>
|
|
|
|
<span className="path-split">/</span>
|
|
|
|
<span className="path-file-name">{item}</span>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
nodePath += '/' + item;
|
|
|
|
return (
|
|
|
|
<Fragment key={index} >
|
|
|
|
<span className="path-split">/</span>
|
|
|
|
<a
|
|
|
|
className="path-link"
|
|
|
|
data-path={nodePath}
|
|
|
|
onClick={this.onMainNavBarClick}>
|
|
|
|
{item}
|
|
|
|
</a>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return pathElem;
|
|
|
|
};
|
|
|
|
|
2024-05-17 15:09:41 +08:00
|
|
|
static getDerivedStateFromProps(props, state) {
|
|
|
|
const { can_edit_file, seadoc_access_token } = props;
|
|
|
|
const config = window.app.config;
|
|
|
|
const pageOptions = window.app.pageOptions;
|
|
|
|
const { assetsUrl, seadocServerUrl: sdocServer, } = window.wiki.config;
|
|
|
|
window.seafile = {
|
|
|
|
...window.seafile, // need docUuid
|
|
|
|
...config,
|
|
|
|
...pageOptions,
|
|
|
|
sdocServer,
|
2024-05-17 16:46:12 +08:00
|
|
|
assetsUrl: assetsUrl || props.assets_url,
|
2024-05-17 15:09:41 +08:00
|
|
|
can_edit_file,
|
|
|
|
accessToken: seadoc_access_token,
|
|
|
|
serviceUrl: config.serviceURL,
|
2024-05-17 16:46:12 +08:00
|
|
|
assets_url: config.assetsUrl,
|
2024-05-17 15:09:41 +08:00
|
|
|
};
|
|
|
|
return { ...props, docUuid: window.seafile.docUuid };
|
|
|
|
}
|
2024-05-15 11:57:30 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
|
|
|
|
const isViewingFile = this.props.pathExist && !this.props.isDataLoading && this.props.isViewFile;
|
2024-05-21 14:05:25 +08:00
|
|
|
const { content, permission } = this.props;
|
2024-05-17 15:09:41 +08:00
|
|
|
const editorContent = content && JSON.parse(content);
|
2024-05-21 14:05:25 +08:00
|
|
|
const isReadOnly = permission.indexOf('w') === -1 || !window.seafile.can_edit_file;
|
2024-05-15 11:57:30 +08:00
|
|
|
return (
|
2024-05-17 15:09:41 +08:00
|
|
|
<div className="main-panel wiki-main-panel" style={{ flex: isEditWiki ? '1 0 76%' : '1 0 80%' }}>
|
2024-05-15 11:57:30 +08:00
|
|
|
<div className="main-panel-hide hide">{this.props.content}</div>
|
|
|
|
<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>
|
2024-05-17 15:09:41 +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>
|
|
|
|
)}
|
2024-05-15 11:57:30 +08:00
|
|
|
</div>
|
|
|
|
<div className="common-toolbar">
|
2024-05-15 14:57:18 +08:00
|
|
|
{/* {isPro && (
|
2024-05-15 11:57:30 +08:00
|
|
|
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
|
2024-05-15 14:57:18 +08:00
|
|
|
)} */}
|
2024-05-15 11:57:30 +08:00
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
{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">
|
2024-05-15 14:57:18 +08:00
|
|
|
{/* {isPro && (
|
2024-05-15 11:57:30 +08:00
|
|
|
<Search isPublic={true} repoID={repoID} onSearchedClick={onSearchedClick} placeholder={gettext('Search files')}/>
|
2024-05-15 14:57:18 +08:00
|
|
|
)} */}
|
2024-05-15 11:57:30 +08:00
|
|
|
<Notification />
|
|
|
|
<Account />
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}>
|
|
|
|
{!this.props.pathExist && errMessage}
|
|
|
|
{this.props.pathExist && this.props.isDataLoading && <Loading />}
|
2024-05-17 16:46:12 +08:00
|
|
|
{/* {isViewingFile && Utils.isMarkdownFile(this.props.path) && (
|
2024-05-15 11:57:30 +08:00
|
|
|
<SeafileMarkdownViewer
|
|
|
|
isWiki={true}
|
|
|
|
path={this.props.path}
|
|
|
|
repoID={repoID}
|
2024-05-17 15:09:41 +08:00
|
|
|
markdownContent={content}
|
2024-05-15 11:57:30 +08:00
|
|
|
isFileLoading={this.props.isDataLoading}
|
2024-05-17 15:09:41 +08:00
|
|
|
lastModified={this.props.lastModified}
|
2024-05-15 11:57:30 +08:00
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
onLinkClick={this.props.onLinkClick}
|
|
|
|
/>
|
2024-05-17 16:46:12 +08:00
|
|
|
)} */}
|
|
|
|
{isViewingFile && Utils.isSdocFile(this.props.path) && (
|
2024-05-21 10:13:54 +08:00
|
|
|
<SdocWikiViewer
|
2024-05-17 15:09:41 +08:00
|
|
|
document={editorContent}
|
|
|
|
showOutline={false}
|
|
|
|
showToolbar={false}
|
|
|
|
docUuid={this.state.docUuid}
|
2024-05-21 14:05:25 +08:00
|
|
|
wikiReadOnly={isReadOnly}
|
2024-05-15 11:57:30 +08:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MainPanel.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default MainPanel;
|