Commit 0958eb60 authored by Medicean's avatar Medicean

(Enhance:Database) 数据管理新增「书签」功能和「全局书签」

parent fb42a9bd
...@@ -16,6 +16,14 @@ ...@@ -16,6 +16,14 @@
* 修复搜索数据时正则表达式输入错误导致crash 问题 #157 * 修复搜索数据时正则表达式输入错误导致crash 问题 #157
### 数据管理
* 添加SQL语句书签功能, 将常用的 SQL 语句保存成书签
### 其它
* 「默认设置」数据管理项中, 增加「全局书签」设置, 设置一些自己常用的 SQL 语句
## 2019/04/24 `v(2.1.0)` ## 2019/04/24 `v(2.1.0)`
### 重要提醒 ### 重要提醒
......
{ {
"name": "antsword", "name": "antsword",
"version": "2.1.0.3", "version": "2.1.0.4",
"description": "中国蚁剑是一款跨平台的开源网站管理工具", "description": "中国蚁剑是一款跨平台的开源网站管理工具",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
......
...@@ -446,7 +446,29 @@ Hot Keys: ...@@ -446,7 +446,29 @@ Hot Keys:
query: { query: {
title: 'Exec SQL', title: 'Exec SQL',
exec: 'Run', exec: 'Run',
clear: 'Clear' clear: 'Clear',
bookmark: {
title: 'Bookmark',
add: 'Add bookmark',
del: 'Remove this bookmark',
clear: 'Clear all bookmarks',
},
prompt: {
add: {
title: 'Add to bookmark',
success: (path) => `Add to bookmark success!\n${path}`,
},
remove: {
title: 'Remove bookmark',
confirm: 'Remove this bookmark ?',
success: 'Remove bookmark success!'
},
clear: {
title: 'Clear all bookmarks',
confirm: 'Clear all bookmarks ?',
success: 'Clear all bookmark success!'
}
},
}, },
result: { result: {
title: 'Result', title: 'Result',
...@@ -781,6 +803,38 @@ Hot Keys: ...@@ -781,6 +803,38 @@ Hot Keys:
success: 'Edit success' success: 'Edit success'
} }
}, },
},
database: {
title: 'Database',
bookmark: {
title: 'Global Bookmark',
nodata: 'No data, click the right mouse button add',
grid: {
name: 'Name',
path: 'SQL'
},
bmenu: {
add: 'Add Bookmark',
del: 'Del Bookmark'
},
add: {
title: 'Add to global SQL bookmark',
success: 'Add success',
namedup: 'The name cannot be duplicated',
name_invalid: 'Name is invalid',
addbtn: 'Confirm'
},
del: {
title: 'Delete Bookmark',
confirm: (num) => antSword.noxss(`Are you sure to delete ${typeof (num) === 'number' ? num + ' Bookmarks' : num + " "}?`),
success: 'Delete success'
},
edit: {
namedup: 'The name cannot be duplicated',
name_invalid: 'Name is invalid',
success: 'Edit success'
}
},
} }
} }
}, },
......
...@@ -448,7 +448,29 @@ module.exports = { ...@@ -448,7 +448,29 @@ module.exports = {
query: { query: {
title: '执行SQL', title: '执行SQL',
exec: '执行', exec: '执行',
clear: '清空' clear: '清空',
bookmark: {
title: '书签',
add: '添加书签',
del: '移除书签',
clear: '清空书签',
},
prompt: {
add: {
title: '添加SQL书签',
success: (sql) => `添加书签成功!\nSQL: ${sql}`,
},
remove: {
title: '移除书签',
confirm: '确定移除此书签?',
success: '移除书签成功',
},
clear: {
title: '清空书签',
confirm: '确定清空所有书签吗?',
success: '清空书签成功',
},
}
}, },
result: { result: {
title: '执行结果', title: '执行结果',
...@@ -783,6 +805,38 @@ module.exports = { ...@@ -783,6 +805,38 @@ module.exports = {
success: '更新成功' success: '更新成功'
} }
}, },
},
database: {
title: '数据管理',
bookmark: {
title: '全局书签',
nodata: '当前暂无数据, 请单击鼠标右键添加',
grid: {
name: '名称',
path: 'SQL'
},
bmenu: {
add: '添加书签',
del: '删除书签'
},
add: {
title: '添加全局SQL书签',
success: '添加成功',
namedup: '名称不能重复',
name_invalid: '名称不合法',
addbtn: '确定'
},
del: {
title: '删除书签',
confirm: (num) => antSword.noxss(`你确定要删除 ${typeof (num) === 'number' ? num + ' 个书签' : num + " "}吗?`),
success: '删除成功'
},
edit: {
namedup: '名称不能重复',
name_invalid: '名称不合法',
success: '更新成功'
}
},
} }
} }
}, },
......
...@@ -447,7 +447,29 @@ module.exports = { ...@@ -447,7 +447,29 @@ module.exports = {
query: { query: {
title: '執行SQL', title: '執行SQL',
exec: '執行', exec: '執行',
clear: '清空' clear: '清空',
bookmark: {
title: '書籤',
add: '添加書籤',
del: '移除書籤',
clear: '清空書籤',
},
prompt: {
add: {
title: '添加SQL書籤',
success: (sql) => `添加書籤成功!\nSQL: ${sql}`,
},
remove: {
title: '移除書籤',
confirm: '確定移除此書籤?',
success: '移除書籤成功',
},
clear: {
title: '清空書籤',
confirm: '確定清空所有書籤嗎?',
success: '清空書籤成功',
},
}
}, },
result: { result: {
title: '執行結果', title: '執行結果',
...@@ -782,6 +804,38 @@ module.exports = { ...@@ -782,6 +804,38 @@ module.exports = {
success: '更新成功' success: '更新成功'
} }
}, },
},
database: {
title: '數據管理',
bookmark: {
title: '全局書籤',
nodata: '當前暫無數據, 請單擊鼠標右鍵添加',
grid: {
name: '名稱',
path: 'SQL'
},
bmenu: {
add: '添加書籤',
del: '刪除書籤'
},
add: {
title: '添加全局SQL書籤',
success: '添加成功',
namedup: '名稱不能重複',
name_invalid: '名稱不合法',
addbtn: '確定'
},
del: {
title: '刪除書籤',
confirm: (num) => antSword.noxss(`你確定要刪除 ${typeof (num) === 'number' ? num + ' 個書籤' : num + " "}嗎?`),
success: '刪除成功'
},
edit: {
namedup: '名稱不能重複',
name_invalid: '名稱不合法',
success: '更新成功'
}
},
} }
} }
}, },
......
...@@ -447,7 +447,29 @@ module.exports = { ...@@ -447,7 +447,29 @@ module.exports = {
query: { query: {
title: '執行SQL', title: '執行SQL',
exec: '執行', exec: '執行',
clear: '清空' clear: '清空',
bookmark: {
title: '書籤',
add: '添加書籤',
del: '移除書籤',
clear: '清空書籤',
},
prompt: {
add: {
title: '添加SQL書籤',
success: (sql) => `添加書籤成功!\nSQL: ${sql}`,
},
remove: {
title: '移除書籤',
confirm: '確定移除此書籤?',
success: '移除書籤成功',
},
clear: {
title: '清空書籤',
confirm: '確定清空所有書籤嗎?',
success: '清空書籤成功',
},
}
}, },
result: { result: {
title: '執行結果', title: '執行結果',
...@@ -782,6 +804,38 @@ module.exports = { ...@@ -782,6 +804,38 @@ module.exports = {
success: '更新成功' success: '更新成功'
} }
}, },
},
database: {
title: '數據管理',
bookmark: {
title: '全局書籤',
nodata: '當前暫無數據, 請單擊鼠標右鍵添加',
grid: {
name: '名稱',
path: 'SQL'
},
bmenu: {
add: '添加書籤',
del: '刪除書籤'
},
add: {
title: '添加全局SQL書籤',
success: '添加成功',
namedup: '名稱不能重複',
name_invalid: '名稱不合法',
addbtn: '確定'
},
del: {
title: '刪除書籤',
confirm: (num) => antSword.noxss(`你確定要刪除 ${typeof (num) === 'number' ? num + ' 個書籤' : num + " "}嗎?`),
success: '刪除成功'
},
edit: {
namedup: '名稱不能重複',
name_invalid: '名稱不合法',
success: '更新成功'
}
},
} }
} }
}, },
......
...@@ -8,12 +8,17 @@ ...@@ -8,12 +8,17 @@
const LANG = antSword['language']['database']; const LANG = antSword['language']['database'];
const LANG_T = antSword['language']['toastr']; const LANG_T = antSword['language']['toastr'];
const crypto = require('crypto');
class Database { class Database {
constructor(opt) { constructor(opt) {
this.hash = (+new Date * Math.random()).toString(16).substr(2, 8); this.hash = (+new Date * Math.random()).toString(16).substr(2, 8);
this.opt = opt;
let config = {
bookmarks: {},
};
this.config = JSON.parse(antSword['storage']("adefault_database", false, JSON.stringify(config)));
// 初始化UI // 初始化UI
const tabbar = antSword['tabbar']; const tabbar = antSword['tabbar'];
tabbar.addTab( tabbar.addTab(
...@@ -32,7 +37,6 @@ class Database { ...@@ -32,7 +37,6 @@ class Database {
this.query = this.initQuery(this.layout_right.cells('a')); this.query = this.initQuery(this.layout_right.cells('a'));
this.result = this.initResult(this.layout_right.cells('b')); this.result = this.initResult(this.layout_right.cells('b'));
this.opt = opt;
this.win = new dhtmlXWindows(); this.win = new dhtmlXWindows();
this.win.attachViewportTo(this.cell.cell); this.win.attachViewportTo(this.cell.cell);
...@@ -98,31 +102,11 @@ class Database { ...@@ -98,31 +102,11 @@ class Database {
// 初始化右侧::SQL执行 // 初始化右侧::SQL执行
initQuery(layout) { initQuery(layout) {
let self = this;
layout.setText(`<i class="fa fa-code"></i> ${LANG['query']['title']}`); layout.setText(`<i class="fa fa-code"></i> ${LANG['query']['title']}`);
layout.setHeight('200'); layout.setHeight('200');
let editor; let editor;
// SQL语句toolbar
const toolbar = layout.attachToolbar();
toolbar.loadStruct([
{ id: 'exec', text: LANG['query']['exec'], icon: 'play', type: 'button', disabled: true },
// { type: 'separator' },
// { id: 'import', text: '导入', icon: 'download', type: 'button' },
{ type: 'separator' },
{ id: 'clear', text: LANG['query']['clear'], icon: 'remove', type: 'button' }
]);
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'clear':
editor.session.setValue('');
break;
case 'exec':
this.drive.execSQL(editor.session.getValue());
break;
}
});
// SQL语句编辑器 // SQL语句编辑器
editor = ace.edit(layout.cell.lastChild); editor = ace.edit(layout.cell.lastChild);
editor.$blockScrolling = Infinity; editor.$blockScrolling = Infinity;
...@@ -152,7 +136,146 @@ class Database { ...@@ -152,7 +136,146 @@ class Database {
editor.session.setValue("SELECT 'Hello antSword :)' AS welcome;"); editor.session.setValue("SELECT 'Hello antSword :)' AS welcome;");
// SQL语句toolbar
const toolbar = layout.attachToolbar();
let bookmark = JSON.parse(this.storage('dbbookmarks').get('{}'));
let reloadToolbar = () => {
let bookmark_opts = [{
id: 'bookmark_add',
type: 'button',
icon: 'plus-circle',
text: LANG['query']['bookmark']['add'],
// enabled: !!bookmark[Buffer.from(editor.session.getValue()).toString('base64')],
}];
let global_bookmarks = this.config.bookmarks || {};
if(Object.keys(global_bookmarks).length > 0) {
bookmark_opts.push({type: 'separator'});
for(let gb in global_bookmarks) {
bookmark_opts.push({
id: 'bookmark_'+ global_bookmarks[gb],
text: antSword.noxss(gb),
icon: 'bookmark',
type: 'button',
// enabled: Buffer.from(editor.session.getValue()).toString('base64') != global_bookmarks[gb] ,
});
}
}
if (!$.isEmptyObject(bookmark)) {
bookmark_opts.push({ type: 'separator' });
};
for (let _ in bookmark) {
bookmark_opts.push({
id: 'bookmark_' + _, // _ 是 base64 格式
text: antSword.noxss(bookmark[_]),
icon: 'bookmark-o',
type: 'button',
// enabled: Buffer.from(editor.session.getValue()).toString('base64') != _ ,
});
}
// 添加清除按钮
if (bookmark_opts.length > 2) {
bookmark_opts.push({
type: 'separator'
});
bookmark_opts.push({
id: 'bookmark_remove',
icon: 'remove',
text: LANG['query']['bookmark']['del'],
type: 'button',
});
bookmark_opts.push({
id: 'bookmark_clear',
icon: 'trash-o',
text: LANG['query']['bookmark']['clear'],
type: 'button'
});
};
let btnstatus = {};
['exec', 'clear'].map((btn)=>{
try{
btnstatus[btn] = toolbar.isEnabled(btn);
}catch(e){
btnstatus[btn] = true;
}
})
toolbar.clearAll();
toolbar.loadStruct([
{ id: 'exec', text: LANG['query']['exec'], icon: 'play', type: 'button', disabled: !btnstatus['exec'] },
// { type: 'separator' },
// { id: 'import', text: '导入', icon: 'download', type: 'button' },
{ type: 'separator' },
{ id: 'clear', text: LANG['query']['clear'], icon: 'remove', type: 'button' },
{ type: 'separator' },
{ id: 'bookmark', text: LANG['query']['bookmark']['title'], icon: 'bookmark', type: 'buttonSelect', openAll: true, options: bookmark_opts },
]);
}
reloadToolbar();
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'clear':
editor.session.setValue('');
break;
case 'exec':
this.drive.execSQL(editor.session.getValue());
break;
case 'bookmark_add':
// 添加书签
layer.prompt({
value: antSword.noxss(editor.session.getValue()),
title: LANG['query']['prompt']['add']['title']
}, (value, i, e) => {
bookmark[Buffer.from(editor.session.getValue()).toString('base64')] = value;
self.storage('dbbookmarks').set(JSON.stringify(bookmark));
toastr.success(LANG['query']['prompt']['add']['success'](editor.session.getValue()), LANG_T['success']);
reloadToolbar();
layer.close(i);
});
break;
case 'bookmark_remove':
layer.confirm(
LANG['query']['prompt']['remove']['confirm']
, {
icon: 2, shift: 6,
title: `<i class="fa fa-remove"></i> ${LANG['query']['prompt']['remove']['title']}`,
}
, (_) => {
// 删除书签并刷新
delete bookmark[Buffer.from(editor.session.getValue()).toString('base64')];
self.storage('dbbookmarks').set(JSON.stringify(bookmark));
reloadToolbar();
toastr.success(LANG['query']['prompt']['remove']['success'], LANG_T['success']);
layer.close(_);
}
)
break;
case 'bookmark_clear':
layer.confirm(
LANG['query']['prompt']['clear']['confirm']
, {
icon: 2, shift: 6,
title: `<i class="fa fa-trash-o"></i> ${LANG['query']['prompt']['clear']['title']}`
}
, (_) => {
bookmark = {};
self.storage('dbbookmarks').set('{}');
reloadToolbar();
toastr.success(LANG['query']['prompt']['clear']['success'], LANG_T['success']);
layer.close(_);
}
);
break;
default:
let arr = id.split('_');
if (arr.length === 2 && arr[0] === 'bookmark') {
editor.session.setValue(Buffer.from(arr[1], 'base64').toString());
// toolbar.enableItem('exec');
};
}
});
return { return {
reloadToolbar: reloadToolbar,
editor: editor, editor: editor,
layout: layout, layout: layout,
toolbar: toolbar toolbar: toolbar
...@@ -267,6 +390,19 @@ class Database { ...@@ -267,6 +390,19 @@ class Database {
toastr.error(JSON.stringify(err), LANG_T['error']); toastr.error(JSON.stringify(err), LANG_T['error']);
}); });
} }
// 本地存储
// storage('save_key').get('{}')
// storage('save_key').set('{a:123}')
storage(key) {
let md5 = crypto.createHash('md5');
md5.update(this.opt['url']);
const k = `${md5.digest('hex').substr(0, 11)}_${key}`
return {
get: (def) => localStorage.getItem(k) || def,
set: (val) => localStorage.setItem(k, val)
}
}
} }
// export default Database; // export default Database;
......
...@@ -19,6 +19,9 @@ class ADefault { ...@@ -19,6 +19,9 @@ class ADefault {
openfileintab: false, openfileintab: false,
bookmarks: {}, bookmarks: {},
}, },
database: {
bookmarks: {},
},
}; };
// 读取配置 // 读取配置
const filemanager_settings = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(default_config.filemanager))); const filemanager_settings = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(default_config.filemanager)));
...@@ -27,6 +30,12 @@ class ADefault { ...@@ -27,6 +30,12 @@ class ADefault {
this.filemanager_settings.bookmarks = default_config.filemanager.bookmarks; this.filemanager_settings.bookmarks = default_config.filemanager.bookmarks;
} }
const database_settings = JSON.parse(antSword['storage']("adefault_database", false, JSON.stringify(default_config.database)));
this.database_settings = database_settings;
if(!this.database_settings.bookmarks){
this.database_settings.bookmarks = default_config.database.bookmarks;
}
const toolbar = cell.attachToolbar(); const toolbar = cell.attachToolbar();
toolbar.loadStruct([ toolbar.loadStruct([
{ id: 'save', type: 'button', text: LANG['toolbar']['save'], icon: 'save' } { id: 'save', type: 'button', text: LANG['toolbar']['save'], icon: 'save' }
...@@ -36,7 +45,7 @@ class ADefault { ...@@ -36,7 +45,7 @@ class ADefault {
type: 'block', name: 'filemanager', list: [ type: 'block', name: 'filemanager', list: [
// {type: "label", label: LANG['filemanager']['title']}, // {type: "label", label: LANG['filemanager']['title']},
{ {
type: "fieldset", label: LANG['filemanager']['title'], list:[ type: "fieldset", label: `<i class="fa fa-folder"></i> ${LANG['filemanager']['title']}`, list:[
{ type: "block", list: [ { type: "block", list: [
{type: "label", label: LANG['filemanager']['openfileintab']['title']}, {type: "label", label: LANG['filemanager']['openfileintab']['title']},
{type: 'newcolumn', offset:20}, {type: 'newcolumn', offset:20},
...@@ -54,11 +63,19 @@ class ADefault { ...@@ -54,11 +63,19 @@ class ADefault {
{type: 'container', name: 'filemanager_bookmarks', inputWidth: 600, inputHeight: 200}, {type: 'container', name: 'filemanager_bookmarks', inputWidth: 600, inputHeight: 200},
]}, ]},
] ]
} }, {
type: 'fieldset', label: '<i class="fa fa-database"></i> 数据管理', list: [
{ type: 'block', list: [
{ type: 'label', label: '全局书签' },
{type: 'container', name: 'database_bookmarks', inputWidth: 600, inputHeight: 200},
]},
]
},
// 后续其它模块
]}, ]},
// 后续其它模块
], true); ], true);
form.enableLiveValidation(true); form.enableLiveValidation(true);
let bookmark_grid = new dhtmlXGridObject(form.getContainer('filemanager_bookmarks')); let bookmark_grid = new dhtmlXGridObject(form.getContainer('filemanager_bookmarks'));
bookmark_grid.setHeader(` bookmark_grid.setHeader(`
&nbsp;, &nbsp;,
...@@ -73,7 +90,7 @@ class ADefault { ...@@ -73,7 +90,7 @@ class ADefault {
// grid右键 // grid右键
// 空白数据右键fix // 空白数据右键fix
$('.objbox').on('contextmenu', (e) => { $('.objbox').on('contextmenu', (e) => {
(e.target.nodeName === 'DIV' && bookmark_grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab() === "tab_about" && sidebar.getActiveItem() === "adefault") ? bookmark_grid.callEvent('onRightClick', [-1, -1, e]) : null; (e.target.nodeName === 'DIV' && e.target.grid === bookmark_grid && bookmark_grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab() === "tab_about" && sidebar.getActiveItem() === "adefault") ? bookmark_grid.callEvent('onRightClick', [-1, -1, e]) : null;
}); });
$('.objbox').on('click', (e) => { $('.objbox').on('click', (e) => {
bmenu.hide(); bmenu.hide();
...@@ -139,6 +156,81 @@ class ADefault { ...@@ -139,6 +156,81 @@ class ADefault {
bookmark_grid.init(); bookmark_grid.init();
this.bookmark_grid = bookmark_grid; this.bookmark_grid = bookmark_grid;
// 数据管理配置
let db_bookmark_grid = new dhtmlXGridObject(form.getContainer('database_bookmarks'));
db_bookmark_grid.setHeader(`
&nbsp;,
${LANG['database']['bookmark']['grid']['name']},
${LANG['database']['bookmark']['grid']['path']}
`);
db_bookmark_grid.setColTypes("ro,edtxt,edtxt");
db_bookmark_grid.setColSorting('str,str,str');
db_bookmark_grid.setInitWidths("40,220,*");
db_bookmark_grid.setColAlign("center,left,left");
db_bookmark_grid.enableMultiselect(true);
// grid右键
// 空白数据右键fix
$('.objbox').on('contextmenu', (e) => {
(e.target.nodeName === 'DIV' && e.target.grid === db_bookmark_grid && db_bookmark_grid.callEvent instanceof Function && antSword['tabbar'].getActiveTab() === "tab_about" && sidebar.getActiveItem() === "adefault") ? db_bookmark_grid.callEvent('onRightClick', [-1, -1, e]) : null;
});
$('.objbox').on('click', (e) => {
bmenu.hide();
});
db_bookmark_grid.attachEvent('onRightClick', (id, lid, event)=>{
let _ids = (db_bookmark_grid.getSelectedId()|| '').split(',');
if (id === -1) {
_ids = [];
} else if (_ids.length === 1) {
// 如果没有选中?则选中右键对应选项
db_bookmark_grid.selectRowById(id);
_ids = [id];
};
let ids = [];
_ids.map((_) => {
ids.push(db_bookmark_grid.getRowAttribute(_, 'bname'));
});
id = ids[0] || '';
let dbmenu = [
{ text: LANG['database']['bookmark']['bmenu']['add'], icon: 'fa fa-plus-circle', action: self.addDatabaseBookMarks.bind(self)},
{ text: LANG['database']['bookmark']['bmenu']['del'], icon: 'fa fa-trash-o', action: () => {
self.delDatabaseBookMarks(ids);
}},
];
bmenu(dbmenu, event);
return true;
});
db_bookmark_grid.attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){
// 2 编辑完成
if(stage === 2) {
if(nValue === oValue){return;}
var obname = db_bookmark_grid.getRowAttribute(rId, "bname"); // string
var obpath = db_bookmark_grid.getRowAttribute(rId, "bpath"); // base64 格式的
switch(cInd){ // 具体是哪一列被编辑了
case 1: // name
// if(!nValue.match(/^[a-zA-Z0-9_/]+$/)){
// toastr.error(LANG["database"]['bookmark']['edit']["name_invalid"], LANG_T['error']);
// return
// }
if(self.database_settings.bookmarks.hasOwnProperty(obname)){
delete self.database_settings.bookmarks[obname];
self.database_settings.bookmarks[nValue] = obpath;
}
toastr.success(LANG["database"]['bookmark']['edit']["success"],LANG_T["success"]);
break;
case 2: // sql
if(self.database_settings.bookmarks.hasOwnProperty(obname)){
self.database_settings.bookmarks[obname] = Buffer.from(nValue).toString('base64');
}
break;
}
antSword['storage']('adefault_database', self.database_settings);
self.reloadDatabaseBookmarks();
}
});
db_bookmark_grid.init();
this.db_bookmark_grid = db_bookmark_grid;
// 保存 // 保存
toolbar.attachEvent('onClick', (id) => { toolbar.attachEvent('onClick', (id) => {
switch(id){ switch(id){
...@@ -148,9 +240,12 @@ class ADefault { ...@@ -148,9 +240,12 @@ class ADefault {
let config = default_config; let config = default_config;
config.filemanager.openfileintab = _formvals['openfileintab']; config.filemanager.openfileintab = _formvals['openfileintab'];
config.filemanager.bookmarks = self.filemanager_settings.bookmarks; config.filemanager.bookmarks = self.filemanager_settings.bookmarks;
config.database.bookmarks = self.database_settings.bookmarks;
// save // save
// save 文件管理设置 // save 文件管理设置
antSword['storage']('adefault_filemanager', config.filemanager); antSword['storage']('adefault_filemanager', config.filemanager);
antSword['storage']('adefault_database', config.database);
toastr.success(LANG['success'], LANG_T['success']); toastr.success(LANG['success'], LANG_T['success']);
// 重启应用 // 重启应用
layer.confirm(LANG['confirm']['content'], { layer.confirm(LANG['confirm']['content'], {
...@@ -167,6 +262,7 @@ class ADefault { ...@@ -167,6 +262,7 @@ class ADefault {
}); });
this.reloadFMBookmarks(); this.reloadFMBookmarks();
this.reloadDatabaseBookmarks();
} }
// 重载 bookmarks grid // 重载 bookmarks grid
reloadFMBookmarks(){ reloadFMBookmarks(){
...@@ -261,6 +357,99 @@ class ADefault { ...@@ -261,6 +357,99 @@ class ADefault {
) )
} }
// 重载 database_bookmarks grid
reloadDatabaseBookmarks(){
let self = this;
let data = [];
let _id = 1;
Object.keys(self.database_settings.bookmarks).map((t)=>{
data.push({
id: _id,
bname: t,
bpath: self.database_settings.bookmarks[t],
data: [
`<i class="fa fa-bookmark-o"></i>`,
// TODO: 测试是否会引起XSS
t,
Buffer.from(self.database_settings.bookmarks[t], 'base64').toString(),
]
});
_id++;
});
if(data.length == 0){
data.push({
id: _id,
bname: '',
bpath: '',
data: [
`<i class="fa fa-bookmark-o"></i>`,
LANG['database']['bookmark']['nodata'],
'&nbsp;'
]
});
}
self.db_bookmark_grid.clearAll();
self.db_bookmark_grid.parse({
'rows': data
}, 'json');
}
addDatabaseBookMarks() {
let self = this;
let hash = +new Date();
let index = layer.prompt({
title: `<i class="fa fa-bookmark"></i> ${LANG['database']['bookmark']['add']['title']}`,
content: '<input type="text" style="width:300px;" class="layui-layer-input" id="bname_' + hash + '" value="" placeholder="bookmark name"><p/><input style="width:300px;" type="text" id="bpath_' + hash + '" class="layui-layer-input" value="" placeholder="bookmark sql">',
btn: [LANG['database']['bookmark']['add']['addbtn']],
yes: (i) => {
let _bname = $(`#bname_${hash}`);
let _bpath = $(`#bpath_${hash}`);
let bname = _bname.val();
let bpath = _bpath.val();
let gbm = self.database_settings.bookmarks;
if(gbm.hasOwnProperty(bname)) {
_bname.focus();
return toastr.warning(LANG['database']['bookmark']['add']['namedup'], LANG_T['warning']);
}
// bpath = bpath.replace(/\\/g,'/');
// if(!bpath.endsWith('/')) {
// bpath += '/';
// }
gbm[bname] = Buffer.from(bpath).toString('base64');
self.database_settings.bookmarks = gbm;
antSword['storage']('adefault_database', self.database_settings);
self.reloadDatabaseBookmarks();
toastr.success(LANG['database']['bookmark']['add']['success'], LANG_T['success']);
layer.close(i);
}
});
}
delDatabaseBookMarks(ids) {
let self = this;
if(ids.length === 1 && !ids[0]) {
return
}
layer.confirm(
LANG['database']['bookmark']['del']['confirm'](ids.length > 1 ? ids.length:ids[0]),
{
icon: 2,
shift: 6,
title: `<i class="fa fa-trash"></i> ${LANG['database']['bookmark']['del']['title']}`,
},
(_) => {
layer.close(_);
ids.map((p)=>{
if(self.database_settings.bookmarks.hasOwnProperty(p)) {
delete self.database_settings.bookmarks[p];
}
});
antSword['storage']('adefault_database', self.database_settings);
self.reloadDatabaseBookmarks();
toastr.success(LANG['database']['bookmark']['del']['success'], LANG_T['success']);
}
)
}
} }
module.exports = ADefault; module.exports = ADefault;
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