From 46daeeecdc296a4b6f16edbc0978941f33343690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Adamczyk?= Date: Mon, 30 Oct 2017 15:08:57 +0100 Subject: [PATCH] EZP-28055: As a v2 Editor I want to search for content items by entering a search keyword --- composer.json | 3 - src/bundle/Controller/SearchController.php | 107 ++++++++++++++++++ src/bundle/Resources/config/routing.yml | 6 + .../Resources/translations/dashboard.en.yml | 1 + .../Resources/translations/search.en.xliff | 96 ++++++++++++++++ .../views/admin/search/list.html.twig | 79 +++++++++++++ .../views/admin/search/search.html.twig | 32 ++++++ .../views/admin/search/search_form.html.twig | 9 ++ .../admin/search/search_table_row.html.twig | 16 +++ .../views/admin/trash/list.html.twig | 25 +--- .../views/content/locationview.html.twig | 25 +--- .../views/dashboard/dashboard.html.twig | 23 +--- src/bundle/Resources/views/layout.html.twig | 27 ++++- src/lib/Form/Data/Search/SimpleSearchData.php | 95 ++++++++++++++++ src/lib/Form/Type/Search/SimpleSearchType.php | 48 ++++++++ 15 files changed, 528 insertions(+), 64 deletions(-) create mode 100644 src/bundle/Controller/SearchController.php create mode 100644 src/bundle/Resources/translations/search.en.xliff create mode 100644 src/bundle/Resources/views/admin/search/list.html.twig create mode 100644 src/bundle/Resources/views/admin/search/search.html.twig create mode 100644 src/bundle/Resources/views/admin/search/search_form.html.twig create mode 100644 src/bundle/Resources/views/admin/search/search_table_row.html.twig create mode 100644 src/lib/Form/Data/Search/SimpleSearchData.php create mode 100644 src/lib/Form/Type/Search/SimpleSearchType.php diff --git a/composer.json b/composer.json index 22f2bc0a9d..e404a26d6a 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/bundle/Controller/SearchController.php b/src/bundle/Controller/SearchController.php new file mode 100644 index 0000000000..7c83f7d421 --- /dev/null +++ b/src/bundle/Controller/SearchController.php @@ -0,0 +1,107 @@ +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(), + ]); + } +} diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index 0479aa80a2..76d474a11e 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -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' diff --git a/src/bundle/Resources/translations/dashboard.en.yml b/src/bundle/Resources/translations/dashboard.en.yml index 6ad866b90a..df84c2f91f 100644 --- a/src/bundle/Resources/translations/dashboard.en.yml +++ b/src/bundle/Resources/translations/dashboard.en.yml @@ -8,6 +8,7 @@ navigation: admin: # Desc: Trash trash: Trash + search: Search tab: name: diff --git a/src/bundle/Resources/translations/search.en.xliff b/src/bundle/Resources/translations/search.en.xliff new file mode 100644 index 0000000000..72e375327e --- /dev/null +++ b/src/bundle/Resources/translations/search.en.xliff @@ -0,0 +1,96 @@ + + + +
+ + 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. +
+ + + Search results (%total%) + Search results (%total%) + key: search.header + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Search + Search + key: search.headline + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/search.html.twig + + + search.list + search.list + key: search.list + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Modified + Modified + key: search.modified + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Name + Name + key: search.name + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Sorry, no results were found for "%query%". + Sorry, no results were found for "%query%". + key: search.no_result + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + search.perform + search.perform + key: search.perform + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/search.html.twig + + + Check spelling of keywords. + Check spelling of keywords. + key: search.tips.check_spelling + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Try different keywords. + Try different keywords. + key: search.tips.different_keywords + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Try fewer keywords. Reducing keywords result in more matches. + Try fewer keywords. Reducing keywords result in more matches. + key: search.tips.fewer_keywords + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Some helpful search tips: + Some helpful search tips: + key: search.tips.headline + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Try more general keywords. + Try more general keywords. + key: search.tips.more_general_keywords + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Content Type + Content Type + key: search.type + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + + Viewing %viewing% out of %total% sub-items + Viewing %viewing% out of %total% sub-items + key: search.viewing + /../../../../vendor/ezsystems/ezplatform-admin-ui/src/bundle/Resources/views/admin/search/list.html.twig + + +
+
diff --git a/src/bundle/Resources/views/admin/search/list.html.twig b/src/bundle/Resources/views/admin/search/list.html.twig new file mode 100644 index 0000000000..616ab07ae1 --- /dev/null +++ b/src/bundle/Resources/views/admin/search/list.html.twig @@ -0,0 +1,79 @@ +{% extends "EzPlatformAdminUiBundle::layout.html.twig" %} + +{% trans_default_domain 'search' %} + +{% block pageTitle %}{% endblock %} + +{% block content %} +
+
+ + {% block sidebar %} + {{ parent() }} + {% endblock sidebar %} + +
+
+ {% 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 } %} + +
+
{{ 'search.header'|trans({'%total%': pagerfanta.nbResults})|desc('Search results (%total%)') }}
+
+ + {% if results is empty %} + + + + +
+ {{ 'search.no_result'|trans({'%query%': form.vars.value.query})|desc('Sorry, no results were found for "%query%".') }} +
+
+
{{ 'search.tips.headline'|trans|desc('Some helpful search tips:') }}
+
    +
  • {{ 'search.tips.check_spelling'|trans|desc('Check spelling of keywords.') }}
  • +
  • {{ 'search.tips.different_keywords'|trans|desc('Try different keywords.') }}
  • +
  • {{ 'search.tips.more_general_keywords'|trans|desc('Try more general keywords.') }}
  • +
  • {{ 'search.tips.fewer_keywords'|trans|desc('Try fewer keywords. Reducing keywords result in more matches.') }}
  • +
+
+ {% else %} + + + + + + + + + + + {% for row in results %} + {% include '@EzPlatformAdminUi/admin/search/search_table_row.html.twig' with { row: row } %} + {% endfor %} + +
{{ 'search.name'|trans|desc('Name') }}{{ 'search.modified'|trans|desc('Modified') }}{{ 'search.type'|trans|desc('Content Type') }}
+
+
{{ 'search.viewing'|trans({'%viewing%': pagerfanta.currentPageResults|length, '%total%': pagerfanta.nbResults})|desc('Viewing %viewing% out of %total% sub-items') }}
+
+
+ {% if pagerfanta.haveToPaginate %} + {{ pagination|raw }} + {% endif %} +
+ {% endif %} +
+
+
+{% endblock %} + +{% block title %}{{ 'search.list'|trans }}{% endblock %} + +{% block javascripts %} + {% javascripts + 'bundles/ezplatformadminui/js/scripts/udw/browse.js' %} + + {% endjavascripts %} +{% endblock %} diff --git a/src/bundle/Resources/views/admin/search/search.html.twig b/src/bundle/Resources/views/admin/search/search.html.twig new file mode 100644 index 0000000000..368acd9d58 --- /dev/null +++ b/src/bundle/Resources/views/admin/search/search.html.twig @@ -0,0 +1,32 @@ +{% extends "EzPlatformAdminUiBundle::layout.html.twig" %} + +{% trans_default_domain 'search' %} + +{% block pageTitle %}{% endblock %} + +{% block content %} +
+
+ + {% block sidebar %} + {{ parent() }} + {% endblock sidebar %} + +
+
+ {% 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 } %} +
+
+
+{% endblock %} + +{% block title %}{{ 'search.perform'|trans }}{% endblock %} + +{% block javascripts %} + {% javascripts + 'bundles/ezplatformadminui/js/scripts/udw/browse.js' %} + + {% endjavascripts %} +{% endblock %} diff --git a/src/bundle/Resources/views/admin/search/search_form.html.twig b/src/bundle/Resources/views/admin/search/search_form.html.twig new file mode 100644 index 0000000000..97c2900ae0 --- /dev/null +++ b/src/bundle/Resources/views/admin/search/search_form.html.twig @@ -0,0 +1,9 @@ +{{ form_start(form) }} +
+ {{ form_widget(form.query, {'attr': {'style': 'width: 200px', 'class': 'form-control'} }) }} + + + + +
+{{ form_end(form) }} diff --git a/src/bundle/Resources/views/admin/search/search_table_row.html.twig b/src/bundle/Resources/views/admin/search/search_table_row.html.twig new file mode 100644 index 0000000000..b0663d60e1 --- /dev/null +++ b/src/bundle/Resources/views/admin/search/search_table_row.html.twig @@ -0,0 +1,16 @@ + + + {{ row.name }} + + {{ row.modified|date('M d, Y h:iA') }} + {{ row.type }} + + + + + + \ No newline at end of file diff --git a/src/bundle/Resources/views/admin/trash/list.html.twig b/src/bundle/Resources/views/admin/trash/list.html.twig index 44232c7db8..2081fd8f76 100644 --- a/src/bundle/Resources/views/admin/trash/list.html.twig +++ b/src/bundle/Resources/views/admin/trash/list.html.twig @@ -7,26 +7,11 @@ {% block content %}
-
{# @todo sidebars should be moved to layout.html.twig !! #} - - - - - - - Trash - -
+ + {% block sidebar %} + {{ parent() }} + {% endblock sidebar %} +
{% include '@EzPlatformAdminUi/parts/page_title.html.twig' with { title: 'trash.headline'|trans|desc('Trash'), iconName: 'trash' } %} diff --git a/src/bundle/Resources/views/content/locationview.html.twig b/src/bundle/Resources/views/content/locationview.html.twig index b9adaf9d25..00057ee77a 100644 --- a/src/bundle/Resources/views/content/locationview.html.twig +++ b/src/bundle/Resources/views/content/locationview.html.twig @@ -14,26 +14,11 @@ data-parent-content-type-identifier="{{ contentType.identifier }}" data-parent-content-type-id="{{ contentType.id }}">
-
- - - - - - - Trash - -
+ + {% block sidebar %} + {{ parent() }} + {% endblock sidebar %} +
diff --git a/src/bundle/Resources/views/dashboard/dashboard.html.twig b/src/bundle/Resources/views/dashboard/dashboard.html.twig index a9c0d63b9c..63ae427d53 100644 --- a/src/bundle/Resources/views/dashboard/dashboard.html.twig +++ b/src/bundle/Resources/views/dashboard/dashboard.html.twig @@ -6,26 +6,9 @@ {% block content %}
-
- - - - - - - {{ 'navigation.admin.trash'|trans|desc('Trash') }} - -
+ {% block sidebar %} + {{ parent() }} + {% endblock sidebar %}
diff --git a/src/bundle/Resources/views/layout.html.twig b/src/bundle/Resources/views/layout.html.twig index 1cf8077efc..96f11ca3ff 100644 --- a/src/bundle/Resources/views/layout.html.twig +++ b/src/bundle/Resources/views/layout.html.twig @@ -48,7 +48,32 @@
- {% block content %}{% endblock %} + {% block content %} + + {% block sidebar %} + + {% endblock sidebar %} + + {% endblock content %}
{% for label, messages in app.flashes %} diff --git a/src/lib/Form/Data/Search/SimpleSearchData.php b/src/lib/Form/Data/Search/SimpleSearchData.php new file mode 100644 index 0000000000..93b60d3d44 --- /dev/null +++ b/src/lib/Form/Data/Search/SimpleSearchData.php @@ -0,0 +1,95 @@ +limit = $limit; + $this->page = $page; + $this->query = $query; + } + + /** + * @param int $limit + * + * @return SimpleSearchData + */ + public function setLimit(int $limit): SimpleSearchData + { + $this->limit = $limit; + + return $this; + } + + /** + * @param int $page + * + * @return SimpleSearchData + */ + public function setPage(int $page): SimpleSearchData + { + $this->page = $page; + + return $this; + } + + /** + * @param string|null $query + * + * @return SimpleSearchData + */ + public function setQuery(?string $query): SimpleSearchData + { + $this->query = $query; + + return $this; + } + + /** + * @return int + */ + public function getLimit(): int + { + return $this->limit; + } + + /** + * @return int + */ + public function getPage(): int + { + return $this->page; + } + + /** + * @return string|null + */ + public function getQuery(): ?string + { + return $this->query; + } +} diff --git a/src/lib/Form/Type/Search/SimpleSearchType.php b/src/lib/Form/Type/Search/SimpleSearchType.php new file mode 100644 index 0000000000..e0bcd83d19 --- /dev/null +++ b/src/lib/Form/Type/Search/SimpleSearchType.php @@ -0,0 +1,48 @@ +setMethod('GET') + ->add('query', SearchType::class) + ->add('page', HiddenType::class) + ->add('limit', HiddenType::class) + ; + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => SimpleSearchData::class, + 'csrf_protection' => false, + ]); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return null; + } +}