Skip to content

Commit

Permalink
feature(cloudcmd) add ability to override modules (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Mar 23, 2017
1 parent 3044ac0 commit 51481fb
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 129 deletions.
12 changes: 12 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,22 @@ const plugins = [
__dirname + '/plugin.js'
];

const filePicker = {
data: {
FilePicker: {
key: 'key'
}
}
};

// override option from json/modules.json
const modules = {filePicker};

app.use(cloudcmd({
socket, /* used by Config, Edit (optional) and Console (required) */
config, /* config data (optional) */
plugins, /* optional */
modules, /* optional */
}));

server.listen(port);
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,22 @@ const plugins = [
__dirname + '/plugin.js'
];

const filePicker = {
data: {
FilePicker: {
key: 'key',
}
}
};

// override option from json/modules.json
const modules = {filePicker};

app.use(cloudcmd({
socket, /* used by Config, Edit (optional) and Console (required) */
config, /* config data (optional) */
plugins, /* optional */
modules, /* optional */
}));

server.listen(port);
Expand Down
70 changes: 26 additions & 44 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const itype = require('itype/legacy');
const rendy = require('rendy');
const exec = require('execon');
const Images = require('./dom/images');
const join = require('join-io/www/join');

Expand Down Expand Up @@ -134,7 +135,7 @@ function CloudCmdProto(Util, DOM) {
const prefix = CloudCmd.PREFIX;
const pathFull = prefix + CloudCmd.DIRCLIENT_MODULES + path;

Util.exec(doBefore);
exec(doBefore);

return DOM.load.js(pathFull, func ||
function(error) {
Expand Down Expand Up @@ -172,7 +173,7 @@ function CloudCmdProto(Util, DOM) {
*/
this.init = (prefix, config) => {
const func = () => {
Util.exec.series([
exec.series([
initModules,
baseInit,
loadPlugins,
Expand Down Expand Up @@ -208,7 +209,7 @@ function CloudCmdProto(Util, DOM) {
if (config.onePanelMode)
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;

Util.exec.if(document.body.scrollIntoViewIfNeeded, func, funcBefore);
exec.if(document.body.scrollIntoViewIfNeeded, func, funcBefore);
};

function loadPlugins(callback) {
Expand Down Expand Up @@ -263,7 +264,7 @@ function CloudCmdProto(Util, DOM) {
};

function initModules(callback) {
Util.exec.if(CloudCmd.Key, () => {
exec.if(CloudCmd.Key, () => {
Key = new CloudCmd.Key();
CloudCmd.Key = Key;
Key.bind();
Expand All @@ -278,13 +279,11 @@ function CloudCmdProto(Util, DOM) {
});

Files.get('modules', (error, modules) => {
const STORAGE = 'storage';
const showLoad = Images.show.load;

const doBefore = {
'edit' : showLoad,
'menu' : showLoad,
'storage/_filepicker' : showLoad
'edit': showLoad,
'menu': showLoad,
};

const load = (name, path, dobefore) => {
Expand All @@ -302,32 +301,17 @@ function CloudCmdProto(Util, DOM) {
if (!modules)
modules = [];

modules.forEach((module) => {
const isStr = itype.string(module);

if (!isStr)
return;

modules.local.forEach((module) => {
load(null, module, doBefore[module]);
});

const storageObj = Util.findObjByNameInArr(modules, STORAGE);
const mod = Util.getNamesFromObjArray(storageObj);

mod.forEach((name) => {
const path = STORAGE + '/_' + name.toLowerCase();

load(name, path, doBefore[path]);
});

callback();
});
}

function baseInit(callback) {
var dirPath = '',
files = DOM.getFiles();

const files = DOM.getFiles();

/* выделяем строку с первым файлом */
if (files)
DOM.setCurrentFile(files[0], {
Expand All @@ -337,37 +321,35 @@ function CloudCmdProto(Util, DOM) {
history: !location.hash
});

dirPath = DOM.getCurrentDirPath(),
Listeners = CloudCmd.Listeners;
const dirPath = DOM.getCurrentDirPath();
Listeners = CloudCmd.Listeners;
Listeners.init();

Listeners.setOnPanel('left');
Listeners.setOnPanel('right');

Listeners.initKeysPanel();

Storage.get(dirPath, function(error, data) {
Storage.get(dirPath, (error, data) => {
if (!data) {
data = getJSONfromFileTable();
data = getJSONfromFileTable();
Storage.set(dirPath, data);
}
});

callback();
}

this.execFromModule = function(moduleName, funcName) {
var args = [].slice.call(arguments, 2),
obj = CloudCmd[moduleName],
isObj = itype.object(obj);

Util.exec.if(isObj,
function() {
var obj = CloudCmd[moduleName],
func = obj[funcName];

func.apply(null, args);
}, obj);
this.execFromModule = (moduleName, funcName, ...args) => {
const obj = CloudCmd[moduleName];
const isObj = itype.object(obj);

exec.if(isObj, () => {
const obj = CloudCmd[moduleName];
const func = obj[funcName];

func(...args);
}, obj);
};

this.refresh = function(panelParam, options, callback) {
Expand Down Expand Up @@ -437,7 +419,7 @@ function CloudCmdProto(Util, DOM) {
DOM.setCurrentByName(name);
}

Util.exec(callback);
exec(callback);
});
});
};
Expand Down Expand Up @@ -511,7 +493,7 @@ function CloudCmdProto(Util, DOM) {
});
}

Util.exec(callback);
exec(callback);
});
}

Expand Down
4 changes: 1 addition & 3 deletions client/dom/load-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ module.exports = (name, options, callback = options) => {

Files.get('modules', (error, modules) => {
const online = config('online') && navigator.onLine;

const remoteObj = findObjByNameInArr(modules, 'remote');
const module = findObjByNameInArr(remoteObj, name);
const module = findObjByNameInArr(modules.remote, name);

const isArray = itype.array(module.local);
const version = module.version;
Expand Down
4 changes: 1 addition & 3 deletions client/modules/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ function loadFiles(callback) {

load.js('//api.filepicker.io/v1/filepicker.js', () => {
Files.get('modules', (error, modules) => {
const storage = Util.findObjByNameInArr(modules, 'storage');
const picker = Util.findObjByNameInArr(storage, 'FilePicker');
const key = picker && picker.key;
const {key} = modules.data.FilePicker;

filepicker.setKey(key);

Expand Down
18 changes: 0 additions & 18 deletions common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,6 @@ function UtilProto(exec) {
return ret;
};

/**
* get values from Object Array name properties
* or
* @pObj
*/
this.getNamesFromObjArray = function(arr) {
var ret = [];

if (!Array.isArray(arr))
throw Error('arr should be array!');

ret = arr.map(function(item) {
return item.name;
});

return ret;
};

/**
* find object by name in arrray
*
Expand Down
111 changes: 55 additions & 56 deletions json/modules.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
[
"edit",
"edit-file",
"edit-names",
"menu",
"view",
"help",
"markdown",
"config",
"contact",
"upload",
"operation",
"konsole",
"terminal",
"cloud", [{
"name": "remote",
"data": [{
"name": "jquery",
"version": "3.1.1",
"local": "/modules/jquery/dist/jquery.min.js",
"remote": "//ajax.googleapis.com/ajax/libs/jquery/{{ version }}/jquery.min.js"
}, {
"name": "socket",
"version": "1.7.3",
"local": "/socket.io/socket.io.js",
"remote": "https://cdnjs.cloudflare.com/ajax/libs/socket.io/{{ version }}/socket.io.js"
}, {
"name": "fancybox",
"version": "2.1.6",
"local": [
"/modules/fancybox/source/jquery.fancybox.css",
"/modules/fancybox/source/jquery.fancybox.pack.js"
],
"remote": [
"//cdnjs.cloudflare.com/ajax/libs/fancybox/{{ version }}/css/jquery.fancybox.min.css",
"//cdnjs.cloudflare.com/ajax/libs/fancybox/{{ version }}/js/jquery.fancybox.min.js"
]
}, {
"name": "menu",
"version": "1.0.2",
"local": [
"/modules/menu/menu-io.min.css",
"/modules/menu/menu-io.min.js"
],
"remote": [
"//cdn.jsdelivr.net/menu-io/{{ version }}/menu-io.min.js",
"//cdn.jsdelivr.net/menu-io/{{ version }}/menu-io.min.css"
]
}]
{
"local": [
"edit",
"edit-file",
"edit-names",
"menu",
"view",
"help",
"markdown",
"config",
"contact",
"upload",
"operation",
"konsole",
"terminal",
"cloud"
],
"remote": [{
"name": "jquery",
"version": "3.1.1",
"local": "/modules/jquery/dist/jquery.min.js",
"remote": "//ajax.googleapis.com/ajax/libs/jquery/{{ version }}/jquery.min.js"
}, {
"name": "storage",
"data": [{
"name" : "FilePicker",
"key" : "AACq5fTfzRY2E_Rw_4kyaz"
}]
}]
]
"name": "socket",
"version": "1.7.3",
"local": "/socket.io/socket.io.js",
"remote": "https://cdnjs.cloudflare.com/ajax/libs/socket.io/{{ version }}/socket.io.js"
}, {
"name": "fancybox",
"version": "2.1.6",
"local": [
"/modules/fancybox/source/jquery.fancybox.css",
"/modules/fancybox/source/jquery.fancybox.pack.js"
],
"remote": [
"//cdnjs.cloudflare.com/ajax/libs/fancybox/{{ version }}/css/jquery.fancybox.min.css",
"//cdnjs.cloudflare.com/ajax/libs/fancybox/{{ version }}/js/jquery.fancybox.min.js"
]
}, {
"name": "menu",
"version": "1.0.2",
"local": [
"/modules/menu/menu-io.min.css",
"/modules/menu/menu-io.min.js"
],
"remote": [
"//cdn.jsdelivr.net/menu-io/{{ version }}/menu-io.min.js",
"//cdn.jsdelivr.net/menu-io/{{ version }}/menu-io.min.css"
]
}],
"data": {
"FilePicker": {
"key": "AACq5fTfzRY2E_Rw_4kyaz"
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"copymitter": "^2.0.0",
"criton": "^1.0.0",
"currify": "^2.0.3",
"deepmerge": "^1.3.2",
"deepword": "^1.3.0",
"dword": "^4.1.0",
"edward": "^4.2.0",
Expand Down

0 comments on commit 51481fb

Please sign in to comment.