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;
$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') );

View file

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

View file

@ -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;

View file

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

View file

@ -13,14 +13,19 @@
% }
<form action="<%= url_for %>" method="post">
<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 %>">
</div>
<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 %>">
<p class="help-block">Do not change the ID unless <strong>absolutely</strong> necessary.</p>
</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">
<button class="btn btn-primary form-control" type="submit">Update</button>
</div>