From 626ba6a542b055c8a2b64da1cb9db9ea27db083f Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 14 Jun 2018 16:40:50 +0100 Subject: [PATCH] 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/.

+