feature(cloudcmd) --columns: add ability to set visible columns (#146)

This commit is contained in:
coderaiser 2018-03-02 18:00:15 +02:00
parent 6c9913e5f1
commit b5f98be162
18 changed files with 115 additions and 30 deletions

View file

@ -92,6 +92,7 @@ Cloud Commander supports command line parameters:
| `--terminal` | enable terminal
| `--terminal-path` | set terminal path
| `--vim` | enable vim hot keys
| `--columns` | set visible columns
| `--no-server` | do not start server
| `--no-auth` | disable authorization
| `--no-online` | load scripts from local server
@ -107,7 +108,7 @@ Cloud Commander supports command line parameters:
| `--no-console` | disable console
| `--no-terminal` | disable terminal
| `--no-vim` | disable vim hot keys
| `--no-columns` | set visible default columns
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.
@ -378,6 +379,7 @@ Here is description of options:
"terminal" : false, /* disable terminal */
"terminalPath" : '', /* path of a terminal */
"vim" : false, /* disable vim hot keys */
"columns" : "name-size-date-owner-mode", /* set visible columns */
}
```
@ -387,6 +389,7 @@ Some config options can be overridden with `environment variables` such:
- `CLOUDCMD_NAME` - set tab name in web browser
- `CLOUDCMD_EDITOR` - set editor
- `CLOUDCMD_COLUMNS` - set visible columns
- `CLOUDCMD_CONTACT` - enable contact
- `CLOUDCMD_CONFIG_DIALOG` - enable config dialog
- `CLOUDCMD_CONSOLE` - enable console

View file

@ -29,6 +29,7 @@ const args = require('minimist')(argv.slice(2), {
'root',
'prefix',
'terminal-path',
'columns',
],
boolean: [
'auth',
@ -74,6 +75,7 @@ const args = require('minimist')(argv.slice(2), {
'confirm-move': choose(env.bool('confirm_move'), config('confirmMove')),
'html-dialogs': config('htmlDialogs'),
'vim': choose(env.bool('vim'), config('vim')),
'columns': env('columns') || config('columns') || '',
},
alias: {
v: 'version',
@ -119,6 +121,7 @@ function main() {
config('prefix', args.prefix);
config('root', args.root);
config('vim', args.vim);
config('columns', args.columns);
config('htmlDialogs', args['html-dialogs']);
config('confirmCopy', args['confirm-copy']);
config('confirmMove', args['confirm-move']);
@ -131,7 +134,8 @@ function main() {
root: args.root || '/', /* --no-root */
editor: args.editor,
packer: args.packer,
prefix: args.prefix
prefix: args.prefix,
columns: args.columns,
};
const password = env('password') || args.password;

View file

@ -2,6 +2,7 @@
require('../css/main.css');
require('../css/nojs.css');
require('../css/columns/name-size-date.css');
// prevent additional loading of exec by spero, remedy, ishtar, salam, omnes
window.exec = require('execon');

View file

@ -358,3 +358,4 @@ load.style = (params) => {
element,
});
};

View file

@ -165,6 +165,9 @@ function fillTemplate(error, template) {
obj[obj.packer + '-selected'] = 'selected';
delete obj.packer;
obj[obj.columns + '-selected'] = 'selected';
delete obj.columns;
const inner = rendy(Template, obj);
Element = DOM.load({

View file

@ -0,0 +1,12 @@
.name {
width: 59%;
}
.owner {
display: none;
}
.mode {
display: none;
}

View file

@ -7,12 +7,14 @@
<!-- mobile first design -->
<meta content="width=device-width,initial-scale=1" name="viewport">
<link rel="icon" href="{{ prefix }}/favicon.ico">
<title>{{ title }}</title>
<link rel=stylesheet href="{{ prefix }}/dist/cloudcmd.css">
<noscript>
<link rel=stylesheet href="{{ prefix }}/dist/nojs.css">
</noscript>
<style data-name="columns">
{{ columns }}
</style>
</head>
<body>
<div class=fm>{{ fm }}</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

After

Width:  |  Height:  |  Size: 165 KiB

Before After
Before After

View file

@ -30,6 +30,7 @@
"terminal": false,
"terminalPath": "",
"showConfig": false,
"vim": false
"vim": false,
"columns": "name-size-date-owner-mode"
}

View file

@ -26,6 +26,7 @@
"--terminal ": "enable terminal",
"--terminal-path ": "set terminal path",
"--vim ": "enable vim hot keys",
"--columns ": "set visible columns",
"--no-server ": "do not start server",
"--no-auth ": "disable authorization",
"--no-online ": "load scripts from local server",
@ -40,5 +41,6 @@
"--no-console ": "disable console",
"--no-contact ": "disable contact",
"--no-terminal ": "disable terminal",
"--no-vim ": "disable vim hot keys"
"--no-vim ": "disable vim hot keys",
"--no-columns ": "set default visible columns"
}

View file

@ -49,6 +49,7 @@ programs in browser from any computer, mobile or tablet device.
--terminal enable terminal
--terminal-path set terminal path
--vim enable vim hot keys
--columns` set visible columns
--no-auth disable authorization
--no-server do not start server
--no-online load scripts from local server
@ -64,6 +65,7 @@ programs in browser from any computer, mobile or tablet device.
--no-console disable console
--no-terminal disable terminal
--no-vim disable vim hot keys
--no-columns set visible default columns
.SH RESOURCES AND DOCUMENTATION

View file

@ -54,19 +54,8 @@ module.exports = (params) => {
keys.forEach((name) => {
const value = options[name];
switch(name) {
case 'root':
validate.root(value);
break;
case 'editor':
validate.editor(value);
break;
case 'packer':
validate.packer(value);
break;
}
if (/root|editor|packer|columns/.test(name))
validate[name](value);
config(name, value);
});

17
server/columns.js Normal file
View file

@ -0,0 +1,17 @@
'use strict';
const fs = require('fs');
const isDev = process.NODE_ENV === 'development';
const dir = getDirPath(isDev);
module.exports = {
'': '',
'name-size-date': fs.readFileSync(`${dir}/name-size-date.css`, 'utf8'),
'name-size-date-owner-mode': '',
};
function getDirPath (isDev) {
const dist = isDev ? 'dist-dev' : 'dist';
return `${__dirname}/../${dist}/columns`;
}

View file

@ -14,6 +14,7 @@ const format = require('format-io');
const squad = require('squad/legacy');
const apart = require('apart');
const columns = require(DIR_SERVER + 'columns');
const config = require(DIR_SERVER + 'config');
const root = require(DIR_SERVER + 'root');
const prefixer = require(DIR_SERVER + 'prefixer');
@ -99,6 +100,7 @@ function indexProcessing(options) {
fm: left + right,
prefix: prefix(),
config: JSON.stringify(config('*')),
columns: columns[config('columns')],
});
return data;

View file

@ -1,12 +1,9 @@
'use strict';
const exit = require('./exit');
const columns = require('./columns');
module.exports.root = root;
module.exports.editor = editor;
module.exports.packer = packer;
function root(dir, fn) {
module.exports.root = (dir, fn) => {
if (typeof dir !== 'string')
throw Error('dir should be a string');
@ -22,19 +19,28 @@ function root(dir, fn) {
if (typeof fn === 'function')
fn('root:', dir);
});
}
};
function editor(name) {
module.exports.editor = (name) => {
const reg = /^(dword|edward|deepword)$/;
if (!reg.test(name))
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
}
};
function packer(name) {
module.exports.packer = (name) => {
const reg = /^(tar|zip)$/;
if (!reg.test(name))
exit('cloudcmd --packer: could be "tar" or "zip" only');
}
};
module.exports.columns = (type) => {
const all = Object
.keys(columns)
.concat('');
if (!~all.indexOf(type))
exit('cloudcmd --columns: could be "name-size-date" or "name-size-date-owner-mode"');
};

View file

@ -107,6 +107,37 @@ test('validate: editor: not valid', (t) => {
t.end();
});
test('validate: columns', (t) => {
const fn = sinon.stub();
clean();
require(exitPath);
stub(exitPath, fn);
const {columns} = require(validatePath);
columns('name-size-date');
t.notOk(fn.called, 'should not call exit');
t.end();
});
test('validate: columns: wrong', (t) => {
const fn = sinon.stub();
clean();
require(exitPath);
stub(exitPath, fn);
const {columns} = require(validatePath);
const msg = 'cloudcmd --columns: could be "name-size-date" or "name-size-date-owner-mode"';
columns('hello');
t.ok(fn.calledWith(msg), 'should call exit');
t.end();
});
function clean() {
clear(validatePath);
clear(exitPath);

View file

@ -43,6 +43,12 @@
Zip
</label>
</li>
<li>
<select data-name="js-columns" class="form-control full-width" title="Columns">
<option {{ name-size-date-owner-mode-selected }}>name-size-date-owner-mode</option>
<option {{ name-size-date-selected }}>name-size-date</option>
</select>
</li>
<li>
<select data-name="js-editor" class="form-control full-width" title="Editor">
<option {{ edward-selected }}>edward</option>

View file

@ -23,6 +23,7 @@ const extractNojs = new ExtractTextPlugin('nojs.css');
const extractView = new ExtractTextPlugin('view.css');
const extractConfig = new ExtractTextPlugin('config.css');
const extractNameSizeDate = new ExtractTextPlugin('columns/name-size-date.css');
const plugins = [
new HtmlWebpackPlugin({
@ -34,6 +35,7 @@ const plugins = [
extractNojs,
extractView,
extractConfig,
extractNameSizeDate,
];
const rules = clean([
@ -43,7 +45,7 @@ const rules = clean([
loader: 'babel-loader',
}, {
test: /\.css$/,
exclude: /css\/(nojs|view|config)\.css/,
exclude: /css\/(nojs|view|config|columns.*)\.css/,
use: extractMain.extract([
'css-loader?minimize',
]),
@ -51,6 +53,7 @@ const rules = clean([
extract('nojs', extractNojs),
extract('view', extractView),
extract('config', extractConfig),
extract('columns/name-size-date', extractNameSizeDate),
{
test: /\.(png|gif|svg|woff|woff2|eot|ttf)$/,
loader: 'url-loader?limit=50000',
@ -154,7 +157,7 @@ function getMinifyHtmlOptions() {
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
minifyCSS: false,
};
}