Business intelligence made simple
Modernized code [skip ci]
Andrew Kane05452659c2d6
diff --git a/app/views/blazer/_variables.html.erb b/app/views/blazer/_variables.html.erbindex e9b3fa9f..703b9716 100644--- a/app/views/blazer/_variables.html.erb+++ b/app/views/blazer/_variables.html.erb@@ -39,8 +39,8 @@<%= javascript_tag nonce: true do %>(function() {<%= blazer_js_var "varId", var %>- var input = $(document.getElementById(varId))- var datePicker = $("#<%= var %>-select")+ const input = $(document.getElementById(varId))+ const datePicker = $("#<%= var %>-select")datePicker.daterangepicker({singleDatePicker: true,locale: {format: format},@@ -55,7 +55,7 @@submitIfCompleted($("#<%= var %>").closest("form"))})if (input.val().length > 0) {- var picker = datePicker.data("daterangepicker")+ const picker = datePicker.data("daterangepicker")datePicker.find("span").html(toDate(picker.startDate).format("MMMM D, YYYY"))}})()diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erbindex 16aecfe0..27d01c0f 100644--- a/app/views/blazer/queries/_form.html.erb+++ b/app/views/blazer/queries/_form.html.erb@@ -72,10 +72,10 @@<%= blazer_js_var "variableParams", @variable_params %><%= blazer_js_var "previewStatement", Blazer.data_sources.to_h { |k, v| [k, (v.preview_statement rescue "")] } %>- var runButton = document.getElementById("run-button")- var cancelButton = document.getElementById("cancel-button")- var results = document.getElementById("results-html")- var loading = document.getElementById("loading")+ const runButton = document.getElementById("run-button")+ const cancelButton = document.getElementById("cancel-button")+ const results = document.getElementById("results-html")+ const loading = document.getElementById("loading")function cancel(e) {stopRunning()@@ -83,8 +83,8 @@}function getSQL() {- var selectedText = editor.getSelectedText()- var text = selectedText.length < 10 ? editor.getValue() : selectedText+ const selectedText = editor.getSelectedText()+ const text = selectedText.length < 10 ? editor.getValue() : selectedTextreturn text.replace(/\n/g, "\r\n")}@@ -108,9 +108,9 @@startRunning()cancelAllQueries()- var data = {statement: getSQL(), data_source: $("#query_data_source").val(), variables: variableParams}+ const runData = {statement: getSQL(), data_source: $("#query_data_source").val(), variables: variableParams}- runQuery(data, function (data) {+ runQuery(runData, function (data) {stopRunning()$(results).html(data)}, function (data) {@@ -124,8 +124,8 @@cancelButton.addEventListener("click", cancel)var dataSource- var $select = $("#table_names").selectize({})- var selectize = $select[0].selectize+ const $select = $("#table_names").selectize({})+ const selectize = $select[0].selectizeselectize.on("change", function(val) {editor.setValue(previewStatement[dataSource].replace("{table}", val), 1)run()@@ -133,8 +133,7 @@selectize.blur()})- var tablesXhr-+ let tablesXhrfunction updateDataSource(dataSource) {window.dataSource = dataSourcedocument.getElementById("schema-link").setAttribute("href", Routes.schema_queries_path({data_source: dataSource}))@@ -146,10 +145,9 @@tablesXhr.abort()}- tablesXhr = $.getJSON(Routes.tables_queries_path({data_source: dataSource}), function(data) {- var newOptions = []- for (var i = 0; i < data.length; i++) {- var table = data[i]+ tablesXhr = $.getJSON(Routes.tables_queries_path({data_source: dataSource}), function (data) {+ const newOptions = []+ for (const table of data) {if (typeof table === "object") {newOptions.push({text: table.table, value: table.value})} else {@@ -164,8 +162,8 @@updateDataSource($("#query_data_source").val())- var $dsSelect = $("#query_data_source").selectize({})- var dsSelectize = $dsSelect[0].selectize+ const $dsSelect = $("#query_data_source").selectize({})+ const dsSelectize = $dsSelect[0].selectizedsSelectize.on("change", function(val) {updateDataSource(val)dsSelectize.blur()@@ -173,13 +171,12 @@function adjustHeight() {// https://stackoverflow.com/questions/11584061/- var editor = this.editor- var lines = editor.getSession().getScreenLength()+ let lines = editor.getSession().getScreenLength()if (lines < 9) {lines = 9}- this.editorHeight = ((lines + 1) * 16).toString() + "px"+ editorHeight = ((lines + 1) * 16).toString() + "px"editor.resize()}@@ -210,8 +207,6 @@// fix command+Leditor.commands.removeCommands(["gotoline", "find"])- this.editor = editor-editor.getSession().on("change", function () {$("#query_statement").val(editor.getValue())adjustHeight()diff --git a/app/views/blazer/queries/show.html.erb b/app/views/blazer/queries/show.html.erbindex c657a14f..8d199590 100644--- a/app/views/blazer/queries/show.html.erb+++ b/app/views/blazer/queries/show.html.erb@@ -47,7 +47,7 @@</div><%= javascript_tag nonce: true do %>- var results = document.getElementById("results")+ const results = document.getElementById("results")function showRun(data) {$(results).html(data)@@ -68,7 +68,7 @@<%= javascript_tag nonce: true do %>// do not highlight really long queries// this can lead to performance issues- var code = document.querySelector("#code code")+ const code = document.querySelector("#code code")if (code.textContent.length < 10000) {hljs.highlightElement(code)}