2018-11-28 00:57:42 +00:00
|
|
|
import React, { Fragment } from 'react';
|
2018-11-27 06:47:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-11-28 00:57:42 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2019-02-20 03:54:25 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
2018-11-28 00:57:42 +00:00
|
|
|
import ModalPortal from '../modal-portal';
|
|
|
|
import CreateFolder from '../../components/dialog/create-folder-dialog';
|
|
|
|
import CreateFile from '../../components/dialog/create-file-dialog';
|
2018-12-06 03:28:16 +00:00
|
|
|
import ShareDialog from '../../components/dialog/share-dialog';
|
2018-11-27 06:47:19 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
2018-11-28 00:57:42 +00:00
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
2019-02-21 09:37:04 +00:00
|
|
|
repoName: PropTypes.string.isRequired,
|
|
|
|
repoEncrypted: PropTypes.bool.isRequired,
|
|
|
|
enableDirPrivateShare: PropTypes.bool.isRequired,
|
|
|
|
userPerm: PropTypes.string.isRequired,
|
|
|
|
isGroupOwnedRepo: PropTypes.bool.isRequired,
|
2019-01-24 02:02:18 +00:00
|
|
|
showShareBtn: PropTypes.bool.isRequired,
|
2018-11-28 00:57:42 +00:00
|
|
|
onAddFile: PropTypes.func.isRequired,
|
|
|
|
onAddFolder: PropTypes.func.isRequired,
|
|
|
|
onUploadFile: PropTypes.func.isRequired,
|
|
|
|
onUploadFolder: PropTypes.func.isRequired,
|
2019-01-25 07:44:04 +00:00
|
|
|
direntList: PropTypes.array.isRequired,
|
2018-11-27 06:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DirOperationToolbar extends React.Component {
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
fileType: '.md',
|
|
|
|
isCreateFileDialogShow: false,
|
|
|
|
isCreateFolderDialogShow: false,
|
|
|
|
isUploadMenuShow: false,
|
|
|
|
isCreateMenuShow: false,
|
2018-12-06 03:28:16 +00:00
|
|
|
isShareDialogShow: false,
|
2018-11-28 00:57:42 +00:00
|
|
|
operationMenuStyle: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('click', this.hideOperationMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('click', this.hideOperationMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
hideOperationMenu = () => {
|
|
|
|
this.setState({
|
|
|
|
isUploadMenuShow: false,
|
|
|
|
isCreateMenuShow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
|
|
|
onUploadClick = (e) => {
|
|
|
|
this.toggleOperationMenu(e);
|
|
|
|
this.setState({
|
|
|
|
isUploadMenuShow: true,
|
|
|
|
isCreateMenuShow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-25 02:46:49 +00:00
|
|
|
onUploadFile = (e) => {
|
|
|
|
this.setState({isUploadMenuShow: false});
|
|
|
|
this.props.onUploadFile(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
onUploadFolder = (e) => {
|
|
|
|
this.setState({isUploadMenuShow: false});
|
|
|
|
this.props.onUploadFolder(e);
|
|
|
|
}
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
onCreateClick = (e) => {
|
|
|
|
this.toggleOperationMenu(e);
|
|
|
|
this.setState({
|
|
|
|
isCreateMenuShow: true,
|
|
|
|
isUploadMenuShow: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onShareClick = (e) => {
|
2018-12-06 03:28:16 +00:00
|
|
|
e.nativeEvent.stopImmediatePropagation(); //for document event
|
|
|
|
this.setState({
|
|
|
|
isShareDialogShow: !this.state.isShareDialogShow
|
|
|
|
});
|
2018-11-28 00:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onCreateFolderToggle = () => {
|
|
|
|
this.setState({isCreateFolderDialogShow: !this.state.isCreateFolderDialogShow});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreateFileToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
|
|
|
fileType: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreateMarkdownToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
|
|
|
fileType: '.md'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-19 04:14:55 +00:00
|
|
|
onCreateExcelToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
|
|
|
fileType: '.xlsx'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreatePPTToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
|
|
|
fileType: '.pptx'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreateWordToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
|
|
|
fileType: '.docx'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-28 00:57:42 +00:00
|
|
|
onAddFile = (filePath, isDraft) => {
|
|
|
|
this.setState({isCreateFileDialogShow: false});
|
|
|
|
this.props.onAddFile(filePath, isDraft);
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddFolder = (dirPath) => {
|
|
|
|
this.setState({isCreateFolderDialogShow: false});
|
|
|
|
this.props.onAddFolder(dirPath);
|
|
|
|
}
|
|
|
|
|
2019-01-25 07:44:04 +00:00
|
|
|
checkDuplicatedName = (newName) => {
|
|
|
|
let direntList = this.props.direntList;
|
|
|
|
let isDuplicated = direntList.some(object => {
|
|
|
|
return object.name === newName;
|
|
|
|
});
|
|
|
|
return isDuplicated;
|
|
|
|
}
|
|
|
|
|
2018-12-17 13:38:55 +00:00
|
|
|
render() {
|
2019-03-07 09:31:52 +00:00
|
|
|
let { path, repoName, userPerm } = this.props;
|
|
|
|
|
|
|
|
if (userPerm !== 'rw' && userPerm !== 'admin') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-02-27 05:53:36 +00:00
|
|
|
let itemType = path === '/' ? 'library' : 'dir';
|
2019-02-20 03:54:25 +00:00
|
|
|
let itemName = path == '/' ? repoName : Utils.getFolderName(path);
|
2018-11-27 06:47:19 +00:00
|
|
|
return (
|
2018-11-28 00:57:42 +00:00
|
|
|
<Fragment>
|
|
|
|
<div className="operation">
|
2019-02-20 03:54:25 +00:00
|
|
|
{Utils.isSupportUploadFolder() ?
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Upload')} onClick={this.onUploadClick}>{gettext('Upload')}</button> :
|
2019-04-02 09:38:08 +00:00
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Upload')} onClick={this.onUploadFile}>{gettext('Upload')}</button>
|
2019-02-20 03:54:25 +00:00
|
|
|
}
|
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('New')} onClick={this.onCreateClick}>{gettext('New')}</button>
|
2019-01-24 02:02:18 +00:00
|
|
|
{this.props.showShareBtn &&
|
2018-12-16 12:45:26 +00:00
|
|
|
<button className="btn btn-secondary operation-item" title={gettext('Share')} onClick={this.onShareClick}>{gettext('Share')}</button>
|
2019-01-24 02:02:18 +00:00
|
|
|
}
|
2018-11-28 00:57:42 +00:00
|
|
|
</div>
|
|
|
|
{this.state.isUploadMenuShow && (
|
|
|
|
<ul className="menu dropdown-menu" style={this.state.operationMenuStyle}>
|
2019-01-28 08:35:45 +00:00
|
|
|
<li className="dropdown-item" onClick={this.onUploadFile}>{gettext('Upload Files')}</li>
|
|
|
|
<li className="dropdown-item" onClick={this.onUploadFolder}>{gettext('Upload Folder')}</li>
|
2018-11-28 00:57:42 +00:00
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
{this.state.isCreateMenuShow && (
|
|
|
|
<ul className="menu dropdown-menu" style={this.state.operationMenuStyle}>
|
|
|
|
<li className="dropdown-item" onClick={this.onCreateFolderToggle}>{gettext('New Folder')}</li>
|
|
|
|
<li className="dropdown-item" onClick={this.onCreateFileToggle}>{gettext('New File')}</li>
|
|
|
|
<li className="dropdown-divider"></li>
|
|
|
|
<li className="dropdown-item" onClick={this.onCreateMarkdownToggle}>{gettext('New Markdown File')}</li>
|
2018-12-19 04:14:55 +00:00
|
|
|
<li className="dropdown-item" onClick={this.onCreateExcelToggle}>{gettext('New Excel File')}</li>
|
|
|
|
<li className="dropdown-item" onClick={this.onCreatePPTToggle}>{gettext('New PowerPoint File')}</li>
|
|
|
|
<li className="dropdown-item" onClick={this.onCreateWordToggle}>{gettext('New Word File')}</li>
|
2018-11-28 00:57:42 +00:00
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
{this.state.isCreateFileDialogShow && (
|
|
|
|
<ModalPortal>
|
|
|
|
<CreateFile
|
|
|
|
parentPath={this.props.path}
|
|
|
|
fileType={this.state.fileType}
|
|
|
|
onAddFile={this.onAddFile}
|
2019-01-25 07:44:04 +00:00
|
|
|
checkDuplicatedName={this.checkDuplicatedName}
|
2018-11-28 00:57:42 +00:00
|
|
|
addFileCancel={this.onCreateFileToggle}
|
2019-01-31 09:37:02 +00:00
|
|
|
/>
|
2018-11-28 00:57:42 +00:00
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
{this.state.isCreateFolderDialogShow && (
|
|
|
|
<ModalPortal>
|
|
|
|
<CreateFolder
|
|
|
|
parentPath={this.props.path}
|
|
|
|
onAddFolder={this.onAddFolder}
|
2019-01-25 07:44:04 +00:00
|
|
|
checkDuplicatedName={this.checkDuplicatedName}
|
2018-11-28 00:57:42 +00:00
|
|
|
addFolderCancel={this.onCreateFolderToggle}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
)}
|
2018-12-06 03:28:16 +00:00
|
|
|
{this.state.isShareDialogShow &&
|
|
|
|
<ModalPortal>
|
|
|
|
<ShareDialog
|
2018-12-17 13:38:55 +00:00
|
|
|
itemType={itemType}
|
2018-12-12 02:34:58 +00:00
|
|
|
itemName={itemName}
|
2018-12-06 03:28:16 +00:00
|
|
|
itemPath={this.props.path}
|
|
|
|
repoID={this.props.repoID}
|
2019-01-29 02:06:26 +00:00
|
|
|
repoEncrypted={this.props.repoEncrypted}
|
|
|
|
enableDirPrivateShare={this.props.enableDirPrivateShare}
|
|
|
|
userPerm={this.props.userPerm}
|
|
|
|
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
|
2018-12-06 03:28:16 +00:00
|
|
|
toggleDialog={this.onShareClick}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
}
|
2018-11-28 00:57:42 +00:00
|
|
|
</Fragment>
|
2018-11-27 06:47:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DirOperationToolbar.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default DirOperationToolbar;
|