Skip to content

Commit

Permalink
Merge pull request #438 from ibexa/temp_2.3_to_4.1
Browse files Browse the repository at this point in the history
Merge branch '2.3' of ezsystems/ezplatform-admin-ui into 4.1
  • Loading branch information
mikadamczyk authored May 31, 2022
2 parents 309eb42 + b2c7eb1 commit 1a217e6
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services/forms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ services:
tags:
- { name: form.type, alias: ezplatform_content_forms_url_list }

Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardListType: ~

Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardDeleteType: ~

Ibexa\AdminUi\Form\Type\URLWildcard\URLWildcardType: ~
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module.exports = (Encore) => {
])
.addEntry('ibexa-admin-ui-link-manager-list-js', [path.resolve(__dirname, '../public/js/scripts/admin.linkmanager.list.js')])
.addEntry('ibexa-admin-ui-link-manager-view-js', [path.resolve(__dirname, '../public/js/scripts/button.content.edit.js')])
.addEntry('ibexa-admin-ui-url-wildcards-list-js', [path.resolve(__dirname, '../public/js/scripts/admin.urlwildcards.list.js')])
.addEntry('ibexa-admin-ui-change-user-password-js', [path.resolve(__dirname, '../public/js/scripts/user_password.change.js')])
.addEntry('ibexa-admin-ui-content-edit-parts-js', [
path.resolve('./vendor/ibexa/admin-ui-assets/src/bundle/Resources/public/vendors/leaflet/dist/leaflet.js'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function (doc) {
const typeField = doc.getElementById('url_wildcard_list_type');

typeField.addEventListener('change', function () {
this.form.submit();
});
})(document);
13 changes: 13 additions & 0 deletions src/bundle/Resources/public/js/scripts/fieldType/ezgmaplocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const VALIDATE_LONGITUDE = 'validateLongitude';
const VALIDATE_LATITUDE = 'validateLatitude';
const VALIDATE_ADDRESS = 'validateAddress';
const maps = [];

class EzGMapLocationValidator extends ibexa.BaseFieldValidator {
/**
Expand Down Expand Up @@ -460,6 +461,7 @@
};
const map = Leaflet.map(field.querySelector('.ibexa-data-source__map'), mapConfig);

maps.push(map);
longitudeInput.value = longitudeInput.dataset.value.replace(',', '.');
latitudeInput.value = latitudeInput.dataset.value.replace(',', '.');

Expand Down Expand Up @@ -615,5 +617,16 @@
}
});

const invalidateSizeMap = (event) => {
const tabPaneSelector = event.target.getAttribute('href');
const tabPane = doc.querySelector(tabPaneSelector);

if (tabPane.querySelectorAll(SELECTOR_FIELD).length > 0) {
maps.forEach((map) => map.invalidateSize(true));
}
};

doc.querySelectorAll('.ibexa-tabs .nav-link').forEach((tab) => tab.addEventListener('shown.bs.tab', invalidateSizeMap));

ibexa.addConfig('fieldTypeValidators', [validator], true);
})(window, window.document, window.ibexa, window.L, window.Translator);
15 changes: 15 additions & 0 deletions src/bundle/Resources/translations/ezplatform_url_wildcard.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
<target state="new">Forward</target>
<note>key: url_wildcard.type.forward</note>
</trans-unit>
<trans-unit id="5646653e7d129c0a5c96b6b87e99eeb9d92a6fee" resname="url_wildcard.type.all">
<source>All</source>
<target state="new">All</target>
<note>key: url_wildcard.type.all</note>
</trans-unit>
<trans-unit id="d5f8b02988ca5a63f52253b3eec84f9cc8f799cd" resname="url_wildcard.search.placeholder">
<source>Search for URL wildcards</source>
<target state="new">Search for URL wildcards</target>
<note>key: url_wildcard.search.placeholder</note>
</trans-unit>
<trans-unit id="fc64faec5bb26550f5008c70a89e7ba76f0d5dd1" resname="url_wildcard.search">
<source>Search</source>
<target state="new">Search</target>
<note>key: url_wildcard.search</note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% trans_default_domain "ezplatform_url_wildcard" %}

{% form_theme form '@ibexadesign/ui/form_fields.html.twig' %}
{% form_theme form_list '@ibexadesign/ui/form_fields.html.twig' %}

{%
set wildcard_types = {
Expand All @@ -9,6 +10,24 @@
}
%}

<section class="container">
{{ form_start(form_list, {'attr': {'class': 'ibexa-search-links-form'}}) }}
<div class="ibexa-search-links-form__input-wrapper">
{{ form_widget(form_list.searchQuery, {
attr: {
'placeholder': 'url_wildcard.search.placeholder'|trans|desc('Search for URL wildcards'),
},
has_search: true,
}) }}
</div>
<div class="ibexa-search-links-form__status-wrapper">
{{ form_label(form_list.type) }}
{{ form_widget(form_list.type) }}
</div>

{{ form_end(form_list) }}
</section>

<section class="mt-4">
{% if not url_wildcards_enabled %}
{% include '@ibexadesign/ui/component/alert/alert.html.twig' with {
Expand Down Expand Up @@ -154,3 +173,7 @@
} %}
{% endif %}
</section>

{% block javascripts %}
{{ encore_entry_script_tags('ibexa-admin-ui-url-wildcards-list-js', null, 'ibexa') }}
{% endblock %}
51 changes: 51 additions & 0 deletions src/lib/Form/Data/URLWildcard/URLWildcardListData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Form\Data\URLWildcard;

final class URLWildcardListData
{
/** @var string|null */
public $searchQuery;

/** @var bool|null */
public $type;

/** @var int */
public $limit;

public function getSearchQuery(): ?string
{
return $this->searchQuery;
}

public function setSearchQuery(?string $searchQuery): void
{
$this->searchQuery = $searchQuery;
}

public function getType(): ?bool
{
return $this->type;
}

public function setType(?bool $type): void
{
$this->type = $type;
}

public function getLimit(): int
{
return $this->limit;
}

public function setLimit(int $limit): void
{
$this->limit = $limit;
}
}
64 changes: 64 additions & 0 deletions src/lib/Form/Type/URLWildcard/URLWildcardListType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\AdminUi\Form\Type\URLWildcard;

use Ibexa\AdminUi\Form\Data\URLWildcard\URLWildcardListData;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class URLWildcardListType extends AbstractType implements TranslationContainerInterface
{
private const TYPE_DIRECT = 'url_wildcard.type.direct';
private const TYPE_FORWARD = 'url_wildcard.type.forward';
private const PLACEHOLDER = 'url_wildcard.type.all';

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('type', ChoiceType::class, [
'choices' => [
self::TYPE_DIRECT => true,
self::TYPE_FORWARD => false,
],
'placeholder' => self::PLACEHOLDER,
'required' => false,
]);

$builder->add('searchQuery', TextareaType::class, [
'required' => false,
]);

$builder->add('limit', HiddenType::class);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => URLWildcardListData::class,
'translation_domain' => 'ezplatform_url_wildcard',
]);
}

/**
* @return array<\JMS\TranslationBundle\Model\Message>
*/
public static function getTranslationMessages(): array
{
return [
(new Message(self::TYPE_DIRECT, 'ezplatform_url_wildcard'))->setDesc('Direct'),
(new Message(self::TYPE_FORWARD, 'ezplatform_url_wildcard'))->setDesc('Forward'),
(new Message(self::PLACEHOLDER, 'ezplatform_url_wildcard'))->setDesc('All'),
];
}
}
33 changes: 21 additions & 12 deletions src/lib/Pagination/Pagerfanta/URLWildcardAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Ibexa\AdminUi\Pagination\Pagerfanta;

use Ibexa\Contracts\Core\Repository\URLWildcardService;
use Ibexa\Contracts\Core\Repository\Values\Content\URLWildcard\URLWildcardQuery;
use Pagerfanta\Adapter\AdapterInterface;

final class URLWildcardAdapter implements AdapterInterface
Expand All @@ -17,35 +18,43 @@ final class URLWildcardAdapter implements AdapterInterface
/** @var int */
private $nbResults;

public function __construct(URLWildcardService $urlWildcardService)
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\URLWildcard\URLWildcardQuery */
private $query;

public function __construct(URLWildcardQuery $query, URLWildcardService $urlWildcardService)
{
$this->query = $query;
$this->urlWildcardService = $urlWildcardService;
}

/**
* Returns the number of results.
* {@inheritdoc}
*
* @return int the number of results
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
public function getNbResults(): int
{
if ($this->nbResults !== null) {
return $this->nbResults;
}
$query = clone $this->query;
$query->offset = 0;
$query->limit = 0;

return $this->nbResults = $this->urlWildcardService->countAll();
return $this->urlWildcardService->findUrlWildcards($query)->totalCount;
}

/**
* Returns a slice of the results.
*
* @param int $offset the offset
* @param int $length the length
* {@inheritdoc}
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\URLWildcard[]
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*/
public function getSlice($offset, $length): array
{
return $this->urlWildcardService->loadAll($offset, $length);
$query = clone $this->query;
$query->offset = $offset;
$query->limit = $length;
$query->performCount = false;

return $this->urlWildcardService->findUrlWildcards($query)->items;
}
}
Loading

0 comments on commit 1a217e6

Please sign in to comment.