1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-21 18:32:37 +00:00
seahub/frontend/src/components/dirent-list-view/dirent-list-item.js

904 lines
31 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
2018-10-13 09:07:54 +00:00
import PropTypes from 'prop-types';
2018-12-18 01:02:16 +00:00
import MD5 from 'MD5';
import moment from 'moment';
2018-12-18 01:02:16 +00:00
import { UncontrolledTooltip } from 'reactstrap';
import { Dropdown, DropdownToggle, DropdownItem } from 'reactstrap';
import { gettext, siteRoot, mediaUrl, username, useGoFileserver, fileServerRoot } from '../../utils/constants';
2018-11-30 03:52:19 +00:00
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api';
import URLDecorator from '../../utils/url-decorator';
2019-04-22 06:00:16 +00:00
import ItemDropdownMenu from '../dropdown-menu/item-dropdown-menu';
import Rename from '../rename';
import ModalPortal from '../modal-portal';
import MoveDirentDialog from '../dialog/move-dirent-dialog';
import CopyDirentDialog from '../dialog/copy-dirent-dialog';
import ShareDialog from '../dialog/share-dialog';
import ZipDownloadDialog from '../dialog/zip-download-dialog';
2019-04-17 02:48:44 +00:00
import EditFileTagDialog from '../dialog/edit-filetag-dialog';
import LibSubFolderPermissionDialog from '../dialog/lib-sub-folder-permission-dialog';
2018-10-13 09:07:54 +00:00
2018-12-28 03:12:24 +00:00
import '../../css/dirent-list-item.css';
import toaster from '../toast';
2018-12-28 03:12:24 +00:00
2018-10-13 09:07:54 +00:00
const propTypes = {
2018-11-22 03:26:00 +00:00
path: PropTypes.string.isRequired,
2018-11-28 04:41:49 +00:00
repoID: PropTypes.string.isRequired,
2018-10-13 09:07:54 +00:00
isItemFreezed: PropTypes.bool.isRequired,
dirent: PropTypes.object.isRequired,
onItemClick: PropTypes.func.isRequired,
2019-04-22 04:18:35 +00:00
freezeItem: PropTypes.func.isRequired,
unfreezeItem: PropTypes.func.isRequired,
2018-11-23 12:19:42 +00:00
onItemRenameToggle: PropTypes.func.isRequired,
onItemSelected: PropTypes.func.isRequired,
2018-10-13 09:07:54 +00:00
onItemDelete: PropTypes.func.isRequired,
onItemRename: PropTypes.func.isRequired,
onItemMove: PropTypes.func.isRequired,
onItemCopy: PropTypes.func.isRequired,
onDirentClick: PropTypes.func.isRequired,
2018-11-22 03:26:00 +00:00
updateDirent: PropTypes.func.isRequired,
2019-03-11 03:14:49 +00:00
showImagePopup: PropTypes.func.isRequired,
2018-12-18 09:21:01 +00:00
currentRepoInfo: PropTypes.object,
2018-11-01 10:40:18 +00:00
isRepoOwner: PropTypes.bool,
2019-03-11 03:14:49 +00:00
isAdmin: PropTypes.bool.isRequired,
repoEncrypted: PropTypes.bool.isRequired,
isGroupOwnedRepo: PropTypes.bool.isRequired,
onItemMouseDown: PropTypes.func.isRequired,
onItemContextMenu: PropTypes.func.isRequired,
selectedDirentList: PropTypes.array.isRequired,
activeDirent: PropTypes.object,
2019-04-21 02:43:34 +00:00
getDirentItemMenuList: PropTypes.func.isRequired,
onFileTagChanged: PropTypes.func,
enableDirPrivateShare: PropTypes.bool.isRequired,
2019-05-29 04:02:07 +00:00
showDirentDetail: PropTypes.func.isRequired,
2019-06-17 08:11:54 +00:00
onItemsMove: PropTypes.func.isRequired,
2019-07-26 06:55:09 +00:00
onShowDirentsDraggablePreview: PropTypes.func,
2018-10-13 09:07:54 +00:00
};
2020-05-06 10:24:16 +00:00
class DirentListItem extends React.Component {
2018-10-13 09:07:54 +00:00
constructor(props) {
super(props);
this.state = {
isOperationShow: false,
highlight: false,
isZipDialogOpen: false,
isMoveDialogShow: false,
isCopyDialogShow: false,
isShareDialogShow: false,
isMutipleOperation: false,
2018-12-18 01:02:16 +00:00
isShowTagTooltip: false,
2019-03-27 03:25:27 +00:00
isDragTipShow: false,
isDropTipshow: false,
2019-04-17 02:48:44 +00:00
isEditFileTagShow: false,
isPermissionDialogOpen: false,
isOpMenuOpen: false // for mobile
2018-10-13 09:07:54 +00:00
};
const { dirent } = this.props;
const { isCustomPermission, customPermission } = Utils.getUserPermission(dirent.permission);
this.isCustomPermission = isCustomPermission;
this.customPermission = customPermission;
this.canPreview = true;
this.canDrag = dirent.permission === 'rw';
if (isCustomPermission) {
const { preview, modify } = customPermission.permission;
this.canPreview = preview || modify;
this.canDrag = modify;
}
2018-10-13 09:07:54 +00:00
}
componentWillReceiveProps(nextProps) {
2020-04-11 09:54:52 +00:00
if (nextProps.isItemFreezed !== this.props.isItemFreezed && !nextProps.isItemFreezed) {
this.setState({
highlight: false,
isOperationShow: false,
2019-04-13 08:56:06 +00:00
}, () => {
if (nextProps.activeDirent && nextProps.activeDirent.name === nextProps.dirent.name) {
this.setState({isOperationShow: true});
}
});
}
}
toggleOpMenu = () => {
this.setState({
isOpMenuOpen: !this.state.isOpMenuOpen
});
}
2018-10-13 09:07:54 +00:00
//UI Interactive
onMouseEnter = () => {
if (!this.props.isItemFreezed) {
this.setState({
highlight: true,
isOperationShow: true,
});
}
if (this.canDrag) {
this.setState({isDragTipShow: true});
}
2018-10-13 09:07:54 +00:00
}
onMouseOver = () => {
if (!this.props.isItemFreezed) {
this.setState({
highlight: true,
isOperationShow: true,
});
}
if (this.canDrag) {
this.setState({isDragTipShow: true});
}
2018-10-13 09:07:54 +00:00
}
onMouseLeave = () => {
if (!this.props.isItemFreezed) {
this.setState({
highlight: false,
isOperationShow: false,
});
}
this.setState({isDragTipShow: false});
2018-10-13 09:07:54 +00:00
}
2019-04-22 04:18:35 +00:00
unfreezeItem = () => {
2018-10-13 09:07:54 +00:00
this.setState({
2019-01-16 09:44:44 +00:00
highlight: false,
2018-10-13 09:07:54 +00:00
isOperationShow: false,
});
2019-04-22 04:18:35 +00:00
this.props.unfreezeItem();
2018-10-13 09:07:54 +00:00
}
//buiness handler
onItemSelected = () => {
2018-11-23 12:19:42 +00:00
this.props.onItemSelected(this.props.dirent);
2018-10-13 09:07:54 +00:00
}
2018-11-22 03:26:00 +00:00
onItemStarred = (e) => {
let dirent = this.props.dirent;
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let filePath = this.getDirentPath(dirent);
2019-02-18 12:26:55 +00:00
e.preventDefault();
if (dirent.starred) {
2019-03-27 03:28:00 +00:00
seafileAPI.unstarItem(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'starred', false);
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
} else {
2019-02-18 12:26:55 +00:00
seafileAPI.starItem(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'starred', true);
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
2018-10-13 09:07:54 +00:00
}
2018-11-22 03:26:00 +00:00
// on '<tr>'
onDirentClick = (e) => {
// '<td>' is clicked
2019-04-13 05:35:33 +00:00
e.stopPropagation();
if (e.target.tagName == 'TD') {
this.props.onDirentClick(this.props.dirent);
}
}
2018-11-30 03:52:19 +00:00
onItemClick = (e) => {
e.preventDefault();
const dirent = this.props.dirent;
if (this.state.isRenameing) {
return;
}
if (dirent.isDir()) {
this.props.onItemClick(dirent);
return;
}
if (!this.canPreview) {
return;
}
if (Utils.imageCheck(dirent.name)) {
this.props.showImagePopup(dirent);
} else {
this.props.onItemClick(dirent);
}
}
onItemDelete = (e) => {
e.preventDefault();
e.nativeEvent.stopImmediatePropagation(); //for document event
2018-11-22 03:26:00 +00:00
this.props.onItemDelete(this.props.dirent);
}
onItemShare = (e) => {
e.preventDefault();
e.nativeEvent.stopImmediatePropagation(); //for document event
this.setState({isShareDialogShow: !this.state.isShareDialogShow});
}
closeSharedDialog = () => {
this.setState({isShareDialogShow: !this.state.isShareDialogShow});
}
onMobileMenuItemClick = (e) => {
const operation = e.target.getAttribute('data-op');
this.onMenuItemClick(operation, e);
}
2019-04-21 09:56:55 +00:00
onMenuItemClick = (operation, event) => {
switch(operation) {
case 'Download':
this.onItemDownload(event);
break;
case 'Share':
this.onItemShare(event);
break;
case 'Delete':
this.onItemDelete(event);
break;
case 'Rename':
this.onItemRenameToggle();
break;
case 'Move':
this.onItemMoveToggle();
break;
case 'Copy':
this.onItemCopyToggle();
break;
2019-04-17 02:48:44 +00:00
case 'Tags':
this.onEditFileTagToggle();
break;
case 'Permission':
this.onPermissionItem();
break;
case 'Unlock':
this.onUnlockItem();
break;
case 'Lock':
this.onLockItem();
break;
2023-07-17 08:18:14 +00:00
case 'Mark as draft':
this.onMarkAsDraft();
break;
2023-07-17 08:18:14 +00:00
case 'Unmark as draft':
this.onUnmarkAsDraft();
break;
2023-07-07 08:07:14 +00:00
case 'List revisions':
this.openRevisionsPage();
break;
case 'Comment':
2019-05-30 06:48:25 +00:00
this.props.onDirentClick(this.props.dirent);
2019-05-29 04:02:07 +00:00
this.props.showDirentDetail('comments');
break;
case 'History':
this.onHistory();
break;
case 'Access Log':
this.onAccessLog();
break;
case 'Open via Client':
this.onOpenViaClient();
break;
case 'Convert with ONLYOFFICE':
this.onConvertWithONLYOFFICE();
break;
default:
break;
}
}
2019-04-17 02:48:44 +00:00
onEditFileTagToggle = () => {
this.setState({
isEditFileTagShow: !this.state.isEditFileTagShow
});
}
onFileTagChanged = () => {
let direntPath = this.getDirentPath(this.props.dirent);
this.props.onFileTagChanged(this.props.dirent, direntPath);
}
2018-11-23 12:19:42 +00:00
onItemRenameToggle = () => {
this.props.onItemRenameToggle(this.props.dirent);
this.setState({
isOperationShow: false,
isRenameing: true,
});
}
onRenameConfirm = (newName) => {
2018-11-22 03:26:00 +00:00
this.props.onItemRename(this.props.dirent, newName);
this.onRenameCancel();
}
onRenameCancel = () => {
2019-01-16 09:44:44 +00:00
this.setState({isRenameing: false});
2019-04-22 04:18:35 +00:00
this.unfreezeItem();
}
2018-11-22 03:26:00 +00:00
2018-11-23 12:19:42 +00:00
onItemMoveToggle = () => {
this.setState({isMoveDialogShow: !this.state.isMoveDialogShow});
}
2018-11-23 12:19:42 +00:00
onItemCopyToggle = () => {
this.setState({isCopyDialogShow: !this.state.isCopyDialogShow});
2018-10-13 09:07:54 +00:00
}
onPermissionItem = () => {
this.setState({isPermissionDialogOpen: !this.state.isPermissionDialogOpen});
2018-10-13 09:07:54 +00:00
}
onLockItem = () => {
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.lockfile(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'is_locked', true);
this.props.updateDirent(this.props.dirent, 'locked_by_me', true);
2019-04-23 02:32:12 +00:00
let lockName = username.split('@');
this.props.updateDirent(this.props.dirent, 'lock_owner_name', lockName[0]);
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
onUnlockItem = () => {
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.unlockfile(repoID, filePath).then(() => {
this.props.updateDirent(this.props.dirent, 'is_locked', false);
this.props.updateDirent(this.props.dirent, 'locked_by_me', false);
2019-04-23 02:32:12 +00:00
this.props.updateDirent(this.props.dirent, 'lock_owner_name', '');
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
2023-07-17 08:18:14 +00:00
onMarkAsDraft = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.sdocMarkAsDraft(repoID, filePath).then((res) => {
this.props.updateDirent(this.props.dirent, 'is_sdoc_draft', true);
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
2023-07-17 08:18:14 +00:00
onUnmarkAsDraft = () => {
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
seafileAPI.sdocUnmarkAsDraft(repoID, filePath).then((res) => {
this.props.updateDirent(this.props.dirent, 'is_sdoc_draft', false);
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
2023-07-07 08:07:14 +00:00
openRevisionsPage = () => {
const repoID = this.props.repoID;
const filePath = this.getDirentPath(this.props.dirent);
const url = Utils.generateRevisionsURL(siteRoot, repoID, filePath);
if (!url) return;
window.open(url);
}
onHistory = () => {
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
let url = URLDecorator.getUrl({type: 'file_revisions', repoID: repoID, filePath: filePath});
location.href = url;
}
onAccessLog = () => {
2019-05-28 02:43:17 +00:00
let filePath = this.getDirentPath(this.props.dirent);
let path = siteRoot + 'repo/file-access/' + this.props.repoID + '/?p=' + encodeURIComponent(filePath) ;
window.open(path);
}
onOpenViaClient = () => {
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let filePath = this.getDirentPath(this.props.dirent);
let url = URLDecorator.getUrl({type: 'open_via_client', repoID: repoID, filePath: filePath});
location.href = url;
}
onConvertWithONLYOFFICE = ()=> {
2021-09-18 04:35:23 +00:00
let repoID = this.props.repoID;
2021-09-18 04:35:23 +00:00
let filePath = this.getDirentPath(this.props.dirent)
seafileAPI.onlyofficeConvert(repoID, filePath).then(res => {
this.props.loadDirentList(res.data.parent_dir)
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
});
}
onItemDownload = (e) => {
e.preventDefault();
e.nativeEvent.stopImmediatePropagation();
let dirent = this.props.dirent;
2018-11-28 04:41:49 +00:00
let repoID = this.props.repoID;
let direntPath = this.getDirentPath(dirent);
if (dirent.type === 'dir') {
if (!useGoFileserver) {
this.setState({
isZipDialogOpen: true
});
} else {
seafileAPI.zipDownload(repoID, this.props.path, this.props.dirent.name).then((res) => {
const zipToken = res.data['zip_token'];
location.href = `${fileServerRoot}zip/${zipToken}`;
}).catch((error) => {
let errorMsg = Utils.getErrorMsg(error);
this.setState({
isLoading: false,
errorMsg: errorMsg
});
});
}
} else {
let url = URLDecorator.getUrl({type: 'download_file_url', repoID: repoID, filePath: direntPath});
location.href = url;
}
}
closeZipDialog = () => {
this.setState({
isZipDialogOpen: false
});
}
getDirentPath = (dirent) => {
2018-11-22 03:26:00 +00:00
let path = this.props.path;
return path === '/' ? path + dirent.name : path + '/' + dirent.name;
2018-10-13 09:07:54 +00:00
}
2018-12-18 01:02:16 +00:00
onTagTooltipToggle = (e) => {
e.stopPropagation();
this.setState({isShowTagTooltip: !this.state.isShowTagTooltip});
2018-12-18 01:02:16 +00:00
}
2019-03-27 03:25:27 +00:00
onItemMove = (destRepo, dirent, selectedPath, currentPath) => {
this.props.onItemMove(destRepo, dirent, selectedPath, currentPath);
}
onItemDragStart = (e) => {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
e.dataTransfer.effectAllowed = 'move';
2019-06-17 08:11:54 +00:00
let { selectedDirentList } = this.props;
if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item
2019-07-26 06:55:09 +00:00
this.props.onShowDirentsDraggablePreview();
e.dataTransfer.setDragImage(this.refs.empty_content, 0, 0); // Show an empty content
2019-06-18 13:35:39 +00:00
let selectedList = selectedDirentList.map(item => {
let nodeRootPath = this.getDirentPath(item);
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
2019-06-18 09:55:57 +00:00
return dragStartItemData;
});
2019-06-17 08:11:54 +00:00
selectedList = JSON.stringify(selectedList);
e.dataTransfer.setData('applicaiton/drag-item-info', selectedList);
return ;
}
2019-07-26 06:55:09 +00:00
if (e.dataTransfer && e.dataTransfer.setDragImage) {
e.dataTransfer.setDragImage(this.refs.drag_icon, 15, 15);
}
2019-06-18 13:35:39 +00:00
let nodeRootPath = this.getDirentPath(this.props.dirent);
let dragStartItemData = {nodeDirent: this.props.dirent, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
2019-06-17 08:11:54 +00:00
dragStartItemData = JSON.stringify(dragStartItemData);
2019-03-27 03:25:27 +00:00
e.dataTransfer.setData('applicaiton/drag-item-info', dragStartItemData);
}
onItemDragEnter = (e) => {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
2019-03-27 03:25:27 +00:00
if (this.props.dirent.type === 'dir') {
e.stopPropagation();
2019-03-27 03:25:27 +00:00
this.setState({isDropTipshow: true});
}
}
2019-03-27 03:25:27 +00:00
onItemDragOver = (e) => {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
if (e.dataTransfer.dropEffect === 'copy') {
return;
}
2019-03-27 03:25:27 +00:00
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
}
onItemDragLeave = (e) => {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
if (this.props.dirent.type === 'dir') {
e.stopPropagation();
}
2019-03-27 03:25:27 +00:00
this.setState({isDropTipshow: false});
}
onItemDragDrop = (e) => {
if (Utils.isIEBrower() || !this.canDrag) {
return false;
}
2019-03-27 03:25:27 +00:00
this.setState({isDropTipshow: false});
if (e.dataTransfer.files.length) { // uploaded files
return;
}
if (this.props.dirent.type === 'dir') {
e.stopPropagation();
2019-07-26 06:55:09 +00:00
} else {
return;
}
2019-03-27 03:25:27 +00:00
let dragStartItemData = e.dataTransfer.getData('applicaiton/drag-item-info');
dragStartItemData = JSON.parse(dragStartItemData);
2019-06-17 08:11:54 +00:00
if (Array.isArray(dragStartItemData)) { //move items
2019-06-18 13:35:39 +00:00
let direntPaths = dragStartItemData.map(draggedItem => {
2019-06-21 05:59:17 +00:00
return draggedItem.nodeRootPath;
2019-06-17 08:11:54 +00:00
});
let selectedPath = Utils.joinPath(this.props.path, this.props.dirent.name);
if (direntPaths.some(direntPath => { return direntPath === selectedPath;})) { //eg; A/B, A/C --> A/B
return;
}
2019-06-17 08:11:54 +00:00
this.props.onItemsMove(this.props.currentRepoInfo, selectedPath);
return ;
}
2019-06-18 04:06:24 +00:00
let { nodeDirent, nodeParentPath, nodeRootPath } = dragStartItemData;
2019-03-27 03:25:27 +00:00
let dropItemData = this.props.dirent;
if (nodeDirent.name === dropItemData.name) {
return;
}
// copy the dirent to it's child. eg: A/B -> A/B/C
if (dropItemData.type === 'dir' && nodeDirent.type === 'dir') {
if (nodeParentPath !== this.props.path) {
if (this.props.path.indexOf(nodeRootPath) !== -1) {
return;
}
}
}
let selectedPath = Utils.joinPath(this.props.path, this.props.dirent.name);
this.onItemMove(this.props.currentRepoInfo, nodeDirent, selectedPath, nodeParentPath);
}
onItemMouseDown = (event) => {
this.props.onItemMouseDown(event);
}
onItemContextMenu = (event) => {
let dirent = this.props.dirent;
this.props.onItemContextMenu(event, dirent);
}
2019-04-18 09:32:34 +00:00
renderItemOperation = () => {
2019-12-23 04:03:06 +00:00
let { dirent, currentRepoInfo, selectedDirentList } = this.props;
let canDownload = true;
let canDelete = true;
const { isCustomPermission, customPermission } = this;
if (isCustomPermission) {
const { permission } = customPermission;
canDownload = permission.download;
canDelete = permission.delete;
}
// https://dev.seafile.com/seahub/lib/d6f300e7-bb2b-4722-b83e-cf45e370bfbc/file/seaf-server%20%E5%8A%9F%E8%83%BD%E8%AE%BE%E8%AE%A1/%E6%9D%83%E9%99%90%E7%9B%B8%E5%85%B3/%E8%B5%84%E6%96%99%E5%BA%93%E6%9D%83%E9%99%90%E8%A7%84%E8%8C%83.md
2019-12-23 04:03:06 +00:00
let showShareBtn = Utils.isHasPermissionToShare(currentRepoInfo, dirent.permission, dirent);
2019-06-21 02:44:41 +00:00
2019-04-18 09:32:34 +00:00
return (
<Fragment>
{selectedDirentList.length > 1 ?
2019-04-18 09:32:34 +00:00
<Fragment>
{this.state.isOperationShow && !dirent.isSelected &&
<div className="operations">
{(dirent.permission === 'rw' || dirent.permission === 'r' || (isCustomPermission && canDownload)) && (
<a href="#" className="op-icon sf2-icon-download" title={gettext('Download')} role="button" aria-label={gettext('Download')} onClick={this.onItemDownload}></a>
)}
{showShareBtn && (
<a href="#" className="op-icon sf2-icon-share" title={gettext('Share')} role="button" aria-label={gettext('Share')} onClick={this.onItemShare}></a>
)}
{(dirent.permission === 'rw' || (isCustomPermission && canDelete)) && (
<a href="#" className="op-icon sf2-icon-delete" title={gettext('Delete')} role="button" aria-label={gettext('Delete')} onClick={this.onItemDelete}></a>
)}
<ItemDropdownMenu
item={this.props.dirent}
toggleClass={'sf2-icon-caret-down'}
isHandleContextMenuEvent={true}
getMenuList={this.props.getDirentItemMenuList}
onMenuItemClick={this.onMenuItemClick}
unfreezeItem={this.unfreezeItem}
freezeItem={this.props.freezeItem}
/>
2019-04-18 09:32:34 +00:00
</div>
}
</Fragment> :
2019-04-18 09:32:34 +00:00
<Fragment>
{this.state.isOperationShow &&
2019-04-18 09:32:34 +00:00
<div className="operations">
{(dirent.permission === 'rw' || dirent.permission === 'r' || (isCustomPermission && canDownload)) && (
<a href="#" className="op-icon sf2-icon-download" title={gettext('Download')} role="button" aria-label={gettext('Download')} onClick={this.onItemDownload}></a>
)}
{showShareBtn && (
<a href="#" className="op-icon sf2-icon-share" title={gettext('Share')} role="button" aria-label={gettext('Share')} onClick={this.onItemShare}></a>
)}
{(dirent.permission === 'rw' || (isCustomPermission && canDelete)) && (
<a href="#" className="op-icon sf2-icon-delete" title={gettext('Delete')} role="button" aria-label={gettext('Delete')} onClick={this.onItemDelete}></a>
)}
<ItemDropdownMenu
item={this.props.dirent}
toggleClass={'sf2-icon-caret-down'}
isHandleContextMenuEvent={true}
getMenuList={this.props.getDirentItemMenuList}
onMenuItemClick={this.onMenuItemClick}
unfreezeItem={this.unfreezeItem}
freezeItem={this.props.freezeItem}
/>
2019-04-18 09:32:34 +00:00
</div>
}
</Fragment>
}
</Fragment>
);
2019-04-18 09:32:34 +00:00
}
2018-10-13 09:07:54 +00:00
render() {
2019-04-18 09:32:34 +00:00
let { path, dirent, activeDirent } = this.props;
2018-11-30 03:52:19 +00:00
let direntPath = Utils.joinPath(path, dirent.name);
let dirHref = '';
if (this.props.currentRepoInfo) {
dirHref = siteRoot + 'library/' + this.props.repoID + '/' + this.props.currentRepoInfo.repo_name + Utils.encodePath(direntPath);
}
2019-01-02 03:52:44 +00:00
let fileHref = siteRoot + 'lib/' + this.props.repoID + '/file' + Utils.encodePath(direntPath);
let toolTipID = '';
2018-12-17 10:43:18 +00:00
let tagTitle = '';
2018-12-18 01:02:16 +00:00
if (dirent.file_tags && dirent.file_tags.length > 0) {
toolTipID = MD5(dirent.name).slice(0, 7);
tagTitle = dirent.file_tags.map(item => item.name).join(' ');
2018-12-17 10:43:18 +00:00
}
let iconUrl = Utils.getDirentIcon(dirent);
let trClass = this.state.highlight ? 'tr-highlight ' : '';
trClass += this.state.isDropTipshow ? 'tr-drop-effect' : '';
trClass += (activeDirent && activeDirent.name === dirent.name) ? 'tr-active' : '';
trClass += dirent.isSelected? 'tr-active' : '';
let lockedInfo = gettext('locked by {name}').replace('{name}', dirent.lock_owner_name);
const isDesktop = Utils.isDesktop();
const desktopItem = (
<tr
className={trClass}
draggable={this.canDrag}
onFocus={this.onMouseEnter}
onMouseEnter={this.onMouseEnter}
onMouseOver={this.onMouseOver}
onMouseLeave={this.onMouseLeave}
onClick={this.onDirentClick}
onDragStart={this.onItemDragStart}
onDragEnter={this.onItemDragEnter}
onDragOver={this.onItemDragOver}
onDragLeave={this.onItemDragLeave}
onDrop={this.onItemDragDrop}
onMouseDown={this.onItemMouseDown}
onContextMenu={this.onItemContextMenu}
>
<td className={`pl10 ${this.state.isDragTipShow ? 'tr-drag-effect' : ''}`}>
<input type="checkbox" className="vam" onChange={this.onItemSelected} checked={dirent.isSelected}/>
</td>
<td className="pl10">
{dirent.starred !== undefined &&
<a href="#" role="button" aria-label={dirent.starred ? gettext('Unstar') : gettext('Star')} onClick={this.onItemStarred}>
<i className={`fa-star ${dirent.starred ? 'fas' : 'far star-empty'}`}></i>
</a>
}
</td>
<td className="pl10">
<div className="dir-icon">
2022-08-11 02:55:53 +00:00
{(this.canPreview && dirent.encoded_thumbnail_src) ?
<img ref='drag_icon' src={`${siteRoot}${dirent.encoded_thumbnail_src}`} className="thumbnail cursor-pointer" onClick={this.onItemClick} alt="" /> :
<img ref='drag_icon' src={iconUrl} width="24" alt='' />
}
{dirent.is_locked && <img className="locked" src={mediaUrl + 'img/file-locked-32.png'} alt={gettext('locked')} title={lockedInfo}/>}
<div ref="empty_content" style={{position: 'absolute', width: '1px', height: '1px'}}></div>
</div>
</td>
<td className="name">
{this.state.isRenameing && <Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} />}
{!this.state.isRenameing && (
<Fragment>
{(!dirent.isDir() && !this.canPreview) ?
<a className="sf-link" onClick={this.onItemClick}>{dirent.name}</a> :
<a href={dirent.type === 'dir' ? dirHref : fileHref} onClick={this.onItemClick}>{dirent.name}</a>
}
{(Utils.isSdocFile(dirent.name) && dirent.is_sdoc_draft) &&
<span className="sdoc-draft-identifier">{gettext('Draft')}</span>
}
</Fragment>
)}
</td>
<td className="tag-list-title">
{(dirent.type !== 'dir' && dirent.file_tags && dirent.file_tags.length > 0) && (
<Fragment>
<div id={`tag-list-title-${toolTipID}`} className="dirent-item tag-list tag-list-stacked">
{dirent.file_tags.map((fileTag, index) => {
let length = dirent.file_tags.length;
return (
<span className="file-tag" key={fileTag.id} style={{zIndex:length - index, backgroundColor:fileTag.color}}></span>
);
})}
</div>
<UncontrolledTooltip target={`tag-list-title-${toolTipID}`} placement="bottom">
{tagTitle}
</UncontrolledTooltip>
</Fragment>
)}
</td>
<td className="operation">{this.renderItemOperation()}</td>
<td className="file-size">{dirent.size && dirent.size}</td>
<td className="last-update" title={moment.unix(dirent.mtime).format('llll')}>{dirent.mtime_relative}</td>
</tr>
);
const mobileItem = (
<tr>
<td onClick={this.onItemClick}>
<div className="dir-icon">
2022-08-11 02:55:53 +00:00
{(this.canPreview && dirent.encoded_thumbnail_src) ?
<img src={`${siteRoot}${dirent.encoded_thumbnail_src}`} className="thumbnail cursor-pointer" alt="" /> :
<img src={iconUrl} width="24" alt="" />
}
{dirent.is_locked && <img className="locked" src={mediaUrl + 'img/file-locked-32.png'} alt={gettext('locked')} title={lockedInfo}/>}
</div>
</td>
<td onClick={this.onItemClick}>
{this.state.isRenameing && <Rename hasSuffix={dirent.type !== 'dir'} name={dirent.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel} /> }
{!this.state.isRenameing && (
<Fragment>
{(!dirent.isDir() && !this.canPreview) ?
<a className="sf-link">{dirent.name}</a> :
<a href={dirent.type === 'dir' ? dirHref : fileHref}>{dirent.name}</a>
}
</Fragment>
)}
<br />
{dirent.size && <span className="item-meta-info">{dirent.size}</span>}
<span className="item-meta-info">{dirent.mtime_relative}</span>
</td>
<td>
<Dropdown isOpen={this.state.isOpMenuOpen} toggle={this.toggleOpMenu}>
<DropdownToggle
tag="i"
className="sf-dropdown-toggle fa fa-ellipsis-v ml-0"
title={gettext('More Operations')}
data-toggle="dropdown"
aria-expanded={this.state.isOpMenuOpen}
/>
<div className={this.state.isOpMenuOpen ? '' : 'd-none'} onClick={this.toggleOpMenu}>
<div className="mobile-operation-menu-bg-layer"></div>
<div className="mobile-operation-menu">
{dirent.starred !== undefined &&
<DropdownItem className="mobile-menu-item" onClick={this.onItemStarred}>{dirent.starred ? gettext('Unstar') : gettext('Star')}</DropdownItem>}
{this.props.getDirentItemMenuList(dirent, true).map((item, index) => {
if (item != 'Divider' && item.key != 'Open via Client') {
2018-12-18 01:02:16 +00:00
return (
<DropdownItem className="mobile-menu-item" key={index} data-op={item.key} onClick={this.onMobileMenuItemClick}>{item.value}</DropdownItem>
2018-12-18 01:02:16 +00:00
);
} else {
return null;
}
})}
</div>
</div>
</Dropdown>
</td>
</tr>
);
return (
<Fragment>
{isDesktop ? desktopItem : mobileItem}
{this.state.isMoveDialogShow &&
<ModalPortal>
<MoveDirentDialog
path={this.props.path}
2018-11-28 04:41:49 +00:00
repoID={this.props.repoID}
dirent={this.props.dirent}
isMutipleOperation={this.state.isMutipleOperation}
onItemMove={this.props.onItemMove}
onCancelMove={this.onItemMoveToggle}
2019-03-11 03:14:49 +00:00
repoEncrypted={this.props.repoEncrypted}
/>
</ModalPortal>
}
{this.state.isCopyDialogShow &&
<ModalPortal>
<CopyDirentDialog
path={this.props.path}
2018-11-28 04:41:49 +00:00
repoID={this.props.repoID}
dirent={this.props.dirent}
isMutipleOperation={this.state.isMutipleOperation}
onItemCopy={this.props.onItemCopy}
onCancelCopy={this.onItemCopyToggle}
2019-03-11 03:14:49 +00:00
repoEncrypted={this.props.repoEncrypted}
/>
</ModalPortal>
}
2019-04-17 02:48:44 +00:00
{this.state.isEditFileTagShow &&
<EditFileTagDialog
repoID={this.props.repoID}
fileTagList={dirent.file_tags}
filePath={direntPath}
toggleCancel={this.onEditFileTagToggle}
onFileTagChanged={this.onFileTagChanged}
/>
}
{this.state.isZipDialogOpen &&
<ModalPortal>
<ZipDownloadDialog
repoID={this.props.repoID}
path={this.props.path}
target={this.props.dirent.name}
toggleDialog={this.closeZipDialog}
/>
</ModalPortal>
}
{this.state.isShareDialogShow &&
<ModalPortal>
<ShareDialog
2018-12-14 07:09:07 +00:00
itemType={dirent.type}
itemName={dirent.name}
2018-12-14 07:09:07 +00:00
itemPath={direntPath}
2019-01-29 02:06:26 +00:00
userPerm={dirent.permission}
repoID={this.props.repoID}
repoEncrypted={this.props.repoEncrypted}
2019-01-29 02:06:26 +00:00
enableDirPrivateShare={this.props.enableDirPrivateShare}
isGroupOwnedRepo={this.props.isGroupOwnedRepo}
toggleDialog={this.closeSharedDialog}
/>
</ModalPortal>
}
{this.state.isPermissionDialogOpen &&
<ModalPortal>
<LibSubFolderPermissionDialog
toggleDialog={this.onPermissionItem}
repoID={this.props.repoID}
folderPath={direntPath}
folderName={dirent.name}
isDepartmentRepo={this.props.isGroupOwnedRepo}
/>
</ModalPortal>
}
</Fragment>
2018-10-13 09:07:54 +00:00
);
}
}
DirentListItem.propTypes = propTypes;
export default DirentListItem;