From cbbd152e7590601c6e52e06cfb8ae70da92993ac Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 24 Sep 2024 17:13:08 -0500 Subject: [PATCH] Initial attempt at showing whitespace in SQL results --- src/pgwui_sql/static/pgwui_sql.css | 6 +- src/pgwui_sql/templates/sql.mak | 97 ++++++++++++++++++++++-------- src/pgwui_sql/views/sql.py | 61 +++++++++++++++++-- 3 files changed, 132 insertions(+), 32 deletions(-) diff --git a/src/pgwui_sql/static/pgwui_sql.css b/src/pgwui_sql/static/pgwui_sql.css index 0463a2e..458e3b9 100644 --- a/src/pgwui_sql/static/pgwui_sql.css +++ b/src/pgwui_sql/static/pgwui_sql.css @@ -59,4 +59,8 @@ textarea.sqltext { height: 40em; top: 0; background-color: white; /* kludge, see above */ text-align: left; } -.stickycontainer { overflow-y: clip; } /* attach to heading's container */ +.stickycontainer { overflow-y: clip; } /* attach to heading's container */ +.stickyfooting { position: sticky; /* attach to footer */ + bottom: 0; + background-color: white; /* kludge, see above */ + text-align: right; } diff --git a/src/pgwui_sql/templates/sql.mak b/src/pgwui_sql/templates/sql.mak index 7e28e0d..18adeba 100644 --- a/src/pgwui_sql/templates/sql.mak +++ b/src/pgwui_sql/templates/sql.mak @@ -26,6 +26,8 @@ search_path The requested search_path sql Text of the sql command(s) result_rows List of SQLResult objects + show_spaces HTML attribute of input element indicating checked checkbox + of the "Show spaces" checkbox @@ -93,32 +95,47 @@ status_result = [] %> - <% stmt_break = '
' %> - % for result_row in result_rows: - ${stmt_break | n} - <% stmt_break = '
' %> - - % if result_row.statusmessage is not None: -

- ${result_row.statusmessage.data.split(' ')[0]}

- % endif - - % if result_row.rows: - - % if result_row.heading is not None: - ${self.render_heading(result_row.heading.data)} - % endif - - % for row in result_row.rows: - ${self.render_row(row.data)} - % endfor - -
- % endif - -

${result_row.rowcount.data}

- % endfor -
+
+ <% stmt_break = '
' %> + % for result_row in result_rows: + ${stmt_break | n} + <% stmt_break = '
' %> + + % if result_row.statusmessage is not None: +

+ ${result_row.statusmessage.data.split(' ')[0]}

+ % endif + + % if result_row.rows: + + % if result_row.heading is not None: + ${self.render_heading(result_row.heading.data)} + % endif + + % for row in result_row.rows: + ${self.render_row(row.data)} + % endfor + +
+ % endif + +

${result_row.rowcount.data}

+ % endfor +
+
+ + Show spaces + + + + +
+
<%def name="result_form(tab_index)"> @@ -140,6 +157,34 @@ + ',top=' + window.screenTop) .focus(); } + function whitespaceDisplay(checked) { + const tdSqltextSheet = document.adoptedStyleSheets[0]; + + if (checked) { + tdSqltextSheet.disabled = false; + } else { + tdSqltextSheet.disabled = true; + } + } + + // See: https://web.dev/articles/constructable-stylesheets + function setupCSS() { + tdSqltextSheet = new CSSStyleSheet(disabled=true); + tdSqltextSheet.replaceSync( + 'td.sqltext { + text-decoration-line: underline; + text-decoration-color: silver; + text-decoration-style: double; }'); + document.adoptedStyleSheets = [tdSqltextSheet]; + } + + if (document.readyState === "loading") { + // Loading hasn't finished yet + document.addEventListener("DOMContentLoaded", setupCSS); + } else { + // `DOMContentLoaded` has already fired + setupCSS(); + }