Skip to content

Commit

Permalink
feature(cloudcmd) --name: add ability to set tab name in web browser
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 26, 2017
1 parent 9ef0dd0 commit 9cdca9e
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 20 deletions.
15 changes: 10 additions & 5 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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" */
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions bin/cloudcmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const choose = (a, b) => {
const argv = process.argv;
const args = require('minimist')(argv.slice(2), {
string: [
'name',
'port',
'password',
'username',
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion client/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions client/modules/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions common/cloudfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' - ');
};

/** Функция получает адреса каждого каталога в пути
Expand Down
1 change: 1 addition & 0 deletions json/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "",
"auth": false,
"username": "root",
"password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9",
Expand Down
4 changes: 3 additions & 1 deletion json/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
4 changes: 3 additions & 1 deletion man/cloudcmd.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion server/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('*')),
Expand Down
31 changes: 24 additions & 7 deletions test/common/cloudfunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
});

8 changes: 8 additions & 0 deletions tmpl/config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
<input data-name="js-showKeysPanel" type="checkbox" {{ showKeysPanel }}>
Show keys panel
</label>
</li>
<li>
<input
data-name="js-name"
title="Name"
value="{{ name }}"
placeholder="name"
class="form-control">
</li>
<li>
<input
Expand Down

0 comments on commit 9cdca9e

Please sign in to comment.