From 423c68aca26eae3ed2ab69a0fec62cf3b9363c95 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 14 Nov 2017 18:41:54 +0000 Subject: [PATCH] Allow for ignoring of values in import and toggle showing of them --- lib/Pear/LocalLoop.pm | 3 +- lib/Pear/LocalLoop/Controller/Admin/Import.pm | 36 ++++++++++++++----- .../LocalLoop/Schema/ResultSet/ImportSet.pm | 9 +++-- templates/admin/import/list.html.ep | 10 +++++- templates/layouts/admin_errors.html.ep | 8 ++--- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index b8d768b..7038f70 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -208,8 +208,7 @@ sub startup { $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/:value_id')->to('admin-import#get_value'); - $admin_routes->post('/import/:set_id/:value_id')->to('admin-import#post_value'); + $admin_routes->get('/import/:set_id/ignore/:value_id')->to('admin-import#ignore_value'); # my $user_routes = $r->under('/')->to('root#under'); # $user_routes->get('/home')->to('root#home'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Import.pm b/lib/Pear/LocalLoop/Controller/Admin/Import.pm index 9d840a1..8f40971 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Import.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Import.pm @@ -27,10 +27,12 @@ sub list { my $c = shift; my $set_id = $c->param('set_id'); + my $include_ignored = $c->param('ignored'); + my $import_set = $c->result_set->find($set_id); - 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_value_rs = $c->result_set->get_values($set_id, $include_ignored); + my $import_users_rs = $c->result_set->get_users($set_id, $include_ignored); + my $import_org_rs = $c->result_set->get_orgs($set_id, $include_ignored); my $import_lookup_rs = $c->result_set->get_lookups($set_id); $c->stash( @@ -240,14 +242,32 @@ sub get_org { ); } -sub get_value { +sub ignore_value { my $c = shift; my $set_id = $c->param('set_id'); -} + my $value_id = $c->param('value_id'); -sub post_value { - my $c = shift; - my $set_id = $c->param('set_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' ); + } + + my $value_result = $set_result->values->find($value_id); + unless ( defined $value_result ) { + $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; diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/ImportSet.pm b/lib/Pear/LocalLoop/Schema/ResultSet/ImportSet.pm index b8bd24e..9efad48 100644 --- a/lib/Pear/LocalLoop/Schema/ResultSet/ImportSet.pm +++ b/lib/Pear/LocalLoop/Schema/ResultSet/ImportSet.pm @@ -8,10 +8,11 @@ use base 'DBIx::Class::ResultSet'; sub get_values { my $self = shift; my $id = shift; + my $include_ignored = shift; return $self->find($id)->search_related( 'values', - undef, + ( $include_ignored ? {} : { ignore_value => 0 } ), { order_by => { '-asc' => 'id' }, }, @@ -21,8 +22,9 @@ sub get_values { sub get_users { my $self = 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', }, @@ -32,8 +34,9 @@ sub get_users { sub get_orgs { my $self = 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', }, diff --git a/templates/admin/import/list.html.ep b/templates/admin/import/list.html.ep index e7b8bac..b1c8045 100644 --- a/templates/admin/import/list.html.ep +++ b/templates/admin/import/list.html.ep @@ -78,6 +78,10 @@

%= format_human_datetime $import_set->date; + + Toggle show Ignored +

Content listed in original order of import @@ -99,7 +103,11 @@ <%= $import_value->org_name %>
- Ignore + % if ( $import_value->ignore_value ) { + Un Ignore + % } else { + Ignore + % }
diff --git a/templates/layouts/admin_errors.html.ep b/templates/layouts/admin_errors.html.ep index 930bdf3..808a5b9 100644 --- a/templates/layouts/admin_errors.html.ep +++ b/templates/layouts/admin_errors.html.ep @@ -60,13 +60,13 @@
- % if ( my $error = flash 'error' ) { + % if ( my $f_error = flash 'error' ) { - % } elsif ( my $error = stash 'error' ) { + % } elsif ( my $s_error = stash 'error' ) { % } elsif ( my $success = flash 'success' ) {