feature(cloudcmd) add progress of pack/extract operations

This commit is contained in:
coderaiser 2015-07-09 11:41:25 -04:00
parent 6081f7a1c4
commit 450c2598fa
5 changed files with 118 additions and 77 deletions

View file

@ -466,80 +466,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
});
}
function twopack(operation) {
var op,
RESTful = DOM.RESTful,
Images = DOM.Images,
Info = DOM.CurrentInfo,
name = Info.name,
path = Info.path,
dirPath = Info.dirPath,
activeFiles = DOM.getActiveFiles(),
names = DOM.getSelectedNames(activeFiles),
fileFrom;
Util.check(arguments, ['operation']);
if (!names.length) {
Dialog.alert.noFiles();
} else {
switch(operation) {
case 'extract':
op = RESTful.extract;
fileFrom = {
from : path,
to : dirPath
};
name = name.replace(/\.tar\.gz$/, '');
break;
case 'pack':
op = RESTful.pack;
if (names.length > 1)
name = Info.dir;
name += '.tar.gz';
fileFrom = {
from : dirPath,
to : dirPath + name,
names : names
};
break;
}
Images.show.load('top');
op(fileFrom, function(error) {
!error && CloudCmd.refresh(null, function() {
var file = DOM.getCurrentByName(name);
DOM.setCurrentFile(file);
});
});
}
}
/**
* zip file
*
*/
this.pack = function() {
twopack('pack');
};
/**
* unzip file
*
*/
this.extract = function() {
twopack('extract');
};
/**
* get current direcotory name
*/

View file

@ -171,8 +171,12 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
'Delete' : function() {
CloudCmd.Operation.show('delete');
},
'Pack' : DOM.pack,
'Extract' : DOM.extract,
'Pack' : function() {
CloudCmd.Operation.show('pack');
},
'Extract' : function() {
CloudCmd.Operation.show('extract');
},
'Upload To' : {},
'Download' : download,
'Cut' : Buffer.cut,

View file

@ -4,6 +4,7 @@
/* global rendy */
/* global spero */
/* global remedy */
/* global ishtar */
(function(CloudCmd, Util, DOM, rendy) {
'use strict';
@ -18,6 +19,8 @@
copyFn = RESTful.cp,
moveFn = RESTful.mv,
deleteFn = RESTful.delete,
packFn = RESTful.pack,
extractFn = RESTful.extract,
Images = DOM.Images,
Dialog = DOM.Dialog,
@ -86,6 +89,26 @@
});
});
ishtar(function() {
ishtar.on('connect', function() {
packFn = function(data, callback) {
setListeners(ishtar, callback);
ishtar.pack(data.from, data.to, data.names);
};
extractFn = function(data, callback) {
setListeners(ishtar, callback);
ishtar.pack(data.from, data.to);
};
});
ishtar.on('disconnect', function() {
packFn = RESTful.pack;
extractFn = RESTful.extract;
});
});
Util.exec(callback);
}
@ -149,6 +172,16 @@
case 'delete:silent':
Operation.deleteShift();
break;
case 'pack':
Operation.pack();
break;
case 'extract':
Operation.extract();
break;
}
};
@ -168,6 +201,15 @@
deleteSilent();
};
this.pack = function() {
twopack('pack');
};
this.extract = function() {
twopack('extract');
};
/**
* prompt and delete current file or selected files
*
@ -345,6 +387,63 @@
}
}
function twopack(operation) {
var op,
Images = DOM.Images,
Info = DOM.CurrentInfo,
name = Info.name,
path = Info.path,
dirPath = Info.dirPath,
activeFiles = DOM.getActiveFiles(),
names = DOM.getSelectedNames(activeFiles),
fileFrom;
Util.check(arguments, ['operation']);
if (!names.length) {
Dialog.alert.noFiles();
} else {
switch(operation) {
case 'extract':
op = extractFn;
fileFrom = {
from : path,
to : dirPath
};
name = name.replace(/\.tar\.gz$/, '');
break;
case 'pack':
op = packFn;
if (names.length > 1)
name = Info.dir;
name += '.tar.gz';
fileFrom = {
from : dirPath,
to : dirPath + name,
names : names
};
break;
}
Images.show.load('top');
op(fileFrom, function(error) {
!error && CloudCmd.refresh(null, function() {
var file = DOM.getCurrentByName(name);
DOM.setCurrentFile(file);
});
});
}
}
function message(msg) {
return function(to, names) {
var ret,
@ -369,7 +468,8 @@
function load(callback) {
var files = [
'/spero/spero.js',
'/remedy/remedy.js'
'/remedy/remedy.js',
'/ishtar/ishtar.js'
];
DOM.load.parallel(files, function(error) {

View file

@ -24,6 +24,7 @@
dword = require('dword'),
spero = require('spero'),
remedy = require('remedy'),
ishtar = require('ishtar'),
root = function() {
return config('root');
@ -104,6 +105,10 @@
remedy.listen(socket, {
root: root
});
ishtar.listen(socket, {
root: root
});
}
function cloudcmd(prefix, socket) {
@ -171,6 +176,11 @@
online: isOnline
}),
ishtar({
minify: isMinify,
online: isOnline
}),
mollify({
dir : DIR_ROOT,
is : isMinify

View file

@ -46,6 +46,7 @@
"flop": "~1.3.0",
"format-io": "~0.9.6",
"http-auth": "~2.2.3",
"ishtar": "~1.0.0",
"jaguar": "~1.1.0",
"join-io": "~1.4.0",
"jonny": "~1.0.0",