Merge pull request #124 from Pear-Trading/finn/icons

Added icons to category list
This commit is contained in:
Finn 2018-06-18 12:29:34 +01:00 committed by GitHub
commit e974325d98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 3 deletions

View file

@ -59,6 +59,7 @@ sub update {
my $validation = $c->validation; my $validation = $c->validation;
$validation->required('id'); $validation->required('id');
$validation->required('category', 'trim')->like(qr/^[\w]*$/); $validation->required('category', 'trim')->like(qr/^[\w]*$/);
$validation->optional('line_icon');
my $id = $c->param('id'); my $id = $c->param('id');
@ -70,6 +71,7 @@ sub update {
$category->update({ $category->update({
id => $validation->param('id'), id => $validation->param('id'),
name => $validation->param('category'), name => $validation->param('category'),
line_icon => (defined $validation->param('line_icon') ? $validation->param('line_icon') : undef ),
}); });
$c->flash( success => 'Category Updated' ); $c->flash( success => 'Category Updated' );
$c->redirect_to( '/admin/categories/' . $validation->param('id') ); $c->redirect_to( '/admin/categories/' . $validation->param('id') );

View file

@ -132,7 +132,8 @@ sub post_customer {
$cat_total_list{$category_list->{$category}} += $value; $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->{$_} || 'question'} } sort keys %cat_total_list;
$data->{cat_list} = [ sort { $b->{value} <=> $a->{value} } @cat_lists ]; $data->{cat_list} = [ sort { $b->{value} <=> $a->{value} } @cat_lists ];
my $purchase_no_essential_rs = $purchase_rs->search({ my $purchase_no_essential_rs = $purchase_rs->search({

View file

@ -19,4 +19,18 @@ sub as_hash {
return \%category_list; 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; 1;

View file

@ -86,6 +86,7 @@ $t->post_ok('/api/stats/customer' => json => {
}, },
cat_list => [{ cat_list => [{
category => "Uncategorised", category => "Uncategorised",
icon => 'question',
value => 1180, value => 1180,
}], }],
essentials => { essentials => {

View file

@ -13,14 +13,19 @@
% } % }
<form action="<%= url_for %>" method="post"> <form action="<%= url_for %>" method="post">
<div class="form-group"> <div class="form-group">
<label for="category-name">Token Name</label> <label for="category-name">Category Name</label>
<input id="category-name" type="text" class="form-control" placeholder="Token Text" name="category" value="<%= $category->name %>"> <input id="category-name" type="text" class="form-control" placeholder="Token Text" name="category" value="<%= $category->name %>">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="category-id">Token ID</label> <label for="category-id">Category ID</label>
<input id="category-id" type="text" class="form-control" placeholder="Token ID" name="id" value="<%= $category->id %>"> <input id="category-id" type="text" class="form-control" placeholder="Token ID" name="id" value="<%= $category->id %>">
<p class="help-block">Do not change the ID unless <strong>absolutely</strong> necessary.</p> <p class="help-block">Do not change the ID unless <strong>absolutely</strong> necessary.</p>
</div> </div>
<div class="form-group">
<label for="line-icon">Simple Line Icon</label>
<input id="line-icon" type="text" class="form-control" placeholder="Icon text" name="line_icon" value="<%= $category->line_icon %>">
<p class="help-block">See here for all possible options http://simplelineicons.com/.</p>
</div>
<div class="form-group"> <div class="form-group">
<button class="btn btn-primary form-control" type="submit">Update</button> <button class="btn btn-primary form-control" type="submit">Update</button>
</div> </div>