mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(util) rm copyObj
This commit is contained in:
parent
005d6e6cff
commit
05659e5873
3 changed files with 53 additions and 71 deletions
|
|
@ -57,7 +57,7 @@ function EditProto(callback) {
|
|||
}
|
||||
|
||||
function initConfig(config, options) {
|
||||
Util.copyObj(config, ConfigView);
|
||||
Object.assign(config, ConfigView);
|
||||
|
||||
if (!options)
|
||||
return config;
|
||||
|
|
|
|||
|
|
@ -123,13 +123,13 @@ function MenuProto(position) {
|
|||
}
|
||||
|
||||
function getMenuData(isAuth) {
|
||||
var menu = {
|
||||
'Paste' : Buffer.paste,
|
||||
'New' : {
|
||||
'File' : DOM.promptNewFile,
|
||||
'Directory' : DOM.promptNewDir
|
||||
const menu = {
|
||||
'Paste': Buffer.paste,
|
||||
'New': {
|
||||
'File': DOM.promptNewFile,
|
||||
'Directory': DOM.promptNewDir
|
||||
},
|
||||
'Upload' : function() {
|
||||
'Upload': () => {
|
||||
CloudCmd.Upload.show();
|
||||
},
|
||||
'Upload From Cloud': uploadFromCloud,
|
||||
|
|
@ -151,42 +151,42 @@ function MenuProto(position) {
|
|||
}
|
||||
|
||||
function loadFileMenuData(callback) {
|
||||
var is = CloudCmd.config('auth');
|
||||
var show = function(name) {
|
||||
CloudCmd[name].show();
|
||||
},
|
||||
Dialog = DOM.Dialog,
|
||||
menuData = getMenuData(is),
|
||||
menu = {
|
||||
'View' : curry(show, 'View'),
|
||||
'Edit' : curry(show, 'Edit'),
|
||||
'Rename' : function() {
|
||||
setTimeout(DOM.renameCurrent, 100);
|
||||
},
|
||||
'Delete' : function() {
|
||||
CloudCmd.Operation.show('delete');
|
||||
},
|
||||
'Pack' : function() {
|
||||
CloudCmd.Operation.show('pack');
|
||||
},
|
||||
'Extract' : function() {
|
||||
CloudCmd.Operation.show('extract');
|
||||
},
|
||||
'Download' : preDownload,
|
||||
'Upload To Cloud': curry(uploadTo, 'Cloud'),
|
||||
'Cut' : function() {
|
||||
isCurrent(Buffer.cut, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
'Copy' : function() {
|
||||
isCurrent(Buffer.copy, function() {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
};
|
||||
const is = CloudCmd.config('auth');
|
||||
const show = (name) => {
|
||||
CloudCmd[name].show();
|
||||
};
|
||||
|
||||
Util.copyObj(menu, menuData);
|
||||
const Dialog = DOM.Dialog;
|
||||
const menuData = getMenuData(is);
|
||||
|
||||
const menu = Object.assign({}, menuData, {
|
||||
'View' : curry(show, 'View'),
|
||||
'Edit' : curry(show, 'Edit'),
|
||||
'Rename' : () => {
|
||||
setTimeout(DOM.renameCurrent, 100);
|
||||
},
|
||||
'Delete' : () => {
|
||||
CloudCmd.Operation.show('delete');
|
||||
},
|
||||
'Pack' : () => {
|
||||
CloudCmd.Operation.show('pack');
|
||||
},
|
||||
'Extract' : () => {
|
||||
CloudCmd.Operation.show('extract');
|
||||
},
|
||||
'Download' : preDownload,
|
||||
'Upload To Cloud': curry(uploadTo, 'Cloud'),
|
||||
'Cut' : () => {
|
||||
isCurrent(Buffer.cut, () => {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
'Copy' : () => {
|
||||
isCurrent(Buffer.copy, () => {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
callback(is, menu);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
const exec = require('execon');
|
||||
const rendy = require('rendy');
|
||||
const jonny = require('jonny');
|
||||
const itype = require('itype/legacy');
|
||||
|
||||
module.exports = new UtilProto(exec);
|
||||
|
||||
|
|
@ -13,43 +14,24 @@ function UtilProto(exec) {
|
|||
this.getStrBigFirst = getStrBigFirst;
|
||||
this.kebabToCamelCase = kebabToCamelCase;
|
||||
|
||||
/**
|
||||
* Copy properties from from to to
|
||||
*
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
this.copyObj = function(to, from) {
|
||||
if (!from) {
|
||||
from = to;
|
||||
to = {};
|
||||
}
|
||||
|
||||
if (to)
|
||||
Object.keys(from).forEach(function(name) {
|
||||
to[name] = from[name];
|
||||
});
|
||||
|
||||
return to;
|
||||
};
|
||||
|
||||
/**
|
||||
* copy objFrom properties to target
|
||||
*
|
||||
* @target
|
||||
* @objFrom
|
||||
*/
|
||||
this.extend = function(target, objFrom) {
|
||||
var obj;
|
||||
var keys;
|
||||
var proto;
|
||||
var isFunc = typeof objFrom === 'function';
|
||||
var isArray = Array.isArray(objFrom);
|
||||
var isObj = typeof target === 'object';
|
||||
var ret = isObj ? target : {};
|
||||
this.extend = (target, objFrom) => {
|
||||
let obj;
|
||||
let keys;
|
||||
let proto;
|
||||
|
||||
const isFunc = itype.function(objFrom);
|
||||
const isArray = Array.isArray(objFrom);
|
||||
const isObj = itype.object(target);
|
||||
let ret = isObj ? target : {};
|
||||
|
||||
if (isArray)
|
||||
objFrom.forEach(function(item) {
|
||||
objFrom.forEach((item) => {
|
||||
ret = Util.extend(target, item);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue