mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 23:48:47 +00:00
optimization code
This commit is contained in:
@@ -538,9 +538,14 @@ class LibContentView extends React.Component {
|
|||||||
getThumbnail(0);
|
getThumbnail(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMoveCopyTreeNode = (temporaryData, path) => {
|
updateMoveCopyTreeNode = (path) => {
|
||||||
let repoID = this.props.repoID;
|
let repoID = this.props.repoID;
|
||||||
|
|
||||||
|
let tree = this.state.treeData.clone();
|
||||||
|
let node = tree.getNodeByPath(path);
|
||||||
|
|
||||||
|
let temporaryData = node.children.map(item => item.object);
|
||||||
|
|
||||||
seafileAPI.listDir(repoID, path).then(res => {
|
seafileAPI.listDir(repoID, path).then(res => {
|
||||||
let name = res.data.dirent_list;
|
let name = res.data.dirent_list;
|
||||||
let names = this.getTreeNodeNames(temporaryData, name);
|
let names = this.getTreeNodeNames(temporaryData, name);
|
||||||
@@ -549,6 +554,27 @@ class LibContentView extends React.Component {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTreeNodeNames = (beforeArrData, arrData) => {
|
||||||
|
let result = [];
|
||||||
|
for (let i = 0; i < arrData.length; i++) {
|
||||||
|
let obj = arrData[i];
|
||||||
|
let arrDataName = obj.name;
|
||||||
|
let isExist = false;
|
||||||
|
for (let j = 0; j < beforeArrData.length; j++) {
|
||||||
|
let beforeArrDataName = beforeArrData[j].name;
|
||||||
|
if (arrDataName === beforeArrDataName) {
|
||||||
|
isExist = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isExist) {
|
||||||
|
result.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// toolbar operations
|
// toolbar operations
|
||||||
@@ -567,10 +593,7 @@ class LibContentView extends React.Component {
|
|||||||
|
|
||||||
if (repoID === destRepo.repo_id) {
|
if (repoID === destRepo.repo_id) {
|
||||||
if (this.state.currentMode === 'column') {
|
if (this.state.currentMode === 'column') {
|
||||||
let tree = this.state.treeData.clone();
|
this.updateMoveCopyTreeNode(destDirentPath);
|
||||||
let node = tree.getNodeByPath(destDirentPath);
|
|
||||||
let temporaryData = node.children.map(item => item.object);
|
|
||||||
this.updateMoveCopyTreeNode(temporaryData, node.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let message = Utils.getMoveSuccessMessage(dirNames);
|
let message = Utils.getMoveSuccessMessage(dirNames);
|
||||||
@@ -589,10 +612,7 @@ class LibContentView extends React.Component {
|
|||||||
seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
|
seafileAPI.copyDir(repoID, destRepo.repo_id, destDirentPath, this.state.path, dirNames).then(res => {
|
||||||
if (repoID === destRepo.repo_id) {
|
if (repoID === destRepo.repo_id) {
|
||||||
if (this.state.currentMode === 'column') {
|
if (this.state.currentMode === 'column') {
|
||||||
let tree = this.state.treeData.clone();
|
this.updateMoveCopyTreeNode(destDirentPath);
|
||||||
let node = tree.getNodeByPath(destDirentPath);
|
|
||||||
let temporaryData = node.children.map(item => item.object);
|
|
||||||
this.updateMoveCopyTreeNode(temporaryData, node.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,26 +795,6 @@ class LibContentView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getTreeNodeNames = (beforeArrData, arrData) => {
|
|
||||||
let result = [];
|
|
||||||
for (let i = 0; i < arrData.length; i++) {
|
|
||||||
let obj = arrData[i];
|
|
||||||
let arrDataName = obj.name;
|
|
||||||
let isExist = false;
|
|
||||||
for (let j = 0; j < beforeArrData.length; j++) {
|
|
||||||
let beforeArrDataName = beforeArrData[j].name;
|
|
||||||
if (arrDataName === beforeArrDataName) {
|
|
||||||
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);
|
||||||
@@ -889,10 +889,7 @@ class LibContentView extends React.Component {
|
|||||||
if (this.state.currentMode === 'column') {
|
if (this.state.currentMode === 'column') {
|
||||||
this.deleteTreeNode(direntPath);
|
this.deleteTreeNode(direntPath);
|
||||||
if (repoID === destRepo.repo_id) {
|
if (repoID === destRepo.repo_id) {
|
||||||
let tree = this.state.treeData.clone();
|
this.updateMoveCopyTreeNode(moveToDirentPath);
|
||||||
let node = tree.getNodeByPath(moveToDirentPath);
|
|
||||||
let temporaryData = node.children.map(item => item.object);
|
|
||||||
this.updateMoveCopyTreeNode(temporaryData, node.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.moveDirent(direntPath, moveToDirentPath);
|
this.moveDirent(direntPath, moveToDirentPath);
|
||||||
@@ -919,10 +916,8 @@ class LibContentView extends React.Component {
|
|||||||
seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => {
|
seafileAPI.copyDir(repoID, destRepo.repo_id, copyToDirentPath, nodeParentPath, dirName).then(res => {
|
||||||
if (this.state.currentMode === 'column') {
|
if (this.state.currentMode === 'column') {
|
||||||
if (repoID === destRepo.repo_id) {
|
if (repoID === destRepo.repo_id) {
|
||||||
let tree = this.state.treeData.clone();
|
|
||||||
let node = tree.getNodeByPath(copyToDirentPath);
|
this.updateMoveCopyTreeNode(copyToDirentPath);
|
||||||
let temporaryData = node.children.map(item => item.object);
|
|
||||||
this.updateMoveCopyTreeNode(temporaryData, node.path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user