From e7631dd90e38d401c8e621575a25b6a85496c39b Mon Sep 17 00:00:00 2001 From: Finn Date: Tue, 5 Sep 2017 13:44:58 +0100 Subject: [PATCH] Code for viewing single transaction added --- lib/Pear/LocalLoop.pm | 4 ++ .../Controller/Admin/Transactions.pm | 49 +++++++++++++++++++ templates/admin/transactions/index.html.ep | 35 +++++++++++++ templates/admin/transactions/read.html.ep | 38 ++++++++++++++ templates/layouts/admin.html.ep | 1 + 5 files changed, 127 insertions(+) create mode 100644 lib/Pear/LocalLoop/Controller/Admin/Transactions.pm create mode 100644 templates/admin/transactions/index.html.ep create mode 100644 templates/admin/transactions/read.html.ep diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index df43bf5..c4ee95e 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -185,6 +185,10 @@ sub startup { $admin_routes->get('/feedback')->to('admin-feedback#index'); $admin_routes->get('/feedback/:id')->to('admin-feedback#read'); + $admin_routes->get('/transactions')->to('admin-transactions#index'); + $admin_routes->get('/transactions/:id')->to('admin-transactions#read'); + $admin_routes->get('/transactions/:id/image')->to('admin-transactions#image'); + # my $user_routes = $r->under('/')->to('root#under'); # $user_routes->get('/home')->to('root#home'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm new file mode 100644 index 0000000..86a168c --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -0,0 +1,49 @@ +package Pear::LocalLoop::Controller::Admin::Transactions; +use Mojo::Base 'Mojolicious::Controller'; + +has result_set => sub { + my $c = shift; + return $c->schema->resultset('Transaction'); +}; + +sub index { + my $c = shift; + + my $transactions = $c->result_set->search( + undef, { + page => $c->param('page') || 1, + rows => 10, + order_by => { -desc => 'submitted_at' }, + }, + ); + $c->stash( + transactions => $transactions, + ); +} + +sub read { + my $c = shift; + + my $id = $c->param('id'); + + if ( my $transaction = $c->result_set->find($id) ) { + $c->stash( transaction => $transaction ); + } else { + $c->flash( error => 'No transaction found' ); + $c->redirect_to( '/admin/transactions' ); + } +} + +sub image { + my $c = shift; + + my $id = $c->param('id'); + + my $transaction = $c->result_set->find($id); + + if ( $transaction->proof_image ) { + $c->reply->asset($c->get_file_from_uuid($transaction->proof_image)); + } +} + +1; diff --git a/templates/admin/transactions/index.html.ep b/templates/admin/transactions/index.html.ep new file mode 100644 index 0000000..191f845 --- /dev/null +++ b/templates/admin/transactions/index.html.ep @@ -0,0 +1,35 @@ +% layout 'admin'; +% title 'Transactions'; +% content_for javascript => begin +% end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } +
+ % for my $transaction ( $transactions->all ) { +
  • + +
  • + % } +
  • +
    + %= bootstrap_pagination( $c->param('page') || 1, $transactions->pager->last_page, { class => 'justify-content-center' } ); +
    +
  • +
    diff --git a/templates/admin/transactions/read.html.ep b/templates/admin/transactions/read.html.ep new file mode 100644 index 0000000..a40f384 --- /dev/null +++ b/templates/admin/transactions/read.html.ep @@ -0,0 +1,38 @@ +% layout 'admin'; +% title 'Transactions'; +% content_for javascript => begin +% end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    diff --git a/templates/layouts/admin.html.ep b/templates/layouts/admin.html.ep index e13f18f..417937d 100644 --- a/templates/layouts/admin.html.ep +++ b/templates/layouts/admin.html.ep @@ -30,6 +30,7 @@