From ae8415758be0943c0f1408eb4f103bd255a91b5e Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sun, 7 May 2023 06:12:37 +0200 Subject: [PATCH] Adding the option to ignore extensions. --- lib/BurguillosInfo/Controller/Metrics.pm | 20 +++++++++++++++++++- templates/metrics/stats.html.ep | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/BurguillosInfo/Controller/Metrics.pm b/lib/BurguillosInfo/Controller/Metrics.pm index ac010a7..05ed9e8 100644 --- a/lib/BurguillosInfo/Controller/Metrics.pm +++ b/lib/BurguillosInfo/Controller/Metrics.pm @@ -9,7 +9,7 @@ use Data::Dumper; use BurguillosInfo::Tracking; -use Mojo::Base 'Mojolicious::Controller'; +use Mojo::Base 'Mojolicious::Controller', '-signatures'; use DateTime::Format::ISO8601; use DateTime::Format::Mail; @@ -37,9 +37,27 @@ sub stats { } my $data = $tracking->get_global_data($self); my $data_per_url = $tracking->get_data_for_urls($self); + $self->_filter_data_per_url($data_per_url); $self->render(tracking_data => $data, tracking_by_url => $data_per_url); } +sub _filter_data_per_url($self, $data_per_url) { + my $filter = $self->param('filter'); + if (!defined $filter) { + return; + } + my @new_data_per_url; + if ($filter eq 'remove-extensions') { + for my $url (@$data_per_url) { + if ($url->{path} =~ /\.\w+$/) { + next; + } + push @new_data_per_url, $url; + } + } + @$data_per_url = @new_data_per_url; +} + sub submit_login { my $self = shift; if ($self->valid_login) { diff --git a/templates/metrics/stats.html.ep b/templates/metrics/stats.html.ep index f9fb79f..615046f 100644 --- a/templates/metrics/stats.html.ep +++ b/templates/metrics/stats.html.ep @@ -6,6 +6,8 @@

Unique visitors last 24 hours <%=$tracking_data->{unique_ips_last_24_hours}%>

Unique visitors last week <%=$tracking_data->{unique_ips_last_week}%>

Unique visitors last month <%=$tracking_data->{unique_ips_last_month}%>

+

Ver datos sin extensiones.

+

Ver todo.

Path