diff --git a/src/public/javascripts/dialogs/sql_console.js b/src/public/javascripts/dialogs/sql_console.js index 19698b385..366d69d3e 100644 --- a/src/public/javascripts/dialogs/sql_console.js +++ b/src/public/javascripts/dialogs/sql_console.js @@ -13,38 +13,15 @@ let codeEditor; $dialog.on("shown.bs.modal", e => initEditor()); -function showDialog() { +async function showDialog() { glob.activeDialog = $dialog; + await showTables(); + $dialog.modal(); } async function initEditor() { - server.get('sql/schema').then(tables => { - $tables.empty(); - - for (const table of tables) { - const $tableLink = $('').text(table.name); - - const $columns = $(""); - - for (const column of table.columns) { - $columns.append( - $("") - .append($("
").text(column.name)) - .append($("").text(column.type)) - ); - } - - $tableLink - .attr("title", $columns.html()) - .tooltip({ html: true }) - .click(() => codeEditor.setValue("SELECT * FROM " + table.name + " LIMIT 100")); - - $tables.append($tableLink).append(" "); - } - }); - if (!codeEditor) { await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR); @@ -121,6 +98,32 @@ async function execute(e) { } } +async function showTables() { + const tables = await server.get('sql/schema'); + + $tables.empty(); + + for (const table of tables) { + const $tableLink = $('