Database-BI
view release on metacpan or search on metacpan
lib/Database/BI/Controller/Dashboard.pm view on Meta::CPAN
}
$html .= '</tr></thead><tbody>';
my $count = 0;
for my $row (@$vis_recs) {
last if $count++ >= $max_rows_t;
$html .= '<tr>';
for my $c (@cols) {
my $v = $row->{$c} // '';
$v =~ s/&/&/g; $v =~ s/</</g; $v =~ s/>/>/g;
$html .= "<td>$v</td>";
}
$html .= '</tr>';
}
$html .= '</tbody></table></div>';
return { html => $html, title => $title };
}
return { error => "Unknown visual kind: $kind" };
}
# _vis_cf_col(\%vis) -> $col_name | undef
#
# Returns the primary categorical dimension of a visual -- the column that
# makes sense to cross-filter on when the user clicks a mark.
# Priority: cat > group > x > col (histogram). Series/size/val are measures,
# not dimensions, so they are intentionally excluded.
sub _vis_cf_col {
my ($vis) = @_;
my $enc = $vis->{encode} // {};
for my $key (qw(cat group x col)) {
return $enc->{$key} if length($enc->{$key} // '');
}
return undef;
}
# GET /a/:id -- render a saved canvas
#
# redirects to the reconstructed data-view URL when the
# canvas has no visuals array.
# renders N visuals in a CSS grid when visuals are present.
# _bound_canvas_params($self, $a, $lookup) -> (\%bound, \@errors)
#
# Resolve the canvas's declared parameters against URL values. $lookup takes a
# parameter name ("p.<name>") and returns the raw string from the request or
# undef; the default is used when it returns undef. Numbers are coerced and
# range-checked, and an error is reported rather than a value bound, so the
# canvas page and a card appended to it draw the same parameter values.
sub _bound_canvas_params :Protected ($self, $a, $lookup) {
my %param_defs = %{ $a->{params} // {} };
my (%bound_params, @errors);
for my $pname (sort keys %param_defs) {
my $def = ref $param_defs{$pname} eq 'HASH' ? $param_defs{$pname} : {};
my $type = $def->{type} // 'string';
my $default = $def->{default} // '';
my $raw = $lookup->("p.$pname");
my $val = defined $raw ? $raw : $default;
if ($type eq 'number') {
require Scalar::Util;
# looks_like_number accepts these, and every comparison with NaN is
# false, so it would walk straight past min and max below.
unless (Scalar::Util::looks_like_number($val) && $val !~ /\A\s*[-+]?(?:nan|inf)/i) {
push @errors, sprintf(_message_text('error_param_type'), $pname);
next;
}
$val = $val + 0;
my ($lo, $hi) = ($def->{min}, $def->{max});
if (defined $lo && $val < $lo) {
push @errors, sprintf(_message_text('error_param_range'),
$pname, $lo, defined $hi ? $hi : '+inf');
next;
}
if (defined $hi && $val > $hi) {
push @errors, sprintf(_message_text('error_param_range'),
$pname, defined $lo ? $lo : '-inf', $hi);
next;
}
}
$bound_params{$pname} = $val;
}
return (\%bound_params, \@errors);
}
sub canvas_render ($self) {
my $id = $self->stash('id') // '';
return $self->render(text => _message_text('error_analysis_id_invalid'), status => 400)
unless $id =~ /\A[A-Za-z0-9]+\z/;
my $analyses = $self->_read_analyses;
unless (exists $analyses->{$id}) {
# An HTML page, not plain text, so the user keeps the breadcrumb and
# the site navigation. No canvas_id: there is nothing to delete.
my ($platform, $language) = $self->_resolve_template;
return $self->render(
handler => 'tt',
template => "$platform/$language/canvas_error",
format => 'html',
status => 404,
title => 'Canvas not found',
canvas_name => $id,
error_msg => sprintf(_message_text('error_analysis_not_found'), $id),
error_specs => [],
language => $language,
);
}
my $a = $analyses->{$id};
# freshness: compare each dataset's current mtime against
# the analysis's saved updated timestamp. Flag stale when any source
# is newer. Non-fatal: the canvas renders with a stale banner.
my ($freshness_stale, $freshness_msg, $freshness_source_mtime) = (0, '', '');
{
my $analysis_updated = $a->{updated} // 0;
# Parse ISO-8601 to epoch for comparison if needed.
if ($analysis_updated && $analysis_updated =~ /
\A
(\d{4}) - (\d{2}) - (\d{2}) # $1 yr $2 mon $3 day
T
(\d{2}) : (\d{2}) : (\d{2}) # $4 hr $5 min $6 sec
( run in 1.396 second using v1.01-cache-2.11-cpan-60884a8df76 )