mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-01 04:05:18 +00:00
feature(cloudcmd) improved progress of file operations
This commit is contained in:
parent
7da7bc8606
commit
009628c3ee
4 changed files with 116 additions and 32 deletions
9
client/modules/operation/format.js
Normal file
9
client/modules/operation/format.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (operation, from, to) => {
|
||||
if (!to)
|
||||
return `${operation} ${from}`;
|
||||
|
||||
return `${operation} ${from} -> ${to}`;
|
||||
};
|
||||
|
||||
|
|
@ -103,35 +103,87 @@ function _initOperations(prefix, socketPrefix, fn) {
|
|||
}
|
||||
|
||||
function onConnect(operator) {
|
||||
packTarFn = (data, callback) => {
|
||||
operator.tar(data.from, data.to, data.names)
|
||||
.then(setListeners({noContinue: true}, callback));
|
||||
packTarFn = ({from, to, names}, callback) => {
|
||||
const operation = 'Tar';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
noContinue: true,
|
||||
from,
|
||||
to,
|
||||
});
|
||||
|
||||
operator.tar(from, to, names)
|
||||
.then(listen);
|
||||
};
|
||||
|
||||
packZipFn = (data, callback) => {
|
||||
operator.zip(data.from, data.to, data.names)
|
||||
.then(setListeners({noContinue: true}, callback));
|
||||
packZipFn = ({from, to, names}, callback) => {
|
||||
const operation = 'Zip';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
noContinue: true,
|
||||
from,
|
||||
to,
|
||||
});
|
||||
|
||||
operator.zip(from, to, names)
|
||||
.then(listen);
|
||||
};
|
||||
|
||||
deleteFn = (from, files, callback) => {
|
||||
from = removeQuery(from);
|
||||
|
||||
const operation = 'Delete';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
from,
|
||||
});
|
||||
|
||||
operator.remove(from, files)
|
||||
.then(setListeners(callback));
|
||||
.then(listen);
|
||||
};
|
||||
|
||||
copyFn = (data, callback) => {
|
||||
operator.copy(data.from, data.to, data.names)
|
||||
.then(setListeners(callback));
|
||||
copyFn = ({from, to, names}, callback) => {
|
||||
const operation = 'Copy';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
from,
|
||||
to,
|
||||
names,
|
||||
});
|
||||
|
||||
operator.copy(from, to, names)
|
||||
.then(listen);
|
||||
};
|
||||
|
||||
moveFn = (data, callback) => {
|
||||
operator.move(data.from, data.to, data.names)
|
||||
.then(setListeners(callback));
|
||||
moveFn = ({from, to, names}, callback) => {
|
||||
const operation = 'Move';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
from,
|
||||
to,
|
||||
});
|
||||
|
||||
operator.move(from, to, names)
|
||||
.then(listen);
|
||||
};
|
||||
|
||||
extractFn = (data, callback) => {
|
||||
operator.extract(data.from, data.to)
|
||||
.then(setListeners({noContinue: true}, callback));
|
||||
extractFn = ({from, to}, callback) => {
|
||||
const operation = 'Extract';
|
||||
const listen = setListeners({
|
||||
operation,
|
||||
callback,
|
||||
noContinue: true,
|
||||
from,
|
||||
to,
|
||||
});
|
||||
|
||||
operator.extract(from, to)
|
||||
.then(listen);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -393,8 +445,6 @@ function twopack(operation, type) {
|
|||
let fileFrom;
|
||||
let currentName = Info.name;
|
||||
|
||||
const {Images} = DOM;
|
||||
|
||||
const {
|
||||
path,
|
||||
dirPath,
|
||||
|
|
@ -437,7 +487,7 @@ function twopack(operation, type) {
|
|||
break;
|
||||
}
|
||||
|
||||
Images.show.load('top');
|
||||
showLoad();
|
||||
|
||||
op(fileFrom, (error) => {
|
||||
!error && CloudCmd.refresh({
|
||||
|
|
|
|||
|
|
@ -3,37 +3,62 @@
|
|||
/* global DOM */
|
||||
/* global CloudCmd */
|
||||
|
||||
const smalltalk = require('smalltalk');
|
||||
|
||||
const {
|
||||
Images,
|
||||
Dialog,
|
||||
Images,
|
||||
} = DOM;
|
||||
|
||||
const forEachKey = require('for-each-key/legacy');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
const {TITLE} = CloudCmd;
|
||||
|
||||
module.exports = (options, callback) => (emitter) => {
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
const format = require('./format');
|
||||
|
||||
module.exports = (options) => (emitter) => {
|
||||
const {
|
||||
operation,
|
||||
callback,
|
||||
noContinue,
|
||||
from,
|
||||
to,
|
||||
} = options;
|
||||
|
||||
let done;
|
||||
let lastError;
|
||||
|
||||
const onAbort = wraptile(({emitter, operation}) => {
|
||||
emitter.abort();
|
||||
|
||||
const msg = `${operation} aborted`;
|
||||
lastError = true;
|
||||
|
||||
Dialog.alert(TITLE, msg, {
|
||||
noCancel: true,
|
||||
});
|
||||
});
|
||||
|
||||
const removeListener = emitter.removeListener.bind(emitter);
|
||||
const on = emitter.on.bind(emitter);
|
||||
|
||||
const message = format(operation, from, to);
|
||||
|
||||
const progress = smalltalk.progress(TITLE, message);
|
||||
|
||||
progress.catch(onAbort({
|
||||
emitter,
|
||||
operation,
|
||||
}));
|
||||
|
||||
const listeners = {
|
||||
progress: (value) => {
|
||||
done = value === 100;
|
||||
Images.setProgress(value);
|
||||
progress.setProgress(value);
|
||||
},
|
||||
|
||||
end: () => {
|
||||
Images
|
||||
.hide()
|
||||
.clearProgress();
|
||||
|
||||
Images.hide();
|
||||
forEachKey(removeListener, listeners);
|
||||
|
||||
if (lastError || done)
|
||||
|
|
@ -43,7 +68,7 @@ module.exports = (options, callback) => (emitter) => {
|
|||
error: (error) => {
|
||||
lastError = error;
|
||||
|
||||
if (options.noContinue) {
|
||||
if (noContinue) {
|
||||
listeners.end(error);
|
||||
Dialog.alert(TITLE, error);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@
|
|||
"scroll-into-view-if-needed": "^2.2.5",
|
||||
"serve-once": "^1.5.0",
|
||||
"serviceworker-webpack-plugin": "^1.0.1",
|
||||
"smalltalk": "^3.1.0",
|
||||
"smalltalk": "^3.3.0",
|
||||
"style-loader": "^0.23.0",
|
||||
"stylelint": "^9.0.0",
|
||||
"stylelint-config-standard": "^18.0.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue