1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-15 16:04:01 +00:00

modify move_copy sync api

This commit is contained in:
zxj96 2019-06-12 14:59:33 +08:00 committed by plt
parent 82a6196b24
commit abc51fb659

View File

@ -544,16 +544,35 @@ class LibContentView extends React.Component {
let direntPaths = this.getSelectedDirentPaths(); let direntPaths = this.getSelectedDirentPaths();
let dirNames = this.getSelectedDirentNames(); let dirNames = this.getSelectedDirentNames();
seafileAPI.moveDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => { let temporaryData = [];
let names = res.data.map(item => {
return item.obj_name; if (repoID === destRepo.repo_id) {
seafileAPI.listDir(repoID, destDirentPath).then(res => {
temporaryData = res.data.dirent_list;
}); });
}
seafileAPI.moveDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
direntPaths.forEach((direntPath, index) => { direntPaths.forEach((direntPath, index) => {
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
this.moveTreeNode(direntPath, destDirentPath, destRepo, names[index]); this.deleteTreeNode(direntPath);
} }
this.moveDirent(direntPath); this.moveDirent(direntPath);
}); });
if (repoID === destRepo.repo_id) {
if (this.state.currentMode === 'column') {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(destDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => {
let name = res.data.dirent_list;
let names = this.compareArray(temporaryData, name);
names.map(item => {
this.addNodeToTree(item.name, destDirentPath, item.type)
})
});
}
}
let message = Utils.getMoveSuccessMessage(dirNames); let message = Utils.getMoveSuccessMessage(dirNames);
toaster.success(message); toaster.success(message);
}).catch(() => { }).catch(() => {
@ -567,15 +586,27 @@ class LibContentView extends React.Component {
let direntPaths = this.getSelectedDirentPaths(); let direntPaths = this.getSelectedDirentPaths();
let dirNames = this.getSelectedDirentNames(); let dirNames = this.getSelectedDirentNames();
seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => { let temporaryData = [];
let names = res.data.map(item => { if (repoID === destRepo.repo_id) {
return item.obj_name; seafileAPI.listDir(repoID, destDirentPath).then(res => {
temporaryData = res.data.dirent_list;
}); });
if (this.state.currentMode === 'column') { }
direntPaths.forEach((direntPath, index) => { seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
this.copyTreeNode(direntPath, destDirentPath, destRepo, names[index]); if (repoID === destRepo.repo_id) {
}); if (this.state.currentMode === 'column') {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(destDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => {
let name = res.data.dirent_list;
let names = this.compareArray(temporaryData, name);
names.map(item => {
this.addNodeToTree(item.name, destDirentPath, item.type)
})
});
}
} }
if (destDirentPath === this.state.path) { if (destDirentPath === this.state.path) {
this.loadDirentList(this.state.path); this.loadDirentList(this.state.path);
} }
@ -755,6 +786,26 @@ class LibContentView extends React.Component {
} }
} }
compareArray = (arr1, arr2) => {
let result = [];
for (let i = 0; i < arr2.length; i++) {
let obj = arr2[i];
let a = obj.name;
let isExist = false;
for (let j = 0; j < arr1.length; j++) {
let b = arr1[j].name;
if (a === b) {
isExist = true;
break;
}
}
if (!isExist) {
result.push(obj)
}
}
return result;
}
// list&tree operations // list&tree operations
onMainPanelItemRename = (dirent, newName) => { onMainPanelItemRename = (dirent, newName) => {
let path = Utils.joinPath(this.state.path, dirent.name); let path = Utils.joinPath(this.state.path, dirent.name);
@ -845,10 +896,24 @@ class LibContentView extends React.Component {
nodeParentPath = this.state.path; nodeParentPath = this.state.path;
} }
let direntPath = Utils.joinPath(nodeParentPath, dirName); let direntPath = Utils.joinPath(nodeParentPath, dirName);
let temporaryData = [];
if (repoID === destRepo.repo_id) {
seafileAPI.listDir(repoID, moveToDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
}
seafileAPI.moveDir(repoID, destRepo.repo_id, moveToDirentPath, nodeParentPath, dirName).then(res => { seafileAPI.moveDir(repoID, destRepo.repo_id, moveToDirentPath, nodeParentPath, dirName).then(res => {
let nodeName = res.data[0].obj_name;
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
this.moveTreeNode(direntPath, moveToDirentPath, destRepo, nodeName); this.deleteTreeNode(direntPath);
if (repoID === destRepo.repo_id) {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(moveToDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => {
let name = res.data.dirent_list;
let names = this.compareArray(temporaryData, name);
this.addNodeToTree(names[0].name, moveToDirentPath, dirent.type)
});
}
} }
this.moveDirent(direntPath, moveToDirentPath); this.moveDirent(direntPath, moveToDirentPath);
@ -870,11 +935,26 @@ class LibContentView extends React.Component {
nodeParentPath = this.state.path; nodeParentPath = this.state.path;
} }
let direntPath = Utils.joinPath(nodeParentPath, dirName); let direntPath = Utils.joinPath(nodeParentPath, dirName);
let temporaryData = [];
seafileAPI.listDir(repoID, copyToDirentPath).then(res => {
temporaryData = res.data.dirent_list;
});
seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => { seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => {
let nodeName = res.data[0].obj_name;
if (this.state.currentMode === 'column') { if (this.state.currentMode === 'column') {
this.copyTreeNode(direntPath, copyToDirentPath, destRepo, nodeName); if (repoID === destRepo.repo_id) {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(copyToDirentPath);
seafileAPI.listDir(repoID, node.path).then(res => {
let name = res.data.dirent_list;
let names = this.compareArray(temporaryData, name);
this.addNodeToTree(names[0].name, copyToDirentPath, dirent.type)
});
}
} }
if (copyToDirentPath === nodeParentPath) { if (copyToDirentPath === nodeParentPath) {
this.loadDirentList(this.state.path); this.loadDirentList(this.state.path);
} }