From 07f3926a9c07a2e45139b22d86eb2308f0e71a0b Mon Sep 17 00:00:00 2001 From: CasperVerswijvelt Date: Sat, 24 Apr 2021 12:51:56 +0200 Subject: [PATCH] Show snippet on service page when not hits are recorded yet --- shynet/core/models.py | 5 +++++ .../templates/dashboard/includes/service_snippet.html | 5 +++++ .../dashboard/templates/dashboard/pages/service.html | 11 +++++++++++ .../templates/dashboard/pages/service_update.html | 7 +------ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 shynet/dashboard/templates/dashboard/includes/service_snippet.html diff --git a/shynet/core/models.py b/shynet/core/models.py index e67f614..7c8122c 100644 --- a/shynet/core/models.py +++ b/shynet/core/models.py @@ -132,6 +132,10 @@ class Service(models.Model): service=self, start_time__lt=end_time, start_time__gt=start_time ) hit_count = hits.count() + hits = Hit.objects.filter( + service=self + ) + has_hits = hits.exists() bounces = sessions.filter(is_bounce=True) bounce_count = bounces.count() @@ -218,6 +222,7 @@ class Service(models.Model): "currently_online": currently_online, "session_count": session_count, "hit_count": hit_count, + "has_hits": has_hits, "avg_hits_per_session": hit_count / (max(session_count, 1)), "bounce_rate_pct": bounce_count * 100 / session_count if session_count > 0 diff --git a/shynet/dashboard/templates/dashboard/includes/service_snippet.html b/shynet/dashboard/templates/dashboard/includes/service_snippet.html new file mode 100644 index 0000000..cfdce40 --- /dev/null +++ b/shynet/dashboard/templates/dashboard/includes/service_snippet.html @@ -0,0 +1,5 @@ +
{% filter force_escape %} +{% endfilter %} +
\ No newline at end of file diff --git a/shynet/dashboard/templates/dashboard/pages/service.html b/shynet/dashboard/templates/dashboard/pages/service.html index 8a0dec0..f8d67da 100644 --- a/shynet/dashboard/templates/dashboard/pages/service.html +++ b/shynet/dashboard/templates/dashboard/pages/service.html @@ -11,6 +11,17 @@ {% endblock %} {% block service_content %} +{% if not stats.has_hits %} +
+
Get started
+

+ It seems that you have not recorded any data yet! +
+ Get started by placing the following snippet at the end of the <body> tag on any page you'd like to track. +

+ {% include 'dashboard/includes/service_snippet.html' %} +
+{% endif %}
{% with classes="text-sm font-semibold" good_classes="text-positive-400" bad_classes="text-critical-400" neutral_classes="text-gray-400" %}
diff --git a/shynet/dashboard/templates/dashboard/pages/service_update.html b/shynet/dashboard/templates/dashboard/pages/service_update.html index 53483cf..097335f 100644 --- a/shynet/dashboard/templates/dashboard/pages/service_update.html +++ b/shynet/dashboard/templates/dashboard/pages/service_update.html @@ -12,12 +12,7 @@
Installation

Place the following snippet at the end of the <body> tag on any page you'd like to track.

-
- {% filter force_escape %} - - {% endfilter %} -
+ {% include 'dashboard/includes/service_snippet.html' %}
Settings