Added assigning users to import values
This commit is contained in:
parent
9096bef00d
commit
72929bf86b
8 changed files with 233 additions and 6 deletions
|
@ -204,6 +204,10 @@ sub startup {
|
|||
$admin_routes->get('/import/add')->to('admin-import#get_add');
|
||||
$admin_routes->post('/import/add')->to('admin-import#post_add');
|
||||
$admin_routes->get('/import/:set_id')->to('admin-import#list');
|
||||
$admin_routes->get('/import/:set_id/user')->to('admin-import#get_user');
|
||||
$admin_routes->get('/import/:set_id/org')->to('admin-import#get_org');
|
||||
$admin_routes->post('/import/:set_id/org')->to('admin-import#set_org');
|
||||
|
||||
$admin_routes->get('/import/:set_id/:value_id')->to('admin-import#get_value');
|
||||
$admin_routes->post('/import/:set_id/:value_id')->to('admin-import#post_value');
|
||||
# my $user_routes = $r->under('/')->to('root#under');
|
||||
|
|
|
@ -31,12 +31,14 @@ sub list {
|
|||
my $import_value_rs = $c->result_set->get_values($set_id);
|
||||
my $import_users_rs = $c->result_set->get_users($set_id);
|
||||
my $import_org_rs = $c->result_set->get_orgs($set_id);
|
||||
my $import_lookup_rs = $c->result_set->get_lookups($set_id);
|
||||
|
||||
$c->stash(
|
||||
import_set => $import_set,
|
||||
import_value_rs => $import_value_rs,
|
||||
import_users_rs => $import_users_rs,
|
||||
import_org_rs => $import_org_rs,
|
||||
import_lookup_rs => $import_lookup_rs,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -90,7 +92,6 @@ sub post_add {
|
|||
}
|
||||
|
||||
for my $data ( @$csv_output ) {
|
||||
Dwarn $data;
|
||||
for my $key ( qw/ user value organisation / ) {
|
||||
unless ( defined $data->{$key} ) {
|
||||
$c->flash( error => "Undefined [$key] data found", csv_data => $csv_data, date_format => $date_format );
|
||||
|
@ -134,6 +135,63 @@ sub post_add {
|
|||
$c->redirect_to( '/admin/import/' . $value_set->id );
|
||||
}
|
||||
|
||||
sub get_user {
|
||||
my $c = shift;
|
||||
my $set_id = $c->param('set_id');
|
||||
my $user_name = $c->param('user');
|
||||
|
||||
my $values_rs = $c->result_set->find($set_id)->values->search(
|
||||
{
|
||||
user_name => $user_name,
|
||||
ignore_value => 0,
|
||||
}
|
||||
);
|
||||
|
||||
unless ( $values_rs->count > 0 ) {
|
||||
$c->flash( error => 'User not found or all values are ignored' );
|
||||
return $c->redirect_to( '/admin/import/' . $set_id );
|
||||
}
|
||||
|
||||
my $lookup_result = $c->result_set->find($set_id)->lookups->find(
|
||||
{ name => $user_name },
|
||||
);
|
||||
|
||||
my $entity_id = $c->param('entity');
|
||||
|
||||
my $users_rs = $c->schema->resultset('User');
|
||||
|
||||
if ( defined $entity_id && $users_rs->find({ entity_id => $entity_id }) ) {
|
||||
if ( defined $lookup_result ) {
|
||||
$lookup_result->update({ entity_id => $entity_id });
|
||||
} else {
|
||||
$lookup_result = $c->result_set->find($set_id)->lookups->create(
|
||||
{
|
||||
name => $user_name,
|
||||
entity_id => $entity_id,
|
||||
},
|
||||
);
|
||||
}
|
||||
} elsif ( defined $entity_id ) {
|
||||
$c->stash( error => "User does not exist" );
|
||||
}
|
||||
|
||||
$c->stash(
|
||||
users_rs => $users_rs,
|
||||
lookup => $lookup_result,
|
||||
user_name => $user_name,
|
||||
);
|
||||
}
|
||||
|
||||
sub get_org {
|
||||
my $c = shift;
|
||||
|
||||
}
|
||||
|
||||
sub set_org {
|
||||
my $c = shift;
|
||||
|
||||
}
|
||||
|
||||
sub get_value {
|
||||
my $c = shift;
|
||||
my $set_id = $c->param('set_id');
|
||||
|
|
|
@ -128,6 +128,18 @@ sub name {
|
|||
}
|
||||
}
|
||||
|
||||
sub full_name {
|
||||
my $self = shift;
|
||||
|
||||
if ( defined $self->entity->customer ) {
|
||||
return $self->entity->customer->full_name;
|
||||
} elsif ( defined $self->entity->organisation ) {
|
||||
return $self->entity->organisation->name;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# TODO Deprecate this sub?
|
||||
sub type {
|
||||
my $self = shift;
|
||||
|
|
|
@ -13,7 +13,7 @@ sub get_values {
|
|||
'values',
|
||||
undef,
|
||||
{
|
||||
order_by => { -asc => 'id' },
|
||||
order_by => { '-asc' => 'id' },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -40,4 +40,17 @@ sub get_orgs {
|
|||
);
|
||||
}
|
||||
|
||||
sub get_lookups {
|
||||
my $self = shift;
|
||||
my $id = shift;
|
||||
|
||||
return $self->find($id)->search_related(
|
||||
'lookups',
|
||||
undef,
|
||||
{
|
||||
order_by => { '-asc' => 'id' },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
48
templates/admin/import/get_user.html.ep
Normal file
48
templates/admin/import/get_user.html.ep
Normal file
|
@ -0,0 +1,48 @@
|
|||
% layout 'admin_errors';
|
||||
% title 'Import';
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<h3><%= $user_name %></h3>
|
||||
</div>
|
||||
<div class="col-4 mb-3">
|
||||
<a href="<%= url_for '/admin/import/' . $c->param('set_id') %>"
|
||||
class="btn btn-success">
|
||||
Return to Import
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<h4 class="card-header">
|
||||
Users
|
||||
</h4>
|
||||
<div class="card-body text-muted">
|
||||
Choose a user to assign to this name
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
% for my $user ( $users_rs->all ) {
|
||||
<a href="<%= url_with->query([ entity => $user->entity_id ]) %>"
|
||||
class="list-group-item list-group-item-action<%= defined $lookup && $lookup->entity_id == $user->entity_id ? ' list-group-item-success' : '' %>">
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
%= $user->email
|
||||
</div>
|
||||
<div class="col-4">
|
||||
%= $user->full_name
|
||||
</div>
|
||||
<div class="col-4">
|
||||
% if ( $user->type eq 'customer' ) {
|
||||
<span class="badge badge-success">Customer</span>
|
||||
% } elsif ( $user->type eq 'organisation' ) {
|
||||
<span class="badge badge-warning">Organisation</span>
|
||||
% } else {
|
||||
<span class="badge badge-danger">Unknown User Type</span>
|
||||
% }
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
% }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -28,10 +28,14 @@
|
|||
%= $user->user_name
|
||||
</div>
|
||||
<div class="col-4">
|
||||
% if ( my $lookup = $import_lookup_rs->find({ name => $user->user_name }) ) {
|
||||
<span class="text-muted"><%= $lookup->entity->name %></span>
|
||||
% } else {
|
||||
<span class="text-muted font-italic">Unassigned</span>
|
||||
% }
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<a class="btn btn-primary">Select</a>
|
||||
<a href="<%= url_for(url_for . '/user')->query([ user => $user->user_name ]) %>" class="btn btn-primary">Select</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
89
templates/layouts/admin_errors.html.ep
Normal file
89
templates/layouts/admin_errors.html.ep
Normal file
|
@ -0,0 +1,89 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LocalLoop Admin - <%= title %></title>
|
||||
|
||||
<!-- Bootstrap and jQuery js -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
||||
|
||||
|
||||
%= stylesheet '/static/admin/css/main.css';
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md fixed-top navbar-dark bg-danger">
|
||||
<a class="navbar-brand" href="<%= url_for '/admin/home' %>">LocalLoop Admin</a>
|
||||
<button class="navbar-toggler navbar-toggler-right"
|
||||
type="button"
|
||||
data-toggle="collapse"
|
||||
data-target="#navbarNav"
|
||||
aria-controls="navbarNav"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
Reports
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="<%= url_for '/admin/reports/transactions' %>">Transactions (Hourly)</a>
|
||||
<a class="dropdown-item" href="<%= url_for('/admin/reports/transactions')->query(scale =>'days') %>">Transactions (Daily)</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Feedback' ? ' active' : '' %>" href="<%= url_for '/admin/feedback' %>">Feedback</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Tokens' ? ' active' : '' %>" href="<%= url_for '/admin/tokens' %>">Tokens</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Transactions' ? ' active' : '' %>" href="<%= url_for '/admin/transactions' %>">Transactions</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Users' ? ' active' : '' %>" href="<%= url_for '/admin/users' %>">Users</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Organisations' ? ' active' : '' %>" href="<%= url_for '/admin/organisations' %>">Organisations</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link<%= title eq 'Import' ? ' active' : '' %>" href="<%= url_for '/admin/import' %>">Import</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="<%= url_for '/admin/logout' %>">Logout</a>
|
||||
</li>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container">
|
||||
% if ( my $error = flash 'error' ) {
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> <%= $error %>
|
||||
</div>
|
||||
% } elsif ( my $error = stash '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>
|
||||
% }
|
||||
<%= content %>
|
||||
</div>
|
||||
<div class="navbar bg-dark fixed-bottom">
|
||||
<span class="navbar-text ml-auto text-muted">
|
||||
Version: <%= $c->config->{version} %>
|
||||
</span>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.min.js" integrity="sha256-jpW4gXAhFvqGDD5B7366rIPD7PDbAmqq4CO0ZnHbdM4=" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
|
||||
|
||||
%= content_for 'javascript';
|
||||
</body>
|
||||
</html>
|
|
@ -25,11 +25,10 @@
|
|||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<a class="navbar-brand" href="<%= url_for '/home' %>">LocalLoop</a>
|
||||
<a class="navbar-brand" href="<%= url_for '/admin' %>">LocalLoop - Admin</a>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<div class="navbar-nav ml-auto">
|
||||
<a class="nav-item nav-link<%= title eq 'Login' ? ' active' : '' %>" href="<%= url_for '/' %>">Login</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Register' ? ' active' : '' %>" href="<%= url_for '/register' %>">Register</a>
|
||||
<a class="nav-item nav-link<%= title eq 'Login' ? ' active' : '' %>" href="<%= url_for '/admin' %>">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
Reference in a new issue