Allow for ignoring of values in import and toggle showing of them

This commit is contained in:
Tom Bloor 2017-11-14 18:41:54 +00:00
parent 9d07830e27
commit 423c68aca2
5 changed files with 48 additions and 18 deletions

View file

@ -208,8 +208,7 @@ sub startup {
$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->get('/import/:set_id/:value_id')->to('admin-import#get_value'); $admin_routes->get('/import/:set_id/ignore/:value_id')->to('admin-import#ignore_value');
$admin_routes->post('/import/:set_id/:value_id')->to('admin-import#post_value');
# 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');

View file

@ -27,10 +27,12 @@ sub list {
my $c = shift; my $c = shift;
my $set_id = $c->param('set_id'); my $set_id = $c->param('set_id');
my $include_ignored = $c->param('ignored');
my $import_set = $c->result_set->find($set_id); my $import_set = $c->result_set->find($set_id);
my $import_value_rs = $c->result_set->get_values($set_id); my $import_value_rs = $c->result_set->get_values($set_id, $include_ignored);
my $import_users_rs = $c->result_set->get_users($set_id); my $import_users_rs = $c->result_set->get_users($set_id, $include_ignored);
my $import_org_rs = $c->result_set->get_orgs($set_id); my $import_org_rs = $c->result_set->get_orgs($set_id, $include_ignored);
my $import_lookup_rs = $c->result_set->get_lookups($set_id); my $import_lookup_rs = $c->result_set->get_lookups($set_id);
$c->stash( $c->stash(
@ -240,14 +242,32 @@ sub get_org {
); );
} }
sub get_value { sub ignore_value {
my $c = shift; my $c = shift;
my $set_id = $c->param('set_id'); my $set_id = $c->param('set_id');
my $value_id = $c->param('value_id');
my $set_result = $c->result_set->find($set_id);
unless ( defined $set_result ) {
$c->flash( error => "Set does not exist" );
return $c->redirect_to( '/admin/import' );
} }
sub post_value { my $value_result = $set_result->values->find($value_id);
my $c = shift; unless ( defined $value_result ) {
my $set_id = $c->param('set_id'); $c->flash( error => "Value does not exist" );
return $c->redirect_to( '/admin/import/' . $set_id );
}
$value_result->update({ ignore_value => $value_result->ignore_value ? 0 : 1 });
$c->flash( success => "Updated value" );
my $referer = $c->req->headers->header('Referer');
return $c->redirect_to(
defined $referer
? $c->url_for($referer)->path_query
: '/admin/import/' . $set_id
);
} }
1; 1;

View file

@ -8,10 +8,11 @@ use base 'DBIx::Class::ResultSet';
sub get_values { sub get_values {
my $self = shift; my $self = shift;
my $id = shift; my $id = shift;
my $include_ignored = shift;
return $self->find($id)->search_related( return $self->find($id)->search_related(
'values', 'values',
undef, ( $include_ignored ? {} : { ignore_value => 0 } ),
{ {
order_by => { '-asc' => 'id' }, order_by => { '-asc' => 'id' },
}, },
@ -21,8 +22,9 @@ sub get_values {
sub get_users { sub get_users {
my $self = shift; my $self = shift;
my $id = shift; my $id = shift;
my $include_ignored = shift;
return $self->get_values($id)->search({}, return $self->get_values($id, $include_ignored)->search({},
{ {
group_by => 'user_name', group_by => 'user_name',
}, },
@ -32,8 +34,9 @@ sub get_users {
sub get_orgs { sub get_orgs {
my $self = shift; my $self = shift;
my $id = shift; my $id = shift;
my $include_ignored = shift;
return $self->get_values($id)->search({}, return $self->get_values($id, $include_ignored)->search({},
{ {
group_by => 'org_name', group_by => 'org_name',
}, },

View file

@ -78,6 +78,10 @@
<div class="card"> <div class="card">
<h3 class="card-header"> <h3 class="card-header">
%= format_human_datetime $import_set->date; %= format_human_datetime $import_set->date;
<a href="<%= url_for->query({ignored => $c->param('ignored') ? 0 : 1 }) %>"
class="btn btn-primary float-right">
Toggle show Ignored
</a>
</h3> </h3>
<div class="card-body"> <div class="card-body">
Content listed in original order of import Content listed in original order of import
@ -99,7 +103,11 @@
<%= $import_value->org_name %> <%= $import_value->org_name %>
</div> </div>
<div class="col-2"> <div class="col-2">
<a href="#" class="btn btn-danger">Ignore</a> % if ( $import_value->ignore_value ) {
<a href="<%= url_for . '/ignore/' . $import_value->id %>" class="btn btn-success">Un Ignore</a>
% } else {
<a href="<%= url_for . '/ignore/' . $import_value->id %>" class="btn btn-danger">Ignore</a>
% }
</div> </div>
</div> </div>
</div> </div>

View file

@ -60,13 +60,13 @@
</div> </div>
</nav> </nav>
<div class="container"> <div class="container">
% if ( my $error = flash 'error' ) { % if ( my $f_error = flash 'error' ) {
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
<strong>Error!</strong> <%= $error %> <strong>Error!</strong> <%= $f_error %>
</div> </div>
% } elsif ( my $error = stash 'error' ) { % } elsif ( my $s_error = stash 'error' ) {
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
<strong>Error!</strong> <%= $error %> <strong>Error!</strong> <%= $s_error %>
</div> </div>
% } elsif ( my $success = flash 'success' ) { % } elsif ( my $success = flash 'success' ) {
<div class="alert alert-success" role="alert"> <div class="alert alert-success" role="alert">