feature(cloudcmd) add progress of copying

This commit is contained in:
coderaiser 2015-05-28 05:02:13 -04:00
parent 67d3f1f574
commit 546a44f216
12 changed files with 284 additions and 132 deletions

View file

@ -213,6 +213,7 @@ Here is description of options:
"port" : 8000, /* http port */
"ip" : null, /* ip or null(default) */
"root" : "/" /* root directory */
"progressOfCopying" : false /* show progress of copying */
}
```

View file

@ -121,4 +121,10 @@
placeholder="Port"
class="form-control">
</li>
<li>
<label>
<input data-name="js-progressOfCopying" type="checkbox" {{ progressOfCopying }}>
Progress of copying
</label>
</li>
</ul>

View file

@ -16,5 +16,6 @@
"showKeysPanel": true,
"port": 8000,
"ip": null,
"root": "/"
"root": "/",
"progressOfCopying": false
}

View file

@ -7,6 +7,7 @@
"config",
"contact",
"upload",
"operation",
"konsole", [{
"name": "remote",
"data": [{

View file

@ -1,13 +1,15 @@
var Util, DOM;
/* global Util */
/* global DOM */
/* global CloudCmd */
(function(Util, DOM) {
(function(Util, DOM, CloudCmd) {
'use strict';
var DOMProto = Object.getPrototypeOf(DOM);
DOMProto.Buffer = new BufferProto(Util, DOM);
DOMProto.Buffer = new BufferProto(Util, DOM, CloudCmd);
function BufferProto(Util, DOM) {
function BufferProto(Util, DOM, CloudCmd) {
var Storage = DOM.Storage,
Dialog = DOM.Dialog,
Files = DOM.Files,
@ -112,9 +114,10 @@ var Util, DOM;
cut = Storage.get.bind(Storage, CUT);
Util.exec.parallel([copy, cut], function(error, cp, ct) {
var data = {},
msg = 'Path is same!',
path = Info.dirPath;
var data = {},
Operation = CloudCmd.Operation,
msg = 'Path is same!',
path = Info.dirPath;
if (!error && !cp && !ct)
error = 'Buffer is empty!';
@ -128,7 +131,7 @@ var Util, DOM;
if (data.from === path)
Dialog.alert(msg);
else
DOM.copyFiles(data);
Operation.show('copy', data);
} else if (ct) {
data = json.parse(ct);
@ -137,7 +140,7 @@ var Util, DOM;
if (data.from === path)
Dialog.alert(msg);
else
DOM.moveFiles(data);
Operation.show('move', data);
}
clear();
@ -146,4 +149,4 @@ var Util, DOM;
return Buffer;
}
})(Util, DOM);
})(Util, DOM, CloudCmd);

View file

@ -21,8 +21,8 @@ var CloudCmd;
client + 'notify',
client + 'storage',
client + 'files',
client + 'buffer',
'client',
client + 'buffer',
client + 'listeners',
client + 'key'
].map(function(name) {

View file

@ -1576,122 +1576,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}
};
/*
* process files (copy or move)
* @param data
* @param operation
*/
function processFiles(data, operation, message) {
var name, files,
panel,
shouldAsk,
sameName,
ok,
tmpl = '"{{ name }}" already exist. Overwrite?',
from = '',
to = '',
names = [];
if (data) {
from = data.from;
to = data.to;
names = data.names;
panel = CurrentInfo.panel;
} else {
from = CurrentInfo.dirPath;
to = DOM.getNotCurrentDirPath();
names = Cmd.getSelectedNames();
data = {};
shouldAsk = true;
panel = CurrentInfo.panelPassive;
}
if (!names.length)
names.push(DOM.getCurrentName());
name = names[0];
sameName = !!DOM.getCurrentByName(name, panel);
if (name === '..') {
Dialog.alert('No files selected!');
} else {
if (shouldAsk)
to = message(to, names);
ok = from !== to && to;
if (ok && shouldAsk && sameName)
ok = Dialog.confirm(rendy(tmpl, {
name: name
}));
if (ok) {
Images.show.load('top');
files = {
from : from,
to : to,
names : names
};
operation(files, function() {
var path = CloudFunc.rmLastSlash(from);
DOM.Storage.remove(path, function() {
var panel = CurrentInfo.panel,
panelPassive = CurrentInfo.panelPassive,
setCurrent = function() {
var current;
if (!name)
name = data.names[0];
current = DOM.getCurrentByName(name);
DOM.setCurrentFile(current);
};
if (!CurrentInfo.isOnePanel)
CloudCmd.refresh(panelPassive, {noCurrent: true}, function() {});
CloudCmd.refresh(panel, setCurrent);
});
});
}
}
}
function message(msg) {
return function(to, names) {
var ret,
n = names.length,
name = names[0];
msg += ' ';
if (names.length > 1)
msg += n + ' file(s)';
else
msg += '"' + name + '"';
msg += ' to';
ret = Dialog.prompt(msg, to);
return ret;
};
}
this.copyFiles = function(data) {
processFiles(data, DOM.RESTful.cp, message('Copy'));
};
this.moveFiles = function(data) {
processFiles(data, DOM.RESTful.mv, message('Rename/Move'));
};
/**
* unified way to scrollIntoViewIfNeeded
* (native suporte by webkit only)

View file

@ -291,12 +291,12 @@ var CloudCmd, Util, DOM;
break;
case Key.F5:
DOM.copyFiles();
CloudCmd.Operation.show('copy');
event.preventDefault();
break;
case Key.F6:
DOM.moveFiles();
CloudCmd.Operation.show('move');
event.preventDefault();
break;

View file

@ -36,14 +36,14 @@ var Util, DOM, CloudFunc, CloudCmd;
'f1' : CloudCmd.Help.show,
'f3' : CloudCmd.View.show,
'f4' : CloudCmd.Edit.show,
'f5' : CloudCmd.Operation.show.bind(null, 'copy'),
'f6' : CloudCmd.Operation.show.bind(null, 'move'),
'f9' : CloudCmd.Menu.show,
'f10' : CloudCmd.Config.show,
'~' : CloudCmd.Konsole.show,
'contact' : CloudCmd.Contact.show,
'f2' : DOM.renameCurrent,
'f5' : DOM.copyFiles,
'f6' : DOM.moveFiles,
'f7' : DOM.promptNewDir,
'f8' : DOM.promptDelete
},

245
lib/client/operation.js Normal file
View file

@ -0,0 +1,245 @@
/* global CloudCmd */
/* global Util */
/* global DOM */
/* global CloudFunc */
/* global rendy */
/* global spero */
(function(CloudCmd, Util, DOM, CloudFunc, rendy) {
'use strict';
CloudCmd.Operation = OperationProto;
function OperationProto(operation, data) {
var Name = 'Operation',
Loaded,
copyFn = DOM.RESTful.cp,
moveFn = DOM.RESTful.mv,
Images = DOM.Images,
Dialog = DOM.Dialog,
Operation = this;
function init() {
Images.show.load();
Util.exec.series([
function(callback) {
var Files = DOM.Files;
Files.get('config', function(error, config) {
if (error)
alert(error);
else if (config.progressOfCopying)
load(function() {
create(callback);
});
else
callback();
});
},
function() {
Loaded = true;
Operation.show(operation, data);
}
]);
}
function create(callback) {
spero(function() {
var parse = function(fn) {
return function(data, callback) {
var progress = function(value) {
Images.setProgress(value);
},
end = function() {
callback();
spero.removeListener('progress', progress);
spero.removeListener('end', end);
},
error = function(data) {
var msg = data + '\n Continue?',
is = confirm(msg);
if (is)
spero.continue();
else
spero.abort();
};
Images.show('top');
fn(data.from, data.to, data.names);
spero.on('progress', progress);
spero.on('end', end);
spero.on('error', error);
};
};
spero.on('connect', function() {
copyFn = parse(spero.copy);
});
spero.on('disconnect', function() {
copyFn = DOM.RESTful.cp;
});
Util.exec(callback);
});
}
this.hide = function() {
CloudCmd.View.hide();
};
this.show = function(operation, data) {
if (Loaded)
switch(operation) {
case 'copy':
this.copy(data);
break;
case 'move':
this.move(data);
break;
}
};
this.copy = function(data) {
processFiles(data, copyFn, message('Copy'));
};
this.move = function(data) {
processFiles(data, moveFn, message('Rename/Move'));
};
/*
* process files (copy or move)
* @param data
* @param operation
*/
function processFiles(data, operation, message) {
var name, files,
CurrentInfo = DOM.CurrentInfo,
panel,
shouldAsk,
sameName,
ok,
tmpl = '"{{ name }}" already exist. Overwrite?',
from = '',
to = '',
names = [];
if (data) {
from = data.from;
to = data.to;
names = data.names;
panel = CurrentInfo.panel;
} else {
from = CurrentInfo.dirPath;
to = DOM.getNotCurrentDirPath();
names = DOM.getSelectedNames();
data = {};
shouldAsk = true;
panel = CurrentInfo.panelPassive;
}
if (!names.length)
names.push(DOM.getCurrentName());
name = names[0];
sameName = !!DOM.getCurrentByName(name, panel);
if (name === '..') {
Dialog.alert('No files selected!');
} else {
if (shouldAsk)
to = message(to, names);
ok = from !== to && to;
if (ok && shouldAsk && sameName)
ok = Dialog.confirm(rendy(tmpl, {
name: name
}));
if (ok) {
Images.show.load('top');
files = {
from : from,
to : to,
names : names
};
operation(files, function() {
var path = CloudFunc.rmLastSlash(from);
DOM.Storage.remove(path, function() {
var panel = CurrentInfo.panel,
panelPassive = CurrentInfo.panelPassive,
setCurrent = function() {
var current;
if (!name)
name = data.names[0];
current = DOM.getCurrentByName(name);
DOM.setCurrentFile(current);
};
if (!CurrentInfo.isOnePanel)
CloudCmd.refresh(panelPassive, {noCurrent: true}, function() {});
CloudCmd.refresh(panel, setCurrent);
});
});
}
}
}
function message(msg) {
return function(to, names) {
var ret,
n = names.length,
name = names[0];
msg += ' ';
if (names.length > 1)
msg += n + ' file(s)';
else
msg += '"' + name + '"';
msg += ' to';
ret = Dialog.prompt(msg, to);
return ret;
};
}
function load(callback) {
DOM.load.js('/spero/spero.js', function(error) {
if (error) {
Dialog.alert(error.message);
} else {
Loaded = true;
Util.timeEnd(Name + ' load');
Util.exec(callback);
}
});
Util.time(Name + ' load');
}
init();
}
})(CloudCmd, Util, DOM, CloudFunc, rendy);

View file

@ -20,6 +20,7 @@
webconsole = require('console-io'),
edward = require('edward'),
dword = require('dword'),
spero = require('spero'),
root = function() {
return config('root');
@ -72,6 +73,10 @@
size: size,
root: root
});
spero.listen(socket, {
root: root
});
};
function cloudcmd() {
@ -125,6 +130,11 @@
zip : isZip
}),
spero({
minify: isMinify,
online: isOnline
}),
mollify({
dir : DIR_ROOT,
is : isMinify

View file

@ -58,6 +58,7 @@
"rendy": "~1.1.0",
"restafary": "~1.3.0",
"socket.io": "~1.3.5",
"spero": "~1.0.0",
"try-catch": "~1.0.0",
"tryrequire": "~1.1.5"
},