Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for filtering on 'taxonomies' on the overview pages. #3278

Merged
merged 1 commit into from
Mar 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions app/view/twig/overview/_panel-actions_overview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,44 @@
<i class="fa fa-plus"></i> {{ __('contenttypes.generic.new', {'%contenttype%': context.contenttype.slug}) }}
</a>

<form class="form-inline" style="margin-top:15px;">
<input type="text" class="form-control" value="{{ request('filter', '', true) }}" name="filter" style="width: 110px;" placeholder="{{ __('Filtering …') }}">
<button type="submit" class="btn btn-tertiary">{{ __('Filter') }}</button>
<p style="margin-top: 15px;"><strong>{{ __("Filter") }}</strong></p>

<form class="form-inline">

{% set taxonomyfilter = false %}

<div class="form-group">
{% for taxonomy in context.contenttype.taxonomy %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing to this passes acceptance tests:

{% for taxonomy in context.contenttype.taxonomy|default([]) %}

{% if app.config.get('taxonomy/' ~ taxonomy ~ '/options') is iterable %}
{% if request('taxonomy-' ~ taxonomy ) %}
{% set taxonomyfilter = true %}
{% endif %}
<select name='taxonomy-{{taxonomy}}' class='form-control'>
<option value=''>
({{ app.config.get('taxonomy/' ~ taxonomy ~ '/name')|default(taxonomy) }})
</option>
{% for slug, name in app.config.get('taxonomy/' ~ taxonomy ~ '/options') %}
<option value='{{slug}}' {% if request('taxonomy-' ~ taxonomy ) == slug %}selected{% endif %}>
{{name}}
</option>
{% endfor %}
</select>
{{ __("or") }}
{% endif %}
{% endfor %}
<input type="text" class="form-control" value="{{ request('filter', '', true) }}" name="filter" style="width: 110px;" placeholder="{{ __('Keyword …') }}">
</div>

<div class="form-group" style="display: block; margin-top: 12px;">
<button type="submit" class="btn btn-tertiary"><i class="fa fa-filter"></i> {{ __('Filter') }}</button>

{% if request('filter') or request('order') or taxonomyfilter %}
<a class="btn btn-tertiary" href="?"><i class="fa fa-close"></i> {{ __('Clear sort/filter') }}</a>
{% endif %}
</div>

</form>

{% if request('filter') or request('order') %}
<a class="btn btn-tertiary" href="?" style="margin-top: 15px">{{ __('Clear sort/filter') }}</a>
{% endif %}

{% set description = __(['contenttypes', context.contenttype.slug, 'description'], {DEFAULT: context.contenttype.description|default()}) %}
<div class="description">
Expand Down
7 changes: 6 additions & 1 deletion app/view/twig/overview/overview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

{% block page_title __('Overview') %}

{% block page_subtitle __(['contenttypes', context.contenttype.slug, 'name', 'plural'], {DEFAULT: context.contenttype.name}) %}
{% block page_subtitle %}
{{ __(['contenttypes', context.contenttype.slug, 'name', 'plural'], {DEFAULT: context.contenttype.name}) }}
{% if context.filter %}
<small>({{ __("filtered by <em>'%filter%'</em>", {'%filter%': context.filter|join(', ') }) }})</small>
{% endif %}
{% endblock %}

{# clear default messages, because we use them in a different spot, in this template #}
{% block messages "" %}
Expand Down
31 changes: 22 additions & 9 deletions src/Controllers/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,30 +554,43 @@ public function overview(Application $app, $contenttypeslug)

$contenttype = $app['storage']->getContentType($contenttypeslug);

$filter = array();

$contentparameters = array('paging' => true, 'hydrate' => true);

// Order has to be set carefully. Either set it explicitly when the user
// sorts, or fall back to what's defined in the contenttype. The exception
// is a contenttype that has a "grouping taxonomy", because that should
// override it. The exception is handled in $app['storage']->getContent().
$order = $app['request']->query->get('order', $contenttype['sort']);
$contentparameters['order'] = $app['request']->query->get('order', $contenttype['sort']);
$contentparameters['page'] = $app['request']->query->get('page');

$page = $app['request']->query->get('page');
$filter = $app['request']->query->get('filter');
if ($app['request']->query->get('filter')) {
$contentparameters['filter'] = $app['request']->query->get('filter');
$filter[] = $app['request']->query->get('filter');
}

// Set the amount of items to show per page.
if (!empty($contenttype['recordsperpage'])) {
$limit = $contenttype['recordsperpage'];
$contentparameters['limit'] = $contenttype['recordsperpage'];
} else {
$limit = $app['config']->get('general/recordsperpage');
$contentparameters['limit'] = $app['config']->get('general/recordsperpage');
}

$multiplecontent = $app['storage']->getContent(
$contenttype['slug'],
array('limit' => $limit, 'order' => $order, 'page' => $page, 'filter' => $filter, 'paging' => true, 'hydrate' => true)
);
// Perhaps also filter on taxonomies
foreach($app['config']->get('taxonomy') as $taxonomykey => $taxonomy) {
if ($app['request']->query->get('taxonomy-' . $taxonomykey)) {
$contentparameters[$taxonomykey] = $app['request']->query->get('taxonomy-' . $taxonomykey);
$filter[] = $app['request']->query->get('taxonomy-' . $taxonomykey);
}
}

$multiplecontent = $app['storage']->getContent($contenttype['slug'], $contentparameters);

$context = array(
'contenttype' => $contenttype,
'multiplecontent' => $multiplecontent,
'filter' => $filter
);

return $app['render']->render('overview/overview.twig', array('context' => $context));
Expand Down