mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 00:20:07 +00:00
Modify the motion algorithm
This commit is contained in:
@@ -111,7 +111,8 @@ class CopyDirent extends React.Component {
|
||||
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) {
|
||||
message = gettext('Can not copy directory %(src)s to its subdirectory %(des)s');
|
||||
message = message.replace('%(src)s', direntPath);
|
||||
|
@@ -100,10 +100,10 @@ class TreeView extends React.Component {
|
||||
}
|
||||
this.props.onItemsMove(this.props.currentRepoInfo, '/');
|
||||
this.setState({isTreeViewDropTipShow: false});
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
this.onMoveItems(dragStartNodeData, dropNodeData, this.props.currentRepoInfo, node.path);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dropNodeData) {
|
||||
@@ -134,9 +134,23 @@ class TreeView extends React.Component {
|
||||
// copy the dirent to it's child. eg: A/B -> A/B/C
|
||||
if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') {
|
||||
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;
|
||||
}
|
||||
// if (dropNodeData.path.indexOf(nodeRootPath) !== -1) {
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +159,7 @@ class TreeView extends React.Component {
|
||||
|
||||
onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => {
|
||||
let direntPaths = [];
|
||||
let destDirentPathArr = destDirentPath.split('/')
|
||||
dragStartNodeData.forEach(dirent => {
|
||||
let path = dirent.nodeRootPath;
|
||||
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
|
||||
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;
|
||||
});
|
||||
if (isChildPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dropNodeData) { //selectPath === '/'
|
||||
this.setState({isTreeViewDropTipShow: false});
|
||||
return;
|
||||
}
|
||||
|
||||
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 = () => {
|
||||
this.setState({isItemFreezed: true});
|
||||
}
|
||||
|
Reference in New Issue
Block a user