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

EZP-28055: As a v2 Editor I want to search for content items by entering a search keyword
  • Loading branch information
mikadamczyk committed Oct 30, 2017
1 parent 921f05e commit 0f0bfcb
Show file tree
Hide file tree
Showing 15 changed files with 527 additions and 64 deletions.
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"require-dev": {
"phpunit/phpunit": "^6.4"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
Expand Down
106 changes: 106 additions & 0 deletions src/bundle/Controller/SearchController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?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\Core\Repository\SearchService;
use EzSystems\EzPlatformAdminUi\Form\Data\Search\SimpleSearchData;
use EzSystems\EzPlatformAdminUi\Form\Type\Search\SimpleSearchType;
use EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper;
use Pagerfanta\View\TwitterBootstrap4View;
use Symfony\Component\HttpFoundation\Request;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use eZ\Publish\API\Repository\Values\Content\Query;
use Pagerfanta\Pagerfanta;
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter;
use Symfony\Component\HttpFoundation\Response;

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

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

/**
* @param SearchService $searchService
* @param PagerContentToDataMapper $pagerContentToDataMapper
*/
public function __construct(
SearchService $searchService,
PagerContentToDataMapper $pagerContentToDataMapper
) {
$this->searchService = $searchService;
$this->pagerContentToDataMapper = $pagerContentToDataMapper;
}

/**
* Renders the simple search form and search results.
*
* @param Request $request
*
* @return Response
*/
public function searchAction(Request $request): Response
{
$limit = $request->query->getInt('limit', 10);
$page = $request->query->getInt('page', 1);
$query = $request->query->get('query');

$form = $this->createForm(SimpleSearchType::class, new SimpleSearchData($limit, $page, $query));

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/** @var SimpleSearchData $data */
$data = $form->getData();

$query = new Query();
$query->filter = new Criterion\LogicalAnd(
[
new Criterion\Visibility(Criterion\Visibility::VISIBLE),
new Criterion\FullText($data->getQuery()),
]
);
$query->sortClauses[] = new SortClause\DateModified(Query::SORT_ASC);

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

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

$urlGenerator = $this->get('router');

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

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

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

return $this->render('@EzPlatformAdminUi/admin/search/search.html.twig', [
'form' => $form->createView(),
]);
}
}
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,9 @@ ezplatform.location.swap:
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:Location:swap'

ezplatform.search:
path: /search
methods: ['GET']
defaults:
_controller: 'EzPlatformAdminUiBundle:Search:search'
1 change: 1 addition & 0 deletions src/bundle/Resources/translations/dashboard.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ navigation:
admin:
# Desc: Trash
trash: Trash
search: Search

tab:
name:
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>
79 changes: 79 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,79 @@
{% 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 sidebar %}
{{ parent() }}
{% endblock 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 %}

{% block javascripts %}
{% javascripts
'bundles/ezplatformadminui/js/scripts/udw/browse.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
32 changes: 32 additions & 0 deletions src/bundle/Resources/views/admin/search/search.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% 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 sidebar %}
{{ parent() }}
{% endblock 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 } %}
</section>
</div>
</div>
{% endblock %}

{% block title %}{{ 'search.perform'|trans }}{% endblock %}

{% block javascripts %}
{% javascripts
'bundles/ezplatformadminui/js/scripts/udw/browse.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
9 changes: 9 additions & 0 deletions src/bundle/Resources/views/admin/search/search_form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ form_start(form) }}
<div class="input-group">
{{ form_widget(form.query, {'attr': {'style': 'width: 200px', 'class': 'form-control'} }) }}

<span class="input-group-btn">
<input type="submit" class="btn btn-primary" value="Search"/>
</span>
</div>
{{ form_end(form) }}
16 changes: 16 additions & 0 deletions src/bundle/Resources/views/admin/search/search_table_row.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<tr>
<td>
<a href="{{ url('_ez_content_view', { 'contentId': row.contentId }) }}">{{ row.name }}</a>
</td>
<td>{{ row.modified|date('M d, Y h:iA') }}</td>
<td>{{ row.type }}</td>
<td class="text-center"><a href="{{ path('ez_content_draft_create', {
'contentId': row.contentId,
'fromVersionNo': row.version,
'fromLanguage': row.language
}) }}" class="btn btn-icon">
<svg class="ez-icon ez-icon-edit">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#edit"></use>
</svg>
</a></td>
</tr>
Loading

0 comments on commit 0f0bfcb

Please sign in to comment.