diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-07-20 00:41:45 +0200 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2018-07-20 00:41:45 +0200 |
commit | b59164b0b7451905adcca244e6395281eb0633ca (patch) | |
tree | 098111b525b796221a931aaae5c1688cf1a45d88 /fai_gestion/plugins/CustomTheme/src/Template | |
parent | 76ab63096a25f5bf7b9d076cdc9ab3fc5218d216 (diff) | |
download | chd_gestion-b59164b0b7451905adcca244e6395281eb0633ca.zip chd_gestion-b59164b0b7451905adcca244e6395281eb0633ca.tar.gz chd_gestion-b59164b0b7451905adcca244e6395281eb0633ca.tar.bz2 |
bake add Search filter support
Diffstat (limited to 'fai_gestion/plugins/CustomTheme/src/Template')
3 files changed, 57 insertions, 1 deletions
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig index 181e830..8938f6a 100644 --- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig +++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig @@ -27,7 +27,17 @@ 'contain' => [{{ Bake.stringifyList(belongsTo, {'indent': false})|raw }}] ]; {% endif %} +{%- if BakeExtra.hasFilters(name) %} + $query = $this->{{ currentModelName }} + ->find('search', ['search' => $this->request->getQueryParams()]); + ${{ pluralName }} = $this->paginate($query); +{% else %} ${{ pluralName }} = $this->paginate($this->{{ currentModelName }}); +{% endif %} + $this->set('{{ pluralName }}', ${{ pluralName }}); +{% for model in BakeExtra.getFiltersExtraModels(name, modelObj) %} - $this->set(compact('{{ pluralName }}')); + $this->loadModel('{{ model.getAlias }}'); + $this->set('{{ model.getAlias|variable }}', $this->{{ model.getAlias }}->find('list')->toArray()); +{% endfor %} } diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig index 2ef02e9..fb3a417 100644 --- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig +++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig @@ -156,4 +156,22 @@ class {{ name }}Table extends Table return '{{ connection }}'; } {% endif %} + +{%- if BakeExtra.hasFilters(name) %} + + /** + * @return \Search\Manager + */ + public function searchManager() + { + $searchManager = $this->behaviors()->Search->searchManager(); +{% for k, filter in BakeExtra.getFilters(name) %} + $searchManager->{{ filter.mode }}('{{ k }}', [ + {{- BakeExtra.stringifySearchManagerConfig(filter)|raw -}} + ]); +{% endfor %} + + return $searchManager; + } +{% endif %} } diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig index 074a30b..15bfe45 100644 --- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig +++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig @@ -39,6 +39,9 @@ * @var \{{ namespace }}\View\AppView $this * @var \{{ entityClass }}[]|\Cake\Collection\CollectionInterface ${{ pluralVar }} */ + +// index could contain table head filters and labels in <th> aren't useful +$this->Form->setTemplates(['label' => '']); ?> {% set fields = Bake.filterFields(fields, schema, modelObject, indexColumns, ['binary', 'text']) %} <nav class="large-3 medium-4 columns" id="actions-sidebar"> @@ -61,6 +64,31 @@ <h3><?= __('{{ pluralHumanName }}') ?></h3> <table cellpadding="0" cellspacing="0"> <thead> +{% if BakeExtra.hasFilters(modelClass) %} + <tr class="filter"> + <?= $this->Form->create(null, ['valueSources' => 'query']) . "\n"; ?> +{% for k, filter in BakeExtra.getFilters(modelClass) %} + <th colspan="{{ filter.colspan }}"> + <?= $this->Form->control('{{ k }}', [ + 'placeholder' => __('{{ filter.hint }}'), + 'empty' => __('{{ filter.hint }}') + ]) . "\n"; ?> + </th> +{% endfor %} + <th class="actions"> + <?php + echo $this->Form->button('Filter', [ 'type' => 'submit' ]); + if (!empty($_isSearch)) { + echo " " . $this->Html->link('Reset', [ 'action' => 'index' ]); + } + echo "\n"; + ?> + </th> +{% if BakeExtra.hasFilters(modelClass) %} + <?= $this->Form->end() . "\n"; ?> +{% endif %} + </tr> +{% endif %} <tr> {% for field in fields %} <th scope="col"><?= $this->Paginator->sort('{{ field }}') ?></th> |