mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 08:53:14 +00:00
update shared folder
show progress when save file/folder in shared folder
This commit is contained in:
@@ -26,14 +26,7 @@ class SaveSharedDirDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSaveSharedFile = () => {
|
onSaveSharedFile = () => {
|
||||||
const { sharedToken, parentDir, items } = this.props;
|
this.props.handleSaveSharedDir(this.state.repo.repo_id, this.state.selectedPath)
|
||||||
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});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDirentItemClick = (repo, selectedPath, dirent) => {
|
onDirentItemClick = (repo, selectedPath, dirent) => {
|
||||||
|
@@ -13,6 +13,7 @@ import ZipDownloadDialog from './components/dialog/zip-download-dialog';
|
|||||||
import ImageDialog from './components/dialog/image-dialog';
|
import ImageDialog from './components/dialog/image-dialog';
|
||||||
import FileUploader from './components/shared-link-file-uploader/file-uploader';
|
import FileUploader from './components/shared-link-file-uploader/file-uploader';
|
||||||
import SaveSharedDirDialog from './components/dialog/save-shared-dir-dialog';
|
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/shared-dir-view.css';
|
||||||
import './css/grid-view.css';
|
import './css/grid-view.css';
|
||||||
@@ -51,6 +52,11 @@ class SharedDirView extends React.Component {
|
|||||||
isSaveSharedDirDialogShow: false,
|
isSaveSharedDirDialogShow: false,
|
||||||
itemsForSave: [],
|
itemsForSave: [],
|
||||||
|
|
||||||
|
asyncCopyMoveTaskId: '',
|
||||||
|
asyncOperationProgress: 0,
|
||||||
|
asyncOperatedFilesLength: 0,
|
||||||
|
isCopyMoveProgressDialogShow: false,
|
||||||
|
|
||||||
isImagePopupOpen: false,
|
isImagePopupOpen: false,
|
||||||
imageItems: [],
|
imageItems: [],
|
||||||
imageIndex: 0
|
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 = () => {
|
saveSelectedItems = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isSaveSharedDirDialogShow: true,
|
isSaveSharedDirDialogShow: true,
|
||||||
@@ -212,9 +255,36 @@ class SharedDirView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveSharedDir = () => {
|
handleSaveSharedDir = (destRepoID, dstPath) => {
|
||||||
toaster.success(gettext('Successfully saved'), {
|
|
||||||
duration: 3
|
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}
|
handleSaveSharedDir={this.handleSaveSharedDir}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
{this.state.isCopyMoveProgressDialogShow && (
|
||||||
|
<CopyMoveDirentProgressDialog
|
||||||
|
type='copy'
|
||||||
|
asyncOperatedFilesLength={this.state.asyncOperatedFilesLength}
|
||||||
|
asyncOperationProgress={this.state.asyncOperationProgress}
|
||||||
|
toggleDialog={this.onMoveProgressDialogToggle}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{this.state.isImagePopupOpen &&
|
{this.state.isImagePopupOpen &&
|
||||||
<ModalPortal>
|
<ModalPortal>
|
||||||
<ImageDialog
|
<ImageDialog
|
||||||
|
@@ -1131,12 +1131,20 @@ class ShareLinkSaveItemsToRepo(APIView):
|
|||||||
dst_dirent_name = "\t".join(formated_src_dirents)
|
dst_dirent_name = "\t".join(formated_src_dirents)
|
||||||
|
|
||||||
try:
|
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,
|
dst_repo_id, dst_parent_dir, dst_dirent_name,
|
||||||
username, need_progress=0)
|
username, need_progress=1, synchronous=0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
error_msg = 'Internal Server Error'
|
error_msg = 'Internal Server Error'
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
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)
|
||||||
|
Reference in New Issue
Block a user