-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom widgets now share a base template, closes #78
- Loading branch information
Showing
7 changed files
with
107 additions
and
126 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
django_sql_dashboard/templates/django_sql_dashboard/widgets/_base_widget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="query-results"> | ||
{% block widget_results %}{% endblock %} | ||
<details><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">SQL query</summary> | ||
{% if saved_dashboard %}<pre class="sql">{{ result.sql }}</pre>{% else %}<textarea | ||
name="sql" | ||
>{{ result.sql|default:"" }}</textarea>{% endif %} | ||
{% if not saved_dashboard %}<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p>{% endif %} | ||
</details> | ||
</div> |
105 changes: 44 additions & 61 deletions
105
django_sql_dashboard/templates/django_sql_dashboard/widgets/bar_label-bar_quantity.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,44 @@ | ||
<div class="query-results"> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-dhyUMwHr1RzDslJIbzN+8UMRMobmqrmABSU3vFSBBnARl6XwbW37TVDCTQs+yEc5" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-nAwfbn/eKhGkpj7MbyqVuoGEyL/iSeZq4XJ1NNOxA9nT7eXfJuUQgpxYd27m1tAO" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-RvXMbul/5q2mGE4PXcky3u5+A/K3lk/jv+oizUX/InRPD9wELInOy6YwUxdk/tEu" | ||
crossorigin="anonymous" | ||
></script> | ||
<div id="vis{{ result.index }}"></div> | ||
{% with "vis-data-"|add:result.index as script_name %} | ||
{{ result.rows|json_script:script_name }} | ||
<script> | ||
vegaEmbed("#vis{{ result.index }}", { | ||
$schema: "https://vega.github.io/schema/vega-lite/v5.json", | ||
description: "A simple bar chart with embedded data.", | ||
data: { | ||
values: JSON.parse( | ||
document.getElementById("{{ script_name }}").textContent | ||
), | ||
}, | ||
mark: "bar", | ||
encoding: { | ||
x: { | ||
field: "bar_label", | ||
title: "Label", | ||
type: "nominal", | ||
axis: { labelAngle: 90 }, | ||
}, | ||
y: { field: "bar_quantity", title: "Quantity", type: "quantitative" }, | ||
}, | ||
}); | ||
</script> | ||
{% endwith %} | ||
<details> | ||
<summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer"> | ||
SQL query | ||
</summary> | ||
{% if saved_dashboard %} | ||
<pre class="sql">{{ result.sql }}</pre> | ||
{% else %} | ||
<textarea name="sql">{{ result.sql|default:"" }}</textarea> | ||
{% endif %} | ||
{% if not saved_dashboard %} | ||
<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p> | ||
{% endif %} | ||
</details> | ||
</div> | ||
{% extends "django_sql_dashboard/widgets/_base_widget.html" %} | ||
|
||
{% block widget_results %} | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-dhyUMwHr1RzDslJIbzN+8UMRMobmqrmABSU3vFSBBnARl6XwbW37TVDCTQs+yEc5" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-nAwfbn/eKhGkpj7MbyqVuoGEyL/iSeZq4XJ1NNOxA9nT7eXfJuUQgpxYd27m1tAO" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]" | ||
integrity="sha384-RvXMbul/5q2mGE4PXcky3u5+A/K3lk/jv+oizUX/InRPD9wELInOy6YwUxdk/tEu" | ||
crossorigin="anonymous" | ||
></script> | ||
<div id="vis{{ result.index }}"></div> | ||
{% with "vis-data-"|add:result.index as script_name %} | ||
{{ result.rows|json_script:script_name }} | ||
<script> | ||
vegaEmbed("#vis{{ result.index }}", { | ||
$schema: "https://vega.github.io/schema/vega-lite/v5.json", | ||
description: "A simple bar chart with embedded data.", | ||
data: { | ||
values: JSON.parse( | ||
document.getElementById("{{ script_name }}").textContent | ||
), | ||
}, | ||
mark: "bar", | ||
encoding: { | ||
x: { | ||
field: "bar_label", | ||
title: "Label", | ||
type: "nominal", | ||
axis: { labelAngle: 90 }, | ||
}, | ||
y: { field: "bar_quantity", title: "Quantity", type: "quantitative" }, | ||
}, | ||
}); | ||
</script> | ||
{% endwith %} | ||
{% endblock %} |
24 changes: 8 additions & 16 deletions
24
django_sql_dashboard/templates/django_sql_dashboard/widgets/big_number-label.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,10 @@ | ||
<div class="query-results"> | ||
{% extends "django_sql_dashboard/widgets/_base_widget.html" %} | ||
|
||
{% block widget_results %} | ||
{% for row in result.rows %} | ||
<p>{{ row.label }}</p> | ||
<h1>{{ row.big_number }}</h1> | ||
<div class="big-number"> | ||
<p><strong>{{ row.label }}</strong></p> | ||
<h1>{{ row.big_number }}</h1> | ||
</div> | ||
{% endfor %} | ||
<details><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">SQL query</summary> | ||
{% if saved_dashboard %}<pre class="sql">{{ result.sql }}</pre>{% else %}<textarea | ||
name="sql" | ||
>{{ result.sql|default:"" }}</textarea>{% endif %} | ||
{% if not saved_dashboard %}<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p>{% endif %} | ||
</details> | ||
</div> | ||
{% endblock %} |
26 changes: 8 additions & 18 deletions
26
django_sql_dashboard/templates/django_sql_dashboard/widgets/completed_count-total_count.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
<div class="query-results"> | ||
{% extends "django_sql_dashboard/widgets/_base_widget.html" %} | ||
|
||
{% block widget_results %} | ||
{% for row in result.rows %} | ||
<div class="completed-count-total-count"> | ||
<div class="completed-count-total-count-bar" style="width: {% widthratio row.completed_count row.total_count 100 %}%"> </div> | ||
</div> | ||
<h2>{{ row.completed_count }} / {{ row.total_count }}: {% widthratio row.completed_count row.total_count 100 %}%</h2> | ||
<div class="completed-count-total-count"> | ||
<div class="completed-count-total-count-bar" style="width: {% widthratio row.completed_count row.total_count 100 %}%"> </div> | ||
</div> | ||
<h2>{{ row.completed_count }} / {{ row.total_count }}: {% widthratio row.completed_count row.total_count 100 %}%</h2> | ||
{% endfor %} | ||
<details><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">SQL query</summary> | ||
{% if saved_dashboard %}<pre class="sql">{{ result.sql }}</pre>{% else %}<textarea | ||
name="sql" | ||
>{{ result.sql|default:"" }}</textarea>{% endif %} | ||
{% if not saved_dashboard %}<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p>{% endif %} | ||
</details> | ||
</div> | ||
{% endblock %} |
22 changes: 7 additions & 15 deletions
22
django_sql_dashboard/templates/django_sql_dashboard/widgets/html.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
{% load django_sql_dashboard %}<div class="query-results"> | ||
{% extends "django_sql_dashboard/widgets/_base_widget.html" %} | ||
|
||
{% load django_sql_dashboard %} | ||
|
||
{% block widget_results %} | ||
{% for row in result.rows %} | ||
{{ row.html|sql_dashboard_bleach }} | ||
{{ row.html|sql_dashboard_bleach }} | ||
{% endfor %} | ||
<details><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">SQL query</summary> | ||
{% if saved_dashboard %}<pre class="sql">{{ result.sql }}</pre>{% else %}<textarea | ||
name="sql" style="height: 10em;" | ||
>{{ result.sql|default:"" }}</textarea>{% endif %} | ||
{% if not saved_dashboard %}<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p>{% endif %} | ||
</details> | ||
</div> | ||
{% endblock %} |
22 changes: 7 additions & 15 deletions
22
django_sql_dashboard/templates/django_sql_dashboard/widgets/markdown.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
{% load django_sql_dashboard %}<div class="query-results"> | ||
{% extends "django_sql_dashboard/widgets/_base_widget.html" %} | ||
|
||
{% load django_sql_dashboard %} | ||
|
||
{% block widget_results %} | ||
{% for row in result.rows %} | ||
{{ row.markdown|sql_dashboard_markdown }} | ||
{{ row.markdown|sql_dashboard_markdown }} | ||
{% endfor %} | ||
<details><summary style="font-size: 0.7em; margin-bottom: 0.5em; cursor: pointer;">SQL query</summary> | ||
{% if saved_dashboard %}<pre class="sql">{{ result.sql }}</pre>{% else %}<textarea | ||
name="sql" style="height: 10em;" | ||
>{{ result.sql|default:"" }}</textarea>{% endif %} | ||
{% if not saved_dashboard %}<p> | ||
<input | ||
class="btn" | ||
type="submit" | ||
value="Run quer{% if query_results|length > 1 %}ies{% else %}y{% endif %}" | ||
/> | ||
</p>{% endif %} | ||
</details> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters