Added org lookup and assignment for import
This commit is contained in:
parent
37bc29829f
commit
7df6fecfc4
4 changed files with 81 additions and 7 deletions
|
@ -207,7 +207,6 @@ sub startup {
|
||||||
$admin_routes->get('/import/:set_id')->to('admin-import#list');
|
$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/user')->to('admin-import#get_user');
|
||||||
$admin_routes->get('/import/:set_id/org')->to('admin-import#get_org');
|
$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->get('/import/:set_id/:value_id')->to('admin-import#get_value');
|
||||||
$admin_routes->post('/import/:set_id/:value_id')->to('admin-import#post_value');
|
$admin_routes->post('/import/:set_id/:value_id')->to('admin-import#post_value');
|
||||||
|
|
|
@ -193,16 +193,51 @@ sub get_user {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub get_org {
|
sub get_org {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
my $set_id = $c->param('set_id');
|
||||||
|
my $org_name = $c->param('org');
|
||||||
|
|
||||||
}
|
my $values_rs = $c->result_set->find($set_id)->values->search(
|
||||||
|
{
|
||||||
|
org_name => $org_name,
|
||||||
|
ignore_value => 0,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
sub set_org {
|
unless ( $values_rs->count > 0 ) {
|
||||||
my $c = shift;
|
$c->flash( error => 'Organisation 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 => $org_name },
|
||||||
|
);
|
||||||
|
|
||||||
|
my $entity_id = $c->param('entity');
|
||||||
|
|
||||||
|
my $orgs_rs = $c->schema->resultset('Organisation');
|
||||||
|
|
||||||
|
if ( defined $entity_id && $orgs_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 => $org_name,
|
||||||
|
entity_id => $entity_id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elsif ( defined $entity_id ) {
|
||||||
|
$c->stash( error => "Organisation does not exist" );
|
||||||
|
}
|
||||||
|
|
||||||
|
$c->stash(
|
||||||
|
orgs_rs => $orgs_rs,
|
||||||
|
lookup => $lookup_result,
|
||||||
|
org_name => $org_name,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_value {
|
sub get_value {
|
||||||
|
|
36
templates/admin/import/get_org.html.ep
Normal file
36
templates/admin/import/get_org.html.ep
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
% layout 'admin_errors';
|
||||||
|
% title 'Import';
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8">
|
||||||
|
<h3><%= $org_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">
|
||||||
|
Organisations
|
||||||
|
</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 $org ( $orgs_rs->all ) {
|
||||||
|
<a href="<%= url_with->query([ entity => $org->entity_id ]) %>"
|
||||||
|
class="list-group-item list-group-item-action<%= defined $lookup && $lookup->entity_id == $org->entity_id ? ' list-group-item-success' : '' %>">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
%= $org->name
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
% }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -59,10 +59,14 @@
|
||||||
%= $org->org_name
|
%= $org->org_name
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
|
% if ( my $lookup = $import_lookup_rs->find({ name => $org->org_name }) ) {
|
||||||
|
<span class="text-muted"><%= $lookup->entity->name %></span>
|
||||||
|
% } else {
|
||||||
<span class="text-muted font-italic">Unassigned</span>
|
<span class="text-muted font-italic">Unassigned</span>
|
||||||
|
% }
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<a class="btn btn-primary">Select</a>
|
<a href="<%= url_for(url_for . '/org')->query([ org => $org->org_name ]) %>" class="btn btn-primary">Select</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue