initial support for bind params in custom reports
This commit is contained in:
@@ -22,11 +22,10 @@ foreach my $report (@{setting('reports')}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
get "/ajax/content/report/$r" => require_login sub {
|
get "/ajax/content/report/$r" => require_login sub {
|
||||||
my $rs = schema('netdisco')->resultset('Virtual::GenericReport')->result_source;
|
|
||||||
|
|
||||||
# TODO: this should be done by creating a new Virtual Result class on
|
# TODO: this should be done by creating a new Virtual Result class on
|
||||||
# the fly (package...) and then calling DBIC register_class on it.
|
# the fly (package...) and then calling DBIC register_class on it.
|
||||||
|
|
||||||
|
my $rs = schema('netdisco')->resultset('Virtual::GenericReport')->result_source;
|
||||||
$rs->view_definition($report->{query});
|
$rs->view_definition($report->{query});
|
||||||
$rs->remove_columns($rs->columns);
|
$rs->remove_columns($rs->columns);
|
||||||
$rs->add_columns( exists $report->{query_columns}
|
$rs->add_columns( exists $report->{query_columns}
|
||||||
@@ -35,13 +34,17 @@ foreach my $report (@{setting('reports')}) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
my $set = schema('netdisco')->resultset('Virtual::GenericReport')
|
my $set = schema('netdisco')->resultset('Virtual::GenericReport')
|
||||||
->search(undef, {result_class => 'DBIx::Class::ResultClass::HashRefInflator'});
|
->search(undef, {
|
||||||
|
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
|
||||||
|
( (exists $report->{bind_params})
|
||||||
|
? (bind => [map { param($_) } @{ $report->{bind_params} }]) : () ),
|
||||||
|
});
|
||||||
@data = $set->all;
|
@data = $set->all;
|
||||||
|
|
||||||
# Data Munging support...
|
# Data Munging support...
|
||||||
|
|
||||||
my $compartment = Safe->new;
|
my $compartment = Safe->new;
|
||||||
$config = $report;
|
$config = $report; # closure for the config of this report
|
||||||
$compartment->share(qw/$config @data/);
|
$compartment->share(qw/$config @data/);
|
||||||
$compartment->permit_only(qw/:default sort/);
|
$compartment->permit_only(qw/:default sort/);
|
||||||
|
|
||||||
|
|||||||
@@ -169,15 +169,22 @@ register 'register_report' => sub {
|
|||||||
return error "bad config to register_report";
|
return error "bad config to register_report";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $item (@{setting('_reports_menu')->{ $config->{category} }}) {
|
foreach my $tag (@{setting('_reports_menu')->{ $config->{category} }}) {
|
||||||
if ($item eq $config->{tag}) {
|
if ($tag eq $config->{tag}) {
|
||||||
setting('_reports')->{$config->{tag}} = $config;
|
setting('_reports')->{$tag} = $config;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push @{setting('_reports_menu')->{ $config->{category} }}, $config->{tag};
|
push @{setting('_reports_menu')->{ $config->{category} }}, $config->{tag};
|
||||||
setting('_reports')->{$config->{tag}} = $config;
|
setting('_reports')->{$config->{tag}} = $config;
|
||||||
|
|
||||||
|
foreach my $rconfig (@{setting('reports')}) {
|
||||||
|
if ($rconfig->{tag} eq $config->{tag}) {
|
||||||
|
setting('_reports')->{$config->{tag}}->{'rconfig'} = $rconfig;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
register_plugin;
|
register_plugin;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
[% INCLUDE "sidebar/report/${report.tag}.tt" %]
|
[% INCLUDE "sidebar/report/${report.tag}.tt" %]
|
||||||
[% CATCH %]
|
[% CATCH %]
|
||||||
<script type="text/javascript">has_sidebar["[% report.tag %]"] = 0;</script>
|
<script type="text/javascript">has_sidebar["[% report.tag %]"] = 0;</script>
|
||||||
|
[% INCLUDE "sidebar/report/generic_report.tt" %]
|
||||||
[% END %]
|
[% END %]
|
||||||
</form>
|
</form>
|
||||||
</div> <!-- /tab-pane -->
|
</div> <!-- /tab-pane -->
|
||||||
|
|||||||
4
Netdisco/share/views/sidebar/report/generic_report.tt
Normal file
4
Netdisco/share/views/sidebar/report/generic_report.tt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
[% FOREACH k IN report.rconfig.bind_params %]
|
||||||
|
<input name="[% k %]" value="[% params.$k | html_entity %]" type="hidden"/>
|
||||||
|
[% END %]
|
||||||
Reference in New Issue
Block a user