From 1f73491b9c25d75f9fa0db8cb2ca3025f33b066e Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 26 Apr 2013 09:08:05 +0200 Subject: [PATCH] Create new controller for Billing --- lib/NGCP/Panel/Controller/Billing.pm | 104 +++++++++++++++++++++++++++ lib/NGCP/Panel/Controller/Root.pm | 1 + share/templates/billing/list.tt | 17 +++++ t/controller_Billing.t | 10 +++ 4 files changed, 132 insertions(+) create mode 100644 lib/NGCP/Panel/Controller/Billing.pm create mode 100644 share/templates/billing/list.tt create mode 100644 t/controller_Billing.t diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm new file mode 100644 index 0000000000..605bcb6c57 --- /dev/null +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -0,0 +1,104 @@ +package NGCP::Panel::Controller::Billing; +use Moose; +use namespace::autoclean; + +BEGIN { extends 'Catalyst::Controller'; } + + + +sub list :Chained('/') :PathPart('billing') :CaptureArgs(0) :Args(0) { + my ( $self, $c ) = @_; + + $c->stash(has_edit => 1); + $c->stash(has_preferences => 0); + $c->stash(template => 'billing/list.tt'); +} + +sub root :Chained('list') :PathPart('') :Args(0) { + my ($self, $c) = @_; +} + +sub ajax :Chained('list') :PathPart('ajax') :Args(0) { + my ($self, $c) = @_; + + my $resultset = $c->model('billing')->resultset('billing_profiles'); + + $c->forward( "/ajax_process_resultset", [$resultset, + ["id", "name"], + [0,1]]); + + $c->detach( $c->view("JSON") ); +} + +sub base :Chained('list') :PathPart('') :CaptureArgs(1) :Args(0) { + my ($self, $c, $profile_id) = @_; + + unless($profile_id && $profile_id =~ /^\d+$/) { + $c->flash(messages => [{type => 'error', text => 'Invalid profile id detected!'}]); + $c->response->redirect($c->uri_for()); + return; + } + + my $res = $c->model('billing')->resultset('billing_profiles')->find($profile_id); + unless(defined($res)) { + $c->flash(messages => [{type => 'error', text => 'Domain does not exist!'}]); + $c->response->redirect($c->uri_for()); + return; + } + $c->stash(profile => {$res->get_columns}); + $c->stash(profile_result => $res); +} + +sub edit :Chained('base') :PathPart('edit') { + my ($self, $c) = @_; + +} + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + +=head1 NAME + +NGCP::Panel::Controller::Billing - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=head2 list + +basis for the billing controller + +=head2 root + +just shows a list of billing profiles + +=head2 ajax + +Get billing_profiles and output them as JSON. + +=head2 base + +Fetch a billing_profile by its id. + +=head2 edit + +Show a modal to edit one billing_profile. + +=head1 AUTHOR + +Gerhard Jungwirth C<< >> + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Controller/Root.pm b/lib/NGCP/Panel/Controller/Root.pm index 9a55206847..228d57f225 100644 --- a/lib/NGCP/Panel/Controller/Root.pm +++ b/lib/NGCP/Panel/Controller/Root.pm @@ -247,6 +247,7 @@ sub ajax_process_resultset :Private { sub error_page :Private { my ($self,$c) = @_; + $c->log->info( 'Failed to find: ' . $c->request->path ); $c->stash(template => 'error_page.tt'); #$c->response->body( 'Page not found' ); $c->response->status(404); diff --git a/share/templates/billing/list.tt b/share/templates/billing/list.tt new file mode 100644 index 0000000000..5929539cb3 --- /dev/null +++ b/share/templates/billing/list.tt @@ -0,0 +1,17 @@ +[% META title = 'Billing Profiles' -%] +[% + helper.name = 'Billing Profiles'; + helper.messages = messages; + helper.column_titles = [ '#', 'Profile' ]; + helper.column_fields = [ 'id', 'name' ]; + + helper.close_target = close_target; + helper.create_flag = create_flag; + helper.edit_object = profile; + helper.form_object = form; + helper.has_edit = has_edit; + helper.has_preferences = has_preferences; + + PROCESS 'helpers/datatables.tt'; +-%] +[% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/t/controller_Billing.t b/t/controller_Billing.t new file mode 100644 index 0000000000..d6eb52d3f8 --- /dev/null +++ b/t/controller_Billing.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'NGCP::Panel'; +use NGCP::Panel::Controller::Billing; + +ok( request('/billing')->is_success, 'Request should succeed' ); +done_testing();