Added organisations page to admin interface
This commit is contained in:
parent
25c0d06211
commit
98f15a67af
8 changed files with 217 additions and 19 deletions
|
@ -143,16 +143,23 @@ sub startup {
|
||||||
my $admin_routes = $r->under('/admin')->to('admin#under');
|
my $admin_routes = $r->under('/admin')->to('admin#under');
|
||||||
|
|
||||||
$admin_routes->get('/')->to('admin#home');
|
$admin_routes->get('/')->to('admin#home');
|
||||||
|
|
||||||
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
||||||
$admin_routes->post('/tokens')->to('admin-tokens#create');
|
$admin_routes->post('/tokens')->to('admin-tokens#create');
|
||||||
$admin_routes->get('/tokens/:id')->to('admin-tokens#read');
|
$admin_routes->get('/tokens/:id')->to('admin-tokens#read');
|
||||||
$admin_routes->post('/tokens/:id')->to('admin-tokens#update');
|
$admin_routes->post('/tokens/:id')->to('admin-tokens#update');
|
||||||
$admin_routes->post('/tokens/:id/delete')->to('admin-tokens#delete');
|
$admin_routes->post('/tokens/:id/delete')->to('admin-tokens#delete');
|
||||||
|
|
||||||
$admin_routes->get('/users')->to('admin-users#index');
|
$admin_routes->get('/users')->to('admin-users#index');
|
||||||
$admin_routes->get('/users/:id')->to('admin-users#read');
|
$admin_routes->get('/users/:id')->to('admin-users#read');
|
||||||
$admin_routes->post('/users/:id')->to('admin-users#update');
|
$admin_routes->post('/users/:id')->to('admin-users#update');
|
||||||
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
|
$admin_routes->post('/users/:id/delete')->to('admin-users#delete');
|
||||||
|
|
||||||
|
$admin_routes->get('/organisations')->to('admin-organisations#list');
|
||||||
|
$admin_routes->get('/organisations/valid/:id')->to('admin-organisations#valid_read');
|
||||||
|
$admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read');
|
||||||
|
$admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve');
|
||||||
|
|
||||||
my $user_routes = $r->under('/')->to('root#under');
|
my $user_routes = $r->under('/')->to('root#under');
|
||||||
|
|
||||||
$user_routes->get('/home')->to('root#home');
|
$user_routes->get('/home')->to('root#home');
|
||||||
|
@ -160,12 +167,32 @@ sub startup {
|
||||||
my $portal_api = $r->under('/portal')->to('api-auth#check_json')->under('/')->to('portal#under');
|
my $portal_api = $r->under('/portal')->to('api-auth#check_json')->under('/')->to('portal#under');
|
||||||
|
|
||||||
$portal_api->post('/upload')->to('api-upload#post_upload');
|
$portal_api->post('/upload')->to('api-upload#post_upload');
|
||||||
|
$portal_api->post('/search')->to('api-upload#post_search');
|
||||||
|
|
||||||
$self->hook( before_dispatch => sub {
|
$self->hook( before_dispatch => sub {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
$self->res->headers->header('Access-Control-Allow-Origin' => '*') if $self->app->mode eq 'development';
|
$self->res->headers->header('Access-Control-Allow-Origin' => '*') if $self->app->mode eq 'development';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$self->helper( copy_transactions_and_delete => sub {
|
||||||
|
my ( $c, $from_org, $to_org ) = @_;
|
||||||
|
|
||||||
|
my $from_org_transaction_rs = $from_org->transactions;
|
||||||
|
|
||||||
|
while ( my $from_org_transaction = $from_org_transaction_rs->next ) {
|
||||||
|
$to_org->create_related(
|
||||||
|
'transactions', {
|
||||||
|
buyer_id => $from_org_transaction->buyer_id,
|
||||||
|
value => $from_org_transaction->value,
|
||||||
|
proof_image => $from_org_transaction->proof_image,
|
||||||
|
submitted_at => $from_org_transaction->submitted_at,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$from_org->delete;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
42
lib/Pear/LocalLoop/Controller/Admin/Organisations.pm
Normal file
42
lib/Pear/LocalLoop/Controller/Admin/Organisations.pm
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package Pear::LocalLoop::Controller::Admin::Organisations;
|
||||||
|
use Mojo::Base 'Mojolicious::Controller';
|
||||||
|
|
||||||
|
sub list {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $valid_orgs_rs = $c->schema->resultset('Organisation');
|
||||||
|
my $pending_orgs_rs = $c->schema->resultset('PendingOrganisation');
|
||||||
|
|
||||||
|
$c->stash(
|
||||||
|
valid_orgs_rs => $valid_orgs_rs,
|
||||||
|
pending_orgs_rs => $pending_orgs_rs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub valid_read {
|
||||||
|
my $c = shift;
|
||||||
|
my $valid_org = $c->schema->resultset('Organisation')->find( $c->param('id') );
|
||||||
|
$c->stash( valid_org => $valid_org );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub pending_read {
|
||||||
|
my $c = shift;
|
||||||
|
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
|
||||||
|
$c->stash( pending_org => $pending_org );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub pending_approve {
|
||||||
|
my $c = shift;
|
||||||
|
my $pending_org = $c->schema->resultset('PendingOrganisation')->find( $c->param('id') );
|
||||||
|
my $valid_org = $c->schema->resultset('Organisation')->create({
|
||||||
|
name => $pending_org->name,
|
||||||
|
street_name => $pending_org->street_name,
|
||||||
|
town => $pending_org->town,
|
||||||
|
postcode => $pending_org->postcode,
|
||||||
|
});
|
||||||
|
$c->copy_transactions_and_delete( $pending_org, $valid_org );
|
||||||
|
$c->flash( success => 'Validated Organisation' );
|
||||||
|
$c->redirect_to( '/admin/organisations/valid/' . $valid_org->id );
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -102,24 +102,5 @@ sub post_admin_merge {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub copy_transactions_and_delete {
|
|
||||||
my ( $c, $from_org, $to_org ) = @_;
|
|
||||||
|
|
||||||
my $from_org_transaction_rs = $from_org->transactions;
|
|
||||||
|
|
||||||
while ( my $from_org_transaction = $from_org_transaction_rs->next ) {
|
|
||||||
$to_org->create_related(
|
|
||||||
'transactions', {
|
|
||||||
buyer_id => $from_org_transaction->buyer_id,
|
|
||||||
value => $from_org_transaction->value,
|
|
||||||
proof_image => $from_org_transaction->proof_image,
|
|
||||||
submitted_at => $from_org_transaction->submitted_at,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$from_org->delete;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|
|
@ -134,4 +134,16 @@ sub generate_session {
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub name {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ( defined $self->customer_id ) {
|
||||||
|
return $self->customer->name;
|
||||||
|
} elsif ( defined $self->organisation_id ) {
|
||||||
|
return $self->organisation->name;
|
||||||
|
} else {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
52
templates/admin/organisations/list.html.ep
Normal file
52
templates/admin/organisations/list.html.ep
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
% layout 'admin';
|
||||||
|
% title 'Organisations';
|
||||||
|
% content_for javascript => begin
|
||||||
|
% end
|
||||||
|
% if ( my $error = flash 'error' ) {
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<strong>Error!</strong> <%= $error %>
|
||||||
|
</div>
|
||||||
|
% } elsif ( my $success = flash 'success' ) {
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
<strong>Success!</strong> <%= $success %>
|
||||||
|
</div>
|
||||||
|
% }
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div class="card">
|
||||||
|
<h3 class="card-header">
|
||||||
|
Valid Organisations
|
||||||
|
</h3>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
% for my $valid_org ($valid_orgs_rs->all) {
|
||||||
|
<a href="<%= url_for . '/valid/' . $valid_org->id %>" class="list-group-item list-group-item-action">
|
||||||
|
<div>
|
||||||
|
%= $valid_org->name
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
% }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<div class="card">
|
||||||
|
<h3 class="card-header">
|
||||||
|
Pending Organisations
|
||||||
|
</h3>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
% if ( $pending_orgs_rs->count == 0 ) {
|
||||||
|
<div class="list-group-item">
|
||||||
|
No Pending Organisations!
|
||||||
|
</div>
|
||||||
|
% } else {
|
||||||
|
% for my $pending_org ($pending_orgs_rs->all) {
|
||||||
|
<a href="<%= url_for . '/pending/' . $pending_org->id %>" class="list-group-item list-group-item-action">
|
||||||
|
<div>
|
||||||
|
%= $pending_org->name
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
% }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
42
templates/admin/organisations/pending_read.html.ep
Normal file
42
templates/admin/organisations/pending_read.html.ep
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
% layout 'admin';
|
||||||
|
% title 'Organisations';
|
||||||
|
% content_for javascript => begin
|
||||||
|
% end
|
||||||
|
% if ( my $error = flash 'error' ) {
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<strong>Error!</strong> <%= $error %>
|
||||||
|
</div>
|
||||||
|
% } elsif ( my $success = flash 'success' ) {
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
<strong>Success!</strong> <%= $success %>
|
||||||
|
</div>
|
||||||
|
% }
|
||||||
|
<div class="card mb-3">
|
||||||
|
<h3 class="card-header">
|
||||||
|
%= $pending_org->name
|
||||||
|
</h3>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<li class="list-group-item">Street Name: <%= $pending_org->street_name %></li>
|
||||||
|
<li class="list-group-item">Town: <%= $pending_org->town %></li>
|
||||||
|
<li class="list-group-item">Postcode: <%= $pending_org->postcode %></li>
|
||||||
|
<li class="list-group-item"><a href="<%= url_for . '/approve' %>" class="btn btn-success">Approve Organisation</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="card mb-3">
|
||||||
|
<h3 class="card-header">
|
||||||
|
Transactions
|
||||||
|
</h3>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
% for my $transaction ( $pending_org->transactions->all ) {
|
||||||
|
<li class="list-group-item">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row text-center">
|
||||||
|
<div class="col">From: <%= $transaction->buyer->name %></div>
|
||||||
|
<div class="col">To: <%= $transaction->seller->name %></div>
|
||||||
|
<div class="col">Value: <%= $transaction->value %></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
% }
|
||||||
|
</ul>
|
||||||
|
</div>
|
41
templates/admin/organisations/valid_read.html.ep
Normal file
41
templates/admin/organisations/valid_read.html.ep
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
% layout 'admin';
|
||||||
|
% title 'Organisations';
|
||||||
|
% content_for javascript => begin
|
||||||
|
% end
|
||||||
|
% if ( my $error = flash 'error' ) {
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<strong>Error!</strong> <%= $error %>
|
||||||
|
</div>
|
||||||
|
% } elsif ( my $success = flash 'success' ) {
|
||||||
|
<div class="alert alert-success" role="alert">
|
||||||
|
<strong>Success!</strong> <%= $success %>
|
||||||
|
</div>
|
||||||
|
% }
|
||||||
|
<div class="card mb-3">
|
||||||
|
<h3 class="card-header">
|
||||||
|
%= $valid_org->name
|
||||||
|
</h3>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<li class="list-group-item">Street Name: <%= $valid_org->street_name %></li>
|
||||||
|
<li class="list-group-item">Town: <%= $valid_org->town %></li>
|
||||||
|
<li class="list-group-item">Postcode: <%= $valid_org->postcode %></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="card mb-3">
|
||||||
|
<h3 class="card-header">
|
||||||
|
Transactions
|
||||||
|
</h3>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
% for my $transaction ( $valid_org->transactions->all ) {
|
||||||
|
<li class="list-group-item">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row text-center">
|
||||||
|
<div class="col">From: <%= $transaction->buyer->name %></div>
|
||||||
|
<div class="col">To: <%= $transaction->seller->name %></div>
|
||||||
|
<div class="col">Value: <%= $transaction->value %></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
% }
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -31,6 +31,7 @@
|
||||||
<a class="nav-item nav-link" href="<%= url_for '/home' %>">User Section</a>
|
<a class="nav-item nav-link" href="<%= url_for '/home' %>">User Section</a>
|
||||||
<a class="nav-item nav-link<%= title eq 'Tokens' ? ' active' : '' %>" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
<a class="nav-item nav-link<%= title eq 'Tokens' ? ' active' : '' %>" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||||
<a class="nav-item nav-link<%= title eq 'Users' ? ' active' : '' %>" href="<%= url_for '/admin/users' %>">Users</a>
|
<a class="nav-item nav-link<%= title eq 'Users' ? ' active' : '' %>" href="<%= url_for '/admin/users' %>">Users</a>
|
||||||
|
<a class="nav-item nav-link<%= title eq 'Organisations' ? ' active' : '' %>" href="<%= url_for '/admin/organisations' %>">Organisations</a>
|
||||||
<a class="nav-item nav-link" href="<%= url_for '/logout' %>">Logout</a>
|
<a class="nav-item nav-link" href="<%= url_for '/logout' %>">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue