Skip to content

Commit

Permalink
Merge branch hotfix/v2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Dec 11, 2024
1 parent 99c20f3 commit 5eb9c69
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 147 deletions.
91 changes: 91 additions & 0 deletions src/AjaxControllers/AjaxSearchController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace Themes\Rozier\AjaxControllers;

use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface;
use RZ\Roadiz\CoreBundle\SearchEngine\GlobalNodeSourceSearchHandler;
use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\NodeVoter;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Serializer\SerializerInterface;

final class AjaxSearchController extends AbstractAjaxController
{
public const RESULT_COUNT = 10;

public function __construct(
private readonly Security $security,
private readonly ExplorerItemFactoryInterface $explorerItemFactory,
SerializerInterface $serializer,
) {
parent::__construct($serializer);
}

/**
* Handle AJAX edition requests for Node
* such as coming from node-tree widgets.
*
* @return Response JSON response
*/
public function searchAction(Request $request): Response
{
$this->denyAccessUnlessGranted(NodeVoter::SEARCH);

if (!$request->query->has('searchTerms') || '' == $request->query->get('searchTerms')) {
throw new BadRequestHttpException('searchTerms parameter is missing.');
}

$searchHandler = new GlobalNodeSourceSearchHandler($this->em());
$searchHandler->setDisplayNonPublishedNodes(true);

/** @var array $nodesSources */
$nodesSources = $searchHandler->getNodeSourcesBySearchTerm(
$request->get('searchTerms'),
self::RESULT_COUNT
);

if (0 === count($nodesSources)) {
return new JsonResponse([
'statusCode' => Response::HTTP_OK,
'status' => 'success',
'data' => [],
'responseText' => 'No results found.',
]);
}

$data = [];

foreach ($nodesSources as $source) {
$uniqueKey = null;
if ($source instanceof NodesSources) {
$uniqueKey = 'n_' . $source->getNode()->getId();
if (!$this->security->isGranted(NodeVoter::READ, $source)) {
continue;
}
} elseif ($source instanceof PersistableInterface) {
$uniqueKey = 'p_' . $source->getId();
}
if (key_exists($uniqueKey, $data)) {
continue;
}

$data[$uniqueKey] = $this->explorerItemFactory->createForEntity($source)->toArray();
}

$data = array_values($data);

return $this->createSerializedResponse([
'status' => 'confirm',
'statusCode' => 200,
'data' => $data,
'count' => count($data),
]);
}
}
128 changes: 0 additions & 128 deletions src/AjaxControllers/AjaxSearchNodesSourcesController.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Resources/app/api/NodesSourceSearchApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getNodesSourceFromSearch(searchTerms) {

return request({
method: 'GET',
url: window.RozierRoot.routes.searchNodesSourcesAjax,
url: window.RozierRoot.routes.searchAjax,
params: postData,
})
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
'providerAjaxExplorer' : '{{ path('providerAjaxExplorerPage') }}',
'providerAjaxByArray' : '{{ path('providerAjaxByArray') }}',
'customFormsAjaxExplorer' : '{{ path('customFormsAjaxExplorerPage') }}',
'searchNodesSourcesAjax': '{{ path('searchNodesSourcesAjax') }}',
'searchAjax': '{{ path('searchAjax') }}',
'nodesStatusesAjax' : '{{ path('nodesStatusesAjax') }}',
'nodesTreeAjax' : '{{ path('nodesTreeAjax') }}',
'tagsTreeAjax' : '{{ path('tagsTreeAjax') }}',
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/partials/css-inject.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<link href="{{ asset('css/vendor.9b59501e29a05f532c3c.css', 'Rozier') }}" rel="stylesheet">

<link href="{{ asset('css/app.f8fcd31a684be65ed09b.css', 'Rozier') }}" rel="stylesheet">
<link href="{{ asset('css/app.527fdff666ecb3971c76.css', 'Rozier') }}" rel="stylesheet">



Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/partials/js-inject.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<script src="{{ asset('js/vendor.84fa83ed0cd290364ef4.js', 'Rozier') }}" defer type="text/javascript"></script>
<script src="{{ asset('js/vendor.48b3bf2e8eb28e9948b2.js', 'Rozier') }}" defer type="text/javascript"></script>

<script src="{{ asset('js/app.84fa83ed0cd290364ef4.js', 'Rozier') }}" defer type="text/javascript"></script>
<script src="{{ asset('js/app.48b3bf2e8eb28e9948b2.js', 'Rozier') }}" defer type="text/javascript"></script>

2 changes: 1 addition & 1 deletion src/Resources/views/partials/simple-js-inject.html.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

<script src="{{ asset('js/simple.84fa83ed0cd290364ef4.js', 'Rozier') }}" defer type="text/javascript"></script>
<script src="{{ asset('js/simple.48b3bf2e8eb28e9948b2.js', 'Rozier') }}" defer type="text/javascript"></script>

19 changes: 9 additions & 10 deletions src/Resources/views/widgets/nodesSourcesSearch.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{isActive}}
<div id="nodes-sources-search" v-bind:class="{ 'focus-on': isFocus }">
<form id="nodes-sources-search-form"
v-on:submit.prevent action="{{ path('searchNodesSourcesAjax') }}"
v-on:submit.prevent action="{{ path('searchAjax') }}"
method="GET"
class="uk-form">
<div class="uk-form-icon">
Expand All @@ -24,21 +24,20 @@
<transition name="fade">
<ul id="nodes-sources-search-results" v-if="isFocus" v-cloak>
<li v-for="item in items">
<ajax-link class="nodes-sources-search-results-item" :href="item.url" :title="item.title" :type-color="item.typeColor">
<ajax-link class="nodes-sources-search-results-item" :href="item.editItem" :title="item.displayable" :type-color="item.color">
<span class="image-container">
<picture v-if="item.thumbnail">
<source v-if="!item.thumbnail.endsWith('svg') && !item.thumbnail.endsWith('webp')"
:srcset="item.thumbnail + '.webp'"
<picture v-if="item.thumbnail && item.thumbnail.processable">
<source v-if="!item.thumbnail.url.endsWith('svg') && !item.thumbnail.url.endsWith('webp')"
:srcset="item.thumbnail.url + '.webp'"
type="image/webp">
<img width="60" height="60" loading="lazy" :src="item.thumbnail">
<img width="60" height="60" loading="lazy" :src="item.thumbnail.url">
</picture>
</span>
<span class="texts">
<span class="texts-header">
<span class="parent">${item.parent}</span>
<span class="type">${item.typeName}</span>
<span class="texts-header" v-if="item.classname">
<span class="parent">${item.classname}</span>
</span>
<span class="title">${item.title}</span>
<span class="title">${item.displayable}</span>
</span>
</ajax-link>
</li>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 5eb9c69

Please sign in to comment.