From 2b0abd2606d237875e33ecd7cba473e3ed858dbb Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 14 Jun 2018 16:40:50 +0100 Subject: [PATCH 1/4] added ability to edit icons and gt them in stats --- lib/Pear/LocalLoop/Controller/Admin/Categories.pm | 2 ++ lib/Pear/LocalLoop/Controller/Api/Stats.pm | 4 +++- lib/Pear/LocalLoop/Schema/ResultSet/Category.pm | 14 ++++++++++++++ templates/admin/categories/read.html.ep | 9 +++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Categories.pm b/lib/Pear/LocalLoop/Controller/Admin/Categories.pm index 529239c..cb86d6e 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Categories.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Categories.pm @@ -59,6 +59,7 @@ sub update { my $validation = $c->validation; $validation->required('id'); $validation->required('category', 'trim')->like(qr/^[\w]*$/); + $validation->optional('line_icon'); my $id = $c->param('id'); @@ -70,6 +71,7 @@ sub update { $category->update({ id => $validation->param('id'), name => $validation->param('category'), + line_icon => (defined $validation->param('line_icon') ? $validation->param('line_icon') : undef ), }); $c->flash( success => 'Category Updated' ); $c->redirect_to( '/admin/categories/' . $validation->param('id') ); diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index a467316..0536bb8 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -132,7 +132,9 @@ sub post_customer { $cat_total_list{$category_list->{$category}} += $value; } - my @cat_lists = map { { category => $_, value => $cat_total_list{$_} } } sort keys %cat_total_list; + my @cat_lists = map { { category => $_, value => $cat_total_list{$_}, + icon => $c->schema->resultset('Category')->as_hash_name_icon->{$_} } } sort keys %cat_total_list; + Dwarn @cat_lists; $data->{cat_list} = [ sort { $b->{value} <=> $a->{value} } @cat_lists ]; my $purchase_no_essential_rs = $purchase_rs->search({ diff --git a/lib/Pear/LocalLoop/Schema/ResultSet/Category.pm b/lib/Pear/LocalLoop/Schema/ResultSet/Category.pm index 59f9b98..7f05faa 100644 --- a/lib/Pear/LocalLoop/Schema/ResultSet/Category.pm +++ b/lib/Pear/LocalLoop/Schema/ResultSet/Category.pm @@ -19,4 +19,18 @@ sub as_hash { return \%category_list; } +sub as_hash_name_icon { + my ( $self ) = @_; + + my %category_list = ( + ( + map { + $_->name => $_->line_icon, + } $self->all + ), + 0 => 'Uncategorised', + ); + return \%category_list; +} + 1; diff --git a/templates/admin/categories/read.html.ep b/templates/admin/categories/read.html.ep index 5e32820..219fec4 100644 --- a/templates/admin/categories/read.html.ep +++ b/templates/admin/categories/read.html.ep @@ -13,14 +13,19 @@ % }
- +
- +

Do not change the ID unless absolutely necessary.

+
+ + +

See here for all possible options http://simplelineicons.com/.

+
From 8d4c9703a073699d4155cc36fb2ee0083f8379ac Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 14 Jun 2018 16:47:36 +0100 Subject: [PATCH 2/4] got rid of Dwarn --- lib/Pear/LocalLoop/Controller/Api/Stats.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index 0536bb8..2f698cc 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -134,7 +134,6 @@ sub post_customer { my @cat_lists = map { { category => $_, value => $cat_total_list{$_}, icon => $c->schema->resultset('Category')->as_hash_name_icon->{$_} } } sort keys %cat_total_list; - Dwarn @cat_lists; $data->{cat_list} = [ sort { $b->{value} <=> $a->{value} } @cat_lists ]; my $purchase_no_essential_rs = $purchase_rs->search({ From adb19e84f78fd78e5b4feeb5799f661d65cec9ff Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Jun 2018 12:10:08 +0100 Subject: [PATCH 3/4] added default --- lib/Pear/LocalLoop/Controller/Api/Stats.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Stats.pm b/lib/Pear/LocalLoop/Controller/Api/Stats.pm index 2f698cc..db46fd0 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Stats.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Stats.pm @@ -133,7 +133,7 @@ sub post_customer { } my @cat_lists = map { { category => $_, value => $cat_total_list{$_}, - icon => $c->schema->resultset('Category')->as_hash_name_icon->{$_} } } sort keys %cat_total_list; + icon => $c->schema->resultset('Category')->as_hash_name_icon->{$_} || 'question'} } sort keys %cat_total_list; $data->{cat_list} = [ sort { $b->{value} <=> $a->{value} } @cat_lists ]; my $purchase_no_essential_rs = $purchase_rs->search({ From aabfc6505b241cc81400a866232ad76dcedf8d37 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 18 Jun 2018 12:14:34 +0100 Subject: [PATCH 4/4] amended stats --- t/api/stats.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/api/stats.t b/t/api/stats.t index 0c35519..8ecf259 100644 --- a/t/api/stats.t +++ b/t/api/stats.t @@ -86,6 +86,7 @@ $t->post_ok('/api/stats/customer' => json => { }, cat_list => [{ category => "Uncategorised", + icon => 'question', value => 1180, }], essentials => {