load postal codes dynamically

This commit is contained in:
2018-07-05 13:02:21 +02:00
parent 86a814cfb5
commit 26a4d80ce6
16 changed files with 368 additions and 10 deletions

View File

@@ -1,6 +1,9 @@
Chill\MainBundle\Entity\PostalCode:
type: entity
table: chill_main_postal_code
repositoryClass: Chill\MainBundle\Repository\PostalCodeRepository
indexes:
- { name: search_name_code, columns: [ "code", "label" ] }
id:
id:
type: integer

View File

@@ -17,6 +17,10 @@ chill_main_admin:
chill_main_exports:
resource: "@ChillMainBundle/Resources/config/routing/exports.yml"
prefix: "{_locale}/exports"
chill_postal_code:
resource: "@ChillMainBundle/Resources/config/routing/postal-code.yml"
prefix: "{_locale}/postal-code"
root:
path: /

View File

@@ -0,0 +1,4 @@
chill_main_postal_code_search:
path: /search
defaults: { _controller: ChillMainBundle:PostalCode:search }

View File

@@ -1,4 +1,6 @@
services:
Chill\MainBundle\Controller\:
autowire: true
resource: '../../../Controller'
tags: ['controller.service_arguments']

View File

@@ -54,9 +54,17 @@ services:
class: Chill\MainBundle\Form\Type\PostalCodeType
arguments:
- "@chill.main.helper.translatable_string"
- '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
- '@chill.main.form.choice_loader.postal_code'
- '@Symfony\Component\Translation\TranslatorInterface'
tags:
- { name: form.type }
chill.main.form.choice_loader.postal_code:
class: Chill\MainBundle\Form\ChoiceLoader\PostalCodeChoiceLoader
arguments:
- '@Chill\MainBundle\Repository\PostalCodeRepository'
chill.main.form.type.export:
class: Chill\MainBundle\Form\Type\Export\ExportType
arguments:

View File

@@ -15,4 +15,13 @@ services:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- "Chill\\MainBundle\\Entity\\Scope"
- "Chill\\MainBundle\\Entity\\Scope"
chill.main.postalcode_repository:
class: Doctrine\ORM\EntityRepository
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- "Chill\\MainBundle\\Entity\\PostalCode"
Chill\MainBundle\Repository\PostalCodeRepository: '@chill.main.postalcode_repository'

View File

@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add index to postal code
*/
final class Version20180703191509 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
try {
$this->addSql('CREATE EXTENSION IF NOT EXISTS pg_trgm');
$this->addSql('CREATE INDEX search_name_code ON chill_main_postal_code USING GIN (LOWER(code) gin_trgm_ops, LOWER(label) gin_trgm_ops)');
} catch (\Exception $e) {
$this->skipIf(true, "Could not create extension pg_trgm");
}
}
public function down(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP INDEX search_name_code');
}
}

View File

@@ -0,0 +1,36 @@
window.addEventListener('load', function (e) {
var
postalCodes = document.querySelectorAll('[data-postal-code]')
;
for (let i = 0; i < postalCodes.length; i++) {
let
searchUrl = postalCodes[i].dataset.searchUrl,
noResultsLabel = postalCodes[i].dataset.noResultsLabel,
errorLoadLabel = postalCodes[i].dataset.errorLoadLabel,
searchingLabel = postalCodes[i].dataset.searchingLabel
;
$(postalCodes[i]).select2({
allowClear: true,
language: {
errorLoading: function () {
return errorLoadLabel;
},
noResults: function () {
return noResultsLabel;
},
searching: function () {
return searchingLabel;
}
},
ajax: {
url: searchUrl,
dataType: 'json',
delay: 250
}
});
}
});

View File

@@ -18,4 +18,11 @@ span.force-inline-label label {
align-self: center;
margin-left: 1em;
}
}
.chill-form__errors {
.chill-form_errors__entry.chill-form__errors__entry--warning {
color: var(--chill-green-dark);
}
}

View File

@@ -182,4 +182,9 @@ column: colonne
Comma separated values (CSV): Valeurs séparées par des virgules (CSV - tableur)
# spreadsheet formatter
Choose the format: Choisir le format
Choose the format: Choisir le format
# select2
'select2.no_results': Aucun résultat
'select2.error_loading': Erreur de chargement des résultats
'select2.searching': Recherche en cours...

View File

@@ -141,9 +141,9 @@
{% block form_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<ul class="errors">
<ul class="errors chill-form__errors">
{% for error in errors %}
<li>{{ error.message }}</li>
<li class="chill-form_errors__entry {% if 'severity' in error.cause.constraint.payload|keys %}chill-form__errors__entry--{{ error.cause.constraint.payload.severity }}{% endif %}">{{ error.message }}</li>
{% endfor %}
</ul>
{% endif %}