Skip to content

Commit 9cdca9e

Browse files
committed
feature(cloudcmd) --name: add ability to set tab name in web browser
1 parent 9ef0dd0 commit 9cdca9e

File tree

12 files changed

+93
-20
lines changed

12 files changed

+93
-20
lines changed

HELP.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ Cloud Commander supports command line parameters:
8080
| `--progress` | show progress of file operations
8181
| `--html-dialogs` | use html dialogs
8282
| `--open` | open web browser when server started
83+
| `--name` | set tab name in web browser
8384
| `--one-panel-mode` | set one panel mode
84-
`--config-dialog` | enable config dialog
85-
`--console` | enable console
86-
`--terminal` | enable terminal
87-
`--terminal-path` | set terminal path
85+
| `--config-dialog` | enable config dialog
86+
| `--console` | enable console
87+
| `--terminal` | enable terminal
88+
| `--terminal-path` | set terminal path
8889
| `--no-server` | do not start server
8990
| `--no-auth` | disable authorization
9091
| `--no-online` | load scripts from local server
@@ -95,6 +96,8 @@ Cloud Commander supports command line parameters:
9596
| `--no-config-dialog` | disable config dialog
9697
| `--no-console` | disable console
9798
| `--no-terminal` | disable terminal
99+
| `--no-name` | set empty tab name in web browser
100+
98101

99102
If no parameters given Cloud Commander reads information from `~/.cloudcmd.json` and use
100103
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:
296299

297300
```js
298301
{
302+
"name" : "", /* set tab name in web browser */
299303
"auth" : false, /* enable http authentication */
300304
"username" : "root", /* username for authentication */
301-
   "password"         : "toor",   /* password hash for authentication*/
305+
   "password"         : "toor",   /* password hash for authentication */
302306
"algo" : "sha512WithRSAEncryption", /* cryptographic algorithm */
303307
"editor" : "edward", /* default, could be "dword" or "edward" */
304308
"packer" : "tar", /* default, could be "tar" or "zip" */
@@ -329,6 +333,7 @@ Here is description of options:
329333

330334
Some config options can be overridden with `environment variables` such:
331335

336+
- `CLOUDCMD_NAME` - set tab name in web browser
332337
- `CLOUDCMD_EDITOR` - set editor
333338
- `CLOUDCMD_TERMINAL` - enable terminal
334339
- `CLOUDCMD_TERMINAL_PATH` - set terminal path

app.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"value": "false",
3838
"required": false
3939
},
40+
"CLOUDCMD_NAME": {
41+
"description": "set tab name in web browser",
42+
"value": "",
43+
"required": false
44+
},
4045
"CLOUDCMD_AUTH": {
4146
"description": "enable authorization",
4247
"value": "false",

bin/cloudcmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const choose = (a, b) => {
1919
const argv = process.argv;
2020
const args = require('minimist')(argv.slice(2), {
2121
string: [
22+
'name',
2223
'port',
2324
'password',
2425
'username',
@@ -46,6 +47,7 @@ const args = require('minimist')(argv.slice(2), {
4647
],
4748
default: {
4849
server : true,
50+
name : env('name') || config('name'),
4951
auth : choose(env('auth'), config('auth')),
5052
port : config('port'),
5153
online : config('online'),
@@ -95,6 +97,7 @@ function main() {
9597

9698
port(args.port);
9799

100+
config('name', args.name);
98101
config('auth', args.auth);
99102
config('online', args.online);
100103
config('open', args.open);

client/dom/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,12 @@ function CmdProto() {
461461

462462
let path = DOM.getCurrentDirPath();
463463

464+
const name = CloudCmd.config('name');
464465
if (path !== pathWas) {
465-
DOM.setTitle(getTitle(path));
466+
DOM.setTitle(getTitle({
467+
name,
468+
path,
469+
}));
466470

467471
/* history could be present
468472
* but it should be false

client/modules/config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const Images = require('../dom/images');
1313
const Events = require('../dom/events');
1414
const Files = require('../dom/files');
1515

16-
const {Dialog} = DOM;
16+
const {getTitle} = require('../../common/cloudfunc');
17+
18+
const {Dialog, setTitle} = DOM;
1719

1820
const TITLE = 'Config';
1921
const alert = currify(Dialog.alert, TITLE);
@@ -200,7 +202,9 @@ function onChange(el) {
200202
const data = input.getValue(name, Element);
201203
const type = el.type;
202204

203-
if (type === 'checkbox')
205+
if (name === 'name')
206+
onNameChange(data);
207+
else if (type === 'checkbox')
204208
if (/^(diff|buffer|dirStorage)$/.test(name))
205209
onLSChange(name, data);
206210
else if (name === 'localStorage')
@@ -287,6 +291,12 @@ function onAuthChange(checked) {
287291
elPassword.disabled = !checked;
288292
}
289293

294+
function onNameChange(name) {
295+
setTitle(getTitle({
296+
name
297+
}));
298+
}
299+
290300
function onKey({keyCode, target}) {
291301
switch (keyCode) {
292302
case Key.ESC:

common/cloudfunc.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ module.exports.formatMsg = (msg, name, status) => {
3333
* Функция возвращает заголовок веб страницы
3434
* @path
3535
*/
36-
module.exports.getTitle = (path) => {
37-
return NAME + ' - ' + (path || Path());
36+
module.exports.getTitle = (options) => {
37+
options = options || {};
38+
39+
const path = options.path || Path();
40+
const name = options.name;
41+
42+
const array = [
43+
name || NAME,
44+
path,
45+
];
46+
47+
return array
48+
.filter(Boolean)
49+
.join(' - ');
3850
};
3951

4052
/** Функция получает адреса каждого каталога в пути

json/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"name": "",
23
"auth": false,
34
"username": "root",
45
"password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9",

json/help.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"--terminal ": "enable terminal",
2222
"--terminal-path ": "set terminal path",
2323
"--open ": "open web browser when server started",
24+
"--name ": "set tab name in web browser",
2425
"--no-server ": "do not start server",
2526
"--no-auth ": "disable authorization",
2627
"--no-online ": "load scripts from local server",
@@ -30,5 +31,6 @@
3031
"--no-one-panel-mode ": "unset one panel mode",
3132
"--no-config-dialog ": "disable config dialog",
3233
"--no-console ": "disable console",
33-
"--no-terminal ": "disable terminal"
34+
"--no-terminal ": "disable terminal",
35+
"--no-name ": "set default tab name in web browser"
3436
}

man/cloudcmd.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ programs in browser from any computer, mobile or tablet device.
3838
--port set port number
3939
--progress show progress of file operations
4040
--html-dialogs use html dialogs
41-
--open open web browser when server started
4241
--one-panel-mode set one panel mode
4342
--config-dialog enable config dialog
4443
--console enable console
4544
--terminal enable terminal
4645
--terminal-path set terminal path
46+
--open open web browser when server started
47+
--name set tab name in web browser
4748
--no-auth disable authorization
4849
--no-server do not start server
4950
--no-online load scripts from local server
@@ -54,6 +55,7 @@ programs in browser from any computer, mobile or tablet device.
5455
--no-config-dialog disable config dialog
5556
--no-console disable console
5657
--no-terminal disable terminal
58+
--no-name set default tab name in web browser
5759

5860
.SH RESOURCES AND DOCUMENTATION
5961

server/route.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ function indexProcessing(options) {
107107
className : ''
108108
});
109109

110+
const name = config('name');
111+
110112
data = rendy(data, {
111-
title: CloudFunc.getTitle(),
113+
title: CloudFunc.getTitle({
114+
name,
115+
}),
112116
fm: left + right,
113117
prefix: prefix(),
114118
config: JSON.stringify(config('*')),

0 commit comments

Comments
 (0)