Skip to content

Commit

Permalink
Merge branch 'master' into advanced-uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark authored Aug 2, 2024
2 parents 5274f78 + 3546dbf commit 5da792e
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 196 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ The following people have contributed to django-sql-explorer:
- Calum Smith
- Steven Luoma

A full list of contributors can be found on Github; https://github.com/explorerhq/django-sql-explorer/graphs/contributors
A full list of contributors can be found on Github; https://github.com/explorerhq/sql-explorer/graphs/contributors
327 changes: 170 additions & 157 deletions HISTORY.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion explorer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__version_info__ = {
"major": 5,
"minor": 1,
"patch": 0,
"patch": 1,
"releaselevel": "final",
"serial": 0
}
Expand Down
13 changes: 7 additions & 6 deletions explorer/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
BAR_WIDTH = 0.2


def get_chart(result: QueryResult, chart_type: str) -> Optional[str]:
def get_chart(result: QueryResult, chart_type: str, num_rows: int) -> Optional[str]:
import matplotlib.pyplot as plt
"""
Return a line or bar chart in SVG format if the result table adheres to the expected format.
Expand All @@ -21,26 +21,27 @@ def get_chart(result: QueryResult, chart_type: str) -> Optional[str]:
return
if len(result.data) < 1:
return None
data = result.data[:num_rows]
numeric_columns = [
c for c in range(1, len(result.data[0]))
if all([isinstance(col[c], (int, float)) or col[c] is None for col in result.data])
c for c in range(1, len(data[0]))
if all([isinstance(col[c], (int, float)) or col[c] is None for col in data])
]
# Don't create charts for > 10 series. This is a lightweight visualization.
if len(numeric_columns) < 1 or len(numeric_columns) > 10:
return None
labels = [row[0] for row in result.data]
labels = [row[0] for row in data]
fig, ax = plt.subplots(figsize=(10, 3.8))
bars = []
bar_positions = []
for idx, col_num in enumerate(numeric_columns):
if chart_type == "bar":
values = [row[col_num] if row[col_num] is not None else 0 for row in result.data]
values = [row[col_num] if row[col_num] is not None else 0 for row in data]
bar_container = ax.bar([x + idx * BAR_WIDTH
for x in range(len(labels))], values, BAR_WIDTH, label=result.headers[col_num])
bars.append(bar_container)
bar_positions.append([(rect.get_x(), rect.get_height()) for rect in bar_container])
if chart_type == "line":
ax.plot(labels, [row[col_num] for row in result.data], label=result.headers[col_num])
ax.plot(labels, [row[col_num] for row in data], label=result.headers[col_num])

ax.set_xlabel(result.headers[0])

Expand Down
4 changes: 2 additions & 2 deletions explorer/src/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ 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('show_schema_button')?.addEventListener('click', this.showSchema.bind(this));
document.getElementById('hide_schema_button')?.addEventListener('click', this.hideSchema.bind(this));


$("#format_button").click(function(e) {
Expand Down
30 changes: 13 additions & 17 deletions explorer/src/js/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ function searchFocus() {

export function setupSchema() {

let hasControls = document.getElementById('collapse_all');
if (hasControls) {
let options = {
valueNames: ['app-name'],
handlers: {'updated': [searchFocus]}
};
let options = {
valueNames: ['app-name'],
handlers: {'updated': [searchFocus]}
};

new List('schema-contents', options);
new List('schema-contents', options);


document.getElementById('collapse_all').addEventListener('click', function () {
document.querySelectorAll('.schema-table').forEach(function (element) {
element.style.display = 'none';
});
document.getElementById('collapse_all').addEventListener('click', function () {
document.querySelectorAll('.schema-table').forEach(function (element) {
element.style.display = 'none';
});
});

document.getElementById('expand_all').addEventListener('click', function () {
document.querySelectorAll('.schema-table').forEach(function (element) {
element.style.display = '';
});
document.getElementById('expand_all').addEventListener('click', function () {
document.querySelectorAll('.schema-table').forEach(function (element) {
element.style.display = '';
});
}
});

document.querySelectorAll('.schema-header').forEach(function (header) {
header.addEventListener('click', function () {
Expand Down
15 changes: 8 additions & 7 deletions explorer/templates/explorer/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ <h2>
{% endif %}
{{ form.non_field_errors }}
<div class="my-3 form-floating">
<input class="form-control" id="id_title" maxlength="255" name="title" type="text" {% if not can_change %}disabled{% endif %} value="{{ form.title.value|default_if_none:"" }}" />
<label for="id_title" class="form-label">{% translate "Title" %}</label>
{% if form.title.errors %}{% for error in form.title.errors %}
<div class="alert alert-danger">{{ error|escape }}</div>
{% endfor %}{% endif %}
<input class="form-control" id="id_title" maxlength="255" name="title" type="text" {% if not can_change %}disabled{% endif %} value="{{ form.title.value|default_if_none:"" }}" />
<label for="id_title" class="form-label">{% translate "Title" %}</label>
</div>
{% if form.connections|length > 1 and can_change %}
<div class="mb-3 form-floating">
Expand All @@ -46,21 +46,22 @@ <h2>
</div>
{% else %}
{# still need to submit the connection, just hide the UI element #}
<div class="hidden">
<div class="d-none">
{{ form.connection }}
</div>
<div>{{ form.connection.value }}</div>
{% endif %}
<div class="mb-3 form-floating">
{% if form.description.errors %}
<div class="alert alert-danger">{{ form.description.errors }}</div>
{% endif %}
<textarea
id="id_description" class="form-control" cols="40" name="description"
{% if not can_change %}disabled{% endif %} rows="2"
>{{ form.description.value|default_if_none:"" }}</textarea>
<label for="id_description" class="form-label">
{% translate "Description"%}
</label>
{% if form.description.errors %}
<div class="alert alert-danger">{{ form.description.errors }}</div>
{% endif %}
</div>
{% if form.sql.errors %}
{% for error in form.sql.errors %}
Expand Down Expand Up @@ -121,7 +122,7 @@ <h2>
{% translate "Format" %}
</button>
{% else %}
<button id="refresh_button" type="button" class="btn btn-default">{% translate "Refresh" %}</button>
<button id="refresh_button" type="button" class="btn btn-outline-primary">{% translate "Refresh" %}</button>
{% export_buttons query %}
{% endif %}
</div>
Expand Down
4 changes: 2 additions & 2 deletions explorer/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def query_viewmodel(request, query, title=None, form=None, message=None,

try:
if app_settings.EXPLORER_CHARTS_ENABLED and has_valid_results:
charts["line_chart_svg"] = get_chart(res, "line")
charts["bar_chart_svg"] = get_chart(res, "bar")
charts["line_chart_svg"] = get_chart(res,"line", rows)
charts["bar_chart_svg"] = get_chart(res,"bar", rows)
except TypeError as e:
if ql is not None:
msg = f"Error generating charts for querylog {ql.id}: {e}"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/explorerhq/django-sql-explorer.git"
"url": "git+https://github.com/explorerhq/sql-explorer.git"
},
"author": "Chris Clark",
"license": "MIT",
"bugs": {
"url": "https://github.com/explorerhq/django-sql-explorer/issues"
"url": "https://github.com/explorerhq/sql-explorer/issues"
},
"homepage": "https://www.sqlexplorer.io",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def requirements(fname):
project_urls={
"Changes": "https://django-sql-explorer.readthedocs.io/en/latest/history.html",
"Documentation": "https://django-sql-explorer.readthedocs.io/en/latest/",
"Issues": "https://github.com/explorerhq/django-sql-explorer/issues"
"Issues": "https://github.com/explorerhq/sql-explorer/issues"
},
packages=["explorer"],
long_description=long_description,
Expand Down

0 comments on commit 5da792e

Please sign in to comment.