mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-06 01:12:03 +00:00
optimization code
This commit is contained in:
@@ -359,12 +359,11 @@ class DirentListItem extends React.Component {
|
|||||||
let { selectedDirentList } = this.props;
|
let { selectedDirentList } = this.props;
|
||||||
let selectedList = [];
|
let selectedList = [];
|
||||||
if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item
|
if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item
|
||||||
selectedDirentList.map(item => {
|
selectedList = selectedDirentList.map(item => {
|
||||||
let nodeRootPath = '';
|
let nodeRootPath = this.getDirentPath(item);
|
||||||
nodeRootPath = this.props.path === '/' ? `${this.props.path}${item.name}` : `${this.props.path}/${item.name}`;
|
|
||||||
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
|
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
|
||||||
return selectedList.push(dragStartItemData)
|
return dragStartItemData;
|
||||||
})
|
});
|
||||||
selectedList = JSON.stringify(selectedList);
|
selectedList = JSON.stringify(selectedList);
|
||||||
e.dataTransfer.setData('applicaiton/drag-item-info', selectedList);
|
e.dataTransfer.setData('applicaiton/drag-item-info', selectedList);
|
||||||
return ;
|
return ;
|
||||||
@@ -414,8 +413,8 @@ class DirentListItem extends React.Component {
|
|||||||
dragStartItemData = JSON.parse(dragStartItemData);
|
dragStartItemData = JSON.parse(dragStartItemData);
|
||||||
if (Array.isArray(dragStartItemData)) { //move items
|
if (Array.isArray(dragStartItemData)) { //move items
|
||||||
let direntPaths = [];
|
let direntPaths = [];
|
||||||
dragStartItemData.forEach(dirent => {
|
dragStartItemData.forEach(draggedItem => {
|
||||||
let path = Utils.joinPath(this.props.path, dirent.nodeDirent.name);
|
let path = Utils.joinPath(this.props.path, draggedItem.nodeDirent.name);
|
||||||
direntPaths.push(path);
|
direntPaths.push(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -134,11 +134,10 @@ class TreeView extends React.Component {
|
|||||||
// copy the dirent to it's child. eg: A/B -> A/B/C
|
// copy the dirent to it's child. eg: A/B -> A/B/C
|
||||||
if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') {
|
if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') {
|
||||||
if (dropNodeData.parentNode.path !== nodeParentPath) {
|
if (dropNodeData.parentNode.path !== nodeParentPath) {
|
||||||
let dropNodeDataArr = dropNodeData.path.split('/');
|
let paths = Utils.getPaths(dropNodeData.path);
|
||||||
let nodeRootPathArr = nodeRootPath.split('/');
|
let isChildPath = paths.includes(nodeRootPath);
|
||||||
let flag = this.compareArray(nodeRootPathArr, dropNodeDataArr);
|
if (isChildPath) {
|
||||||
if (flag) {
|
return;
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +147,7 @@ class TreeView extends React.Component {
|
|||||||
|
|
||||||
onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => {
|
onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => {
|
||||||
let direntPaths = [];
|
let direntPaths = [];
|
||||||
let destDirentPathDetail = destDirentPath.split('/');
|
let paths = Utils.getPaths(destDirentPath);
|
||||||
dragStartNodeData.forEach(dirent => {
|
dragStartNodeData.forEach(dirent => {
|
||||||
let path = dirent.nodeRootPath;
|
let path = dirent.nodeRootPath;
|
||||||
direntPaths.push(path);
|
direntPaths.push(path);
|
||||||
@@ -168,11 +167,9 @@ class TreeView extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// move dirents to one of their child. eg: A/B, A/D -> A/B/C
|
// move dirents to one of their child. eg: A/B, A/D -> A/B/C
|
||||||
let isChildPath = direntPaths.some(direntPath => {
|
let isChildPath = direntPaths.some(direntPath => {
|
||||||
let direntPathdetail = direntPath.split('/');
|
let flag = paths.includes(direntPath);
|
||||||
let flag = this.compareArray(direntPathdetail, destDirentPathDetail);
|
|
||||||
return flag;
|
return flag;
|
||||||
});
|
});
|
||||||
if (isChildPath) {
|
if (isChildPath) {
|
||||||
@@ -182,19 +179,6 @@ class TreeView extends React.Component {
|
|||||||
this.props.onItemsMove(destRepo, destDirentPath);
|
this.props.onItemsMove(destRepo, destDirentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
compareArray = (direntPathdetail, destDirentPathDetail) => {
|
|
||||||
if (destDirentPathDetail.length < direntPathdetail.length) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < direntPathdetail.length; i++) {
|
|
||||||
if (direntPathdetail[i] !== destDirentPathDetail[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
freezeItem = () => {
|
freezeItem = () => {
|
||||||
this.setState({isItemFreezed: true});
|
this.setState({isItemFreezed: true});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user