1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

update shared folder

show progress when save file/folder in shared folder
This commit is contained in:
lian
2022-02-11 18:36:03 +08:00
parent 1500afb2ff
commit 90b85a539d
3 changed files with 94 additions and 15 deletions

View File

@@ -26,14 +26,7 @@ class SaveSharedDirDialog extends React.Component {
}
onSaveSharedFile = () => {
const { sharedToken, parentDir, items } = this.props;
seafileAPI.saveSharedDir(this.state.repo.repo_id, this.state.selectedPath, sharedToken, parentDir, items).then((res) => {
this.props.toggleCancel();
this.props.handleSaveSharedDir();
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
this.setState({errMessage: errMessage});
});
this.props.handleSaveSharedDir(this.state.repo.repo_id, this.state.selectedPath)
}
onDirentItemClick = (repo, selectedPath, dirent) => {

View File

@@ -13,6 +13,7 @@ import ZipDownloadDialog from './components/dialog/zip-download-dialog';
import ImageDialog from './components/dialog/image-dialog';
import FileUploader from './components/shared-link-file-uploader/file-uploader';
import SaveSharedDirDialog from './components/dialog/save-shared-dir-dialog';
import CopyMoveDirentProgressDialog from './components/dialog/copy-move-dirent-progress-dialog';
import './css/shared-dir-view.css';
import './css/grid-view.css';
@@ -51,6 +52,11 @@ class SharedDirView extends React.Component {
isSaveSharedDirDialogShow: false,
itemsForSave: [],
asyncCopyMoveTaskId: '',
asyncOperationProgress: 0,
asyncOperatedFilesLength: 0,
isCopyMoveProgressDialogShow: false,
isImagePopupOpen: false,
imageItems: [],
imageIndex: 0
@@ -189,6 +195,43 @@ class SharedDirView extends React.Component {
}
}
async getAsyncCopyMoveProgress() {
let { asyncCopyMoveTaskId } = this.state;
try {
let res = await seafileAPI.queryAsyncOperationProgress(asyncCopyMoveTaskId);
let data = res.data;
if (data.failed) {
let message = gettext('Failed to copy files to another library.');
toaster.danger(message);
this.setState({
asyncOperationProgress: 0,
isCopyMoveProgressDialogShow: false,
});
return;
}
if (data.successful) {
this.setState({
asyncOperationProgress: 0,
isCopyMoveProgressDialogShow: false,
});
let message = gettext('Successfully copied files to another library.');
toaster.success(message);
return;
}
// init state: total is 0
let asyncOperationProgress = !data.total ? 0 : parseInt((data.done/data.total * 100).toFixed(2));
this.getAsyncCopyMoveProgress();
this.setState({asyncOperationProgress: asyncOperationProgress});
} catch (error) {
this.setState({
asyncOperationProgress: 0,
isCopyMoveProgressDialogShow: false,
});
}
}
saveSelectedItems = () => {
this.setState({
isSaveSharedDirDialogShow: true,
@@ -212,9 +255,36 @@ class SharedDirView extends React.Component {
});
}
handleSaveSharedDir = () => {
toaster.success(gettext('Successfully saved'), {
duration: 3
handleSaveSharedDir = (destRepoID, dstPath) => {
const itemsForSave = this.state.itemsForSave;
seafileAPI.saveSharedDir(destRepoID, dstPath, token, relativePath, itemsForSave).then((res) => {
this.setState({
isSaveSharedDirDialogShow: false,
itemsForSave: [],
isCopyMoveProgressDialogShow: true,
asyncCopyMoveTaskId: res.data.task_id,
asyncOperatedFilesLength: itemsForSave.length,
}, () => {
this.getAsyncCopyMoveProgress();
});
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
this.setState({errMessage: errMessage});
});
}
onMoveProgressDialogToggle = () => {
let { asyncOperationProgress } = this.state;
if (asyncOperationProgress !== 100) {
let taskId = this.state.asyncCopyMoveTaskId;
seafileAPI.cancelCopyMoveOperation(taskId);
}
this.setState({
asyncOperationProgress: 0,
isCopyMoveProgressDialogShow: false,
});
}
@@ -428,6 +498,14 @@ class SharedDirView extends React.Component {
handleSaveSharedDir={this.handleSaveSharedDir}
/>
}
{this.state.isCopyMoveProgressDialogShow && (
<CopyMoveDirentProgressDialog
type='copy'
asyncOperatedFilesLength={this.state.asyncOperatedFilesLength}
asyncOperationProgress={this.state.asyncOperationProgress}
toggleDialog={this.onMoveProgressDialogToggle}
/>
)}
{this.state.isImagePopupOpen &&
<ModalPortal>
<ImageDialog

View File

@@ -1131,12 +1131,20 @@ class ShareLinkSaveItemsToRepo(APIView):
dst_dirent_name = "\t".join(formated_src_dirents)
try:
seafile_api.copy_file(src_repo_id, src_parent_dir, src_dirent_name,
res = seafile_api.copy_file(src_repo_id, src_parent_dir, src_dirent_name,
dst_repo_id, dst_parent_dir, dst_dirent_name,
username, need_progress=0)
username, need_progress=1, synchronous=0)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
if not res:
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
result = {}
if res.background:
result['task_id'] = res.task_id
return Response(result)