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..ecb18a0 --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -0,0 +1,51 @@ +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)); + } else { + $c->reply->static('image/no_transaction.jpg'); + } +} + +1; diff --git a/public/image/no_transaction.jpg b/public/image/no_transaction.jpg new file mode 100644 index 0000000..8c2e148 Binary files /dev/null and b/public/image/no_transaction.jpg differ diff --git a/templates/admin/organisations/valid_read.html.ep b/templates/admin/organisations/valid_read.html.ep index 5bbe739..e390e5d 100644 --- a/templates/admin/organisations/valid_read.html.ep +++ b/templates/admin/organisations/valid_read.html.ep @@ -71,13 +71,15 @@ % for my $transaction ( $transactions->all ) {
  • -
    -
    From: <%= $transaction->buyer->name %>
    -
    To: <%= $transaction->seller->name %>
    -
    Value: <%= $transaction->value %>
    -
    Submitted At: <%= $transaction->submitted_at %>
    -
    Purchase Time: <%= $transaction->purchase_time %>
    -
    + +
    +
    From: <%= $transaction->buyer->name %>
    +
    To: <%= $transaction->seller->name %>
    +
    Value: <%= $transaction->value %>
    +
    Submitted At: <%= $transaction->submitted_at %>
    +
    Purchase Time: <%= $transaction->purchase_time %>
    +
    +
  • % } 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/admin/users/read.html.ep b/templates/admin/users/read.html.ep index 37d7763..2970b15 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -94,13 +94,15 @@ % for my $transaction ( $transactions->all ) {
  • -
    -
    From: <%= $transaction->buyer->name %>
    -
    To: <%= $transaction->seller->name %>
    -
    Value: <%= $transaction->value %>
    -
    Submitted At: <%= $transaction->submitted_at %>
    -
    Purchase Time: <%= $transaction->purchase_time %>
    -
    + +
    +
    From: <%= $transaction->buyer->name %>
    +
    To: <%= $transaction->seller->name %>
    +
    Value: <%= $transaction->value %>
    +
    Submitted At: <%= $transaction->submitted_at %>
    +
    Purchase Time: <%= $transaction->purchase_time %>
    +
    +
  • % } 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 @@