feature(cloudcmd) add --no-config-dialog: add ability to hide config dialog (#65)

This commit is contained in:
coderaiser 2016-11-07 20:38:29 +02:00
parent 0f79fc3037
commit b4c5b5a77a
10 changed files with 131 additions and 32 deletions

View file

@ -76,6 +76,7 @@ Cloud Commander supports command line parameters:
| `--progress` | show progress of file operations
| `--open` | open web browser when server started
| `--one-panel-mode` | set one panel mode
`--config-dialog` | enable config dialog
| `--no-server` | do not start server
| `--no-auth` | disable authorization
| `--no-online` | load scripts from local server
@ -83,6 +84,7 @@ Cloud Commander supports command line parameters:
| `--no-minify` | disable minification
| `--no-progress` | do not show progress of file operations
| `--no-one-panel-mode` | unset one panel mode
| `--no-config-dialog` | disable config dialog
If no parameters given Cloud Commander reads information from `~/.cloudcmd.json` and use
port from it (`8000` default). if port variables `PORT` or `VCAP_APP_PORT` isn't exist.

View file

@ -32,6 +32,7 @@ var Info = require('../package'),
'open',
'minify',
'progress',
'config-dialog',
'one-panel-mode'
],
default: {
@ -47,6 +48,7 @@ var Info = require('../package'),
prefix : config('prefix') || '',
progress : config('progress'),
'config-dialog': defaultTrue(config('configDialog')),
'one-panel-mode': config('onePanelMode'),
},
alias: {
@ -85,6 +87,7 @@ if (args.version) {
config('prefix', args.prefix);
config('root', args.root);
config('onePanelMode', args['one-panel-mode']);
config('configDialog', args['config-dialog']);
readConfig(args.config);
@ -107,6 +110,13 @@ if (args.version) {
});
}
function defaultTrue(value) {
if (typeof value === 'undefined')
return true;
return value;
}
function validateRoot(root) {
var validate = require('../lib/server/validate');
validate.root(root, console.log);

View file

@ -20,5 +20,6 @@
"root": "/",
"prefix": "",
"progress": true,
"onePanelMode": false
"onePanelMode": false,
"configDialog": true
}

View file

@ -14,6 +14,7 @@
"--minify ": "enable minification",
"--progress ": "show progress of file operations",
"--one-panel-mode ": "set one panel mode",
"--config-dialog ": "enable config dialog",
"--open ": "open web browser when server started",
"--no-server ": "do not start server",
"--no-auth ": "disable authorization",
@ -21,5 +22,6 @@
"--no-open ": "do not open web browser when server started",
"--no-minify ": "disable minification",
"--no-progress ": "do not show progress of file operations",
"--no-one-panel-mode ": "unset one panel mode"
"--no-one-panel-mode ": "unset one panel mode",
"--no-config-dialog ": "disable config dialog"
}

View file

@ -293,7 +293,16 @@ var CloudCmd, Util, DOM, io;
}
}
init();
DOM.Files.get('config', function(error, config) {
if (error)
return Dialog.alert(TITLE, error);
if (!config.configDialog)
return;
init();
});
}
})(CloudCmd, Util, DOM);

View file

@ -48,11 +48,10 @@ module.exports = manage;
module.exports.save = save;
module.exports.middle = middle;
module.exports.listen = function(socket, authCheck) {
if (!socket)
throw Error('socket could not be empty!');
check(socket, authCheck);
if (authCheck && typeof authCheck !== 'function')
throw Error('authCheck should be function!');
if (!manage('configDialog'))
return middle;
listen(socket, authCheck);
@ -115,6 +114,8 @@ function connection(socket) {
}
function middle(req, res, next) {
var noConfigDialog = !manage('configDialog');
if (req.url !== apiURL + '/config') {
next();
} else {
@ -124,6 +125,11 @@ function middle(req, res, next) {
break;
case 'PATCH':
if (noConfigDialog)
return res
.status(404)
.send('Config is disabled');
patch(req, res, next);
break;
@ -190,3 +196,11 @@ function cryptoPass(json) {
json.password = criton(json.password, algo);
}
function check(socket, authCheck) {
if (!socket)
throw Error('socket could not be empty!');
if (authCheck && typeof authCheck !== 'function')
throw Error('authCheck should be function!');
}

View file

@ -48,6 +48,8 @@ var DIR = __dirname + '/../../',
}).join(':');
module.exports = function(req, res, next) {
check(req, res, next);
readFiles(function() {
route(req, res, next);
});
@ -62,6 +64,7 @@ function indexProcessing(options) {
right = '',
keysPanel = '<div id="js-keyspanel" class="{{ className }}',
isOnePanel = config('onePanelMode'),
isConfig = config('configDialog'),
data = options.data,
panel = options.panel;
@ -82,6 +85,10 @@ function indexProcessing(options) {
.replace('icon-move', 'icon-move none')
.replace('icon-copy', 'icon-copy none');
if (!isConfig)
data = data
.replace('icon-config', 'icon-config none');
left = rendy(Template.panel, {
side : 'left',
content : panel,
@ -96,10 +103,10 @@ function indexProcessing(options) {
});
data = rendy(data, {
title : CloudFunc.getTitle(),
fm : left + right,
prefix : prefix(),
css : CSS_URL
title: CloudFunc.getTitle(),
fm: left + right,
prefix: prefix(),
css: CSS_URL
});
return data;
@ -148,15 +155,6 @@ function readFiles(callback) {
function route(request, response, callback) {
var name, p, isAuth, isFS, fullPath;
if (!request)
throw Error('request could not be empty!');
if (!response)
throw Error('response could not be empty!');
if (typeof callback !== 'function')
throw Error('callback should be function!');
name = ponse.getPathName(request);
isAuth = RegExp('^(/auth|/auth/github)$').test(name);
@ -233,3 +231,14 @@ function buildIndex(json, callback) {
minify(PATH_INDEX, 'name', callback);
});
}
function check(req, res, next) {
if (!req)
throw Error('req could not be empty!');
if (!res)
throw Error('res could not be empty!');
if (typeof next !== 'function')
throw Error('next should be function!');
}

View file

@ -38,6 +38,7 @@ programs in browser from any computer, mobile or tablet device.
--progress show progress of file operations
--open open web browser when server started
--one-panel-mode set one panel mode
--config-dialog enable config dialog
--no-auth disable authorization
--no-server do not start server
--no-online load scripts from local server
@ -45,6 +46,7 @@ programs in browser from any computer, mobile or tablet device.
--no-minify disable minification
--no-progress do not show progress of file operations
--no-one-panel-mode unset one panel mode
--no-config-dialog disable config dialog
.SH RESOURCES AND DOCUMENTATION

View file

@ -8,6 +8,7 @@ const writejson = require('writejson');
const readjson = require('readjson');
const cloudcmd = require('..');
const {assign} = Object;
const pathConfig = os.homedir() + '/.cloudcmd.json';
const currentConfig = readjson.sync.try(pathConfig);
@ -23,10 +24,7 @@ module.exports = (config, fn = config) => {
};
app.use(cloudcmd({
config: {
auth: false,
root: __dirname
}
config: assign(defaultConfig(), config)
}));
server.listen(() => {
@ -34,3 +32,10 @@ module.exports = (config, fn = config) => {
});
};
function defaultConfig() {
return {
auth: false,
root: __dirname
};
}

View file

@ -35,16 +35,18 @@ test('cloudcmd: rest: config: get', (t) => {
});
});
test('cloudcmd: rest: config: put', (t) => {
before((port, after) => {
patch(`http://localhost:${port}/api/v1/config`, {
json: {
auth: false
}
})
test('cloudcmd: rest: config: patch', (t) => {
const configDialog = true;
before({configDialog}, (port, after) => {
const json = {
auth: false,
};
patch(`http://localhost:${port}/api/v1/config`, json)
.then(warp(_pullout, 'string'))
.then((result) => {
t.equal(result, 'config: ok("json")', 'should patch config');
t.equal(result, 'config: ok("auth")', 'should patch config');
t.end();
after();
})
@ -54,3 +56,46 @@ test('cloudcmd: rest: config: put', (t) => {
});
});
test('cloudcmd: rest: config: patch: no configDialog', (t) => {
const configDialog = false;
before({configDialog}, (port, after) => {
const json = {
ip: null
};
patch(`http://localhost:${port}/api/v1/config`, json)
.then(warp(_pullout, 'string'))
.then((result) => {
t.equal(result, 'Config is disabled', 'should return error');
t.end();
after();
})
.catch((error) => {
console.log(error);
});
});
});
test('cloudcmd: rest: config: patch: no configDialog: statusCode', (t) => {
const configDialog = false;
before({configDialog}, (port, after) => {
const json = {
ip: null
};
patch(`http://localhost:${port}/api/v1/config`, json)
.then((result) => {
result.on('response', (response) => {
t.equal(response.statusCode, 404);
t.end();
after();
});
})
.catch((error) => {
console.log(error);
});
});
});