From 89ac7b44e4f5f82b7e540b2465fae331662f6f11 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 26 Dec 2015 22:39:53 +0200 Subject: [PATCH] Support filtering by version in App::Web::NAOdash --- lib/App/Web/NAOdash.pm | 22 ++++++++++++++++++---- web/dash.css | 18 ++++++++++++++++++ web/dash.html | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/App/Web/NAOdash.pm b/lib/App/Web/NAOdash.pm index 985aacc..be36928 100644 --- a/lib/App/Web/NAOdash.pm +++ b/lib/App/Web/NAOdash.pm @@ -13,6 +13,7 @@ use File::Slurp; use HTML::TreeBuilder; use JSON::MaybeXS qw/encode_json/; use NetHack::NAOdash qw/naodash_user/; +use Plack::Request; my ($dash, $css, $css_hash); @@ -49,7 +50,7 @@ sub format_time { } sub make_html { - my ($name, $result) = @_; + my ($name, $query, $result) = @_; my @checks = @{$result->{checks}}; my %numbers = %{$result->{numbers}}; $numbers{totalrealtime} = format_time $numbers{totalrealtime}; @@ -70,6 +71,8 @@ sub make_html { warn "No element for check $id" unless $el; ## no critic (RequireCarping) $el->delete_content->push_content($num); } + my $ahref = $tree->look_down(href => "?$query"); + $ahref->replace_with(join '', $ahref->content_list) if $ahref; $tree->as_HTML; } @@ -87,12 +90,17 @@ sub reply { sub call { my ($self, $env) = @_; - return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $env->{PATH_INFO} =~ m{^/(\w+)$}; + my $req = Plack::Request->new($env); + return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $req->path =~ m{^/(\w+)$}; my $name = $1; - my $result = eval { naodash_user $name } or return reply 500, $@; + my %args = ( + include_versions => [$req->query_parameters->get_all('include_versions')], + exclude_versions => [$req->query_parameters->get_all('exclude_versions')], + ); + my $result = eval { naodash_user \%args, $name } or return reply 500, $@; return reply 200, encode_json($result), 'application/json' if $self->{json}; - return reply 200, make_html($name, $result), 'text/html'; + return reply 200, make_html($name, $req->query_string, $result), 'text/html'; } 1; @@ -124,6 +132,12 @@ It handles URLs of the form C, where I is a NAO username. It retrieves the xlogfile from NAO and returns the result of the analysis. +Two query parameters are accepted: include_versions and +exclude_versions, both of which can take multiple values by +specifiying them multiple times. They are passed directly to the +B function, see the documentation of L +for an explanation of their function. + The constructor takes a single named parameter, I, that is false by default. The result will be returned as HTML is I is false, as JSON if I is true. diff --git a/web/dash.css b/web/dash.css index 5c57cb6..9e18877 100644 --- a/web/dash.css +++ b/web/dash.css @@ -39,6 +39,24 @@ h2:after { text-align: center; } +#versions { + text-align:center; + margin: 5px; +} + +#versions li { + display: inline; +} + +#versions li::after { + content: "|"; + margin: 0 0.5em; +} + +#versions li:last-child::after { + content: ""; +} + span[title] { color: #D33; font-family: monospace; diff --git a/web/dash.html b/web/dash.html index 3131fc7..0dc930c 100644 --- a/web/dash.html +++ b/web/dash.html @@ -5,6 +5,7 @@

NAO dashboard for NAME

+

Achievements

-- 2.39.2