From 401ec6bea08c6d8dd084e4760e881233f36854f0 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Tue, 27 Aug 2024 10:05:09 +0200 Subject: [PATCH 1/8] fix if column exist to avoid error key not exist --- templates/bake/Model/table.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/bake/Model/table.twig b/templates/bake/Model/table.twig index 92646ae..689023e 100644 --- a/templates/bake/Model/table.twig +++ b/templates/bake/Model/table.twig @@ -203,7 +203,7 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void { foreach ($this->getSchema()->columns() as $column) { - if ($this->getSchema()->getColumnType($column) === 'timestampfractional' && $data[$column] !== null) { + if (isset($data[$column]) && $this->getSchema()->getColumnType($column) === 'timestampfractional' && $data[$column] !== null) { $data[$column] = Date::parseDate($data[$column], 'YYYY-MM-dd'); } } From 262ebe7032bbed51ae4dfcb2db3ec58b1421c74d Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Tue, 27 Aug 2024 10:05:55 +0200 Subject: [PATCH 2/8] fix pass options to get using continains deprecated as array --- templates/bake/element/Controller/edit.twig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index 7fefa60..5ad740f 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -22,9 +22,7 @@ public function edit($id = null) { $errors = []; - ${{ singularName }} = $this->{{ currentModelName }}->get($id, [ - 'contain' => {{ Bake.exportArray(belongsToMany)|raw }}, - ]); + ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: [{{ Bake.exportArray(belongsToMany)|raw }}]); if ($this->request->is(['patch', 'post', 'put'])) { ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->getRequest()->getData()); if ($this->{{ currentModelName }}->save(${{ singularName }})) { From 94a8ac4ac1363ba1facf42d3e87f70e29d11adc6 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Tue, 27 Aug 2024 10:55:14 +0200 Subject: [PATCH 3/8] add elseif for boolean to render checkbox instead of string --- templates/bake/element/form.twig | 376 ++++++++++++++++--------------- 1 file changed, 195 insertions(+), 181 deletions(-) diff --git a/templates/bake/element/form.twig b/templates/bake/element/form.twig index feb70e7..25842de 100644 --- a/templates/bake/element/form.twig +++ b/templates/bake/element/form.twig @@ -10,126 +10,126 @@ */ #} {% set fields = Bake.filterFields(fields, schema, modelObject) %} @@ -192,66 +192,80 @@ onMounted(() => {

{{ action|capitalize }} {{ singularHumanName }}

- {{- "\n" }} - {%- for field in fields %} + {{- "\n" }} + {%- for field in fields %} - {%- if field not in primaryKey %} - {%- if keyFields[field] is defined %} -
- {{- "\n" }} {{- "\n" }} - {%- set optionsData = [] %} - {%- if associations.BelongsTo is defined %} - {%- for assocName, assocData in associations.BelongsTo %} - {%- if assocData['foreignKey'] == field %} - {%- set optionsData = assocData['variable'] %} + {%- if field not in primaryKey %} + {%- if keyFields[field] is defined %} +
+ {{- "\n" }} {{- "\n" }} + {%- set optionsData = [] %} + {%- if associations.BelongsTo is defined %} + {%- for assocName, assocData in associations.BelongsTo %} + {%- if assocData['foreignKey'] == field %} + {%- set optionsData = assocData['variable'] %} + {%- endif %} + {%- endfor %} + {{- "\n" }} + {%- else %} + {{- "\n" }} + {%- endif %} + {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %} +
{{ vueVar }}
+
{{- "\n" }} + {%- elseif field not in ['created', 'modified', 'updated'] %}{{- "\n" }} + {%- set fieldData = Bake.columnData(field, schema) %} + {%- if fieldData.type in ['date', 'datetime', 'time', 'timestampfractional'] and fieldData.null %} + + {%- if fieldData.type in ['date', 'timestampfractional'] %} +
+ +
+ {%- else %} + {{ fieldData.type }} Not Implemented in vueTemplate Baked {{- "\n" }} {%- endif %} - {%- endfor %} - {{- "\n" }} - {%- else %} - {{- "\n" }} - {%- endif %} - {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %} -
{{ vueVar }}
-
{{- "\n" }} - {%- elseif field not in ['created', 'modified', 'updated'] %}{{- "\n" }} - {%- set fieldData = Bake.columnData(field, schema) %} - {%- if fieldData.type in ['date', 'datetime', 'time', 'timestampfractional'] and fieldData.null %} - - {%- if fieldData.type in ['date', 'timestampfractional'] %} -
- -
- {%- else %} - {{ fieldData.type }} Not Implemented in vueTemplate Baked {{- "\n" }} - {%- endif %} - {{- "\n" }} - {%- elseif fieldData.type in ['text'] %} -
- - -
{{- "\n" }} - {{- "\n" }} - {%- else %} -
- - {{- "\n" }} - {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %} -
{{ vueVar }}
-
- {{- "\n" }} + {{- "\n" }} + {%- elseif fieldData.type in ['text'] %} +
+ + +
{{- "\n" }} + {{- "\n" }} + {%- elseif fieldData.type in ['string'] %} +
+ + {{- "\n" }} + {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %} +
{{ vueVar }}
+
+ {%- elseif fieldData.type in ['boolean'] %} +
+ + + {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %}{{- "\n" }} +
{{ vueVar }}
+
+ {%- else %} +
+ + {{- "\n" }} + {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %} +
{{ vueVar }}
+
+ {{- "\n" }} + {%- endif %} {%- endif %} {%- endif %} - {%- endif %} - {%- endfor %} - {{- "\n" }} - {%- if associations.BelongsToMany is defined %} - {%- for assocName, assocData in associations.BelongsToMany %} -
- - -
{%- endfor %} - {% endif %} + {{- "\n" }} + {%- if associations.BelongsToMany is defined %} + {%- for assocName, assocData in associations.BelongsToMany %} +
+ + +
+ {%- endfor %} + {% endif %} {{- "\n" }}
From 36d185e5f376558a091497c8f03a1cabf892e9ec Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 2 Sep 2024 12:11:43 +0200 Subject: [PATCH 4/8] add on method delete link function confirm and csrf token on headers --- templates/bake/Template/view.twig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/bake/Template/view.twig b/templates/bake/Template/view.twig index 2472de1..70152f6 100644 --- a/templates/bake/Template/view.twig +++ b/templates/bake/Template/view.twig @@ -34,6 +34,10 @@ function formatDate(date) { return moment(date).format("YYYY-MM-DD") } +function confirm(){ + return window.confirm("Are you sure?"); +} + onMounted(() => { console.log('Component categories/add onMounted hook called') }) @@ -132,7 +136,7 @@ onMounted(() => { View Edit - Delete + Delete From 447bc79c26252fdb38d46bbc6912315935f6b0ef Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 2 Sep 2024 15:14:46 +0200 Subject: [PATCH 5/8] add boolean on pages table to bake template form with checkbox --- config/sql/example(postgresql).psql | 1 + 1 file changed, 1 insertion(+) diff --git a/config/sql/example(postgresql).psql b/config/sql/example(postgresql).psql index 4cd7f59..057452e 100644 --- a/config/sql/example(postgresql).psql +++ b/config/sql/example(postgresql).psql @@ -27,6 +27,7 @@ CREATE TABLE public.pages ( modified timestamp NOT NULL, category_id int4 NULL, published_date date NULL, + active bool DEFAULT false NULL, CONSTRAINT pages_pkey PRIMARY KEY (id) ); From 78b99ae2186d8130f41162f206a163996d9d589a Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 2 Sep 2024 15:22:43 +0200 Subject: [PATCH 6/8] add searchable functionality and placeholder to Multiselect when user on belognsTo and belongsToMany --- templates/bake/element/form.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/bake/element/form.twig b/templates/bake/element/form.twig index 25842de..db1d701 100644 --- a/templates/bake/element/form.twig +++ b/templates/bake/element/form.twig @@ -206,9 +206,9 @@ {%- set optionsData = assocData['variable'] %} {%- endif %} {%- endfor %} - {{- "\n" }} + {{- "\n" }} {%- else %} - {{- "\n" }} + {{- "\n" }} {%- endif %} {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %}
{{ vueVar }}
@@ -262,7 +262,7 @@ {%- for assocName, assocData in associations.BelongsToMany %}
- +
{%- endfor %} {% endif %} From f3b3cfb6b1adb227ef9d9844feea1a266856a1f9 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Mon, 2 Sep 2024 15:30:16 +0200 Subject: [PATCH 7/8] fix set array on paam contains on get method for controller baked --- templates/bake/element/Controller/edit.twig | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/templates/bake/element/Controller/edit.twig b/templates/bake/element/Controller/edit.twig index 5ad740f..a801c77 100644 --- a/templates/bake/element/Controller/edit.twig +++ b/templates/bake/element/Controller/edit.twig @@ -12,38 +12,38 @@ {% set belongsTo = Bake.aliasExtractor(modelObj, 'BelongsTo') %} {% set belongsToMany = Bake.aliasExtractor(modelObj, 'belongsToMany') %} {% set compact = ["'#{singularName}'"] %} - /** - * Edit method VUE - * - * @param string|null $id {{ singularHumanName }} id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. - * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. - */ - public function edit($id = null) - { - $errors = []; - ${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: [{{ Bake.exportArray(belongsToMany)|raw }}]); - if ($this->request->is(['patch', 'post', 'put'])) { - ${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->getRequest()->getData()); - if ($this->{{ currentModelName }}->save(${{ singularName }})) { - $this->Flash->set( - __('The {{ singularHumanName|lower }} has been saved.'), - ['element' => 'success', 'key' => 'alert'] - ); +/** +* Edit method VUE +* +* @param string|null $id {{ singularHumanName }} id. +* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. +* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. +*/ +public function edit($id = null) +{ +$errors = []; +${{ singularName }} = $this->{{ currentModelName }}->get($id, contain: {{ Bake.exportArray(belongsToMany)|raw }}); +if ($this->request->is(['patch', 'post', 'put'])) { +${{ singularName }} = $this->{{ currentModelName }}->patchEntity(${{ singularName }}, $this->getRequest()->getData()); +if ($this->{{ currentModelName }}->save(${{ singularName }})) { +$this->Flash->set( +__('The {{ singularHumanName|lower }} has been saved.'), +['element' => 'success', 'key' => 'alert'] +); - return $this->redirect(['action' => 'index']); - } - $errors = ${{ singularName }}->getErrors(); - $this->Flash->set( - __('The {{ singularHumanName|lower }} could not be saved. Please, try again.'), - ['element' => 'danger', 'key' => 'alert'] - ); - } +return $this->redirect(['action' => 'index']); +} +$errors = ${{ singularName }}->getErrors(); +$this->Flash->set( +__('The {{ singularHumanName|lower }} could not be saved. Please, try again.'), +['element' => 'danger', 'key' => 'alert'] +); +} {% set associations = Bake.aliasExtractor(modelObj, 'BelongsTo') %} {%- for assoc in associations %} {%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %} {%- set otherPlural = otherName|variable %} - ${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', ['limit' => 200])->toArray(); + ${{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('list', ['limit' => 200])->toArray(); {{- "\n" }} {%- set compact = compact|merge(["'#{otherPlural}'"]) %} {% endfor %} @@ -51,11 +51,11 @@ {%- for assoc in associations %} {%- set otherName = Bake.getAssociatedTableAlias(modelObj, assoc) %} {%- set otherPlural = otherName|variable %} - $options_{{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('all', ['limit' => 200])->disableHydration()->toArray(); + $options_{{ otherPlural }} = $this->{{ currentModelName }}->{{ otherName }}->find('all', ['limit' => 200])->disableHydration()->toArray(); {{- "\n" }} - {%- set optionsOtherPlural = 'options_' ~ otherPlural %} - {%- set compact = compact|merge(["'#{optionsOtherPlural}'"]) %} + {%- set optionsOtherPlural = 'options_' ~ otherPlural %} + {%- set compact = compact|merge(["'#{optionsOtherPlural}'"]) %} {% endfor %} {%- set compact = compact|merge(["'errors'"]) %} - $this->set(compact({{ compact|join(', ')|raw }})); - } +$this->set(compact({{ compact|join(', ')|raw }})); +} From 911d4dc71a66a397e1514bf42b4fa13688ed36e5 Mon Sep 17 00:00:00 2001 From: Andres Campanario Date: Tue, 10 Sep 2024 13:51:24 +0200 Subject: [PATCH 8/8] add style select-valid(green) to select without error --- templates/bake/element/form.twig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/templates/bake/element/form.twig b/templates/bake/element/form.twig index db1d701..1361911 100644 --- a/templates/bake/element/form.twig +++ b/templates/bake/element/form.twig @@ -176,6 +176,9 @@ background-position: right calc(.375em + .1875rem) center; background-size: calc(.75em + .375rem) calc(.75em + .375rem); } + .was-validated .select-valid { + border-color: #198754; + } .invalid-feedback { display: block; } @@ -206,9 +209,9 @@ {%- set optionsData = assocData['variable'] %} {%- endif %} {%- endfor %} - {{- "\n" }} + {{- "\n" }} {%- else %} - {{- "\n" }} + {{- "\n" }} {%- endif %} {%- set vueVar = "{{ props.errors." ~ field ~ "._empty }}" %}
{{ vueVar }}
@@ -262,7 +265,7 @@ {%- for assocName, assocData in associations.BelongsToMany %}
- +
{%- endfor %} {% endif %}