From 9cdca9efe52d994a576f1c68c82f36cbbc97582c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 26 Jul 2017 16:57:33 +0300 Subject: [PATCH] feature(cloudcmd) --name: add ability to set tab name in web browser --- HELP.md | 15 ++++++++++----- app.json | 5 +++++ bin/cloudcmd.js | 3 +++ client/dom/index.js | 6 +++++- client/modules/config.js | 14 ++++++++++++-- common/cloudfunc.js | 16 ++++++++++++++-- json/config.json | 1 + json/help.json | 4 +++- man/cloudcmd.1 | 4 +++- server/route.js | 6 +++++- test/common/cloudfunc.js | 31 ++++++++++++++++++++++++------- tmpl/config.hbs | 8 ++++++++ 12 files changed, 93 insertions(+), 20 deletions(-) diff --git a/HELP.md b/HELP.md index 8a37e155..309c1d17 100644 --- a/HELP.md +++ b/HELP.md @@ -80,11 +80,12 @@ Cloud Commander supports command line parameters: | `--progress` | show progress of file operations | `--html-dialogs` | use html dialogs | `--open` | open web browser when server started +| `--name` | set tab name in web browser | `--one-panel-mode` | set one panel mode - `--config-dialog` | enable config dialog - `--console` | enable console - `--terminal` | enable terminal - `--terminal-path` | set terminal path +| `--config-dialog` | enable config dialog +| `--console` | enable console +| `--terminal` | enable terminal +| `--terminal-path` | set terminal path | `--no-server` | do not start server | `--no-auth` | disable authorization | `--no-online` | load scripts from local server @@ -95,6 +96,8 @@ Cloud Commander supports command line parameters: | `--no-config-dialog` | disable config dialog | `--no-console` | disable console | `--no-terminal` | disable terminal +| `--no-name` | set empty tab name in web browser + 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. @@ -296,9 +299,10 @@ Here is description of options: ```js { + "name" : "", /* set tab name in web browser */ "auth" : false, /* enable http authentication */ "username" : "root", /* username for authentication */ -    "password"         : "toor",   /* password hash for authentication*/ +    "password"         : "toor",   /* password hash for authentication */ "algo" : "sha512WithRSAEncryption", /* cryptographic algorithm */ "editor" : "edward", /* default, could be "dword" or "edward" */ "packer" : "tar", /* default, could be "tar" or "zip" */ @@ -329,6 +333,7 @@ Here is description of options: Some config options can be overridden with `environment variables` such: +- `CLOUDCMD_NAME` - set tab name in web browser - `CLOUDCMD_EDITOR` - set editor - `CLOUDCMD_TERMINAL` - enable terminal - `CLOUDCMD_TERMINAL_PATH` - set terminal path diff --git a/app.json b/app.json index 4c22c629..4aa8aaa2 100644 --- a/app.json +++ b/app.json @@ -37,6 +37,11 @@ "value": "false", "required": false }, + "CLOUDCMD_NAME": { + "description": "set tab name in web browser", + "value": "", + "required": false + }, "CLOUDCMD_AUTH": { "description": "enable authorization", "value": "false", diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index c279db61..4de2a48a 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -19,6 +19,7 @@ const choose = (a, b) => { const argv = process.argv; const args = require('minimist')(argv.slice(2), { string: [ + 'name', 'port', 'password', 'username', @@ -46,6 +47,7 @@ const args = require('minimist')(argv.slice(2), { ], default: { server : true, + name : env('name') || config('name'), auth : choose(env('auth'), config('auth')), port : config('port'), online : config('online'), @@ -95,6 +97,7 @@ function main() { port(args.port); + config('name', args.name); config('auth', args.auth); config('online', args.online); config('open', args.open); diff --git a/client/dom/index.js b/client/dom/index.js index 2fbf4e37..391f0798 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -461,8 +461,12 @@ function CmdProto() { let path = DOM.getCurrentDirPath(); + const name = CloudCmd.config('name'); if (path !== pathWas) { - DOM.setTitle(getTitle(path)); + DOM.setTitle(getTitle({ + name, + path, + })); /* history could be present * but it should be false diff --git a/client/modules/config.js b/client/modules/config.js index d4232312..40f65e72 100644 --- a/client/modules/config.js +++ b/client/modules/config.js @@ -13,7 +13,9 @@ const Images = require('../dom/images'); const Events = require('../dom/events'); const Files = require('../dom/files'); -const {Dialog} = DOM; +const {getTitle} = require('../../common/cloudfunc'); + +const {Dialog, setTitle} = DOM; const TITLE = 'Config'; const alert = currify(Dialog.alert, TITLE); @@ -200,7 +202,9 @@ function onChange(el) { const data = input.getValue(name, Element); const type = el.type; - if (type === 'checkbox') + if (name === 'name') + onNameChange(data); + else if (type === 'checkbox') if (/^(diff|buffer|dirStorage)$/.test(name)) onLSChange(name, data); else if (name === 'localStorage') @@ -287,6 +291,12 @@ function onAuthChange(checked) { elPassword.disabled = !checked; } +function onNameChange(name) { + setTitle(getTitle({ + name + })); +} + function onKey({keyCode, target}) { switch (keyCode) { case Key.ESC: diff --git a/common/cloudfunc.js b/common/cloudfunc.js index fd5aa1a1..bf63f9c0 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -33,8 +33,20 @@ module.exports.formatMsg = (msg, name, status) => { * Функция возвращает заголовок веб страницы * @path */ -module.exports.getTitle = (path) => { - return NAME + ' - ' + (path || Path()); +module.exports.getTitle = (options) => { + options = options || {}; + + const path = options.path || Path(); + const name = options.name; + + const array = [ + name || NAME, + path, + ]; + + return array + .filter(Boolean) + .join(' - '); }; /** Функция получает адреса каждого каталога в пути diff --git a/json/config.json b/json/config.json index 5728938a..0c5a6da0 100644 --- a/json/config.json +++ b/json/config.json @@ -1,4 +1,5 @@ { + "name": "", "auth": false, "username": "root", "password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9", diff --git a/json/help.json b/json/help.json index 7d9bfe0e..3d04cc5d 100644 --- a/json/help.json +++ b/json/help.json @@ -21,6 +21,7 @@ "--terminal ": "enable terminal", "--terminal-path ": "set terminal path", "--open ": "open web browser when server started", + "--name ": "set tab name in web browser", "--no-server ": "do not start server", "--no-auth ": "disable authorization", "--no-online ": "load scripts from local server", @@ -30,5 +31,6 @@ "--no-one-panel-mode ": "unset one panel mode", "--no-config-dialog ": "disable config dialog", "--no-console ": "disable console", - "--no-terminal ": "disable terminal" + "--no-terminal ": "disable terminal", + "--no-name ": "set default tab name in web browser" } diff --git a/man/cloudcmd.1 b/man/cloudcmd.1 index e351052d..b8ed2afa 100644 --- a/man/cloudcmd.1 +++ b/man/cloudcmd.1 @@ -38,12 +38,13 @@ programs in browser from any computer, mobile or tablet device. --port set port number --progress show progress of file operations --html-dialogs use html dialogs - --open open web browser when server started --one-panel-mode set one panel mode --config-dialog enable config dialog --console enable console --terminal enable terminal --terminal-path set terminal path + --open open web browser when server started + --name set tab name in web browser --no-auth disable authorization --no-server do not start server --no-online load scripts from local server @@ -54,6 +55,7 @@ programs in browser from any computer, mobile or tablet device. --no-config-dialog disable config dialog --no-console disable console --no-terminal disable terminal + --no-name set default tab name in web browser .SH RESOURCES AND DOCUMENTATION diff --git a/server/route.js b/server/route.js index b56aec5b..71eed350 100644 --- a/server/route.js +++ b/server/route.js @@ -107,8 +107,12 @@ function indexProcessing(options) { className : '' }); + const name = config('name'); + data = rendy(data, { - title: CloudFunc.getTitle(), + title: CloudFunc.getTitle({ + name, + }), fm: left + right, prefix: prefix(), config: JSON.stringify(config('*')), diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index 7751ead4..2cab15cc 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -5,7 +5,9 @@ const COMMONDIR = DIR + 'common/'; const TMPLDIR = DIR + 'tmpl/'; const Util = require(COMMONDIR + 'util'); -const CloudFunc = require(COMMONDIR + 'cloudfunc'); +const CloudFuncPath = COMMONDIR + 'cloudfunc'; + +const CloudFunc = require(CloudFuncPath); const files = require('files-io'); const currify = require('currify'); @@ -151,22 +153,37 @@ test('cloudfunc: formatMsg', (t) => { }); test('cloudfunc: getTitle', (t) => { - const name = COMMONDIR + 'cloudfunc'; + const CloudFunc = fresh(CloudFuncPath); - const CloudFunc = fresh(name); const result = CloudFunc.getTitle(); t.equal(result, 'Cloud Commander - /'); t.end(); }); -test('cloudfunc: getTitle', (t) => { - const name = COMMONDIR + 'cloudfunc'; +test('cloudfunc: getTitle: no name', (t) => { + const CloudFunc = fresh(CloudFuncPath); + const path = '/hello/world'; - const CloudFunc = fresh(name); - const result = CloudFunc.getTitle('/hello/world'); + const result = CloudFunc.getTitle({ + path + }); t.equal(result, 'Cloud Commander - /hello/world'); t.end(); }); +test('cloudfunc: getTitle: name, path', (t) => { + const CloudFunc = fresh(CloudFuncPath); + const name = 'hello'; + const path = '/hello/world'; + + const result = CloudFunc.getTitle({ + name, + path, + }); + + t.equal(result, 'hello - /hello/world'); + t.end(); +}); + diff --git a/tmpl/config.hbs b/tmpl/config.hbs index bd7c4c1a..1fee58f2 100644 --- a/tmpl/config.hbs +++ b/tmpl/config.hbs @@ -93,6 +93,14 @@ Show keys panel + +
  • +