2018-11-27 06:47:19 +00:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-04-12 07:54:05 +00:00
|
|
|
import { Button, ButtonGroup } from 'reactstrap';
|
2019-04-25 07:09:28 +00:00
|
|
|
import { gettext, canGenerateShareLink } from '../../utils/constants';
|
2019-04-21 06:02:12 +00:00
|
|
|
import { Utils, isPro } from '../../utils/utils';
|
2018-11-27 06:47:19 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import URLDecorator from '../../utils/url-decorator';
|
2019-04-21 06:02:12 +00:00
|
|
|
import TextTranslation from '../../utils/text-translation';
|
2018-11-27 06:47:19 +00:00
|
|
|
import MoveDirentDialog from '../dialog/move-dirent-dialog';
|
|
|
|
import CopyDirentDialog from '../dialog/copy-dirent-dialog';
|
2019-03-18 09:32:49 +00:00
|
|
|
import ShareDialog from '../dialog/share-dialog';
|
2019-03-29 02:36:34 +00:00
|
|
|
import RelatedFileDialogs from '../dialog/related-file-dialogs';
|
2019-03-18 09:32:49 +00:00
|
|
|
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
|
2019-04-12 07:54:05 +00:00
|
|
|
import ZipDownloadDialog from '../dialog/zip-download-dialog';
|
2019-03-18 09:32:49 +00:00
|
|
|
import ModalPortal from '../modal-portal';
|
2019-04-22 06:00:16 +00:00
|
|
|
import ItemDropdownMenu from '../dropdown-menu/item-dropdown-menu';
|
2019-04-21 06:02:12 +00:00
|
|
|
|
|
|
|
import '../../css/dirents-menu.css';
|
2018-11-27 06:47:19 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
2019-04-18 09:32:34 +00:00
|
|
|
userPerm: PropTypes.string.isRequired,
|
2018-11-27 06:47:19 +00:00
|
|
|
repoID: PropTypes.string.isRequired,
|
2019-03-11 03:14:49 +00:00
|
|
|
repoEncrypted: PropTypes.bool.isRequired,
|
2018-11-27 06:47:19 +00:00
|
|
|
selectedDirentList: PropTypes.array.isRequired,
|
|
|
|
onItemsMove: PropTypes.func.isRequired,
|
|
|
|
onItemsCopy: PropTypes.func.isRequired,
|
|
|
|
onItemsDelete: PropTypes.func.isRequired,
|
2019-03-18 09:32:49 +00:00
|
|
|
isRepoOwner: PropTypes.bool.isRequired,
|
2019-03-19 10:20:45 +00:00
|
|
|
enableDirPrivateShare: PropTypes.bool.isRequired,
|
|
|
|
currentRepoInfo: PropTypes.object.isRequired,
|
2019-03-20 03:13:32 +00:00
|
|
|
onFilesTagChanged: PropTypes.func.isRequired,
|
2019-03-19 10:20:45 +00:00
|
|
|
unSelectDirent: PropTypes.func.isRequired,
|
|
|
|
updateDirent: PropTypes.func.isRequired,
|
2018-11-27 06:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MutipleDirOperationToolbar extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-04-12 07:54:05 +00:00
|
|
|
isZipDialogOpen: false,
|
2018-11-27 06:47:19 +00:00
|
|
|
isMoveDialogShow: false,
|
|
|
|
isCopyDialogShow: false,
|
|
|
|
isMutipleOperation: true,
|
2019-03-18 09:32:49 +00:00
|
|
|
showLibContentViewDialogs: false,
|
|
|
|
showShareDialog: false,
|
|
|
|
showEditFileTagDialog: false,
|
|
|
|
fileTagList: [],
|
|
|
|
multiFileTagList: [],
|
2019-03-29 02:36:34 +00:00
|
|
|
showRelatedFileDialog: false,
|
|
|
|
viewMode: 'list_related_file',
|
2018-11-27 06:47:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMoveToggle = () => {
|
|
|
|
this.setState({isMoveDialogShow: !this.state.isMoveDialogShow});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCopyToggle = () => {
|
|
|
|
this.setState({isCopyDialogShow: !this.state.isCopyDialogShow});
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemsDelete = () => {
|
|
|
|
this.props.onItemsDelete();
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemsDownload = () => {
|
|
|
|
let { path, repoID, selectedDirentList } = this.props;
|
|
|
|
if (selectedDirentList.length) {
|
|
|
|
if (selectedDirentList.length === 1 && !selectedDirentList[0].isDir()) {
|
|
|
|
let direntPath = Utils.joinPath(path, selectedDirentList[0].name);
|
|
|
|
let url = URLDecorator.getUrl({type: 'download_file_url', repoID: repoID, filePath: direntPath});
|
|
|
|
location.href= url;
|
|
|
|
return;
|
|
|
|
}
|
2019-04-12 07:54:05 +00:00
|
|
|
this.setState({
|
|
|
|
isZipDialogOpen: true
|
2018-11-27 06:47:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 07:54:05 +00:00
|
|
|
closeZipDialog = () => {
|
|
|
|
this.setState({
|
|
|
|
isZipDialogOpen: false
|
2018-11-27 06:47:19 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-21 06:02:12 +00:00
|
|
|
getDirentMenuList = (dirent) => {
|
|
|
|
let menuList = [];
|
|
|
|
let currentRepoInfo = this.props.currentRepoInfo;
|
|
|
|
|
|
|
|
const { SHARE, TAGS, RELATED_FILES, HISTORY, OPEN_VIA_CLIENT, LOCK, UNLOCK } = TextTranslation;
|
|
|
|
|
2019-04-25 07:09:28 +00:00
|
|
|
let shareBtn = currentRepoInfo.encrypted ? [] : [SHARE];
|
|
|
|
|
2019-04-21 06:02:12 +00:00
|
|
|
if (dirent.type === 'dir') {
|
2019-04-25 07:09:28 +00:00
|
|
|
menuList = [...shareBtn];
|
2019-04-21 06:02:12 +00:00
|
|
|
return menuList;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirent.type === 'file') {
|
2019-04-25 07:09:28 +00:00
|
|
|
shareBtn = canGenerateShareLink ? [SHARE] : [];
|
|
|
|
|
|
|
|
menuList = [...shareBtn, TAGS, RELATED_FILES, 'Divider', HISTORY, 'Divider', OPEN_VIA_CLIENT];
|
2019-04-21 06:02:12 +00:00
|
|
|
if (!Utils.isMarkdownFile(dirent.name)) {
|
|
|
|
menuList.splice(2, 1);
|
|
|
|
}
|
|
|
|
if (isPro) {
|
|
|
|
if (dirent.is_locked) {
|
|
|
|
if (dirent.locked_by_me || (dirent.lock_owner === 'OnlineOffice' && currentRepoInfo.permission === 'rw')) {
|
|
|
|
menuList.splice(1, 0, UNLOCK);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
menuList.splice(1, 0, LOCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return menuList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 09:32:49 +00:00
|
|
|
onMenuItemClick = (operation) => {
|
|
|
|
const dirents = this.props.selectedDirentList;
|
|
|
|
const dirent = dirents[0];
|
|
|
|
switch(operation) {
|
|
|
|
case 'Share':
|
|
|
|
this.setState({
|
|
|
|
showLibContentViewDialogs: true,
|
|
|
|
showShareDialog: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'Tags':
|
2019-03-19 02:38:05 +00:00
|
|
|
this.listFileTags(dirent);
|
2019-03-18 09:32:49 +00:00
|
|
|
break;
|
|
|
|
case 'Lock':
|
|
|
|
this.lockFile(dirent);
|
|
|
|
break;
|
|
|
|
case 'Unlock':
|
|
|
|
this.unlockFile(dirent);
|
|
|
|
break;
|
|
|
|
case 'Related Files':
|
|
|
|
this.openRelatedFilesDialog(dirent);
|
|
|
|
break;
|
|
|
|
case 'History':
|
|
|
|
this.onHistory(dirent);
|
|
|
|
break;
|
|
|
|
case 'Open via Client':
|
|
|
|
this.onOpenViaClient(dirent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lockFile = (dirent) => {
|
|
|
|
const filePath = this.getDirentPath(dirent);
|
|
|
|
seafileAPI.lockfile(this.props.repoID, filePath).then((res) => {
|
|
|
|
if (res.data.is_locked) {
|
|
|
|
this.props.updateDirent(dirent, 'is_locked', true);
|
|
|
|
this.props.updateDirent(dirent, 'locked_by_me', true);
|
|
|
|
this.props.unSelectDirent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
unlockFile = (dirent) => {
|
|
|
|
const filePath = this.getDirentPath(dirent);
|
|
|
|
seafileAPI.unlockfile(this.props.repoID, filePath).then((res) => {
|
|
|
|
if (!res.data.is_locked) {
|
|
|
|
this.props.updateDirent(dirent, 'is_locked', false);
|
|
|
|
this.props.updateDirent(dirent, 'locked_by_me', false);
|
|
|
|
this.props.unSelectDirent();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpenViaClient = (dirent) => {
|
|
|
|
const filePath = this.getDirentPath(dirent);
|
|
|
|
let url = URLDecorator.getUrl({
|
|
|
|
type: 'open_via_client',
|
|
|
|
repoID: this.props.repoID,
|
|
|
|
filePath: filePath
|
|
|
|
});
|
|
|
|
location.href = url;
|
|
|
|
this.props.unSelectDirent();
|
|
|
|
}
|
|
|
|
|
|
|
|
onHistory = (dirent) => {
|
|
|
|
let filePath = this.getDirentPath(dirent);
|
|
|
|
let url = URLDecorator.getUrl({
|
|
|
|
type: 'file_revisions',
|
|
|
|
repoID: this.props.repoID,
|
|
|
|
filePath: filePath
|
|
|
|
});
|
|
|
|
location.href = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
openRelatedFilesDialog = (dirent) => {
|
|
|
|
let filePath = this.getDirentPath(dirent);
|
|
|
|
seafileAPI.listRelatedFiles(this.props.repoID, filePath).then(res => {
|
2019-03-29 02:36:34 +00:00
|
|
|
let relatedFiles = res.data.related_files;
|
|
|
|
if (relatedFiles.length > 0) {
|
2019-03-18 09:32:49 +00:00
|
|
|
this.setState({
|
2019-03-29 02:36:34 +00:00
|
|
|
relatedFiles: relatedFiles,
|
|
|
|
showLibContentViewDialogs: true,
|
|
|
|
showRelatedFileDialog: true,
|
|
|
|
viewMode: 'list_related_file',
|
2019-03-18 09:32:49 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
2019-03-29 02:36:34 +00:00
|
|
|
relatedFiles: relatedFiles,
|
|
|
|
showLibContentViewDialogs: true,
|
|
|
|
showRelatedFileDialog: true,
|
|
|
|
viewMode: 'add_related_file',
|
2019-03-18 09:32:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCancel = () => {
|
|
|
|
this.setState({
|
|
|
|
showLibContentViewDialogs: false,
|
|
|
|
showShareDialog: false,
|
|
|
|
showEditFileTagDialog: false,
|
2019-03-29 02:36:34 +00:00
|
|
|
showRelatedFileDialog: false,
|
2019-03-18 09:32:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
listFileTags = (dirent) => {
|
|
|
|
let filePath = this.getDirentPath(dirent);
|
|
|
|
seafileAPI.listFileTags(this.props.repoID, filePath).then(res => {
|
|
|
|
let fileTagList = res.data.file_tags;
|
|
|
|
for (let i = 0, length = fileTagList.length; i < length; i++) {
|
|
|
|
fileTagList[i].id = fileTagList[i].file_tag_id;
|
|
|
|
}
|
|
|
|
this.setState({
|
2019-03-19 02:38:05 +00:00
|
|
|
fileTagList: fileTagList,
|
|
|
|
showLibContentViewDialogs: true,
|
|
|
|
showEditFileTagDialog: true,
|
2019-03-18 09:32:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onMenuFileTagChanged = () => {
|
|
|
|
this.listFileTags(this.props.selectedDirentList[0]);
|
|
|
|
let length = this.props.selectedDirentList.length;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
const dirent = this.props.selectedDirentList[i];
|
|
|
|
const direntPath = this.getDirentPath(dirent);
|
2019-03-20 03:13:32 +00:00
|
|
|
this.props.onFilesTagChanged(dirent, direntPath);
|
2019-03-18 09:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
listRelatedFiles = (dirent) => {
|
|
|
|
let filePath = this.getDirentPath(dirent);
|
|
|
|
seafileAPI.listRelatedFiles(this.props.repoID, filePath).then(res => {
|
|
|
|
this.setState({
|
|
|
|
relatedFiles: res.data.related_files
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onRelatedFileChange = () => {
|
|
|
|
this.listRelatedFiles(this.props.selectedDirentList[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDirentPath = (dirent) => {
|
2019-03-18 10:09:37 +00:00
|
|
|
if (dirent) return Utils.joinPath(this.props.path, dirent.name);
|
2019-03-18 09:32:49 +00:00
|
|
|
}
|
|
|
|
|
2018-11-27 06:47:19 +00:00
|
|
|
render() {
|
2019-04-18 09:32:34 +00:00
|
|
|
|
|
|
|
const { repoID, userPerm } = this.props;
|
2019-03-18 09:32:49 +00:00
|
|
|
let direntPath = this.getDirentPath(this.props.selectedDirentList[0]);
|
2019-04-18 09:32:34 +00:00
|
|
|
|
|
|
|
if (userPerm !== 'rw' && userPerm !== 'admin') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2018-11-27 06:47:19 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-03-18 09:32:49 +00:00
|
|
|
<div className="d-flex">
|
|
|
|
<ButtonGroup className="flex-row group-operations">
|
|
|
|
<Button className="secondary group-op-item action-icon sf2-icon-move" title={gettext('Move')} onClick={this.onMoveToggle}></Button>
|
|
|
|
<Button className="secondary group-op-item action-icon sf2-icon-copy" title={gettext('Copy')} onClick={this.onCopyToggle}></Button>
|
|
|
|
<Button className="secondary group-op-item action-icon sf2-icon-delete" title={gettext('Delete')} onClick={this.onItemsDelete}></Button>
|
|
|
|
<Button className="secondary group-op-item action-icon sf2-icon-download" title={gettext('Download')} onClick={this.onItemsDownload}></Button>
|
2019-04-12 12:21:54 +00:00
|
|
|
{this.props.selectedDirentList.length === 1 &&
|
2019-04-22 06:00:16 +00:00
|
|
|
<ItemDropdownMenu
|
2019-04-21 06:02:12 +00:00
|
|
|
tagName={'button'}
|
2019-04-22 06:00:16 +00:00
|
|
|
item={this.props.selectedDirentList[0]}
|
2019-04-22 07:15:51 +00:00
|
|
|
toggleClass={'fas fa-ellipsis-v dirents-more-menu'}
|
2019-03-20 06:49:16 +00:00
|
|
|
onMenuItemClick={this.onMenuItemClick}
|
2019-04-22 04:18:35 +00:00
|
|
|
getMenuList={this.getDirentMenuList}
|
2019-03-20 06:49:16 +00:00
|
|
|
/>
|
|
|
|
}
|
2019-03-18 09:32:49 +00:00
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
2018-11-27 06:47:19 +00:00
|
|
|
{this.state.isMoveDialogShow &&
|
|
|
|
<MoveDirentDialog
|
|
|
|
path={this.props.path}
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={this.props.repoID}
|
2019-03-11 03:14:49 +00:00
|
|
|
repoEncrypted={this.props.repoEncrypted}
|
2018-11-27 06:47:19 +00:00
|
|
|
isMutipleOperation={this.state.isMutipleOperation}
|
|
|
|
selectedDirentList={this.props.selectedDirentList}
|
|
|
|
onItemsMove={this.props.onItemsMove}
|
|
|
|
onCancelMove={this.onMoveToggle}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{this.state.isCopyDialogShow &&
|
|
|
|
<CopyDirentDialog
|
|
|
|
path={this.props.path}
|
2018-11-28 04:41:49 +00:00
|
|
|
repoID={this.props.repoID}
|
2019-03-11 03:14:49 +00:00
|
|
|
repoEncrypted={this.props.repoEncrypted}
|
2018-11-27 06:47:19 +00:00
|
|
|
selectedDirentList={this.props.selectedDirentList}
|
|
|
|
isMutipleOperation={this.state.isMutipleOperation}
|
|
|
|
onItemsCopy={this.props.onItemsCopy}
|
|
|
|
onCancelCopy={this.onCopyToggle}
|
|
|
|
/>
|
|
|
|
}
|
2019-04-12 07:54:05 +00:00
|
|
|
{this.state.isZipDialogOpen &&
|
|
|
|
<ModalPortal>
|
|
|
|
<ZipDownloadDialog
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
path={this.props.path}
|
|
|
|
target={this.props.selectedDirentList.map(dirent => dirent.name)}
|
|
|
|
toggleDialog={this.closeZipDialog}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
2018-11-27 06:47:19 +00:00
|
|
|
}
|
2019-03-18 09:32:49 +00:00
|
|
|
{this.state.showLibContentViewDialogs && (
|
|
|
|
<Fragment>
|
|
|
|
{this.state.showShareDialog &&
|
|
|
|
<ModalPortal>
|
|
|
|
<ShareDialog
|
|
|
|
itemType={this.props.selectedDirentList[0].type}
|
|
|
|
itemName={this.props.selectedDirentList[0].name}
|
|
|
|
itemPath={direntPath}
|
|
|
|
userPerm={this.props.selectedDirentList[0].permission}
|
|
|
|
repoID={repoID}
|
|
|
|
repoEncrypted={false}
|
|
|
|
enableDirPrivateShare={this.props.enableDirPrivateShare}
|
|
|
|
isGroupOwnedRepo={this.state.isGroupOwnedRepo}
|
|
|
|
toggleDialog={this.toggleCancel}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
}
|
|
|
|
{this.state.showEditFileTagDialog &&
|
|
|
|
<ModalPortal>
|
|
|
|
<EditFileTagDialog
|
|
|
|
repoID={repoID}
|
|
|
|
filePath={direntPath}
|
|
|
|
fileTagList={this.state.fileTagList}
|
|
|
|
toggleCancel={this.toggleCancel}
|
|
|
|
onFileTagChanged={this.onMenuFileTagChanged}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
}
|
2019-03-29 02:36:34 +00:00
|
|
|
{this.state.showRelatedFileDialog &&
|
2019-03-18 09:32:49 +00:00
|
|
|
<ModalPortal>
|
2019-03-29 02:36:34 +00:00
|
|
|
<RelatedFileDialogs
|
|
|
|
repoID={repoID}
|
|
|
|
filePath={direntPath}
|
|
|
|
relatedFiles={this.state.relatedFiles}
|
|
|
|
toggleCancel={this.toggleCancel}
|
|
|
|
onRelatedFileChange={this.onRelatedFileChange}
|
|
|
|
dirent={this.props.selectedDirentList[0]}
|
|
|
|
viewMode={this.state.viewMode}
|
|
|
|
/>
|
2019-03-18 09:32:49 +00:00
|
|
|
</ModalPortal>
|
2019-03-29 02:36:34 +00:00
|
|
|
}
|
2019-03-18 09:32:49 +00:00
|
|
|
</Fragment>
|
|
|
|
)}
|
2018-11-27 06:47:19 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MutipleDirOperationToolbar.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default MutipleDirOperationToolbar;
|