Align billing fees to new DT mechanism.

Finally remove the ajax_process_resultset function from Root controller.
agranig/1_0_subfix
Andreas Granig 12 years ago
parent a884e45915
commit 9b8ce0d783

@ -201,7 +201,13 @@ sub create_without_reseller :Chained('profile_list') :PathPart('create/noreselle
sub fees_list :Chained('base') :PathPart('fees') :CaptureArgs(0) { sub fees_list :Chained('base') :PathPart('fees') :CaptureArgs(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{fee_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => 'id', search => 1, title => '#' },
{ name => 'source', search => 1, title => 'Source Pattern' },
{ name => 'destination', search => 1, title => 'Destination Pattern' },
{ name => 'direction', search => 1, title => 'Match Direction' },
{ name => 'billing_zone.detail', search => 1, title => 'Billing Zone' },
]);
$c->stash(template => 'billing/fees.tt'); $c->stash(template => 'billing/fees.tt');
} }
@ -236,19 +242,8 @@ sub fees_base :Chained('fees_list') :PathPart('') :CaptureArgs(1) {
sub fees_ajax :Chained('fees_list') :PathPart('ajax') :Args(0) { sub fees_ajax :Chained('fees_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
my $resultset = $c->stash->{'profile_result'}->billing_fees my $resultset = $c->stash->{'profile_result'}->billing_fees;
->search(undef, { NGCP::Panel::Utils::Datatables::process($c, $resultset, $c->stash->{fee_dt_columns});
join => 'billing_zone',
columns => [
{'zone' => 'billing_zone.zone'},
'id','source','destination','direction'
]
});
$c->forward( "/ajax_process_resultset", [$resultset,
["id", "source", "destination", "direction", "zone"],
["source", "destination", "direction"]]);
$c->detach( $c->view("JSON") ); $c->detach( $c->view("JSON") );
} }

@ -108,79 +108,6 @@ sub default :Path {
sub end : ActionClass('RenderView') {} sub end : ActionClass('RenderView') {}
sub ajax_process_resultset :Private {
my ($self, $c, $rs, $columns, $searchable) = @_;
#Process Arguments
my $sEcho = int($c->request->params->{sEcho} // 1); #/
# http://datatables.net/usage/server-side#sEcho
my $sSearch = $c->request->params->{sSearch} // ""; #/
my $iDisplayStart = $c->request->params->{iDisplayStart};
my $iDisplayLength = $c->request->params->{iDisplayLength};
my $iSortCol_0 = $c->request->params->{iSortCol_0};
my $sSortDir_0 = $c->request->params->{sSortDir_0};
if (defined $sSortDir_0) {
if ('desc' eq lc $sSortDir_0) {
$sSortDir_0 = 'desc';
} else {
$sSortDir_0 = 'asc';
}
}
my $iIdOnTop = $c->request->params->{iIdOnTop};
#will contain final data to be sent
my $aaData = [];
my $totalRecords = $rs->count;
if ($sSearch) {
$rs = $rs->search([ map{ +{ $_ => { like => '%'.$sSearch.'%' } } } @$searchable ]);
}
my $totalDisplayRecords = $rs->count;
#potentially selected Id as first element
if (defined $iIdOnTop) {
if (defined(my $row = $rs->find($iIdOnTop))) {
push @{ $aaData }, _prune_row($columns, $row->get_inflated_columns);
$rs = $rs->search({ 'me.id' => { '!=', $iIdOnTop} });
} else {
$c->log->error("iIdOnTop $iIdOnTop not found in resultset " . ref $rs);
};
}
#Sorting
if (defined $iSortCol_0 && defined $sSortDir_0) {
$rs = $rs->search(undef, {
order_by => {
"-$sSortDir_0" => $columns->[$iSortCol_0],
}
});
}
#Pagination
# $iDisplayLength will be -1 if bPaginate is false
if (defined $iDisplayStart && $iDisplayLength && $iDisplayLength > 0) {
$rs = $rs->search(undef, {
offset => $iDisplayStart,
rows => $iDisplayLength,
});
}
for my $row ($rs->all) {
push @{ $aaData }, _prune_row($columns, $row->get_inflated_columns);
}
$c->stash(
aaData => $aaData,
iTotalRecords => $totalRecords,
iTotalDisplayRecords => $totalDisplayRecords,
sEcho => $sEcho,
);
}
sub _prune_row { sub _prune_row {
my ($columns, %row) = @_; my ($columns, %row) = @_;
while (my ($k,$v) = each %row) { while (my ($k,$v) = each %row) {
@ -244,20 +171,6 @@ Standard 404 error page
Attempt to render a view, if needed. Attempt to render a view, if needed.
=head2 ajax_process_resultset
Processes a L<ResultSet|DBIx::Class::ResultSet> and prepares data from other controllers to be used
with the JSON view. The items exposed to stash are namely:
* sEcho
* aaData
* iTotalRecords
* iTotalDisplayRecords
They are intended for use with datatables.
Arguments: $resultset, \@columns, \@searchable
=head2 error_page =head2 error_page
should be called if the intended page could not be found (404). should be called if the intended page could not be found (404).

@ -2,10 +2,8 @@
[% [%
helper.name = 'Billing Fees'; helper.name = 'Billing Fees';
helper.show_create_button = 1;
helper.messages = messages; helper.messages = messages;
helper.column_titles = [ '#', 'Source', 'Destination', 'Direction', 'Zone' ]; helper.dt_columns = fee_dt_columns;
helper.column_fields = [ 'id', 'source', 'destination', 'direction', 'zone' ];
helper.close_target = close_target; helper.close_target = close_target;
helper.create_flag = create_flag; helper.create_flag = create_flag;
@ -14,15 +12,17 @@
helper.ajax_uri = c.uri_for_action('/billing/fees_ajax', [c.req.captures.0]); helper.ajax_uri = c.uri_for_action('/billing/fees_ajax', [c.req.captures.0]);
helper.tmpuri = c.uri_for( profile.id, 'fees'); helper.tmpuri = c.uri_for( profile.id, 'fees');
UNLESS c.user.read_only;
helper.dt_buttons = [ helper.dt_buttons = [
{ name = 'Edit', uri = helper.tmpuri _ "/'+full[\"id\"]+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, { name = 'Edit', uri = helper.tmpuri _ "/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
{ name = 'Delete', uri = helper.tmpuri _ "/'+full[\"id\"]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, { name = 'Delete', uri = helper.tmpuri _ "/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
]; ];
helper.top_buttons = [ helper.top_buttons = [
{ name = 'Create Fee Entry', uri = c.uri_for( profile.id, 'fees') _ "/create", icon = 'icon-star' }, { name = 'Create Fee Entry', uri = c.uri_for( profile.id, 'fees') _ "/create", icon = 'icon-star' },
{ name = 'Upload Fees as CSV', uri = c.uri_for_action('/billing/fees_upload',[c.req.captures.0]), icon = 'icon-star' }, { name = 'Upload Fees as CSV', uri = c.uri_for_action('/billing/fees_upload',[c.req.captures.0]), icon = 'icon-star' },
{ name = 'Edit Zones', uri = c.uri_for_action('/billing/zones',[c.req.captures.0]), icon = 'icon-star' }, { name = 'Edit Zones', uri = c.uri_for_action('/billing/zones',[c.req.captures.0]), icon = 'icon-star' },
]; ];
END;
PROCESS 'helpers/datatables.tt'; PROCESS 'helpers/datatables.tt';
-%] -%]

Loading…
Cancel
Save