Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/GADS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,6 @@ prefix '/:layout_name' => sub {
$params->{aggregate} = $records->aggregate_presentation;
$params->{columns} = [ map $_->presentation(
group => $records->is_group,
group_col_ids => $records->group_col_ids,
sort => $records->sort_first,
filters => \@additional_filters,
query_parameters => query_parameters,
Expand Down
9 changes: 4 additions & 5 deletions lib/GADS/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ sub _get_records {
# Check user has access
error __"Invalid column ID for sort"
unless $col_order && $col_order->user_can('read');
my $sort = { type => $params->get('order[0][dir]'), id => $col_order->id };
my $sort = { type => $params->get('order[0][dir]'), id => $col_order->id, parent_id => $col_order->parent_id };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be potentially a multiline?


$records->clear_sorts;
$records->sort($sort);
Expand All @@ -1203,11 +1203,10 @@ sub _get_records {
{
# Construct filter URL which will show all of this group of records
my @filters;
foreach my $group_col_id (@{$records->group_col_ids})
foreach my $group_col (@{$records->group_cols})
{
my $group_col = $layout->column($group_col_id);
my $filter_value = $rec->get_field_value($group_col)->filter_value || '';
push @filters, "$group_col_id=".uri_escape_utf8($filter_value);
push @filters, $group_col->id."=".uri_escape_utf8($filter_value);
}
my $desc = $rec->id_count == 1 ? 'record' : 'records';
$data->{_count} = {
Expand All @@ -1220,7 +1219,7 @@ sub _get_records {
else {
$data->{_id} = $rec->current_id;
};
$data->{$_->id} = $rec->get_field_value($_)->for_table
$data->{$_->full_id} = $rec->get_field_value($_)->for_table
foreach @{$records->columns_render};

push @{$return->{data}}, $data;
Expand Down
44 changes: 31 additions & 13 deletions lib/GADS/Column.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ has instance_id => (
isa => Int,
);

# If this is a field belonging to a curval and if so what that parent curval is
has parent_id => (
is => 'ro',
);

has parent => (
is => 'lazy',
);

sub _build_parent
{ my $self = shift;
return if !$self->parent_id;
$self->layout->column($self->parent_id);
}

has from_id => (
is => 'rw',
trigger => sub {
Expand Down Expand Up @@ -103,6 +118,12 @@ has id => (
isa => Int,
);

sub full_id
{ my $self = shift;
return $self->id if !$self->parent_id;
$self->parent_id."_".$self->id;
}

has internal => (
is => 'ro',
isa => Bool,
Expand Down Expand Up @@ -864,6 +885,16 @@ sub _build_instance_id
$self->layout->instance_id;
}

sub clone
{ my ($self, %params) = @_;
ref($self)->new(
schema => $self->schema,
layout => $self->layout,
set_values => $self->set_values,
%params,
);
}

sub build_values
{ my ($self, $original) = @_;

Expand Down Expand Up @@ -926,19 +957,6 @@ sub filter_value_to_text
return $value;
}

# Overridden where required
sub sort_columns
{ my $self = shift;
($self);
}

# Whether the sort columns when added should be added with a parent, and
# if so what is the paremt
sub sort_parent
{ my $self = shift;
return undef; # default no, undef in case used in arrays
}

# Overridden in child classes. This function is used
# to cleanup specialist column data when a column
# is deleted
Expand Down
7 changes: 5 additions & 2 deletions lib/GADS/Column/Autocur.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ sub _build_refers_from_value_field
}

sub make_join
{ my ($self, @joins) = @_;
{ my ($self, $options, @joins) = @_;
my $join_current_version = $options->{join_current_version};
+{
$self->field => {
record => {
current => {
record_single => ['record_later', @joins],
$join_current_version
? (current_version => [@joins])
: (record_single => ['record_later', @joins])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Column/Createddate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ has '+userinput' => (
default => 0,
);

sub tjoin {};
sub tjoin { undef };

sub has_time { 1 };

Expand Down
19 changes: 8 additions & 11 deletions lib/GADS/Column/Curcommon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ has '+use_id_in_filter' => (

sub tjoin
{ my ($self, %options) = @_;
$self->make_join(map { $_->tjoin(already_seen => $options{already_seen}) } grep { !$_->internal } @{$self->curval_fields_retrieve(%options)});
$self->make_join(
{ join_current_version => $options{join_current_version} },
map {
$_->tjoin(already_seen => $options{already_seen})
} grep {
!$_->internal
} @{$self->curval_fields_retrieve(%options)}
);
}

sub _build_fetch_with_record
Expand Down Expand Up @@ -227,16 +234,6 @@ sub curval_fields_all
[ map { $self->layout_parent->column($_, permission => 'read') } @{$self->curval_field_ids_all} ];
}

sub sort_columns
{ my $self = shift;
map { $_->sort_columns } @{$self->curval_fields};
}

sub sort_parent
{ my $self = shift;
$self; # This field is the parent for sort columns
}

# Does this column reference the field?
sub has_curval_field
{ my ($self, $field) = @_;
Expand Down
7 changes: 5 additions & 2 deletions lib/GADS/Column/Curval.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,16 @@ sub _build_refers_to_instance_id
}

sub make_join
{ my ($self, @joins) = @_;
{ my ($self, $options, @joins) = @_;
my $join_current_version = $options->{join_current_version};
return $self->field
if !@joins;
+{
$self->field => {
value => {
record_single => ['record_later', @joins],
$join_current_version
? ('current_version' => [@joins])
: (record_single => ['record_later', @joins])
}
}
};
Expand Down
7 changes: 5 additions & 2 deletions lib/GADS/Column/Filval.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ has '+table' => (

# Same as Column::Curval
sub make_join
{ my ($self, @joins) = @_;
{ my ($self, $options, @joins) = @_;
my $join_current_version = $options->{join_current_version};
return $self->field
if !@joins;
+{
$self->field => {
value => {
record_single => ['record_later', @joins],
$join_current_version
? (current_version => [@joins])
: (record_single => ['record_later', @joins])
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Column/Id.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ has '+value_field' => (

sub cleanup {}

sub tjoin {}
sub tjoin { undef }

1;

2 changes: 1 addition & 1 deletion lib/GADS/Column/Serial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ has '+value_field' => (
default => 'serial',
);

sub tjoin {}
sub tjoin { undef }

sub validate_search
{ my ($self, $value) = @_;
Expand Down
5 changes: 5 additions & 0 deletions lib/GADS/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,10 @@ sub _parse_db
$db_parser->parse_datetime($value);
}

sub dt_parser
{ my $self = shift;
$self->schema->storage->datetime_parser;
}

1;

45 changes: 42 additions & 3 deletions lib/GADS/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ has _graph => (
my $graph = $self->schema->resultset('Graph')->find({
'me.id' => $self->id
},{
prefetch => [qw/x_axis x_axis_link y_axis group_by/],
prefetch => [qw/x_axis x_axis_link y_axis y_axis_link group_by/],
});
$graph
or error __x"Requested graph ID {id} not found", id => $self->id;
Expand All @@ -66,6 +66,7 @@ has set_values => (
$self->x_axis_link($original->{x_axis_link});
$self->x_axis_grouping($original->{x_axis_grouping});
$self->y_axis($original->{y_axis});
$self->y_axis_link($original->{y_axis_link});
$self->y_axis_stack($original->{y_axis_stack});
$self->description($original->{description});
$self->stackseries($original->{stackseries});
Expand Down Expand Up @@ -238,12 +239,37 @@ has as_percent => (
builder => sub { $_[0]->_graph && $_[0]->_graph->as_percent },
);

sub set_y_axis
{ my ($self, $value) = @_;
if ($value =~ /^([0-9]+)_([0-9]+)$/)
{
$self->y_axis($2);
$self->y_axis_link($1);
return;
}
$self->y_axis_link(undef);
$self->y_axis($value);
}

has y_axis => (
is => 'rw',
lazy => 1,
builder => sub { $_[0]->_graph && $_[0]->_graph->y_axis && $_[0]->_graph->y_axis->id },
);

has y_axis_link => (
is => 'rw',
lazy => 1,
builder => sub { $_[0]->_graph && $_[0]->_graph->y_axis_link && $_[0]->_graph->y_axis_link->id },
);

sub y_axis_full
{ my $self = shift;
return $self->y_axis_link."_".$self->y_axis
if $self->y_axis_link;
return $self->y_axis;
}

has y_axis_label => (
is => 'rw',
lazy => 1,
Expand Down Expand Up @@ -338,8 +364,15 @@ sub write

if ($newgraph->{y_axis} = $self->y_axis)
{
$self->layout->column_this_instance($self->y_axis)
or error __x"Invalid Y-axis {y_axis}", y_axis => $self->y_axis;
if ($self->y_axis_link)
{
$self->layout->column_this_instance($self->y_axis_link)
or error __x"Invalid Y-axis parent {y_axis_link}", y_axis_link => $self->y_axis_link;
}
else {
$self->layout->column_this_instance($self->y_axis)
or error __x"Invalid Y-axis {y_axis}", y_axis => $self->y_axis;
}
}

$newgraph->{y_axis_stack} = $self->y_axis_stack or error __"A valid value is required for Y-axis stacking";
Expand All @@ -348,6 +381,7 @@ sub write

$newgraph->{y_axis_stack} eq 'sum' && !$newgraph->{y_axis}
and error __"Please select a Y-axis";
$newgraph->{y_axis_link} = $self->y_axis_link;

$newgraph->{y_axis_label} = $self->y_axis_label;

Expand Down Expand Up @@ -447,6 +481,10 @@ sub import_hash
old => $self->y_axis_stack, new => $values->{y_axis_stack}, name => $self->title
if $options{report_only} && $self->y_axis_stack ne $values->{y_axis_stack};
$self->y_axis_stack($values->{y_axis_stack});
notice __x"Updating y_axis_link from {old} to {new} for graph {name}",
old => $self->y_axis_link, new => $values->{y_axis_link}, name => $self->title
if $options{report_only} && $self->y_axis_link != $values->{y_axis_link};
$self->y_axis_link($values->{y_axis_link});
notice __x"Updating y_axis_label from {old} to {new} for graph {name}",
old => $self->y_axis_label, new => $values->{y_axis_label}, name => $self->title
if $options{report_only} && $self->y_axis_label ne $values->{y_axis_label};
Expand Down Expand Up @@ -521,6 +559,7 @@ sub export_hash
title => $self->title,
description => $self->description,
y_axis => $self->y_axis,
y_axis_link => $self->y_axis_link,
y_axis_stack => $self->y_axis_stack,
y_axis_label => $self->y_axis_label,
x_axis => $self->x_axis,
Expand Down
19 changes: 10 additions & 9 deletions lib/GADS/Graph/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ sub y_axis_col
$self->records->layout->column($self->y_axis);
}

sub y_axis_link_col
{ my $self = shift;
$self->records->layout->column($self->y_axis_link);
}

sub trend_range_amount
{ my $self = shift;
return undef if !$self->x_axis_range;
Expand Down Expand Up @@ -403,8 +408,9 @@ sub _build_data

$records->view($self->view);
push @columns, +{
id => $self->y_axis,
operator => $self->y_axis_stack,
id => $self->y_axis,
operator => $self->y_axis_stack,
parent_id => $self->y_axis_link, # What the parent curval is, if we're picking a field from within a curval
} if $self->y_axis;

$records->columns(\@columns);
Expand Down Expand Up @@ -473,23 +479,18 @@ sub _build_data
my ($results, $series_keys, $datemin, $datemax);
if ($self->trend)
{
# Force current IDs as of today (without rewind set) to be calculated
# first, otherwise the current IDs as at the start of the period will
# be used
$records->generate_cid_query;

my $search = $records->search; # Retain quick search across historical queries

foreach my $x (@x)
{
$records->clear(retain_current_ids => 1); # Retain record IDs across results
$records->clear;
$records->search($search);

# The period to retrieve ($x) will be at the beginning of the
# period. Move to the end of the period, by adding on one unit
# (e.g. month) and then moving into the previous day by a second
my $rewind = $x->clone->add($self->x_axis_grouping_calculated.'s' => 1)->subtract(seconds => 1);
$records->rewind($rewind);
$records->rewind_values($rewind);
my $this_results; my $this_series_keys;
($this_results, $this_series_keys, $datemin, $datemax) = $self->_records_to_results($records,
x_daterange => $x_daterange,
Expand Down
Loading
Loading