Adds works chart and updates colors

This commit is contained in:
Mouse Reeve 2021-10-04 11:14:50 -07:00
parent 37cd7e684c
commit 551b49b903
6 changed files with 63 additions and 28 deletions

View file

@ -102,6 +102,12 @@
<canvas id="user_stats"></canvas>
</div>
</div>
<div class="column is-half">
<h3>{% trans "User signup activity" %}</h3>
<div class="box">
<canvas id="register_stats"></canvas>
</div>
</div>
<div class="column is-half">
<h3>{% trans "Status activity" %}</h3>
<div class="box">
@ -109,9 +115,9 @@
</div>
</div>
<div class="column is-half">
<h3>{% trans "User signup activity" %}</h3>
<h3>{% trans "Works created" %}</h3>
<div class="box">
<canvas id="register_stats"></canvas>
<canvas id="works_stats"></canvas>
</div>
</div>
</div>
@ -124,4 +130,5 @@
{% include 'settings/dashboard/user_chart.html' %}
{% include 'settings/dashboard/status_chart.html' %}
{% include 'settings/dashboard/registration_chart.html' %}
{% include 'settings/dashboard/works_chart.html' %}
{% endblock %}

View file

@ -8,8 +8,8 @@ var registerStats = new Chart(
labels: [{% for label in register_stats.labels %}"{{ label }}",{% endfor %}],
datasets: [{
label: '{% trans "Registrations" %}',
backgroundColor: 'rgb(75, 192, 192)',
borderColor: 'rgb(75, 192, 192)',
backgroundColor: 'hsl(171, 100%, 41%)',
borderColor: 'hsl(171, 100%, 41%)',
data: {{ register_stats.total }},
}]
},

View file

@ -9,8 +9,8 @@ var statusStats = new Chart(
labels: [{% for label in status_stats.labels %}"{{ label }}",{% endfor %}],
datasets: [{
label: '{% trans "Statuses posted" %}',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
backgroundColor: 'hsl(141, 71%, 48%)',
borderColor: 'hsl(141, 71%, 48%)',
data: {{ status_stats.total }},
}]
},

View file

@ -1,29 +1,25 @@
{% load i18n %}
<script>
const labels = [{% for label in user_stats.labels %}"{{ label }}",{% endfor %}];
const data = {
labels: labels,
datasets: [{
label: '{% trans "Total" %}',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: {{ user_stats.total }},
}, {
label: '{% trans "Active this month" %}',
backgroundColor: 'rgb(75, 192, 192)',
borderColor: 'rgb(75, 192, 192)',
data: {{ user_stats.active }},
}]
};
const config = {
type: 'line',
data: data,
options: {}
};
var userStats = new Chart(
document.getElementById('user_stats'),
config
{
type: 'line',
data: {
labels: [{% for label in user_stats.labels %}"{{ label }}",{% endfor %}],
datasets: [{
label: '{% trans "Total" %}',
backgroundColor: 'hsl(217, 71%, 53%)',
borderColor: 'hsl(217, 71%, 53%)',
data: {{ user_stats.total }},
}, {
label: '{% trans "Active this month" %}',
backgroundColor: 'hsl(171, 100%, 41%)',
borderColor: 'hsl(171, 100%, 41%)',
data: {{ user_stats.active }},
}]
},
options: {}
}
);
</script>

View file

@ -0,0 +1,21 @@
{% load i18n %}
<script>
var worksStats = new Chart(
document.getElementById('works_stats'),
{
type: 'bar',
data: {
labels: [{% for label in works_stats.labels %}"{{ label }}",{% endfor %}],
datasets: [{
label: '{% trans "Works" %}',
backgroundColor: 'hsl(204, 86%, 53%)',
borderColor: 'hsl(204, 86%, 53%)',
data: {{ works_stats.total }},
}]
},
options: {}
}
);
</script>

View file

@ -73,6 +73,16 @@ class Dashboard(View):
}
)
works_chart = Chart(
queryset=models.Work.objects,
queries = {
"total": lambda q, s, e: q.filter(
created_date__gt=s,
created_date__lte=e,
).count()
}
)
data = {
"start": start.strftime("%Y-%m-%d"),
"end": end.strftime("%Y-%m-%d"),
@ -90,6 +100,7 @@ class Dashboard(View):
"user_stats": user_chart.get_chart(start, end, interval),
"status_stats": status_chart.get_chart(start, end, interval),
"register_stats": register_chart.get_chart(start, end, interval),
"works_stats": works_chart.get_chart(start, end, interval),
}
return TemplateResponse(request, "settings/dashboard/dashboard.html", data)