Skip to content

Commit

Permalink
EZP-28055: As a v2 Editor I want to search for content items by enter…
Browse files Browse the repository at this point in the history
…ing a search keyword
  • Loading branch information
mikadamczyk authored and webhdx committed Nov 6, 2017
1 parent bb75981 commit 6fdcd3a
Show file tree
Hide file tree
Showing 19 changed files with 635 additions and 14 deletions.
147 changes: 147 additions & 0 deletions src/bundle/Controller/SearchController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUiBundle\Controller;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter;
use eZ\Publish\Core\Repository\SearchService;
use EzSystems\EzPlatformAdminUi\Form\Data\Search\SearchData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper;
use Pagerfanta\Pagerfanta;
use Pagerfanta\View\TwitterBootstrap4View;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class SearchController extends Controller
{
/** @var SearchService */
private $searchService;

/** @var PagerContentToDataMapper */
private $pagerContentToDataMapper;

/** @var UrlGeneratorInterface */
private $urlGenerator;

/** @var FormFactory */
private $formFactory;

/** @var SubmitHandler */
private $submitHandler;

/** @var int */
private $defaultLimit;

/**
* @param SearchService $searchService
* @param PagerContentToDataMapper $pagerContentToDataMapper
* @param UrlGeneratorInterface $urlGenerator
* @param FormFactory $formFactory
* @param SubmitHandler $submitHandler
* @param int $defaultLimit
*/
public function __construct(
SearchService $searchService,
PagerContentToDataMapper $pagerContentToDataMapper,
UrlGeneratorInterface $urlGenerator,
FormFactory $formFactory,
SubmitHandler $submitHandler,
$defaultLimit
) {
$this->searchService = $searchService;
$this->pagerContentToDataMapper = $pagerContentToDataMapper;
$this->urlGenerator = $urlGenerator;
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->defaultLimit = $defaultLimit;
}

/**
* Renders the simple search form and search results.
*
* @param Request $request
*
* @return Response
*
* @throws \InvalidArgumentException
*/
public function searchAction(Request $request): Response
{
$search = $request->query->get('search');
$limit = $search['limit'] ?? $this->defaultLimit;
$page = $search['page'] ?? 1;
$query = $search['query'];

$form = $this->formFactory->createSearchForm(
new SearchData($limit, $page, $query),
'search',
[
'method' => Request::METHOD_GET,
'csrf_protection' => false,
]
);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$result = $this->submitHandler->handle($form, function (SearchData $data) use ($form) {
$limit = $data->getLimit();
$page = $data->getPage();
$queryString = $data->getQuery();

$query = new Query();
$query->filter = new Criterion\LogicalAnd(
[
new Criterion\Visibility(Criterion\Visibility::VISIBLE),
new Criterion\FullText($queryString),
]
);

$query->sortClauses[] = new SortClause\DateModified(Query::SORT_ASC);

$pagerfanta = new Pagerfanta(
new ContentSearchAdapter($query, $this->searchService)
);

$pagerfanta->setMaxPerPage($limit);
$pagerfanta->setCurrentPage($page);

$routeGenerator = function ($page) use ($data) {
return $this->urlGenerator->generate('ezplatform.search', [
'search' => [
'query' => $data->getQuery(),
'page' => $page,
'limit' => $data->getLimit(),
],
]);
};

$pagination = (new TwitterBootstrap4View())->render($pagerfanta, $routeGenerator);

return $this->render('@EzPlatformAdminUi/admin/search/search.html.twig', [
'results' => $this->pagerContentToDataMapper->map($pagerfanta),
'form' => $form->createView(),
'pagination' => $pagination,
'pagerfanta' => $pagerfanta,
]);
});

if ($result instanceof Response) {
return $result;
}
}

return $this->render('@EzPlatformAdminUi/admin/search/search.html.twig', [
'form' => $form->createView(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ parameters:
ezsettings.default.location_ids.content: 2
ezsettings.default.location_ids.media: 43
ezsettings.default.location_ids.users: 5
ezsettings.default.search_limit: 10
8 changes: 8 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,11 @@ ezplatform.content.create:
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Content:create'

# Search

ezplatform.search:
path: /search
methods: ['GET']
defaults:
_controller: 'EzPlatformAdminUiBundle:Search:search'
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/services/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ services:
public: true
arguments:
$languages: '$languages$'


EzSystems\EzPlatformAdminUiBundle\Controller\SearchController:
public: true
arguments:
$defaultLimit: '$search_limit$'
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/css/ezplatform.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/bundle/Resources/public/scss/_icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
}
}

.ez-icon-search-button{
fill: $ez-white;
height: 1rem;
width: 1rem;
}

.ez-btn--extra-actions {
.ez-icon {
pointer-events: none;
Expand Down
96 changes: 96 additions & 0 deletions src/bundle/Resources/translations/search.en.xliff
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2017-10-30T13:24:04Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
</header>
<body>
<trans-unit id="0ec8148d681b43e87a6d0751fff188517be1ea26" resname="search.header">
<source>Search results (%total%)</source>
<target state="new">Search results (%total%)</target>
<note>key: search.header</note>
<jms:reference-file line="22">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="1d83218940b91b2cc81ae9d0a694682f6cb04813" resname="search.headline">
<source>Search</source>
<target state="new">Search</target>
<note>key: search.headline</note>
<jms:reference-file line="17">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
<jms:reference-file line="17">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/search.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="6ceaf9887c3974130781c3dadfcb129926496770" resname="search.list">
<source>search.list</source>
<target state="new">search.list</target>
<note>key: search.list</note>
<jms:reference-file line="72">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="0ea91510ce49731de30d4d412dc62c83c91b359d" resname="search.modified">
<source>Modified</source>
<target state="new">Modified</target>
<note>key: search.modified</note>
<jms:reference-file line="47">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="6fc6d2e87716ae8feb2ff4536efa8c9db0904509" resname="search.name">
<source>Name</source>
<target state="new">Name</target>
<note>key: search.name</note>
<jms:reference-file line="46">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="8c11cc36acf58db9ff898f3a4cf02fd0fc293f67" resname="search.no_result">
<source>Sorry, no results were found for "%query%".</source>
<target state="new">Sorry, no results were found for "%query%".</target>
<note>key: search.no_result</note>
<jms:reference-file line="29">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="6fa93ef4dfbce97076a254427bb30bf7c5819c5d" resname="search.perform">
<source>search.perform</source>
<target state="new">search.perform</target>
<note>key: search.perform</note>
<jms:reference-file line="25">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/search.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="777cc1ef279096d5a978aa3553e9434d828f8248" resname="search.tips.check_spelling">
<source>Check spelling of keywords.</source>
<target state="new">Check spelling of keywords.</target>
<note>key: search.tips.check_spelling</note>
<jms:reference-file line="36">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="d89a8ff5c4b03f1dd7bd1ce3e3306862e1855751" resname="search.tips.different_keywords">
<source>Try different keywords.</source>
<target state="new">Try different keywords.</target>
<note>key: search.tips.different_keywords</note>
<jms:reference-file line="37">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="013ced9a3284ecebf5a5356397dc9a79eaf76496" resname="search.tips.fewer_keywords">
<source>Try fewer keywords. Reducing keywords result in more matches.</source>
<target state="new">Try fewer keywords. Reducing keywords result in more matches.</target>
<note>key: search.tips.fewer_keywords</note>
<jms:reference-file line="39">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="4af1e76946070e5f61320621d12a171f4206e06c" resname="search.tips.headline">
<source>Some helpful search tips:</source>
<target state="new">Some helpful search tips:</target>
<note>key: search.tips.headline</note>
<jms:reference-file line="34">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="dd61516edc919235a13e3cfadb5d961b8614b744" resname="search.tips.more_general_keywords">
<source>Try more general keywords.</source>
<target state="new">Try more general keywords.</target>
<note>key: search.tips.more_general_keywords</note>
<jms:reference-file line="38">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="0c9866a19fd5d3074bdb05b339df05b7c05a5661" resname="search.type">
<source>Content Type</source>
<target state="new">Content Type</target>
<note>key: search.type</note>
<jms:reference-file line="48">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="fe647ff0e12d67501403559464217be468dba3d8" resname="search.viewing">
<source>Viewing %viewing% out of %total% sub-items</source>
<target state="new">Viewing %viewing% out of %total% sub-items</target>
<note>key: search.viewing</note>
<jms:reference-file line="59">/../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig</jms:reference-file>
</trans-unit>
</body>
</file>
</xliff>
72 changes: 72 additions & 0 deletions src/bundle/Resources/views/admin/search/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{% extends "EzPlatformAdminUiBundle::layout.html.twig" %}

{% trans_default_domain 'search' %}

{% block pageTitle %}{% endblock %}

{% block content %}
<div id="react-udw"></div>
<div class="row align-items-stretch ez-main-row">

{% block left_sidebar %}
{{ parent() }}
{% endblock left_sidebar %}

<div class="col-sm-10 px-0">
<section class="container mt-5">
{% include '@EzPlatformAdminUi/parts/page_title.html.twig' with { title: 'search.headline'|trans|desc('Search'), iconName: 'search' } %}

{% include '@EzPlatformAdminUi/admin/search/search_form.html.twig' with { form: form } %}

<div class="ez-table-header mt-3">
<h5>{{ 'search.header'|trans({'%total%': pagerfanta.nbResults})|desc('Search results (%total%)') }}</h5>
</div>

{% if results is empty %}
<table class="table">
<tr>
<td colspan="4">
<span>{{ 'search.no_result'|trans({'%query%': form.vars.value.query})|desc('Sorry, no results were found for "%query%".') }}</span>
</td>
</tr>
</table>
<div class="ez-main-row">
<h6>{{ 'search.tips.headline'|trans|desc('Some helpful search tips:') }}</h6>
<ul>
<li>{{ 'search.tips.check_spelling'|trans|desc('Check spelling of keywords.') }}</li>
<li>{{ 'search.tips.different_keywords'|trans|desc('Try different keywords.') }}</li>
<li>{{ 'search.tips.more_general_keywords'|trans|desc('Try more general keywords.') }}</li>
<li>{{ 'search.tips.fewer_keywords'|trans|desc('Try fewer keywords. Reducing keywords result in more matches.') }}</li>
</ul>
</div>
{% else %}
<table class="table">
<thead>
<tr>
<th>{{ 'search.name'|trans|desc('Name') }}</th>
<th>{{ 'search.modified'|trans|desc('Modified') }}</th>
<th>{{ 'search.type'|trans|desc('Content Type') }}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for row in results %}
{% include '@EzPlatformAdminUi/admin/search/search_table_row.html.twig' with { row: row } %}
{% endfor %}
</tbody>
</table>
<div class="row justify-content-center align-items-center">
<h6>{{ 'search.viewing'|trans({'%viewing%': pagerfanta.currentPageResults|length, '%total%': pagerfanta.nbResults})|desc('Viewing %viewing% out of %total% sub-items') }}</h6>
</div>
<div class="row justify-content-center align-items-center">
{% if pagerfanta.haveToPaginate %}
{{ pagination|raw }}
{% endif %}
</div>
{% endif %}
</section>
</div>
</div>
{% endblock %}

{% block title %}{{ 'search.list'|trans }}{% endblock %}
Loading

0 comments on commit 6fdcd3a

Please sign in to comment.