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

Modify the motion algorithm

This commit is contained in:
zxj96
2019-06-18 09:39:34 +08:00
parent 614d128dc4
commit ee9b319fb8
2 changed files with 36 additions and 10 deletions

View File

@@ -111,7 +111,8 @@ class CopyDirent extends React.Component {
return; return;
} }
// 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
//find problem eg ABC can't move AB/ABC and A can't move B/AB
if ( selectedPath && selectedPath.length > direntPath.length && selectedPath.indexOf(direntPath) > -1) { if ( selectedPath && selectedPath.length > direntPath.length && selectedPath.indexOf(direntPath) > -1) {
message = gettext('Can not copy directory %(src)s to its subdirectory %(des)s'); message = gettext('Can not copy directory %(src)s to its subdirectory %(des)s');
message = message.replace('%(src)s', direntPath); message = message.replace('%(src)s', direntPath);

View File

@@ -100,10 +100,10 @@ class TreeView extends React.Component {
} }
this.props.onItemsMove(this.props.currentRepoInfo, '/'); this.props.onItemsMove(this.props.currentRepoInfo, '/');
this.setState({isTreeViewDropTipShow: false}); this.setState({isTreeViewDropTipShow: false});
return ; return;
} }
this.onMoveItems(dragStartNodeData, dropNodeData, this.props.currentRepoInfo, node.path); this.onMoveItems(dragStartNodeData, dropNodeData, this.props.currentRepoInfo, node.path);
return ; return;
} }
if (!dropNodeData) { if (!dropNodeData) {
@@ -134,9 +134,23 @@ 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) {
if (dropNodeData.path.indexOf(nodeRootPath) !== -1) { let dropNodeDataArr = dropNodeData.path.split('/');
let nodeRootPathArr = nodeRootPath.split('/');
let isFather = '';
let smallArr = dropNodeDataArr.length > nodeRootPathArr.length ? nodeRootPathArr : dropNodeDataArr;
for (let i = 0; i< smallArr.length; i++) {
if (dropNodeDataArr[i] !== nodeRootPathArr[i]) {
isFather = smallArr[i];
break;
}
}
if (isFather.length === 0) {
return; return;
} }
// if (dropNodeData.path.indexOf(nodeRootPath) !== -1) {
// return;
// }
} }
} }
@@ -145,6 +159,7 @@ class TreeView extends React.Component {
onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => { onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => {
let direntPaths = []; let direntPaths = [];
let destDirentPathArr = destDirentPath.split('/')
dragStartNodeData.forEach(dirent => { dragStartNodeData.forEach(dirent => {
let path = dirent.nodeRootPath; let path = dirent.nodeRootPath;
direntPaths.push(path); direntPaths.push(path);
@@ -161,21 +176,31 @@ class TreeView extends React.Component {
// 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 flag = destDirentPath.length > direntPath.length && destDirentPath.indexOf(direntPath) > -1; let direntPathArr = direntPath.split('/');
let flag = this.compareArray(direntPathArr, destDirentPathArr);
return flag; return flag;
}); });
if (isChildPath) { if (isChildPath) {
return; return;
} }
if (!dropNodeData) { //selectPath === '/'
this.setState({isTreeViewDropTipShow: false});
return;
}
this.props.onItemsMove(destRepo, destDirentPath); this.props.onItemsMove(destRepo, destDirentPath);
} }
compareArray = (direntPathArr, destDirentPathArr) => {
if (destDirentPathArr.length < direntPathArr.length) { // 往上移
return false;
} else {
for (let i = 0; i < direntPathArr.length; i++) { //往下移
if (direntPathArr[i] !== destDirentPathArr[i]) {
return false;
}
}
}
return true;
}
freezeItem = () => { freezeItem = () => {
this.setState({isItemFreezed: true}); this.setState({isItemFreezed: true});
} }