Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Add more info to the items list
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-schwartz committed Sep 29, 2018
1 parent e2b04fa commit e114f3e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
32 changes: 29 additions & 3 deletions templates/inventory/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,59 @@

{% block title %}
{% if breadcrumb %}
<a href="{{ path('inventory_list') }}">Items</a> > {{ breadcrumb }}
{# TODO: Link "items" while stripping tags for base title block #}
{# <a href="{{ path('inventory_list') }}">Items</a> > {{ breadcrumb }} #}
Items > {{ breadcrumb }}
{% else %}
Items
{% endif %}
{% endblock %}

{% block body %}
{% import 'macros.html.twig' as macros %}

<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col"></th>
<th scope="col" class="text-right d-none d-md-table-cell">Location</th>
<th scope="col" class="text-right" style="width:4rem">Qty</th>
<th scope="col" class="text-right" style="width:10rem">Est. Value</th>
</tr>
</thead>
<tbody>
{% set total_quantity = 0 %}
{% set total_value = 0.0 %}

{% for item in items %}
<tr>
<td><a href="{{ path('inventory_get', {'id': item.id}) }}">{{ item.name }}</a></td>
<td>
<a href="{{ path('inventory_get', {'id': item.id}) }}">{{ item.name }}</a>
</td>
<td class="text-right d-none d-md-table-cell">
{{ macros.tags('locations', item.locations) }}
</td>
<td class="text-right">{{ item.quantity }}</td>
<td class="text-right">{{ item.totalValue|localizedcurrency('USD') }}
</tr>
{% set total_quantity = total_quantity + item.quantity %}
{% set total_value = total_value + item.totalValue %}
{% else %}
<tr>
<td colspan="3">No items. Would you like to <a href="{{ path('inventory_add') }}">add one</a>?</td>
<td colspan="4">No items. Would you like to <a href="{{ path('inventory_add') }}">add one</a>?</td>
</tr>
{% endfor %}

{% if total_quantity or total_value %}
<tfoot>
<tr>
<th scope="col"></th>
<th scope="col" class="d-none d-md-table-cell"></th>
<th scope="col" class="text-right">{{ total_quantity }}</th>
<th scope="col" class="text-right">{{ total_value|localizedcurrency('USD') }}
</tr>
</tfoot>
{% endif %}
</tbody>
</table>

Expand Down
7 changes: 2 additions & 5 deletions templates/inventory/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@

{% macro tagrow(header, category, tags) %}
{% if tags %}
{% import 'macros.html.twig' as macros %}
<tr>
<th scope="row">{{ header }}</th>
<td>
{% for tag in tags %}
<a class="btn btn-info" href="{{ path('inventory_list_by_tag', {'category': category, 'tag': tag}) }}">{{ tag }}</a>
{% endfor %}
</td>
<td>{{ macros.tags(category, tags) }}</td>
</tr>
{% endif %}
{% endmacro %}
Expand Down
15 changes: 15 additions & 0 deletions templates/macros.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{# Single tag button #}
{% macro tag(category, tag) %}
<a class="btn btn-info"
href="{{ path('inventory_list_by_tag', {'category': category, 'tag': tag}) }}">
{{ tag }}
</a>
{% endmacro %}

{# Set of tag buttons #}
{% macro tags(category, tags) %}
{% import _self as macros %}
{% for tag in tags %}
{{ macros.tag(category, tag) }}
{% endfor %}
{% endmacro %}

0 comments on commit e114f3e

Please sign in to comment.