From ca357ccc90cae26032e7ea0c58324a4ac158e863 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 1 Jul 2018 02:32:48 +0300 Subject: [PATCH] #9 Simple sortable table headers implemented. --- templates/sortable_table_macro.html.twig | 33 ++++++++++++++++++++++++ templates/torrent_list.html.twig | 13 ++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 templates/sortable_table_macro.html.twig diff --git a/templates/sortable_table_macro.html.twig b/templates/sortable_table_macro.html.twig new file mode 100644 index 0000000..eb4ff21 --- /dev/null +++ b/templates/sortable_table_macro.html.twig @@ -0,0 +1,33 @@ +{# + Sortable table headers ('' blocks) + + If you're using this macro then you must comply with convention and use following query parameters: + - query - search query + - page - current page for pager + - order-by - which column is currently used for orderring + - order - order direction ('asc' or 'desc') + + 'columns' argument must be an associative array like: + 'Human readable column name' => 'propertyName' +#} +{% macro sortable_columns(columns) %} + {% set route = app.request.attributes.get('_route') %} + {% set query = app.request.query.get('query') %} + {% set page = app.request.query.get('page') %} + {% set orderBy = app.request.query.get('order-by') %} + {% set order = app.request.query.get('order') %} + {% for column, property in columns %} + + {% if property is not null %} + {{ column | raw }} + {% else %} + {{ column | raw }} + {% endif %} + + {% endfor %} +{% endmacro %} \ No newline at end of file diff --git a/templates/torrent_list.html.twig b/templates/torrent_list.html.twig index 5133f93..5821794 100644 --- a/templates/torrent_list.html.twig +++ b/templates/torrent_list.html.twig @@ -1,16 +1,19 @@ {% block content %} + {% import 'sortable_table_macro.html.twig' as sortable %} - + - - - - + {{ sortable.sortable_columns({ + '': null, + 'Name': 'name', + 'Size': 'totalSize', + 'Discovered': 'discoveredOn' + }) }} {# @var torrent \App\Magnetico\Entity\Torrent #}
🔗NameSizeDiscovered