1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 01:41:39 +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

@@ -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) {