Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #687

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions explorer/src/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ function selectConnection() {
}
}

function downloadCSVFromTable() {
var table = document.getElementById("preview");
var rows = table.querySelectorAll("tr");
var csv = [];

rows.forEach(function (row) {
var cols = row.querySelectorAll("td, th");
var rowData = [];
cols.forEach(function (col) {
rowData.push(col.innerText);
});
csv.push(rowData.join(","));
});

var csvFile = new Blob([csv.join("\n")], { type: "text/csv" });
var downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(csvFile);
downloadLink.download = "preview.csv";

document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}

export class ExplorerEditor {
constructor(queryId) {

Expand Down Expand Up @@ -100,7 +124,7 @@ export class ExplorerEditor {
this.bind();

if (cookie.get("schema_sidebar_open") === 'true') {
this.showSchema(true);
this.toggleSchema(true, true);
}
}

Expand Down Expand Up @@ -189,28 +213,29 @@ export class ExplorerEditor {
form.submit();
}

showSchema(noAutofocus) {
if (noAutofocus === true) {
$("#schema_frame").addClass("no-autofocus");
}
$("#query_area").removeClass("col").addClass("col-9");
var schema$ = $("#schema");
schema$.addClass("col-md-3");
schema$.show();
$("#show_schema_button").hide();
$("#hide_schema_button").show();
cookie.set("schema_sidebar_open", 'true');
return false;
}
toggleSchema(noAutofocus, doShow) {
var schema = document.getElementById("schema");
var queryArea = document.getElementById("query_area");
var toggleBtn = document.getElementById("toggle_schema_button");

hideSchema() {
$("#query_area").removeClass("col-9").addClass("col");
var schema$ = $("#schema");
schema$.removeClass("col-3");
schema$.hide();
$("#hide_schema_button").hide();
$("#show_schema_button").show();
cookie.set("schema_sidebar_open", 'false');
if (doShow || schema.style.display === "none" || schema.style.display === "") { // show
if (noAutofocus === true) {
schema.classList.add("no-autofocus");
}
queryArea.classList.remove("col");
queryArea.classList.add("col-9");
schema.classList.add("col-md-3");
schema.style.display = "block";
toggleBtn.innerHTML = "Hide Schema";
cookie.set("schema_sidebar_open", 'true');
} else { // hide
queryArea.classList.remove("col-9");
queryArea.classList.add("col");
schema.classList.remove("col-md-3");
schema.style.display = "none";
toggleBtn.innerHTML = "Show Schema";
cookie.set("schema_sidebar_open", 'false');
}
return false;
}

Expand All @@ -237,9 +262,9 @@ export class ExplorerEditor {
element.addEventListener('click', toggleFavorite);
});

document.getElementById('show_schema_button')?.addEventListener('click', this.showSchema.bind(this));
document.getElementById('hide_schema_button')?.addEventListener('click', this.hideSchema.bind(this));
document.getElementById('toggle_schema_button')?.addEventListener('click', this.toggleSchema.bind(this));

document.getElementById('preview-download')?.addEventListener('click', downloadCSVFromTable)

$("#format_button").click(function(e) {
e.preventDefault();
Expand All @@ -262,6 +287,7 @@ export class ExplorerEditor {
}.bind(this));

$("#save_only_button").click(function() {
console.log("here");
var params = this.getParams(this);
if(params) {
this.$form.attr('action', '../' + this.queryId + '/?show=0&params=' + this.serializeParams(params));
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/scss/assistant.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.assistant-icons {
width: 1rem;
position: absolute;
right: .75rem;
right: 1rem;
}

#table-list {
Expand Down
2 changes: 1 addition & 1 deletion explorer/templates/assistant/table_description_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3>Table Annotations</h3>
<tr>
<td>{{ table_description.database_connection }}</td>
<td>{{ table_description.table_name }}</td>
<td>{{ table_description.description|truncatewords:20 }}</td>
<td>{{ table_description.description }}</td>
<td>
<a href="{% url 'table_description_update' table_description.pk %}" class="px-2"><i class="bi-pencil-square"></i></a>
<a href="{% url 'table_description_delete' table_description.pk %}"><i class="bi-trash"></i></a>
Expand Down
36 changes: 18 additions & 18 deletions explorer/templates/explorer/assistant.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
<div id="additional_table_container" class="col-3" style="width: 31% !important">
<div id="table-list"></div>
</div>
</div>
<div class="assistant-icons" style="">
<div>
<i class="bi-check-all" id="select_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Add all"></i>
</div>
<div>
<i class="bi-trash" id="deselect_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Remove all"></i>
</div>
<div>
<i class="bi-repeat" id="refresh_tables_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Refresh autodetect"></i>
</div>
<div>
<i class="bi-card-list" id="assistant_history" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="History"></i>
</div>
<div>
<i class="bi-question-circle" style="cursor: pointer;"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-title="SQL Assistant builds a prompt with your query, your request, and the tables (schema, sample data, and annotations) referenced here."></i>
<div class="assistant-icons" style="">
<div>
<i class="bi-check-all" id="select_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Add all"></i>
</div>
<div>
<i class="bi-trash" id="deselect_all_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Remove all"></i>
</div>
<div>
<i class="bi-repeat" id="refresh_tables_button" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Refresh autodetect"></i>
</div>
<div>
<i class="bi-card-list" id="assistant_history" style="cursor: pointer;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="History"></i>
</div>
<div>
<i class="bi-question-circle" style="cursor: pointer;"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-title="SQL Assistant builds a prompt with your query, your request, and the tables (schema, sample data, and annotations) referenced here."></i>
</div>
</div>
</div>
<div class="row">
Expand Down
6 changes: 1 addition & 5 deletions explorer/templates/explorer/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ <h2>{% translate "Playground" %}</h2>
class="btn btn-outline-primary">{% translate 'Save As New' %}</button>
{% export_buttons query %}

<button type="button" class="btn btn-outline-primary" id="show_schema_button">
<button type="button" class="btn btn-outline-primary" id="toggle_schema_button">
{% translate "Show Schema" %}
</button>
<button type="button" class="btn btn-outline-primary" id="hide_schema_button"
style="display: none;">
{% translate "Hide Schema" %}
</button>
</div>
</div>
<input type="hidden" value="{% translate 'Playground Query' %}" name="title" />
Expand Down
1 change: 1 addition & 0 deletions explorer/templates/explorer/preview_pane.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
title="Fullscreen results">
<i class="bi-arrows-angle-expand"></i>
</a>
<i id="preview-download" class="bi-download ms-1" title="Download table as csv"></i>
</div>
</div>
</div>
Expand Down
30 changes: 20 additions & 10 deletions explorer/templates/explorer/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,29 @@ <h2>
{% endif %}
<div class="btn-group" role="group">
{% if can_change %}
<button id="save_button" type="submit" class="btn btn-primary">
{% translate "Save & Run" %}
</button>
<button class="btn btn-outline-primary" id="save_only_button">
{% translate "Save Only" %}
</button>
<div class="btn-group" role="group">
<button id="save_button"
type="submit"
class="btn btn-primary">
{% translate 'Save & Run' %}
</button>
<button type="button"
class="btn btn-primary dropdown-toggle dropdown-toggle-split"
data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li>
<button type="submit" class="dropdown-item" id="save_only_button">
{% translate 'Save Only' %}
</button>
</li>
</ul>
</div>
{% export_buttons query %}
<button type="button" class="btn btn-outline-primary" id="show_schema_button">
<button type="button" class="btn btn-outline-primary" id="toggle_schema_button">
{% translate "Show Schema" %}
</button>
<button type="button" class="btn btn-outline-primary" id="hide_schema_button" style="display: none;">
{% translate "Hide Schema" %}
</button>
{% else %}
<button id="refresh_button" type="button" class="btn btn-outline-primary">{% translate "Refresh" %}</button>
{% export_buttons query %}
Expand Down