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-10-09 02:56:59 +00:00
|
|
|
import { gettext, repoID, serviceUrl, slug, siteRoot } from '../../utils/constants';
|
2018-10-13 09:07:54 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-11-01 10:40:18 +00:00
|
|
|
import Repo from '../../models/repo';
|
2018-10-16 06:27:21 +00:00
|
|
|
import Dirent from '../../models/dirent';
|
2018-09-20 02:19:11 +00:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-09-19 01:57:17 +00:00
|
|
|
import PathToolbar from '../../components/toolbar/path-toolbar';
|
2018-09-12 02:32:31 +00:00
|
|
|
import MarkdownViewer 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-10-16 06:27:21 +00:00
|
|
|
import CreateFolder from '../../components/dialog/create-folder-dialog';
|
|
|
|
import CreateFile from '../../components/dialog/create-file-dialog';
|
2018-10-13 09:07:54 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
content: PropTypes.string,
|
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
permission: PropTypes.string,
|
|
|
|
filePath: PropTypes.string.isRequired,
|
|
|
|
isFileLoading: PropTypes.bool.isRequired,
|
|
|
|
isViewFileState: PropTypes.bool.isRequired,
|
2018-10-16 10:19:51 +00:00
|
|
|
changedNode: PropTypes.object,
|
2018-10-13 09:07:54 +00:00
|
|
|
onMenuClick: PropTypes.func.isRequired,
|
|
|
|
onSearchedClick: PropTypes.func.isRequired,
|
|
|
|
onMainNavBarClick: PropTypes.func.isRequired,
|
2018-10-16 10:19:51 +00:00
|
|
|
onLinkClick: PropTypes.func.isRequired,
|
2018-10-13 09:07:54 +00:00
|
|
|
onMainItemClick: PropTypes.func.isRequired,
|
|
|
|
onMainItemDelete: PropTypes.func.isRequired,
|
2018-10-25 05:36:06 +00:00
|
|
|
onMainItemRename: PropTypes.func.isRequired,
|
|
|
|
onMainItemMove: PropTypes.func.isRequired,
|
|
|
|
onMainItemCopy: PropTypes.func.isRequired,
|
2018-10-16 10:19:51 +00:00
|
|
|
onMainAddFile: PropTypes.func.isRequired,
|
|
|
|
onMainAddFolder: PropTypes.func.isRequired,
|
|
|
|
switchViewMode: PropTypes.func.isRequired,
|
|
|
|
};
|
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-09-29 07:47:53 +00:00
|
|
|
isWikiMode: true,
|
2018-10-16 06:27:21 +00:00
|
|
|
direntList: [],
|
|
|
|
newMenuShow: false,
|
|
|
|
uploadMenuShow: false,
|
|
|
|
showFileDialog: false,
|
|
|
|
showFolderDialog: false,
|
|
|
|
createFileType: '',
|
2018-10-25 05:36:06 +00:00
|
|
|
isDirentDetailShow: false,
|
|
|
|
currentDirent: null,
|
|
|
|
currentFilePath: '',
|
|
|
|
isDirentListLoading: true,
|
2018-11-01 10:40:18 +00:00
|
|
|
currentRepo: null,
|
|
|
|
isRepoOwner: false,
|
2018-09-29 07:47:53 +00:00
|
|
|
};
|
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-10-16 06:27:21 +00:00
|
|
|
document.addEventListener('click', this.hideOperationMenu);
|
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
let node = nextProps.changedNode;
|
|
|
|
if (node && node.isDir()) {
|
|
|
|
let path = node.path;
|
|
|
|
this.updateViewList(path);
|
|
|
|
}
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 06:27:21 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('click', this.hideOperationMenu);
|
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
updateViewList = (filePath) => {
|
2018-10-25 05:36:06 +00:00
|
|
|
this.setState({isDirentListLoading: true});
|
|
|
|
seafileAPI.listDir(repoID, filePath).then(res => {
|
2018-10-13 09:07:54 +00:00
|
|
|
let direntList = [];
|
|
|
|
res.data.forEach(item => {
|
|
|
|
let dirent = new Dirent(item);
|
|
|
|
direntList.push(dirent);
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
direntList: direntList,
|
2018-10-25 05:36:06 +00:00
|
|
|
isDirentListLoading: false,
|
2018-10-13 09:07:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onMenuClick = () => {
|
|
|
|
this.props.onMenuClick();
|
2018-09-12 02:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMainNavBarClick = (e) => {
|
|
|
|
this.props.onMainNavBarClick(e.target.dataset.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
switchViewMode = (e) => {
|
2018-09-29 10:32:53 +00:00
|
|
|
e.preventDefault();
|
2018-09-19 01:57:17 +00:00
|
|
|
if (e.target.id === 'wiki') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({isWikiMode: false});
|
2018-09-12 02:32:31 +00:00
|
|
|
this.props.switchViewMode(e.target.id);
|
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
onEditClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location.href= serviceUrl + '/lib/' + repoID + '/file' + this.props.filePath + '?mode=edit';
|
|
|
|
}
|
2018-09-12 02:32:31 +00:00
|
|
|
|
2018-10-16 06:27:21 +00:00
|
|
|
onUploadClick = (e) => {
|
|
|
|
this.toggleOperationMenu(e);
|
|
|
|
this.setState({
|
|
|
|
newMenuShow: false,
|
|
|
|
uploadMenuShow: !this.state.uploadMenuShow,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onNewClick = (e) => {
|
|
|
|
this.toggleOperationMenu(e);
|
|
|
|
this.setState({
|
|
|
|
newMenuShow: !this.state.newMenuShow,
|
|
|
|
uploadMenuShow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onShareClick = () => {
|
|
|
|
alert('share btn clicked');
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleOperationMenu = (e) => {
|
|
|
|
e.nativeEvent.stopImmediatePropagation();
|
|
|
|
let targetRect = e.target.getClientRects()[0];
|
|
|
|
let left = targetRect.x;
|
|
|
|
let top = targetRect.y + targetRect.height;
|
|
|
|
let style = {position: 'fixed', display: 'block', left: left, top: top};
|
|
|
|
this.setState({operationMenuStyle: style});
|
|
|
|
}
|
|
|
|
|
|
|
|
hideOperationMenu = () => {
|
|
|
|
this.setState({
|
|
|
|
uploadMenuShow: false,
|
|
|
|
newMenuShow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addFolder = () => {
|
|
|
|
this.setState({showFolderDialog: !this.showFolderDialog});
|
|
|
|
}
|
|
|
|
|
|
|
|
addFile = () => {
|
|
|
|
this.setState({
|
|
|
|
showFileDialog: !this.showFileDialog,
|
|
|
|
createFileType: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addMarkdownFile = () => {
|
|
|
|
this.setState({
|
|
|
|
showFileDialog: !this.showFileDialog,
|
|
|
|
createFileType: '.md',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addFolderCancel = () => {
|
|
|
|
this.setState({showFolderDialog: !this.state.showFolderDialog});
|
|
|
|
}
|
|
|
|
|
|
|
|
addFileCancel = () => {
|
|
|
|
this.setState({showFileDialog: !this.state.showFileDialog});
|
|
|
|
}
|
|
|
|
|
2018-10-24 06:37:41 +00:00
|
|
|
onMainAddFile = (filePath, isDraft) => {
|
2018-10-16 06:27:21 +00:00
|
|
|
this.setState({showFileDialog: !this.state.showFileDialog});
|
2018-10-24 06:37:41 +00:00
|
|
|
this.props.onMainAddFile(filePath, isDraft);
|
2018-10-16 06:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMainAddFolder = (dirPath) => {
|
|
|
|
this.setState({showFolderDialog: !this.state.showFolderDialog});
|
|
|
|
this.props.onMainAddFolder(dirPath);
|
|
|
|
}
|
|
|
|
|
2018-10-25 05:36:06 +00:00
|
|
|
onItemDetails = (dirent, direntPath) => {
|
|
|
|
this.setState({
|
|
|
|
currentDirent: dirent,
|
|
|
|
currentFilePath: direntPath,
|
|
|
|
isDirentDetailShow: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemDetailsClose = () => {
|
|
|
|
this.setState({isDirentDetailShow: false});
|
|
|
|
}
|
|
|
|
|
2018-11-13 08:39:13 +00:00
|
|
|
onFileTagChanged = () => {
|
|
|
|
this.updateViewList(this.props.filePath);
|
|
|
|
}
|
|
|
|
|
2018-10-13 09:07:54 +00:00
|
|
|
render() {
|
2018-09-12 02:32:31 +00:00
|
|
|
let filePathList = this.props.filePath.split('/');
|
2018-09-29 10:32:53 +00:00
|
|
|
let nodePath = '';
|
2018-09-12 02:32:31 +00:00
|
|
|
let pathElem = filePathList.map((item, index) => {
|
2018-09-29 10:32:53 +00:00
|
|
|
if (item === '') {
|
2018-09-12 02:32:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (index === (filePathList.length - 1)) {
|
|
|
|
return (
|
|
|
|
<span key={index}><span className="path-split">/</span>{item}</span>
|
2018-09-29 10:32:53 +00:00
|
|
|
);
|
2018-09-12 02:32:31 +00:00
|
|
|
} else {
|
2018-09-29 10:32:53 +00:00
|
|
|
nodePath += '/' + item;
|
2018-09-12 02:32:31 +00:00
|
|
|
return (
|
2018-09-19 01:57:17 +00:00
|
|
|
<span key={index} >
|
|
|
|
<span className="path-split">/</span>
|
|
|
|
<a
|
|
|
|
className="path-link"
|
|
|
|
data-path={nodePath}
|
|
|
|
onClick={this.onMainNavBarClick}>
|
|
|
|
{item}
|
|
|
|
</a>
|
|
|
|
</span>
|
2018-09-29 10:32:53 +00:00
|
|
|
);
|
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-09-12 02:32:31 +00:00
|
|
|
<div className="main-panel-top panel-top">
|
2018-09-20 02:19:11 +00:00
|
|
|
<div className="cur-view-toolbar border-left-show">
|
2018-09-25 01:13:06 +00:00
|
|
|
<span className="sf2-icon-menu hidden-md-up d-md-none side-nav-toggle" title={gettext('Side Nav Menu')} onClick={this.onMenuClick}></span>
|
2018-10-16 06:27:21 +00:00
|
|
|
<div className="file-operation">
|
|
|
|
<div className="operation">
|
2018-10-25 05:36:06 +00:00
|
|
|
{
|
2018-10-16 06:27:21 +00:00
|
|
|
this.props.permission === 'rw' &&
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Edit File')} onClick={this.onEditClick}>{gettext('Edit')}</button>
|
|
|
|
}
|
2018-10-25 05:36:06 +00:00
|
|
|
{
|
|
|
|
!this.props.isViewFileState &&
|
|
|
|
<Fragment>
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Edit File')} onClick={this.onUploadClick}>{gettext('Upload')}</button>
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Edit File')} onClick={this.onNewClick}>{gettext('New')}</button>
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Edit File')} onClick={this.onShareClick}>{gettext('Share')}</button>
|
|
|
|
</Fragment>
|
|
|
|
}
|
2018-10-16 06:27:21 +00:00
|
|
|
</div>
|
|
|
|
{
|
|
|
|
this.state.uploadMenuShow &&
|
|
|
|
<ul className="menu dropdown-menu" style={this.state.operationMenuStyle}>
|
|
|
|
<li className="dropdown-item">{gettext('Upload Files')}</li>
|
|
|
|
<li className="dropdown-item">{gettext('Upload Folder')}</li>
|
|
|
|
</ul>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.newMenuShow &&
|
|
|
|
<ul className="menu dropdown-menu" style={this.state.operationMenuStyle}>
|
2018-10-16 10:19:51 +00:00
|
|
|
<li className="dropdown-item" onClick={this.addFolder}>{gettext('New Folder')}</li>
|
|
|
|
<li className="dropdown-item" onClick={this.addFile}>{gettext('New File')}</li>
|
2018-10-25 05:36:06 +00:00
|
|
|
<li className="dropdown-divider"></li>
|
2018-10-16 10:19:51 +00:00
|
|
|
<li className="dropdown-item" onClick={this.addMarkdownFile}>{gettext('New Markdown File')}</li>
|
2018-10-16 06:27:21 +00:00
|
|
|
</ul>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div className="view-mode btn-group">
|
|
|
|
<button className="btn btn-secondary btn-icon sf-view-mode-btn sf2-icon-list-view" id='list' title={gettext('List')} onClick={this.switchViewMode}></button>
|
|
|
|
<button className="btn btn-secondary btn-icon sf-view-mode-btn sf2-icon-grid-view" id='grid' title={gettext('Grid')} onClick={this.switchViewMode}></button>
|
|
|
|
<button className={`btn btn-secondary btn-icon sf-view-mode-btn sf2-icon-two-columns ${this.state.isWikiMode ? 'current-mode' : ''}`} id='wiki' title={gettext('wiki')} onClick={this.switchViewMode}></button>
|
2018-09-19 01:57:17 +00:00
|
|
|
</div>
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-09-25 01:13:06 +00:00
|
|
|
<CommonToolbar onSearchedClick={this.props.onSearchedClick} searchPlaceholder={'Search files in this library'}/>
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-10-25 05:36:06 +00:00
|
|
|
<div className="main-panel-center flex-direction-row">
|
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<div className="path-containter">
|
|
|
|
<a href={siteRoot + '#common/'} className="normal">{gettext('Libraries')}</a>
|
|
|
|
<span className="path-split">/</span>
|
|
|
|
{this.props.filePath === '/' ?
|
|
|
|
<span>{slug}</span> :
|
|
|
|
<a className="path-link" data-path="/" onClick={this.onMainNavBarClick}>{slug}</a>
|
|
|
|
}
|
|
|
|
{pathElem}
|
|
|
|
</div>
|
|
|
|
<PathToolbar filePath={this.props.filePath}/>
|
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
|
|
|
{ this.props.isViewFileState ?
|
|
|
|
<MarkdownViewer
|
|
|
|
markdownContent={this.props.content}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
lastModified = {this.props.lastModified}
|
|
|
|
onLinkClick={this.props.onLinkClick}
|
|
|
|
isFileLoading={this.props.isFileLoading}
|
|
|
|
/> :
|
|
|
|
<DirentListView
|
|
|
|
direntList={this.state.direntList}
|
|
|
|
filePath={this.props.filePath}
|
|
|
|
onItemClick={this.props.onMainItemClick}
|
|
|
|
onItemDelete={this.props.onMainItemDelete}
|
|
|
|
onItemRename={this.props.onMainItemRename}
|
|
|
|
onItemMove={this.props.onMainItemMove}
|
|
|
|
onItemCopy={this.props.onMainItemCopy}
|
|
|
|
onItemDetails={this.onItemDetails}
|
|
|
|
updateViewList={this.updateViewList}
|
|
|
|
isDirentListLoading={this.state.isDirentListLoading}
|
2018-11-01 10:40:18 +00:00
|
|
|
currentRepo={this.state.currentRepo}
|
|
|
|
isRepoOwner={this.state.isRepoOwner}
|
2018-10-25 05:36:06 +00:00
|
|
|
/>
|
2018-10-13 09:07:54 +00:00
|
|
|
}
|
2018-09-12 02:32:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-10-25 05:36:06 +00:00
|
|
|
{ this.state.isDirentDetailShow &&
|
|
|
|
<div className="cur-view-detail">
|
|
|
|
<DirentDetail
|
|
|
|
dirent={this.state.currentDirent}
|
|
|
|
direntPath={this.state.currentFilePath}
|
|
|
|
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-09-12 02:32:31 +00:00
|
|
|
</div>
|
2018-10-16 06:27:21 +00:00
|
|
|
{this.state.showFileDialog &&
|
|
|
|
<CreateFile
|
|
|
|
fileType={this.state.createFileType}
|
|
|
|
parentPath={this.props.filePath}
|
|
|
|
addFileCancel={this.addFileCancel}
|
|
|
|
onAddFile={this.onMainAddFile}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{this.state.showFolderDialog &&
|
|
|
|
<CreateFolder
|
|
|
|
parentPath={this.props.filePath}
|
|
|
|
addFolderCancel={this.addFolderCancel}
|
|
|
|
onAddFolder={this.onMainAddFolder}
|
|
|
|
/>
|
|
|
|
}
|
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;
|