1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

[dir view] updated 'top operation list' for current active dirent (#4046)

* [dir view] updated 'top operation list' for current active dirent

* added `getDirentOperationList` to utils.js
* improved code

* [dir view] added operations for current active dirent; bugfix &
improvement

* [utils] rewrote 'get dirent operation list' & bugfix
This commit is contained in:
llj
2019-09-04 14:21:57 +08:00
committed by Daniel Pan
parent 169ee131c9
commit 5c7c13c478
7 changed files with 216 additions and 234 deletions

View File

@@ -66,6 +66,7 @@ class Rename extends React.Component {
this.setState({errMessage: errMessage});
} else {
this.props.onRename(this.state.newName);
this.props.toggleCancel();
}
}
}
@@ -116,7 +117,7 @@ class Rename extends React.Component {
<ModalHeader toggle={this.toggle}>{type === 'file' ? gettext('Rename File') : gettext('Rename Folder') }</ModalHeader>
<ModalBody>
<p>{type === 'file' ? gettext('New file name'): gettext('New folder name')}</p>
<Input onKeyPress={this.handleKeyPress} innerRef={input => {this.newInput = input;}} placeholder="newName" value={this.state.newName} onChange={this.handleChange} />
<Input onKeyPress={this.handleKeyPress} innerRef={input => {this.newInput = input;}} value={this.state.newName} onChange={this.handleChange} />
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
</ModalBody>
<ModalFooter>

View File

@@ -16,7 +16,7 @@ import CopyDirentDialog from '../dialog/copy-dirent-dialog';
import ShareDialog from '../dialog/share-dialog';
import ZipDownloadDialog from '../dialog/zip-download-dialog';
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
import Rename from '../../components/dialog/rename-grid-item-dialog';
import Rename from '../../components/dialog/rename-dirent';
import CreateFile from '../dialog/create-file-dialog';
import CreateFolder from '../dialog/create-folder-dialog';
import LibSubFolderPermissionDialog from '../dialog/lib-sub-folder-permission-dialog';
@@ -150,7 +150,7 @@ class DirentGridView extends React.Component{
this.onLockItem(currentObject);
break;
case 'Comment':
this.onComnentItem();
this.onCommentItem();
break;
case 'History':
this.onHistory(currentObject);
@@ -261,7 +261,7 @@ class DirentGridView extends React.Component{
});
}
onComnentItem = () => {
onCommentItem = () => {
this.props.showDirentDetail('comments');
}
@@ -286,13 +286,9 @@ class DirentGridView extends React.Component{
}
onItemRename = (newName) => {
this.setState({
isRenameDialogShow: !this.state.isRenameDialogShow,
});
this.props.onItemRename(this.state.activeDirent, newName);
}
prepareImageItem = (item) => {
const useThumbnail = !this.repoEncrypted;
const name = item.name;
@@ -351,11 +347,7 @@ class DirentGridView extends React.Component{
}
checkDuplicatedName = (newName) => {
let direntList = this.props.direntList;
let isDuplicated = direntList.some(object => {
return object.name === newName;
});
return isDuplicated;
return Utils.checkDuplicatedNameInList(this.props.direntList, newName);
}
// common contextmenu handle
@@ -434,93 +426,9 @@ class DirentGridView extends React.Component{
}
getDirentItemMenuList = (dirent, isContextmenu) => {
let isRepoOwner = this.isRepoOwner;
let currentRepoInfo = this.props.currentRepoInfo;
let can_set_folder_perm = folderPermEnabled && ((isRepoOwner && currentRepoInfo.has_been_shared_out) || currentRepoInfo.is_admin);
let type = dirent.type;
let permission = dirent.permission;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent);
let menuList = [];
let contextmenuList = [];
if (isContextmenu) {
let { SHARE, DOWNLOAD, DELETE } = TextTranslation;
if (showShareBtn) {
contextmenuList = [SHARE];
}
if (dirent.permission === 'rw' || dirent.permission === 'r') {
contextmenuList = [...contextmenuList, DOWNLOAD];
}
if (dirent.permission === 'rw') {
contextmenuList = [...contextmenuList, DELETE];
}
contextmenuList = contextmenuList.length > 0 ? [...contextmenuList, 'Divider'] : [];
}
let { RENAME, MOVE, COPY, PERMISSION, OPEN_VIA_CLIENT, LOCK, UNLOCK, COMMENT, HISTORY, ACCESS_LOG, TAGS } = TextTranslation;
if (type === 'dir' && permission === 'rw') {
if (can_set_folder_perm) {
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', PERMISSION, 'Divider', OPEN_VIA_CLIENT];
} else {
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', OPEN_VIA_CLIENT];
}
return menuList;
}
if (type === 'dir' && permission === 'r') {
menuList = [...contextmenuList];
menuList = currentRepoInfo.encrypted ? [...menuList, COPY] : menuList.slice(0, menuList.length - 1);
return menuList;
}
if (type === 'file' && permission === 'rw') {
menuList = [...contextmenuList];
if (!dirent.is_locked || (dirent.is_locked && dirent.locked_by_me)) {
menuList.push(RENAME);
menuList.push(MOVE);
}
menuList.push(COPY);
menuList.push(TAGS);
if (isPro) {
if (dirent.is_locked) {
if (dirent.locked_by_me || (dirent.lock_owner === 'OnlineOffice' && permission === 'rw')) {
menuList.push(UNLOCK);
}
} else {
menuList.push(LOCK);
}
}
menuList.push('Divider');
if (enableFileComment) {
menuList.push(COMMENT);
}
menuList.push(HISTORY);
if (isPro && fileAuditEnabled) {
menuList.push(ACCESS_LOG);
}
menuList.push('Divider');
menuList.push(OPEN_VIA_CLIENT);
return menuList;
}
if (type === 'file' && permission === 'r') {
menuList = [...contextmenuList];
if (!currentRepoInfo.encrypted) {
menuList.push(COPY);
}
if (enableFileComment) {
menuList.push(COMMENT);
}
menuList.push(HISTORY);
return menuList;
}
return [];
const isRepoOwner = this.isRepoOwner;
const currentRepoInfo = this.props.currentRepoInfo;
return Utils.getDirentOperationList(isRepoOwner, currentRepoInfo, dirent, isContextmenu);
}
render() {

View File

@@ -474,93 +474,9 @@ class DirentListView extends React.Component {
}
getDirentItemMenuList = (dirent, isContextmenu) => {
let isRepoOwner = this.isRepoOwner;
let currentRepoInfo = this.props.currentRepoInfo;
let can_set_folder_perm = folderPermEnabled && ((isRepoOwner && currentRepoInfo.has_been_shared_out) || currentRepoInfo.is_admin);
let type = dirent.type;
let permission = dirent.permission;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent);
let menuList = [];
let contextmenuList = [];
if (isContextmenu) {
let { SHARE, DOWNLOAD, DELETE } = TextTranslation;
if (showShareBtn) {
contextmenuList = [SHARE];
}
if (dirent.permission === 'rw' || dirent.permission === 'r') {
contextmenuList = [...contextmenuList, DOWNLOAD];
}
if (dirent.permission === 'rw') {
contextmenuList = [...contextmenuList, DELETE];
}
contextmenuList = contextmenuList.length > 0 ? [...contextmenuList, 'Divider'] : [];
}
let { RENAME, MOVE, COPY, PERMISSION, OPEN_VIA_CLIENT, LOCK, UNLOCK, COMMENT, HISTORY, ACCESS_LOG, TAGS } = TextTranslation;
if (type === 'dir' && permission === 'rw') {
if (can_set_folder_perm) {
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', PERMISSION, 'Divider', OPEN_VIA_CLIENT];
} else {
menuList = [...contextmenuList, RENAME, MOVE, COPY, 'Divider', OPEN_VIA_CLIENT];
}
return menuList;
}
if (type === 'dir' && permission === 'r') {
menuList = [...contextmenuList];
menuList = currentRepoInfo.encrypted ? [...menuList, COPY] : menuList.slice(0, menuList.length - 1);
return menuList;
}
if (type === 'file' && permission === 'rw') {
menuList = [...contextmenuList];
if (!dirent.is_locked || (dirent.is_locked && dirent.locked_by_me)) {
menuList.push(RENAME);
menuList.push(MOVE);
}
menuList.push(COPY);
menuList.push(TAGS);
if (isPro) {
if (dirent.is_locked) {
if (dirent.locked_by_me || (dirent.lock_owner === 'OnlineOffice' && permission === 'rw')) {
menuList.push(UNLOCK);
}
} else {
menuList.push(LOCK);
}
}
menuList.push('Divider');
if (enableFileComment) {
menuList.push(COMMENT);
}
menuList.push(HISTORY);
if (isPro && fileAuditEnabled) {
menuList.push(ACCESS_LOG);
}
menuList.push('Divider');
menuList.push(OPEN_VIA_CLIENT);
return menuList;
}
if (type === 'file' && permission === 'r') {
menuList = [...contextmenuList];
if (!currentRepoInfo.encrypted) {
menuList.push(COPY);
}
if (enableFileComment) {
menuList.push(COMMENT);
}
menuList.push(HISTORY);
return menuList;
}
return [];
const isRepoOwner = this.isRepoOwner;
const currentRepoInfo = this.props.currentRepoInfo;
return Utils.getDirentOperationList(isRepoOwner, currentRepoInfo, dirent, isContextmenu);
}
onTableDragEnter = (e) => {

View File

@@ -1,7 +1,7 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { Button, ButtonGroup } from 'reactstrap';
import { gettext, siteRoot, canGenerateShareLink, isPro, fileAuditEnabled } from '../../utils/constants';
import { gettext, siteRoot, canGenerateShareLink, isPro, fileAuditEnabled, name } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api';
import URLDecorator from '../../utils/url-decorator';
@@ -12,6 +12,9 @@ import ShareDialog from '../dialog/share-dialog';
import RelatedFileDialogs from '../dialog/related-file-dialogs';
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
import ZipDownloadDialog from '../dialog/zip-download-dialog';
import Rename from '../dialog/rename-dirent';
import LibSubFolderPermissionDialog from '../dialog/lib-sub-folder-permission-dialog';
import ModalPortal from '../modal-portal';
import ItemDropdownMenu from '../dropdown-menu/item-dropdown-menu';
import toaster from '../toast';
@@ -51,6 +54,8 @@ class MultipleDirOperationToolbar extends React.Component {
multiFileTagList: [],
showRelatedFileDialog: false,
viewMode: 'list_related_file',
isRenameDialogOpen: false,
isPermissionDialogOpen: false
};
}
@@ -87,57 +92,63 @@ class MultipleDirOperationToolbar extends React.Component {
});
}
checkDuplicatedName = (newName) => {
return Utils.checkDuplicatedNameInList(this.props.direntList, newName);
}
onItemRename = (newName) => {
const dirent = this.props.selectedDirentList[0];
this.props.onItemRename(dirent, newName);
}
onPermissionItem = () => {
this.setState({
showLibContentViewDialogs: !this.state.showLibContentViewDialogs,
isPermissionDialogOpen: !this.state.isPermissionDialogOpen
});
}
onCommentItem = () => {
this.props.showDirentDetail('comments');
}
getDirentMenuList = (dirent) => {
let menuList = [];
let currentRepoInfo = this.props.currentRepoInfo;
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, dirent.permission, dirent);
const { SHARE, TAGS, RELATED_FILES, HISTORY, ACCESS_LOG, OPEN_VIA_CLIENT, LOCK, UNLOCK } = TextTranslation;
if (dirent.type === 'dir') {
if (showShareBtn) {
menuList = [SHARE];
}
return menuList;
}
if (dirent.type === 'file') {
let shareBtn = showShareBtn ? [SHARE] : [];
menuList = [...shareBtn, TAGS, RELATED_FILES, 'Divider', HISTORY, ACCESS_LOG, 'Divider', OPEN_VIA_CLIENT];
if (!Utils.isMarkdownFile(dirent.name)) {
menuList = menuList.filter(menu => {
return menu !== RELATED_FILES;
const isRepoOwner = this.props.isRepoOwner;
const currentRepoInfo = this.props.currentRepoInfo;
const isContextmenu = true;
let opList = Utils.getDirentOperationList(isRepoOwner, currentRepoInfo, dirent, isContextmenu);
const list = ['Move', 'Copy', 'Delete', 'Download'];
if (dirent.type == 'dir') {
opList = opList.filter((item, index) => {
return list.indexOf(item.key) == -1 && item != 'Divider';
});
}
if (!isPro || !fileAuditEnabled) {
menuList = menuList.filter(menu => {
return menu !== ACCESS_LOG;
});
}
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;
opList = opList.filter((item, index) => {
return list.indexOf(item.key) == -1;
});
}
return opList;
}
onMenuItemClick = (operation) => {
const dirents = this.props.selectedDirentList;
const dirent = dirents[0];
switch(operation) {
switch (operation) {
case 'Share':
this.setState({
showLibContentViewDialogs: true,
showShareDialog: true,
});
break;
case 'Rename':
this.setState({
showLibContentViewDialogs: true,
isRenameDialogOpen: true
});
break;
case 'Permission':
this.onPermissionItem();
break;
case 'Tags':
this.listFileTags(dirent);
break;
@@ -147,6 +158,9 @@ class MultipleDirOperationToolbar extends React.Component {
case 'Unlock':
this.unlockFile(dirent);
break;
case 'Comment':
this.onCommentItem();
break;
case 'Related Files':
this.openRelatedFilesDialog(dirent);
break;
@@ -170,6 +184,7 @@ class MultipleDirOperationToolbar extends React.Component {
if (res.data.is_locked) {
this.props.updateDirent(dirent, 'is_locked', true);
this.props.updateDirent(dirent, 'locked_by_me', true);
this.props.updateDirent(dirent, 'lock_owner_name', name);
this.props.unSelectDirent();
}
}).catch(error => {
@@ -184,6 +199,7 @@ class MultipleDirOperationToolbar extends React.Component {
if (!res.data.is_locked) {
this.props.updateDirent(dirent, 'is_locked', false);
this.props.updateDirent(dirent, 'locked_by_me', false);
this.props.updateDirent(dirent, 'lock_owner_name', '');
this.props.unSelectDirent();
}
}).catch(error => {
@@ -200,7 +216,6 @@ class MultipleDirOperationToolbar extends React.Component {
filePath: filePath
});
location.href = url;
this.props.unSelectDirent();
}
onHistory = (dirent) => {
@@ -250,6 +265,8 @@ class MultipleDirOperationToolbar extends React.Component {
showShareDialog: false,
showEditFileTagDialog: false,
showRelatedFileDialog: false,
isRenameDialogOpen: false,
isPermissionDialogOpen: false,
});
}
@@ -304,7 +321,9 @@ class MultipleDirOperationToolbar extends React.Component {
render() {
const { repoID, userPerm } = this.props;
let direntPath = this.getDirentPath(this.props.selectedDirentList[0]);
const dirent = this.props.selectedDirentList[0];
let direntPath = this.getDirentPath(dirent);
if (userPerm !== 'rw' && userPerm !== 'admin') {
return '';
@@ -366,18 +385,39 @@ class MultipleDirOperationToolbar extends React.Component {
{this.state.showShareDialog &&
<ModalPortal>
<ShareDialog
itemType={this.props.selectedDirentList[0].type}
itemName={this.props.selectedDirentList[0].name}
itemType={dirent.type}
itemName={dirent.name}
itemPath={direntPath}
userPerm={this.props.selectedDirentList[0].permission}
userPerm={dirent.permission}
repoID={repoID}
repoEncrypted={false}
enableDirPrivateShare={this.props.enableDirPrivateShare}
isGroupOwnedRepo={this.state.isGroupOwnedRepo}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
toggleDialog={this.toggleCancel}
/>
</ModalPortal>
}
{this.state.isRenameDialogOpen &&
<ModalPortal>
<Rename
dirent={dirent}
onRename={this.onItemRename}
checkDuplicatedName={this.checkDuplicatedName}
toggleCancel={this.toggleCancel}
/>
</ModalPortal>
}
{this.state.isPermissionDialogOpen &&
<ModalPortal>
<LibSubFolderPermissionDialog
toggleDialog={this.toggleCancel}
repoID={repoID}
folderPath={direntPath}
folderName={dirent.name}
isDepartmentRepo={this.props.isGroupOwnedRepo}
/>
</ModalPortal>
}
{this.state.showEditFileTagDialog &&
<ModalPortal>
<EditFileTagDialog

View File

@@ -95,9 +95,11 @@ class LibContentToolbar extends React.Component {
userPerm={this.props.userPerm}
repoEncrypted={this.props.repoEncrypted}
selectedDirentList={this.props.selectedDirentList}
direntList={this.props.direntList}
onItemsMove={this.props.onItemsMove}
onItemsCopy={this.props.onItemsCopy}
onItemsDelete={this.props.onItemsDelete}
onItemRename={this.props.onItemRename}
isRepoOwner={this.props.isRepoOwner}
currentRepoInfo={this.props.currentRepoInfo}
enableDirPrivateShare={this.props.enableDirPrivateShare}
@@ -106,6 +108,8 @@ class LibContentToolbar extends React.Component {
unSelectDirent={this.props.unSelectDirent}
onFilesTagChanged={this.props.onFilesTagChanged}
showShareBtn={this.props.showShareBtn}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
showDirentDetail={this.props.showDirentDetail}
/> :
<DirOperationToolBar
path={this.props.path}

View File

@@ -1653,6 +1653,7 @@ class LibContentView extends React.Component {
onItemsMove={this.onMoveItems}
onItemsCopy={this.onCopyItems}
onItemsDelete={this.onDeleteItems}
onItemRename={this.onMainPanelItemRename}
direntList={this.state.direntList}
repoName={this.state.repoName}
repoEncrypted={this.state.repoEncrypted}

View File

@@ -1,5 +1,6 @@
import { mediaUrl, gettext, serviceURL, siteRoot, canGenerateShareLink, canGenerateUploadLink, username } from './constants';
import { mediaUrl, gettext, serviceURL, siteRoot, isPro, enableFileComment, fileAuditEnabled, canGenerateShareLink, canGenerateUploadLink, username, folderPermEnabled } from './constants';
import { strChineseFirstPY } from './pinyin-by-unicode';
import TextTranslation from './text-translation';
export const Utils = {
@@ -137,6 +138,12 @@ export const Utils = {
}
},
checkDuplicatedNameInList: function(list, targetName) {
return list.some(object => {
return object.name === targetName;
});
},
encodePath: function(path) {
// IE8 does not support 'map()'
/*
@@ -377,6 +384,111 @@ export const Utils = {
return title;
},
getFolderOperationList: function(isRepoOwner, currentRepoInfo, dirent, isContextmenu) {
let list = [];
const { SHARE, DOWNLOAD, DELETE, RENAME, MOVE, COPY, PERMISSION, OPEN_VIA_CLIENT } = TextTranslation;
const permission = dirent.permission;
if (isContextmenu) {
if (permission == 'rw' || permission == 'r') {
list.push(DOWNLOAD);
}
if (Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent)) {
list.push(SHARE);
}
if (permission == 'rw') {
list.push(DELETE, 'Divider');
}
}
if (permission == 'rw') {
list.push(RENAME, MOVE, COPY);
if (folderPermEnabled && ((isRepoOwner && currentRepoInfo.has_been_shared_out) || currentRepoInfo.is_admin)) {
list.push('Divider', PERMISSION);
}
list.push('Divider', OPEN_VIA_CLIENT);
}
if (permission == 'r' && !currentRepoInfo.encrypted) {
list.push(COPY);
}
return list;
},
getFileOperationList: function(currentRepoInfo, dirent, isContextmenu) {
let list = [];
const { SHARE, DOWNLOAD, DELETE, RENAME, MOVE, COPY, TAGS, UNLOCK, LOCK,
COMMENT, HISTORY, ACCESS_LOG, OPEN_VIA_CLIENT } = TextTranslation;
const permission = dirent.permission;
if (isContextmenu) {
if (permission == 'rw' || permission == 'r') {
list.push(DOWNLOAD);
}
if (Utils.isHasPermissionToShare(currentRepoInfo, permission, dirent)) {
list.push(SHARE);
}
if (permission == 'rw') {
if (!dirent.is_locked || (dirent.is_locked && dirent.locked_by_me)) {
list.push(DELETE);
}
}
list.push('Divider');
}
if (permission == 'rw') {
if (!dirent.is_locked || (dirent.is_locked && dirent.locked_by_me)) {
list.push(RENAME, MOVE);
}
list.push(COPY, TAGS);
if (isPro) {
if (dirent.is_locked) {
if (dirent.locked_by_me || dirent.lock_owner == 'OnlineOffice') {
list.push(UNLOCK);
}
} else {
list.push(LOCK);
}
}
list.push('Divider');
if (enableFileComment) {
list.push(COMMENT);
}
list.push(HISTORY);
if (isPro && fileAuditEnabled) {
list.push(ACCESS_LOG);
}
list.push('Divider', OPEN_VIA_CLIENT);
}
if (permission == 'r') {
if (!currentRepoInfo.encrypted) {
list.push(COPY);
}
if (enableFileComment) {
list.push(COMMENT);
}
list.push(HISTORY);
}
return list;
},
getDirentOperationList: function(isRepoOwner, currentRepoInfo, dirent, isContextmenu) {
return dirent.type == 'dir' ?
Utils.getFolderOperationList(isRepoOwner, currentRepoInfo, dirent, isContextmenu) :
Utils.getFileOperationList(currentRepoInfo, dirent, isContextmenu);
},
sharePerms: function(permission) {
var title;
switch(permission) {