summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2018-07-22 15:03:12 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2018-07-22 15:03:12 +0200
commita86c0db98c3b5f12b0f47532c5136234a5161f5d (patch)
tree499bf61ef2d5520489a4e15c7e0b67ae577e2d11
parentbee10297dea652f0c22207ae53836fc318067a60 (diff)
downloadchd_gestion-a86c0db98c3b5f12b0f47532c5136234a5161f5d.zip
chd_gestion-a86c0db98c3b5f12b0f47532c5136234a5161f5d.tar.gz
chd_gestion-a86c0db98c3b5f12b0f47532c5136234a5161f5d.tar.bz2
bake : limit action links to defined controller methods
-rw-r--r--app-from-scratch.sh6
-rw-r--r--fai_gestion/config/bake_extra.php2
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/form.twig27
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig13
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig14
5 files changed, 58 insertions, 4 deletions
diff --git a/app-from-scratch.sh b/app-from-scratch.sh
index a438292..8dd51ba 100644
--- a/app-from-scratch.sh
+++ b/app-from-scratch.sh
@@ -377,3 +377,9 @@ git add ../app-from-scratch.sh plugins/CustomTheme/src/Template/Bake/Model/table
git commit -m "bake: sort tables by default (with config) + allow ORDER BY hooks"
# 28e5cfbde499b7d08649596d0f675ad8bba0143a
+# bake : limit action links to defined controller methods
+p=plugins/CustomTheme/src/Template/Bake
+editor $p/Template/view.twig $p/Template/index.twig $p/Element/form.twig config/bake_extra.php
+git add $p/Template/view.twig $p/Template/index.twig $p/Element/form.twig config/bake_extra.php
+git add ../app-from-scratch.sh
+git commit -m "bake : limit action links to defined controller methods"
diff --git a/fai_gestion/config/bake_extra.php b/fai_gestion/config/bake_extra.php
index eb29b3d..ec2fb0b 100644
--- a/fai_gestion/config/bake_extra.php
+++ b/fai_gestion/config/bake_extra.php
@@ -61,7 +61,7 @@ $controllerActions = [
'EquipementModes' => [ ],
'Interesses' => [ 'index', 'view', 'add', 'edit', 'delete'],
'InteresseStatuts' => [ ],
- 'Ippubliques' => [ 'index', 'view' ], # FIXME rename table to ip_publiques
+ 'IpPubliques' => [ 'index', 'view' ],
#'LienFilaire' => [ ], # TODO in equipements ?
#'LienRadio' => [ ], # TODO in equipements ?
#'LienTunnel' => [ ], # TODO in equipements ?
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/form.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/form.twig
index 2ed5249..e48d107 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/form.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/form.twig
@@ -13,6 +13,29 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
#}
+<?php
+/**
+ * Copyright 2016-2018 Ludovic Pouzenc <ludovic@pouzenc.fr>
+ * Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr>
+ *
+ * This file is part of FAI Gestion forked from CHD Gestion.
+ *
+ * FAI Gestion is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * FAI Gestion is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FAI Gestion. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Auto-generated code with CakePHP(tm) bake derived code.
+**/
+?>
{% set fields = Bake.filterFields(fields, schema, modelObject) %}
<nav class="large-2 medium-3 columns" id="actions-sidebar">
<ul class="side-nav">
@@ -31,8 +54,12 @@
{% for type, data in associations %}
{%- for alias, details in data %}
{%- if details.controller is not same as(_view.name) and details.controller not in done %}
+{% if BakeExtra.hasAction('index', details.controller) %}
<li><?= $this->Html->link(__('List {{ alias|underscore|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'index']) ?></li>
+{% endif %}
+{% if BakeExtra.hasAction('add', details.controller) %}
<li><?= $this->Html->link(__('New {{ alias|singularize|underscore|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'add']) ?></li>
+{% endif %}
{{- "\n" }}
{%- set done = done|merge([details.controller]) %}
{%- 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 f057d35..10a8754 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig
@@ -47,13 +47,16 @@ $this->Form->setTemplates(['label' => '']);
<nav class="large-2 medium-3 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
- <li><?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add']) ?></li>
+{% if BakeExtra.hasAction('add', modelClass) %}
+<li><?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add']) ?></li>
+{% endif %}
{% set done = [] %}
{% for type, data in associations %}
{% for alias, details in data %}
{% if details.navLink and details.controller is not same as(_view.name) and details.controller not in done %}
+{% if BakeExtra.hasAction('index', details.controller) %}
<li><?= $this->Html->link(__('List {{ alias|underscore|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'index']) ?></li>
- <li><?= $this->Html->link(__('New {{ alias|singularize|underscore|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'add']) ?></li>
+{% endif %}
{% set done = done|merge([details.controller]) %}
{% endif %}
{% endfor %}
@@ -118,9 +121,15 @@ $this->Form->setTemplates(['label' => '']);
{% endfor %}
{% set pk = '$' ~ singularVar ~ '->' ~ primaryKey[0] %}
<td class="actions">
+{% if BakeExtra.hasAction('view', modelClass) %}
<?= $this->Html->link(__('View'), ['action' => 'view', {{ pk|raw }}]) ?>
+{% endif %}
+{% if BakeExtra.hasAction('edit', modelClass) %}
<?= $this->Html->link(__('Edit'), ['action' => 'edit', {{ pk|raw }}]) ?>
+{% endif %}
+{% if BakeExtra.hasAction('delete', modelClass) %}
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', {{ pk|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ pk|raw }})]) ?>
+{% endif %}
</td>
</tr>
<?php endforeach; ?>
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
index 69abdd2..354ec12 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/view.twig
@@ -48,16 +48,28 @@
<nav class="large-2 medium-3 columns" id="actions-sidebar">
<ul class="side-nav">
<li class="heading"><?= __('Actions') ?></li>
+{% if BakeExtra.hasAction('edit', modelClass) %}
<li><?= $this->Html->link(__('Edit {{ singularHumanName }}'), ['action' => 'edit', {{ pK|raw }}]) ?> </li>
+{% endif %}
+{% if BakeExtra.hasAction('delete', modelClass) %}
<li><?= $this->Form->postLink(__('Delete {{ singularHumanName }}'), ['action' => 'delete', {{ pK|raw }}], ['confirm' => __('Are you sure you want to delete # {0}?', {{ pK|raw }})]) ?> </li>
+{% endif %}
+{% if BakeExtra.hasAction('index', modelClass) %}
<li><?= $this->Html->link(__('List {{ pluralHumanName }}'), ['action' => 'index']) ?> </li>
- <li><?= $this->Html->link(__('New {{ singularHumanName }}'), ['action' => 'add']) ?> </li>
+{% endif %}
{% set done = [] %}
{% for type, data in associations %}
{% for alias, details in data %}
+{% if false %}
+// Bug here _view.name is NULL
+{% endif %}
{% if details.controller is not same as(_view.name) and details.controller not in done %}
+{% if BakeExtra.hasAction('index', details.controller) %}
<li><?= $this->Html->link(__('List {{ alias|underscore|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'index']) ?> </li>
+{% endif %}
+{% if BakeExtra.hasAction('add', details.controller) %}
<li><?= $this->Html->link(__('New {{ alias|underscore|singularize|humanize }}'), ['controller' => '{{ details.controller }}', 'action' => 'add']) ?> </li>
+{% endif %}
{% set done = done|merge(['controller']) %}
{% endif %}
{% endfor %}