2018-10-25 13:36:06 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2018-10-13 17:07:54 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2018-11-28 08:57:42 +08:00
|
|
|
import cookie from 'react-cookies';
|
2018-12-13 14:57:46 +08:00
|
|
|
import { gettext, repoID, siteRoot, permission } from '../../utils/constants';
|
2018-10-13 17:07:54 +08:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-11-14 10:55:11 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-18 17:21:01 +08:00
|
|
|
import RepoInfo from '../../models/repo-info';
|
2018-09-19 21:19:11 -05:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-11-28 08:57:42 +08: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 14:47:19 +08:00
|
|
|
import CurDirPath from '../../components/cur-dir-path';
|
2019-01-15 19:58:25 +08:00
|
|
|
import WikiMarkdownViewer from '../../components/wiki-markdown-viewer';
|
2018-10-13 17:07:54 +08:00
|
|
|
import DirentListView from '../../components/dirent-list-view/dirent-list-view';
|
2018-10-25 13:36:06 +08:00
|
|
|
import DirentDetail from '../../components/dirent-detail/dirent-details';
|
2018-11-14 10:55:11 +08:00
|
|
|
import FileUploader from '../../components/file-uploader/file-uploader';
|
2019-01-09 12:10:33 +08:00
|
|
|
import RepoInfoBar from '../../components/repo-info-bar';
|
2018-10-13 17:07:54 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
content: PropTypes.string,
|
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
permission: PropTypes.string,
|
2018-12-06 14:10:36 +08:00
|
|
|
hash: PropTypes.string,
|
2018-11-22 11:26:00 +08:00
|
|
|
path: PropTypes.string.isRequired,
|
2019-01-16 17:45:46 +08:00
|
|
|
repoEncrypted: PropTypes.bool.isRequired,
|
2018-11-22 11:26:00 +08:00
|
|
|
// whether the file or dir corresponding to the path exist
|
|
|
|
pathExist: PropTypes.bool.isRequired,
|
2018-10-13 17:07:54 +08:00
|
|
|
isFileLoading: PropTypes.bool.isRequired,
|
2018-11-22 11:26:00 +08:00
|
|
|
isViewFile: PropTypes.bool.isRequired,
|
|
|
|
isDirentListLoading: PropTypes.bool.isRequired,
|
2018-11-23 20:19:42 +08:00
|
|
|
isDirentSelected: PropTypes.bool.isRequired,
|
|
|
|
isAllDirentSelected: PropTypes.bool.isRequired,
|
2018-11-22 11:26:00 +08:00
|
|
|
direntList: PropTypes.array.isRequired,
|
2019-01-04 15:06:27 +08:00
|
|
|
sortBy: PropTypes.string.isRequired,
|
|
|
|
sortOrder: PropTypes.string.isRequired,
|
|
|
|
sortItems: PropTypes.func.isRequired,
|
2018-11-23 20:19:42 +08:00
|
|
|
selectedDirentList: PropTypes.array.isRequired,
|
2018-11-22 11:26:00 +08:00
|
|
|
updateDirent: PropTypes.func.isRequired,
|
|
|
|
onSideNavMenuClick: PropTypes.func.isRequired,
|
2018-10-13 17:07:54 +08:00
|
|
|
onSearchedClick: PropTypes.func.isRequired,
|
|
|
|
onMainNavBarClick: PropTypes.func.isRequired,
|
2018-11-22 11:26:00 +08:00
|
|
|
onItemClick: PropTypes.func.isRequired,
|
2018-11-23 20:19:42 +08:00
|
|
|
onAllDirentSelected: PropTypes.func.isRequired,
|
|
|
|
onItemSelected: PropTypes.func.isRequired,
|
2018-11-22 11:26:00 +08: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 20:19:42 +08:00
|
|
|
onItemsMove: PropTypes.func.isRequired,
|
|
|
|
onItemsCopy: PropTypes.func.isRequired,
|
|
|
|
onItemsDelete: PropTypes.func.isRequired,
|
2018-12-12 02:34:58 +00:00
|
|
|
onLinkClick: PropTypes.func.isRequired,
|
2019-01-05 11:43:33 +08:00
|
|
|
onFileUploadSuccess: PropTypes.func.isRequired,
|
2018-12-12 02:34:58 +00:00
|
|
|
isDraft: PropTypes.bool,
|
|
|
|
hasDraft: PropTypes.bool,
|
|
|
|
reviewStatus: PropTypes.any,
|
|
|
|
goReviewPage: PropTypes.func,
|
|
|
|
goDraftPage: PropTypes.func,
|
2018-12-16 12:45:26 +00:00
|
|
|
reviewID: PropTypes.any,
|
2019-01-02 16:45:40 +08:00
|
|
|
usedRepoTags: PropTypes.array.isRequired,
|
2019-01-09 12:10:33 +08:00
|
|
|
readmeMarkdown: PropTypes.object,
|
2018-10-16 18:19:51 +08:00
|
|
|
};
|
2018-09-12 10:32:31 +08:00
|
|
|
|
|
|
|
class MainPanel extends Component {
|
|
|
|
|
2018-09-18 20:57:17 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-11-28 08:57:42 +08:00
|
|
|
currentMode: 'wiki',
|
2018-10-25 13:36:06 +08:00
|
|
|
isDirentDetailShow: false,
|
|
|
|
currentDirent: null,
|
2018-11-23 20:19:42 +08:00
|
|
|
direntPath: '',
|
2018-12-18 17:21:01 +08:00
|
|
|
currentRepoInfo: null,
|
2018-11-01 18:40:18 +08:00
|
|
|
isRepoOwner: false,
|
2018-09-29 15:47:53 +08:00
|
|
|
};
|
2018-09-18 20:57:17 -05:00
|
|
|
}
|
|
|
|
|
2018-10-16 14:27:21 +08:00
|
|
|
componentDidMount() {
|
2018-11-01 18:40:18 +08:00
|
|
|
seafileAPI.getRepoInfo(repoID).then(res => {
|
2018-12-18 17:21:01 +08:00
|
|
|
let repoInfo = new RepoInfo(res.data);
|
2018-11-01 18:40:18 +08:00
|
|
|
seafileAPI.getAccountInfo().then(res => {
|
|
|
|
let user_email = res.data.email;
|
2018-12-18 17:21:01 +08:00
|
|
|
let isRepoOwner = repoInfo.owner_email === user_email;
|
2018-11-01 18:40:18 +08:00
|
|
|
this.setState({
|
2018-12-18 17:21:01 +08:00
|
|
|
currentRepoInfo: repoInfo,
|
2018-11-01 18:40:18 +08:00
|
|
|
isRepoOwner: isRepoOwner,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-12-06 14:10:36 +08:00
|
|
|
if (this.props.hash) {
|
|
|
|
let hash = this.props.hash;
|
|
|
|
setTimeout(function() {
|
|
|
|
window.location.hash = hash;
|
|
|
|
}, 500);
|
|
|
|
}
|
2018-10-16 14:27:21 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 08:57:42 +08:00
|
|
|
switchViewMode = (mode) => {
|
|
|
|
cookie.save('view_mode', mode, { path: '/' });
|
2018-12-20 14:36:07 +08:00
|
|
|
let repoName = this.state.currentRepoInfo.repo_name;
|
2018-11-28 08:57:42 +08:00
|
|
|
let dirPath = this.props.isViewFile ? Utils.getDirName(this.props.path) : this.props.path;
|
2018-12-20 14:36:07 +08:00
|
|
|
window.location.href = siteRoot + 'library/' + repoID + '/' + repoName + dirPath;
|
2018-09-12 10:32:31 +08:00
|
|
|
}
|
|
|
|
|
2018-11-22 11:26:00 +08:00
|
|
|
onSideNavMenuClick = () => {
|
|
|
|
this.props.onSideNavMenuClick();
|
|
|
|
}
|
|
|
|
|
2018-12-29 18:25:18 +08:00
|
|
|
onItemClick = (dirent) => {
|
|
|
|
this.setState({isDirentDetailShow: false});
|
|
|
|
this.props.onItemClick(dirent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 14:47:19 +08:00
|
|
|
onMainNavBarClick = (path) => {
|
2018-12-29 18:25:18 +08:00
|
|
|
this.setState({isDirentDetailShow: false});
|
2018-11-27 14:47:19 +08:00
|
|
|
this.props.onMainNavBarClick(path);
|
2018-11-22 11:26:00 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 17:55:14 +08:00
|
|
|
onItemDetails = (dirent) => {
|
2018-10-25 13:36:06 +08:00
|
|
|
this.setState({
|
|
|
|
currentDirent: dirent,
|
|
|
|
isDirentDetailShow: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemDetailsClose = () => {
|
|
|
|
this.setState({isDirentDetailShow: false});
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:26:00 +08:00
|
|
|
onFileTagChanged = (dirent, direntPath) => {
|
|
|
|
this.props.onFileTagChanged(dirent, direntPath);
|
2018-11-13 16:39:13 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 08:57:42 +08:00
|
|
|
onUploadFile = (e) => {
|
2018-11-14 10:55:11 +08:00
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
this.uploader.onFileUpload();
|
|
|
|
}
|
|
|
|
|
2018-11-28 08:57:42 +08:00
|
|
|
onUploadFolder = (e) => {
|
2018-11-14 10:55:11 +08:00
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
this.uploader.onFolderUpload();
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:43:33 +08:00
|
|
|
onFileUploadSuccess = (direntObject) => {
|
|
|
|
this.props.onFileUploadSuccess(direntObject);
|
2018-11-14 10:55:11 +08:00
|
|
|
}
|
|
|
|
|
2018-10-13 17:07:54 +08:00
|
|
|
render() {
|
2019-01-16 17:44:44 +08:00
|
|
|
|
2018-11-29 17:55:14 +08:00
|
|
|
const ErrMessage = (<div className="message empty-tip err-message"><h2>{gettext('Folder does not exist.')}</h2></div>);
|
|
|
|
|
2018-09-12 10:32:31 +08:00
|
|
|
return (
|
2018-09-25 09:13:06 +08:00
|
|
|
<div className="main-panel wiki-main-panel o-hidden">
|
2018-11-29 17:55:14 +08:00
|
|
|
<div className="main-panel-north">
|
2018-09-19 21:19:11 -05:00
|
|
|
<div className="cur-view-toolbar border-left-show">
|
2018-11-22 11:26:00 +08: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 20:19:42 +08:00
|
|
|
<div className="dir-operation">
|
2018-11-28 08:57:42 +08:00
|
|
|
{this.props.isDirentSelected ?
|
|
|
|
<MutipleDirOperationToolbar
|
2018-11-27 14:47:19 +08: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 08:57:42 +08:00
|
|
|
/> :
|
|
|
|
<DirOperationToolBar
|
|
|
|
path={this.props.path}
|
2018-11-28 12:41:49 +08:00
|
|
|
repoID={repoID}
|
2018-12-12 02:34:58 +00:00
|
|
|
isDraft={this.props.isDraft}
|
|
|
|
hasDraft={this.props.hasDraft}
|
2018-11-28 08:57:42 +08: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 14:47:19 +08:00
|
|
|
/>
|
2018-11-23 20:19:42 +08:00
|
|
|
}
|
2018-09-18 20:57:17 -05:00
|
|
|
</div>
|
2018-11-28 08:57:42 +08:00
|
|
|
<ViewModeToolbar currentMode={this.state.currentMode} switchViewMode={this.switchViewMode}/>
|
2018-09-12 10:32:31 +08:00
|
|
|
</div>
|
2018-12-21 16:16:45 +08:00
|
|
|
<CommonToolbar repoID={repoID} onSearchedClick={this.props.onSearchedClick} searchPlaceholder={gettext('Search files in this library')}/>
|
2018-09-12 10:32:31 +08:00
|
|
|
</div>
|
2018-12-12 15:34:54 +08:00
|
|
|
<div className="main-panel-center flex-row">
|
2018-10-25 13:36:06 +08:00
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path">
|
2018-12-18 17:21:01 +08:00
|
|
|
{this.state.currentRepoInfo && (
|
2018-12-13 14:57:46 +08:00
|
|
|
<CurDirPath
|
|
|
|
repoID={repoID}
|
2018-12-18 17:21:01 +08:00
|
|
|
repoName={this.state.currentRepoInfo.repo_name}
|
2018-12-13 14:57:46 +08:00
|
|
|
currentPath={this.props.path}
|
|
|
|
permission={permission}
|
|
|
|
onPathClick={this.onMainNavBarClick}
|
2018-12-14 04:19:24 +00:00
|
|
|
isViewFile={this.props.isViewFile}
|
2018-12-13 14:57:46 +08:00
|
|
|
/>
|
|
|
|
)}
|
2018-10-25 13:36:06 +08:00
|
|
|
</div>
|
2019-01-16 17:44:44 +08:00
|
|
|
<div className="cur-view-content">
|
2018-11-29 17:55:14 +08:00
|
|
|
{!this.props.pathExist ?
|
|
|
|
ErrMessage :
|
2018-11-14 10:55:11 +08:00
|
|
|
<Fragment>
|
2019-01-16 17:44:44 +08:00
|
|
|
{this.props.isViewFile ?
|
2019-01-15 19:58:25 +08:00
|
|
|
<WikiMarkdownViewer
|
|
|
|
isFileLoading={this.props.isFileLoading}
|
2018-11-22 11:26:00 +08:00
|
|
|
markdownContent={this.props.content}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
lastModified = {this.props.lastModified}
|
2018-12-12 02:34:58 +00:00
|
|
|
onLinkClick={this.props.onLinkClick}
|
2019-01-15 19:58:25 +08:00
|
|
|
>
|
|
|
|
<Fragment>
|
|
|
|
{this.props.reviewStatus === 'open' &&
|
|
|
|
<div className='seafile-btn-view-review text-center'>
|
|
|
|
<div className='tag tag-green'>
|
|
|
|
{gettext('This file is in review stage')}
|
|
|
|
<a className="ml-2" onMouseDown={this.props.goReviewPage}>{gettext('View Review')}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{(!this.props.isDraft && this.props.hasDraft && this.props.reviewStatus !== 'open') &&
|
|
|
|
<div className='seafile-btn-view-review text-center'>
|
|
|
|
<div className='tag tag-green'>
|
|
|
|
{gettext('This file is in draft stage.')}
|
|
|
|
<a className="ml-2" onMouseDown={this.props.goDraftPage}>{gettext('Edit Draft')}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
</WikiMarkdownViewer> :
|
2018-11-22 11:26:00 +08:00
|
|
|
<Fragment>
|
2019-01-09 12:10:33 +08:00
|
|
|
{this.props.path === '/' && !(this.props.usedRepoTags.length === 0 && this.props.readmeMarkdown === null) && (
|
|
|
|
<RepoInfoBar
|
|
|
|
repoID={repoID}
|
|
|
|
currentPath={this.props.path}
|
|
|
|
usedRepoTags={this.props.usedRepoTags}
|
|
|
|
readmeMarkdown={this.props.readmeMarkdown}
|
|
|
|
/>
|
2019-01-07 17:00:09 +08:00
|
|
|
)}
|
2018-11-22 11:26:00 +08:00
|
|
|
<DirentListView
|
|
|
|
path={this.props.path}
|
2018-11-28 12:41:49 +08:00
|
|
|
repoID={repoID}
|
2019-01-16 17:45:46 +08:00
|
|
|
repoEncrypted={this.props.repoEncrypted}
|
2018-11-28 12:41:49 +08:00
|
|
|
direntList={this.props.direntList}
|
2019-01-04 15:06:27 +08:00
|
|
|
sortBy={this.props.sortBy}
|
|
|
|
sortOrder={this.props.sortOrder}
|
|
|
|
sortItems={this.props.sortItems}
|
2019-01-04 17:15:15 +08:00
|
|
|
onAddFile={this.props.onAddFile}
|
2018-12-29 18:25:18 +08:00
|
|
|
onItemClick={this.onItemClick}
|
2018-11-22 11:26:00 +08:00
|
|
|
onItemDelete={this.props.onItemDelete}
|
|
|
|
onItemRename={this.props.onItemRename}
|
2018-11-27 14:47:19 +08:00
|
|
|
onItemMove={this.props.onItemMove}
|
|
|
|
onItemCopy={this.props.onItemCopy}
|
2018-11-22 11:26:00 +08:00
|
|
|
onItemDetails={this.onItemDetails}
|
|
|
|
isDirentListLoading={this.props.isDirentListLoading}
|
|
|
|
updateDirent={this.props.updateDirent}
|
2018-12-18 17:21:01 +08:00
|
|
|
currentRepoInfo={this.state.currentRepoInfo}
|
2018-11-22 11:26:00 +08:00
|
|
|
isRepoOwner={this.state.isRepoOwner}
|
2018-11-23 20:19:42 +08:00
|
|
|
isAllItemSelected={this.props.isAllDirentSelected}
|
|
|
|
onAllItemSelected={this.props.onAllDirentSelected}
|
|
|
|
onItemSelected={this.props.onItemSelected}
|
2018-11-22 11:26:00 +08:00
|
|
|
/>
|
|
|
|
<FileUploader
|
|
|
|
ref={uploader => this.uploader = uploader}
|
|
|
|
dragAndDrop={true}
|
|
|
|
path={this.props.path}
|
2018-11-28 12:41:49 +08:00
|
|
|
repoID={repoID}
|
2018-11-22 11:26:00 +08:00
|
|
|
direntList={this.props.direntList}
|
2019-01-05 11:43:33 +08:00
|
|
|
onFileUploadSuccess={this.onFileUploadSuccess}
|
2018-11-22 11:26:00 +08:00
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
}
|
2018-11-14 10:55:11 +08:00
|
|
|
</Fragment>
|
2018-10-13 17:07:54 +08:00
|
|
|
}
|
2018-09-12 10:32:31 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-11-29 17:55:14 +08:00
|
|
|
{this.state.isDirentDetailShow && (
|
2018-10-25 13:36:06 +08:00
|
|
|
<div className="cur-view-detail">
|
2018-11-22 11:26:00 +08:00
|
|
|
<DirentDetail
|
2018-11-28 12:41:49 +08:00
|
|
|
repoID={repoID}
|
2018-11-29 17:55:14 +08:00
|
|
|
path={this.props.path}
|
2018-10-25 13:36:06 +08:00
|
|
|
dirent={this.state.currentDirent}
|
2018-11-23 20:19:42 +08:00
|
|
|
direntPath={this.state.direntPath}
|
2018-10-25 13:36:06 +08:00
|
|
|
onItemDetailsClose={this.onItemDetailsClose}
|
2018-11-13 16:39:13 +08:00
|
|
|
onFileTagChanged={this.onFileTagChanged}
|
2018-09-21 14:16:15 +08:00
|
|
|
/>
|
2018-10-25 13:36:06 +08:00
|
|
|
</div>
|
2018-11-29 17:55:14 +08:00
|
|
|
)}
|
2018-09-12 10:32:31 +08:00
|
|
|
</div>
|
2018-09-29 18:32:53 +08:00
|
|
|
</div>
|
|
|
|
);
|
2018-09-12 10:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 17:07:54 +08:00
|
|
|
MainPanel.propTypes = propTypes;
|
|
|
|
|
2018-09-12 10:32:31 +08:00
|
|
|
export default MainPanel;
|