Commit c5442207 authored by antoor's avatar antoor

Update the edit-shell features

更新编辑数据功能
parent a2c15de9
...@@ -141,25 +141,30 @@ class Database { ...@@ -141,25 +141,30 @@ class Database {
/** /**
* 编辑shell数据 * 编辑shell数据
* @param {Object} event ipcMain对象 * @param {Object} event ipcMain对象
* @param {Object} opts 数据(url,_id,pwd,type,encode,encoder * @param {Object} opts 数据(old,new
* @return {[type]} [description] * @return {[type]} [description]
*/ */
editShell(event, opts) { editShell(event, opts) {
logger.warn('editShell', opts); logger.warn('editShell', opts);
this._url2ip(opts['url']) const _new = opts.new;
const _old = opts.old;
this._url2ip(_new.base['url'])
.then((ret) => { .then((ret) => {
this.cursor.update({ this.cursor.update({
_id: opts['_id'] _id: _old['_id']
}, { }, {
$set: { $set: {
ip: ret['ip'], ip: ret['ip'],
addr: ret['addr'], addr: ret['addr'],
url: opts['url'], url: _new.base['url'],
pwd: opts['pwd'], pwd: _new.base['pwd'],
type: opts['type'], type: _new.base['type'],
encode: opts['encode'], encode: _new.base['encode'],
encoder: opts['encoder'], encoder: _new.base['encoder'],
httpConf: _new.http,
otherConf: _new.other,
utime: +new Date utime: +new Date
} }
}, (_err, _ret) => { }, (_err, _ret) => {
......
...@@ -18,6 +18,7 @@ class ContextMenu { ...@@ -18,6 +18,7 @@ class ContextMenu {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
constructor(data, event, id, ids) { constructor(data, event, id, ids) {
console.log('data=', data);
let selectedData = !id || ids.length !== 1; let selectedData = !id || ids.length !== 1;
let selectedMultiData = !id; let selectedMultiData = !id;
...@@ -42,7 +43,7 @@ class ContextMenu { ...@@ -42,7 +43,7 @@ class ContextMenu {
], ],
false, false,
['add', 'plus-circle', false, this.addData.bind(this)], ['add', 'plus-circle', false, this.addData.bind(this)],
['edit', 'edit', selectedData, this.editData.bind(this, id)], ['edit', 'edit', selectedData, this.editData.bind(this, data[0])],
['delete', 'remove', selectedMultiData, this.delData.bind(this, ids)], ['delete', 'remove', selectedMultiData, this.delData.bind(this, ids)],
false, false,
['move', 'share-square', selectedMultiData, null, this.parseMoveCategoryMenu(ids)], ['move', 'share-square', selectedMultiData, null, this.parseMoveCategoryMenu(ids)],
...@@ -198,9 +199,9 @@ class ContextMenu { ...@@ -198,9 +199,9 @@ class ContextMenu {
antSword.modules.shellmanager.reloadData({ antSword.modules.shellmanager.reloadData({
category: data['base']['category'] category: data['base']['category']
}); });
return res(); return res(LANG['list']['add']['success']);
} else { } else {
return rej(ret.totring()); return rej(LANG['list']['add']['error'](ret.toString()));
} }
}); });
}) })
...@@ -208,14 +209,31 @@ class ContextMenu { ...@@ -208,14 +209,31 @@ class ContextMenu {
/** /**
* 编辑数据 * 编辑数据
* @param {number} id [description] * @param {Object} info 当前选中的数据
* @return {[type]} [description] * @return {[type]} [description]
*/ */
editData(id) { editData(info) {
new Form({ new Form({
title: LANG['list']['edit']['title'](id), title: LANG['list']['edit']['title'](info.url),
icon: 'save', icon: 'save',
text: LANG['list']['edit']['toolbar']['save'] text: LANG['list']['edit']['toolbar']['save']
}, info, (data) => {
return new Promise((res, rej) => {
// 通知后台更新数据
const ret = antSword.ipcRenderer.sendSync('shell-edit', {
old: info,
new: data
});
if (ret === 1) {
// 重新加载数据
antSword.modules.shellmanager.reloadData({
category: info['category']
});
return res(LANG['list']['edit']['success']);
} else {
return rej(LANG['list']['edit']['error'](ret.toString()));
}
})
}) })
} }
......
...@@ -45,14 +45,14 @@ class Form { ...@@ -45,14 +45,14 @@ class Form {
this.baseForm.getValues(), this.baseForm.getValues(),
this.httpForm.getValues(), this.httpForm.getValues(),
this.otherForm.getValues() this.otherForm.getValues()
)).then(() => { )).then((msg) => {
// 添加/保存完毕后回调 // 添加/保存完毕后回调
win.close(); win.close();
toastr.success(LANG['list']['add']['success'], LANG_T['success']); toastr.success(msg, LANG_T['success']);
}).catch((e) => { }).catch((msg) => {
// 添加/保存错误 // 添加/保存错误
win.progressOff(); win.progressOff();
toastr.error(LANG['list']['add']['error'](e.toString()), LANG_T['error']); toastr.error(msg, LANG_T['error']);
}); });
}; };
}); });
...@@ -137,30 +137,45 @@ class Form { ...@@ -137,30 +137,45 @@ class Form {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
_createBaseForm(arg) { _createBaseForm(arg) {
const opt = Object.assign({}, {
url: '',
pwd: '',
type: 'php',
encode: 'utf8',
encoder: 'default'
}, arg);
const form = this.accordion.cells('base').attachForm([ const form = this.accordion.cells('base').attachForm([
{ type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 400 }, { type: 'settings', position: 'label-left', labelWidth: 80, inputWidth: 400 },
{ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [ { type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ type: 'input', label: LANG['list']['add']['form']['url'], name: 'url', required: true }, {
{ type: 'input', label: LANG['list']['add']['form']['pwd'], name: 'pwd', required: true }, type: 'input', label: LANG['list']['add']['form']['url'],
{ type: 'combo', label: LANG['list']['add']['form']['encode'], readonly: true, name: 'url', required: true, value: opt.url
name: 'encode', options: this._parseEncoders() }, }, {
{ type: 'combo', label: LANG['list']['add']['form']['type'], name: 'type', type: 'input', label: LANG['list']['add']['form']['pwd'],
readonly: true, options: this._parseTypes() } name: 'pwd', required: true, value: opt.pwd
}, {
type: 'combo', label: LANG['list']['add']['form']['encode'],
readonly: true, name: 'encode', options: this._parseEncodes(opt.encode)
}, {
type: 'combo', label: LANG['list']['add']['form']['type'],
name: 'type', readonly: true, options: this._parseTypes(opt.type, opt.encoder)
}
] } ] }
], true); ], true);
return form; return form;
} }
/** /**
* 解析编码器列表 * 解析编码列表
* @param {String} _default 默认编码器
* @return {array} [description] * @return {array} [description]
*/ */
_parseEncoders() { _parseEncodes(_default = 'utf8') {
let ret = []; let ret = [];
ENCODES.map((_) => { ENCODES.map((_) => {
ret.push({ ret.push({
text: _, value: _, text: _, value: _,
selected: _ === 'UTF8' selected: _ === _default.toUpperCase()
}); });
}); });
return ret; return ret;
...@@ -168,15 +183,17 @@ class Form { ...@@ -168,15 +183,17 @@ class Form {
/** /**
* 解析脚本支持列表 * 解析脚本支持列表
* @param {String} _default 默认类型
* @param {String} _encoder 默认编码器
* @return {array} [description] * @return {array} [description]
*/ */
_parseTypes() { _parseTypes(_default = 'php', _encoder = 'default') {
let ret = []; let ret = [];
for (let c in antSword['core']) { for (let c in antSword['core']) {
let encoders = antSword['core'][c].prototype.encoders; let encoders = antSword['core'][c].prototype.encoders;
ret.push({ ret.push({
text: c.toUpperCase(), value: c, text: c.toUpperCase(), value: c,
selected: c === 'php', selected: c === _default,
list: ((c) => { list: ((c) => {
let _ = [ let _ = [
{ type: 'settings', position: 'label-right', offsetLeft: 60, labelWidth: 100 }, { type: 'settings', position: 'label-right', offsetLeft: 60, labelWidth: 100 },
...@@ -186,7 +203,7 @@ class Form { ...@@ -186,7 +203,7 @@ class Form {
encoders.map((e) => { encoders.map((e) => {
_.push({ _.push({
type: 'radio', name: `encoder_${c}`, type: 'radio', name: `encoder_${c}`,
value: e, label: e value: e, label: e, checked: e === _encoder
}) })
}); });
return _; return _;
...@@ -243,14 +260,20 @@ class Form { ...@@ -243,14 +260,20 @@ class Form {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
_createOtherForm(arg) { _createOtherForm(arg) {
const opt = Object.assign({}, {
'ignore-https': 0,
'terminal-cache': 1
}, arg.otherConf);
const form = this.accordion.cells('other').attachForm([{ const form = this.accordion.cells('other').attachForm([{
type: 'settings', position: 'label-right', inputWidth: 400 type: 'settings', position: 'label-right', inputWidth: 400
}, { }, {
type: 'block', inputWidth: 'auto', offsetTop: 12, list: [ type: 'block', inputWidth: 'auto', offsetTop: 12, list: [
{ {
type: "checkbox", name: 'ignore-https', label: "忽略HTTPS证书", checked: false type: "checkbox", name: 'ignore-https', label: "忽略HTTPS证书",
checked: opt['ignore-https'] === 1
}, { }, {
type: "checkbox", name: 'terminal-cache', label: "虚拟终端不使用缓存", checked: true type: "checkbox", name: 'terminal-cache', label: "虚拟终端不使用缓存",
checked: opt['terminal-cache'] === 1
} }
]}], true); ]}], true);
return form; return form;
...@@ -262,6 +285,10 @@ class Form { ...@@ -262,6 +285,10 @@ class Form {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
_createHttpForm(arg) { _createHttpForm(arg) {
const opt = Object.assign({}, {
headers: {},
body: {}
}, arg.httpConf);
const cell = this.accordion.cells('http'); const cell = this.accordion.cells('http');
// 创建toolbar,用于添加数据 // 创建toolbar,用于添加数据
const toolbar = cell.attachToolbar(); const toolbar = cell.attachToolbar();
...@@ -327,8 +354,20 @@ class Form { ...@@ -327,8 +354,20 @@ class Form {
break; break;
} }
}); });
_addHeader(); // 添加存储的配置
_addBody(); for (let _ in opt.headers) {
_addHeader(_, opt.headers[_]);
}
for (let _ in opt.body) {
_addBody(_, opt.body[_]);
}
// 如果没有配置,则添加空白的输入框
if (_headerCount === 0) {
_addHeader();
}
if (_bodyCount === 0) {
_addBody();
}
return form; return form;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment