2018-10-25 05:36:06 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2018-10-13 09:07:54 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-11-28 00:57:42 +00:00
|
|
|
import cookie from 'react-cookies';
|
2018-12-13 06:57:46 +00:00
|
|
|
import { gettext, repoID, siteRoot, permission } from '../../utils/constants';
|
2018-10-13 09:07:54 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-11-14 02:55:11 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-11-01 10:40:18 +00:00
|
|
|
import Repo from '../../models/repo';
|
2018-09-20 02:19:11 +00:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-11-28 00:57:42 +00:00
|
|
|
import ViewModeToolbar from '../../components/toolbar/view-mode-toolbar';
|
|
|
|
import DirOperationToolBar from '../../components/toolbar/dir-operation-toolbar';
|
|
|
|
import MutipleDirOperationToolbar from '../../components/toolbar/mutilple-dir-operation-toolbar';
|
2018-11-27 06:47:19 +00:00
|
|
|
import CurDirPath from '../../components/cur-dir-path';
|
2018-12-06 02:04:32 +00:00
|
|
|
import MarkdownContentViewer from '../../components/markdown-viewer';
|
2018-10-13 09:07:54 +00:00
|
|
|
import DirentListView from '../../components/dirent-list-view/dirent-list-view';
|
2018-10-25 05:36:06 +00:00
|
|
|
import DirentDetail from '../../components/dirent-detail/dirent-details';
|
2018-11-14 02:55:11 +00:00
|
|
|
import FileUploader from '../../components/file-uploader/file-uploader';
|
2018-10-13 09:07:54 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
content: PropTypes.string,
|
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
permission: PropTypes.string,
|
2018-12-06 06:10:36 +00:00
|
|
|
hash: PropTypes.string,
|
2018-11-22 03:26:00 +00:00
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
// whether the file or dir corresponding to the path exist
|
|
|
|
pathExist: PropTypes.bool.isRequired,
|
2018-10-13 09:07:54 +00:00
|
|
|
isFileLoading: PropTypes.bool.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
isViewFile: PropTypes.bool.isRequired,
|
|
|
|
isDirentListLoading: PropTypes.bool.isRequired,
|
2018-11-23 12:19:42 +00:00
|
|
|
isDirentSelected: PropTypes.bool.isRequired,
|
|
|
|
isAllDirentSelected: PropTypes.bool.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
direntList: PropTypes.array.isRequired,
|
2018-11-23 12:19:42 +00:00
|
|
|
selectedDirentList: PropTypes.array.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
updateDirent: PropTypes.func.isRequired,
|
|
|
|
onSideNavMenuClick: PropTypes.func.isRequired,
|
2018-10-13 09:07:54 +00:00
|
|
|
onSearchedClick: PropTypes.func.isRequired,
|
|
|
|
onMainNavBarClick: PropTypes.func.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
onItemClick: PropTypes.func.isRequired,
|
2018-11-23 12:19:42 +00:00
|
|
|
onAllDirentSelected: PropTypes.func.isRequired,
|
|
|
|
onItemSelected: PropTypes.func.isRequired,
|
2018-11-22 03:26:00 +00:00
|
|
|
onItemDelete: PropTypes.func.isRequired,
|
|
|
|
onItemRename: PropTypes.func.isRequired,
|
|
|
|
onItemMove: PropTypes.func.isRequired,
|
|
|
|
onItemCopy: PropTypes.func.isRequired,
|
|
|
|
onAddFile: PropTypes.func.isRequired,
|
|
|
|
onAddFolder: PropTypes.func.isRequired,
|
|
|
|
onFileTagChanged: PropTypes.func.isRequired,
|
2018-11-23 12:19:42 +00:00
|
|
|
onItemsMove: PropTypes.func.isRequired,
|
|
|
|
onItemsCopy: PropTypes.func.isRequired,
|
|
|
|
onItemsDelete: PropTypes.func.isRequired,
|
2018-10-16 10:19:51 +00:00
|
|
|
};
|
2018-09-12 02:32:31 +00:00
|
|
|
|
|
|
|
class MainPanel extends Component {
|
|
|
|
|
2018-09-19 01:57:17 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-11-28 00:57:42 +00:00
|
|
|
currentMode: 'wiki',
|
2018-10-25 05:36:06 +00:00
|
|
|
isDirentDetailShow: false,
|
|
|
|
currentDirent: null,
|
2018-11-23 12:19:42 +00:00
|
|
|
direntPath: '',
|
2018-11-01 10:40:18 +00:00
|
|
|
currentRepo: null,
|
|
|
|
isRepoOwner: false,
|
2018-12-06 02:04:32 +00:00
|
|
|
activeTitleIndex: -1,
|
2018-09-29 07:47:53 +00:00
|
|
|
};
|
2018-12-06 02:04:32 +00:00
|
|
|
this.titlesInfo = null;
|
|
|
|
this.pageScroll = false;
|
2018-09-19 01:57:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 06:27:21 +00:00
|
|
|
componentDidMount() {
|
2018-11-01 10:40:18 +00:00
|
|
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
|
|
|
let repo = new Repo(res.data);
|
|
|
|
seafileAPI.getAccountInfo().then(res => {
|
|
|
|
let user_email = res.data.email;
|
|
|
|
let isRepoOwner = repo.owner_email === user_email;
|
|
|
|
this.setState({
|
|
|
|
currentRepo: repo,
|
|
|
|
isRepoOwner: isRepoOwner,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-12-06 06:10:36 +00:00
|
|
|
if (this.props.hash) {
|
|
|
|
let hash = this.props.hash;
|
|
|
|
setTimeout(function() {
|
|
|
|
window.location.hash = hash;
|
|
|
|
}, 500);
|
|
|
|
}
|
2018-10-16 06:27:21 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
switchViewMode = (mode) => {
|
|
|
|
cookie.save('view_mode', mode, { path: '/' });
|
|
|
|
let dirPath = this.props.isViewFile ? Utils.getDirName(this.props.path) : this.props.path;
|
2018-11-29 09:55:14 +00:00
|
|
|
window.location.href = siteRoot + '#common/lib/' + repoID + dirPath;
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 03:26:00 +00:00
|
|
|
onSideNavMenuClick = () => {
|
|
|
|
this.props.onSideNavMenuClick();
|
|
|
|
}
|
|
|
|
|
2018-11-27 06:47:19 +00:00
|
|
|
onMainNavBarClick = (path) => {
|
|
|
|
this.props.onMainNavBarClick(path);
|
2018-11-22 03:26:00 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 09:55:14 +00:00
|
|
|
onItemDetails = (dirent) => {
|
2018-10-25 05:36:06 +00:00
|
|
|
this.setState({
|
|
|
|
currentDirent: dirent,
|
|
|
|
isDirentDetailShow: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemDetailsClose = () => {
|
|
|
|
this.setState({isDirentDetailShow: false});
|
|
|
|
}
|
|
|
|
|
2018-11-22 03:26:00 +00:00
|
|
|
onFileTagChanged = (dirent, direntPath) => {
|
|
|
|
this.props.onFileTagChanged(dirent, direntPath);
|
2018-11-13 08:39:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
onUploadFile = (e) => {
|
2018-11-14 02:55:11 +00:00
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
this.uploader.onFileUpload();
|
|
|
|
}
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
onUploadFolder = (e) => {
|
2018-11-14 02:55:11 +00:00
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
this.uploader.onFolderUpload();
|
|
|
|
}
|
|
|
|
|
2018-11-29 09:55:14 +00:00
|
|
|
onFileUploadSuccess = (file) => {
|
2018-11-28 00:57:42 +00:00
|
|
|
// todo
|
2018-11-14 02:55:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 10:24:20 +00:00
|
|
|
handlePageScroll = () => {
|
|
|
|
if (this.props.pathExist && this.props.isViewFile && !this.pageScroll && this.titlesInfo && this.titlesInfo.length > 0) {
|
2018-12-06 02:04:32 +00:00
|
|
|
this.pageScroll = true;
|
|
|
|
let that = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
that.pageScroll = false;
|
|
|
|
}, 100);
|
|
|
|
const contentScrollTop = this.refs.curViewContent.scrollTop + 180;
|
|
|
|
let activeTitleIndex;
|
|
|
|
if (contentScrollTop <= this.titlesInfo[0]) {
|
|
|
|
activeTitleIndex = 0;
|
|
|
|
}
|
|
|
|
else if (contentScrollTop > this.titlesInfo[this.titlesInfo.length - 1]) {
|
|
|
|
activeTitleIndex = this.titlesInfo.length - 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (let i = 0; i < this.titlesInfo.length - 1; i++) {
|
|
|
|
if (contentScrollTop > this.titlesInfo[i] && this.titlesInfo[i + 1] &&
|
|
|
|
contentScrollTop < this.titlesInfo[i + 1]) {
|
|
|
|
activeTitleIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
activeTitleIndex: activeTitleIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 10:24:20 +00:00
|
|
|
onContentRendered = (markdownViewer) => {
|
|
|
|
this.titlesInfo = markdownViewer.titlesInfo;
|
2018-12-06 02:04:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
render() {
|
2018-11-29 09:55:14 +00:00
|
|
|
const ErrMessage = (<div className="message empty-tip err-message"><h2>{gettext('Folder does not exist.')}</h2></div>);
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
return (
|
2018-09-25 01:13:06 +00:00
|
|
|
<div className="main-panel wiki-main-panel o-hidden">
|
2018-11-29 09:55:14 +00:00
|
|
|
<div className="main-panel-north">
|
2018-09-20 02:19:11 +00:00
|
|
|
<div className="cur-view-toolbar border-left-show">
|
2018-11-22 03:26:00 +00:00
|
|
|
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title={gettext('Side Nav Menu')} onClick={this.onSideNavMenuClick}></span>
|
2018-11-23 12:19:42 +00:00
|
|
|
<div className="dir-operation">
|
2018-11-28 00:57:42 +00:00
|
|
|
{this.props.isDirentSelected ?
|
|
|
|
<MutipleDirOperationToolbar
|
2018-11-27 06:47:19 +00:00
|
|
|
repoID={repoID}
|
|
|
|
path={this.props.path}
|
|
|
|
selectedDirentList={this.props.selectedDirentList}
|
|
|
|
onItemsMove={this.props.onItemsMove}
|
|
|
|
onItemsCopy={this.props.onItemsCopy}
|
|
|
|
onItemsDelete={this.props.onItemsDelete}
|
2018-11-28 00:57:42 +00:00
|
|
|
/> :
|
|
|
|
<DirOperationToolBar
|
|
|
|
path={this.props.path}
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={repoID}
|
2018-11-28 00:57:42 +00:00
|
|
|
permission={this.props.permission}
|
|
|
|
isViewFile={this.props.isViewFile}
|
|
|
|
onAddFile={this.props.onAddFile}
|
|
|
|
onAddFolder={this.props.onAddFolder}
|
|
|
|
onUploadFile={this.onUploadFile}
|
|
|
|
onUploadFolder={this.onUploadFolder}
|
2018-11-27 06:47:19 +00:00
|
|
|
/>
|
2018-11-23 12:19:42 +00:00
|
|
|
}
|
2018-09-19 01:57:17 +00:00
|
|
|
</div>
|
2018-11-28 00:57:42 +00:00
|
|
|
<ViewModeToolbar currentMode={this.state.currentMode} switchViewMode={this.switchViewMode}/>
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-11-28 04:41:49 +00:00
|
|
|
<CommonToolbar repoID={repoID} onSearchedClick={this.props.onSearchedClick} searchPlaceholder={'Search files in this library'}/>
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-12-12 07:34:54 +00:00
|
|
|
<div className="main-panel-center flex-row">
|
2018-10-25 05:36:06 +00:00
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path">
|
2018-12-13 06:57:46 +00:00
|
|
|
{this.state.currentRepo && (
|
|
|
|
<CurDirPath
|
|
|
|
repoID={repoID}
|
|
|
|
repoName={this.state.currentRepo.repo_name}
|
|
|
|
currentPath={this.props.path}
|
|
|
|
permission={permission}
|
|
|
|
onPathClick={this.onMainNavBarClick}
|
2018-12-14 04:19:24 +00:00
|
|
|
isViewFile={this.props.isViewFile}
|
2018-12-13 06:57:46 +00:00
|
|
|
/>
|
|
|
|
)}
|
2018-10-25 05:36:06 +00:00
|
|
|
</div>
|
2018-12-06 02:04:32 +00:00
|
|
|
<div className="cur-view-content" onScroll={this.handlePageScroll} ref="curViewContent">
|
2018-11-29 09:55:14 +00:00
|
|
|
{!this.props.pathExist ?
|
|
|
|
ErrMessage :
|
2018-11-14 02:55:11 +00:00
|
|
|
<Fragment>
|
2018-11-22 03:26:00 +00:00
|
|
|
{ this.props.isViewFile ?
|
2018-12-06 02:04:32 +00:00
|
|
|
<MarkdownContentViewer
|
2018-11-22 03:26:00 +00:00
|
|
|
markdownContent={this.props.content}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
lastModified = {this.props.lastModified}
|
|
|
|
isFileLoading={this.props.isFileLoading}
|
2018-12-06 02:04:32 +00:00
|
|
|
activeTitleIndex={this.state.activeTitleIndex}
|
2018-12-07 10:24:20 +00:00
|
|
|
onContentRendered={this.onContentRendered}
|
2018-11-22 03:26:00 +00:00
|
|
|
/> :
|
|
|
|
<Fragment>
|
|
|
|
<DirentListView
|
|
|
|
path={this.props.path}
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={repoID}
|
|
|
|
direntList={this.props.direntList}
|
2018-11-22 03:26:00 +00:00
|
|
|
onItemClick={this.props.onItemClick}
|
|
|
|
onItemDelete={this.props.onItemDelete}
|
|
|
|
onItemRename={this.props.onItemRename}
|
2018-11-27 06:47:19 +00:00
|
|
|
onItemMove={this.props.onItemMove}
|
|
|
|
onItemCopy={this.props.onItemCopy}
|
2018-11-22 03:26:00 +00:00
|
|
|
onItemDetails={this.onItemDetails}
|
|
|
|
isDirentListLoading={this.props.isDirentListLoading}
|
|
|
|
updateDirent={this.props.updateDirent}
|
|
|
|
currentRepo={this.state.currentRepo}
|
|
|
|
isRepoOwner={this.state.isRepoOwner}
|
2018-11-23 12:19:42 +00:00
|
|
|
isAllItemSelected={this.props.isAllDirentSelected}
|
|
|
|
onAllItemSelected={this.props.onAllDirentSelected}
|
|
|
|
onItemSelected={this.props.onItemSelected}
|
2018-11-22 03:26:00 +00:00
|
|
|
/>
|
|
|
|
<FileUploader
|
|
|
|
ref={uploader => this.uploader = uploader}
|
|
|
|
dragAndDrop={true}
|
|
|
|
path={this.props.path}
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={repoID}
|
2018-11-29 09:55:14 +00:00
|
|
|
onFileUploadSuccess={this.onFileUploadSuccess}
|
2018-11-22 03:26:00 +00:00
|
|
|
direntList={this.props.direntList}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
}
|
2018-11-14 02:55:11 +00:00
|
|
|
</Fragment>
|
2018-10-13 09:07:54 +00:00
|
|
|
}
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-11-29 09:55:14 +00:00
|
|
|
{this.state.isDirentDetailShow && (
|
2018-10-25 05:36:06 +00:00
|
|
|
<div className="cur-view-detail">
|
2018-11-22 03:26:00 +00:00
|
|
|
<DirentDetail
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={repoID}
|
2018-11-29 09:55:14 +00:00
|
|
|
path={this.props.path}
|
2018-10-25 05:36:06 +00:00
|
|
|
dirent={this.state.currentDirent}
|
2018-11-23 12:19:42 +00:00
|
|
|
direntPath={this.state.direntPath}
|
2018-10-25 05:36:06 +00:00
|
|
|
onItemDetailsClose={this.onItemDetailsClose}
|
2018-11-13 08:39:13 +00:00
|
|
|
onFileTagChanged={this.onFileTagChanged}
|
2018-09-21 06:16:15 +00:00
|
|
|
/>
|
2018-10-25 05:36:06 +00:00
|
|
|
</div>
|
2018-11-29 09:55:14 +00:00
|
|
|
)}
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-09-29 10:32:53 +00:00
|
|
|
</div>
|
|
|
|
);
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
MainPanel.propTypes = propTypes;
|
|
|
|
|
2018-09-12 02:32:31 +00:00
|
|
|
export default MainPanel;
|