From 36b3f4f38773e74c23a7734d6d10e87295465ba5 Mon Sep 17 00:00:00 2001 From: JdSeus Date: Thu, 4 Jul 2024 13:34:53 -0300 Subject: [PATCH 1/5] Preparation of Three Columns List --- .../formfields/three_columns_list.blade.php | 145 ++++++++++++++++++ src/FormFields/ThreeColumnsListHandler.php | 18 +++ .../ContentTypes/ThreeColumnsList.php | 14 ++ src/Http/Controllers/Controller.php | 4 + src/VoyagerServiceProvider.php | 1 + 5 files changed, 182 insertions(+) create mode 100644 resources/views/formfields/three_columns_list.blade.php create mode 100644 src/FormFields/ThreeColumnsListHandler.php create mode 100644 src/Http/Controllers/ContentTypes/ThreeColumnsList.php diff --git a/resources/views/formfields/three_columns_list.blade.php b/resources/views/formfields/three_columns_list.blade.php new file mode 100644 index 0000000000..b427601477 --- /dev/null +++ b/resources/views/formfields/three_columns_list.blade.php @@ -0,0 +1,145 @@ +
+@php + $currentThreeColumnsList = isset($dataTypeContent->{$row->field}) ? $dataTypeContent->{$row->field} : '{}'; + $currentThreeColumnsList = json_decode($currentThreeColumnsList, true); +@endphp +
+
+ +
+ + + + + + + + + + @if(isset($currentThreeColumnsList) && (count($currentThreeColumnsList))) + @foreach($currentThreeColumnsList as $value) + + + + + + @endforeach + @else + + + + + + @endif + +
{{ __('voyager::generic.column_first') }}{{ __('voyager::generic.column_second') }}{{ __('voyager::generic.action') }}
{{ $value['0'] }}{{ $value['1'] }} + + + +
+ + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/FormFields/ThreeColumnsListHandler.php b/src/FormFields/ThreeColumnsListHandler.php new file mode 100644 index 0000000000..fe3f5bca6d --- /dev/null +++ b/src/FormFields/ThreeColumnsListHandler.php @@ -0,0 +1,18 @@ + $row, + 'options' => $options, + 'dataType' => $dataType, + 'dataTypeContent' => $dataTypeContent, + ]); + } +} diff --git a/src/Http/Controllers/ContentTypes/ThreeColumnsList.php b/src/Http/Controllers/ContentTypes/ThreeColumnsList.php new file mode 100644 index 0000000000..b570d35996 --- /dev/null +++ b/src/Http/Controllers/ContentTypes/ThreeColumnsList.php @@ -0,0 +1,14 @@ +request->input($this->row->field) ?? '{}'; + } +} diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php index a37e26c276..17e5d3bf92 100644 --- a/src/Http/Controllers/Controller.php +++ b/src/Http/Controllers/Controller.php @@ -21,6 +21,7 @@ use TCG\Voyager\Http\Controllers\ContentTypes\SelectMultiple; use TCG\Voyager\Http\Controllers\ContentTypes\Text; use TCG\Voyager\Http\Controllers\ContentTypes\Timestamp; +use TCG\Voyager\Http\Controllers\ContentTypes\ThreeColumnsList; use TCG\Voyager\Traits\AlertsMessages; use Validator; @@ -284,6 +285,9 @@ public function getContentBasedOnType(Request $request, $slug, $row, $options = /********** TIMESTAMP TYPE **********/ case 'timestamp': return (new Timestamp($request, $slug, $row, $options))->handle(); + /********** THREE COLUMNS LIST TYPE **********/ + case 'three_columns_list': + return (new ThreeColumnsList($request, $slug, $row, $options))->handle(); /********** COORDINATES TYPE **********/ case 'coordinates': return (new Coordinates($request, $slug, $row, $options))->handle(); diff --git a/src/VoyagerServiceProvider.php b/src/VoyagerServiceProvider.php index 053556c1ad..3d1a775521 100644 --- a/src/VoyagerServiceProvider.php +++ b/src/VoyagerServiceProvider.php @@ -332,6 +332,7 @@ protected function registerFormFields() 'text_area', 'time', 'timestamp', + 'three_columns_list', 'hidden', 'coordinates', ]; From b119cf8c6a4bc05016029d0f817c9f459c85d1d4 Mon Sep 17 00:00:00 2001 From: JdSeus Date: Thu, 4 Jul 2024 13:43:24 -0300 Subject: [PATCH 2/5] Three Columns is now working --- .../views/formfields/three_columns_list.blade.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/resources/views/formfields/three_columns_list.blade.php b/resources/views/formfields/three_columns_list.blade.php index b427601477..6d803980c2 100644 --- a/resources/views/formfields/three_columns_list.blade.php +++ b/resources/views/formfields/three_columns_list.blade.php @@ -12,6 +12,7 @@ {{ __('voyager::generic.column_first') }} {{ __('voyager::generic.column_second') }} + {{ __('voyager::generic.column_third') }} {{ __('voyager::generic.action') }} @@ -21,6 +22,7 @@ {{ $value['0'] }} {{ $value['1'] }} + {{ $value['2'] }} @@ -30,6 +32,7 @@ @endforeach @else + @@ -52,6 +55,7 @@ function threeColumnsListAddRow{{ $row->field }}() { const table = document.querySelector('#threeColumnsListContainer-{{ $row->field }} .three-columns-list-table tbody'); const newRow = table.insertRow(); newRow.innerHTML = ` + @@ -61,7 +65,8 @@ function threeColumnsListAddRow{{ $row->field }}() { `; attachCellEventListeners{{ $row->field }}(newRow.cells[0]); - attachCellEventListeners{{ $row->field }}(newRow.cells[1]); // Attach event listener to the new second column cell + attachCellEventListeners{{ $row->field }}(newRow.cells[1]); + attachCellEventListeners{{ $row->field }}(newRow.cells[2]); updateJson{{ $row->field }}(); // Update JSON immediately after adding a row updateMoveButtons{{ $row->field }}(); // Update move buttons state } @@ -75,8 +80,9 @@ function updateJson{{ $row->field }}() { table.querySelectorAll('tr').forEach((row, index) => { const column1 = row.cells[0].innerText.trim(); const column2 = row.cells[1].innerText.trim(); - if (column1 !== '' || column2 !== '') { - json[index] = { "0": column1, "1": column2 }; + const column3 = row.cells[2].innerText.trim(); + if (column1 !== '' || column2 !== '' || column3 !== '') { + json[index] = { "0": column1, "1": column2, "2": column3 }; } }); @@ -137,7 +143,8 @@ function updateMoveButtons{{ $row->field }}() { // Attach initial event listeners to existing cells and update move buttons document.querySelectorAll('#threeColumnsListContainer-{{ $row->field }} .three-columns-list-table tbody tr').forEach(row => { attachCellEventListeners{{ $row->field }}(row.cells[0]); - attachCellEventListeners{{ $row->field }}(row.cells[1]); // Attach event listener to the second column cells + attachCellEventListeners{{ $row->field }}(row.cells[1]); + attachCellEventListeners{{ $row->field }}(row.cells[2]); }); updateMoveButtons{{ $row->field }}(); From c4f2ec934582529564883706926e0cae1e7890c4 Mon Sep 17 00:00:00 2001 From: JdSeus Date: Thu, 4 Jul 2024 13:45:51 -0300 Subject: [PATCH 3/5] Add Three Columns List to Browse and Read --- resources/views/bread/browse.blade.php | 21 +++++++++++++++++++++ resources/views/bread/read.blade.php | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/resources/views/bread/browse.blade.php b/resources/views/bread/browse.blade.php index 3498a56443..7832d1bfb5 100644 --- a/resources/views/bread/browse.blade.php +++ b/resources/views/bread/browse.blade.php @@ -185,6 +185,27 @@ @elseif($row->type == 'text_area') @include('voyager::multilingual.input-hidden-bread-browse')
{{ mb_strlen( $data->{$row->field} ) > 200 ? mb_substr($data->{$row->field}, 0, 200) . ' ...' : $data->{$row->field} }}
+ @elseif($row->type == 'three_columns_list') + @php + $currentThreeColumnsList = isset($data->{$row->field}) ? $data->{$row->field} : '{}'; + $currentThreeColumnsList = json_decode($currentThreeColumnsList, true); + @endphp + @if(isset($currentThreeColumnsList) && (count($currentThreeColumnsList))) +
    + @foreach($currentThreeColumnsList as $values) +
  • + @if(isset($values) && (count($values))) +
      + @foreach($values as $value) +
    1. {{ $value }}
    2. + @endforeach +
    +
    + @endif +
  • + @endforeach +
+ @endif @elseif($row->type == 'file' && !empty($data->{$row->field}) ) @include('voyager::multilingual.input-hidden-bread-browse') @if(json_decode($data->{$row->field}) !== null) diff --git a/resources/views/bread/read.blade.php b/resources/views/bread/read.blade.php index 658f46b401..ebf939457b 100644 --- a/resources/views/bread/read.blade.php +++ b/resources/views/bread/read.blade.php @@ -126,6 +126,27 @@ {{ __('voyager::generic.download') }} @endif + @elseif($row->type == 'three_columns_list') + @php + $currentThreeColumnsList = isset($dataTypeContent->{$row->field}) ? $dataTypeContent->{$row->field} : '{}'; + $currentThreeColumnsList = json_decode($currentThreeColumnsList, true); + @endphp + @if(isset($currentThreeColumnsList) && (count($currentThreeColumnsList))) +
    + @foreach($currentThreeColumnsList as $values) +
  • + @if(isset($values) && (count($values))) +
      + @foreach($values as $value) +
    1. {{ $value }}
    2. + @endforeach +
    +
    + @endif +
  • + @endforeach +
+ @endif @else @include('voyager::multilingual.input-hidden-bread-read')

{{ $dataTypeContent->{$row->field} }}

From e2ca86eee9609347fee7f8041548dbeed3613563 Mon Sep 17 00:00:00 2001 From: JdSeus Date: Thu, 4 Jul 2024 13:51:43 -0300 Subject: [PATCH 4/5] Add Three Columns Translations --- publishable/lang/en/generic.php | 5 +++++ publishable/lang/pt/generic.php | 5 +++++ publishable/lang/pt_br/generic.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/publishable/lang/en/generic.php b/publishable/lang/en/generic.php index 484122f22d..e3b41d1898 100644 --- a/publishable/lang/en/generic.php +++ b/publishable/lang/en/generic.php @@ -5,6 +5,7 @@ 'action' => 'Action', 'actions' => 'Actions', 'add' => 'Add', + 'add_element' => 'Add Element', 'add_folder' => 'Add Folder', 'add_new' => 'Add New', 'all_done' => 'All done', @@ -22,6 +23,10 @@ 'choose_type' => 'Choose Type', 'click_here' => 'Click Here', 'close' => 'Close', + 'column' => 'Column', + 'column_first' => 'First Column', + 'column_second' => 'Second Column', + 'column_third' => 'Third Column', 'compass' => 'Compass', 'created_at' => 'Created at', 'custom' => 'Custom', diff --git a/publishable/lang/pt/generic.php b/publishable/lang/pt/generic.php index f2f1899c86..e387036499 100644 --- a/publishable/lang/pt/generic.php +++ b/publishable/lang/pt/generic.php @@ -5,6 +5,7 @@ 'action' => 'Ação', 'actions' => 'Ações', 'add' => 'Adicionar', + 'add_element' => 'Adicionar Elemento', 'add_folder' => 'Adicionar Pasta', 'add_new' => 'Adicionar', 'all_done' => 'Concluído', @@ -17,6 +18,10 @@ 'choose_type' => 'Escolha o tipo', 'click_here' => 'Clique aqui', 'close' => 'Fechar', + 'column' => 'Coluna', + 'column_first' => 'Primeira Coluna', + 'column_second' => 'Segunda Coluna', + 'column_third' => 'Terceira Coluna', 'compass' => 'Bússola', 'created_at' => 'Criado em', 'custom' => 'Personalizado', diff --git a/publishable/lang/pt_br/generic.php b/publishable/lang/pt_br/generic.php index fb5d440c2c..b9a81a33d2 100644 --- a/publishable/lang/pt_br/generic.php +++ b/publishable/lang/pt_br/generic.php @@ -5,6 +5,7 @@ 'action' => 'Ação', 'actions' => 'Ações', 'add' => 'Adicionar', + 'add_element' => 'Adicionar Elemento', 'add_folder' => 'Adicionar Pasta', 'add_new' => 'Adicionar', 'all_done' => 'Concluído', @@ -22,6 +23,10 @@ 'choose_type' => 'Escolha o tipo', 'click_here' => 'Clique aqui', 'close' => 'Fechar', + 'column' => 'Coluna', + 'column_first' => 'Primeira Coluna', + 'column_seconf' => 'Segunda Coluna', + 'column_third' => 'Terceira Coluna', 'compass' => 'Bússola', 'created_at' => 'Criado em', 'custom' => 'Personalizado', From 4547fd32d451969ff5b665465417580ea438207d Mon Sep 17 00:00:00 2001 From: JdSeus Date: Thu, 4 Jul 2024 13:55:39 -0300 Subject: [PATCH 5/5] Adjust on Typo on PT BR Translation --- publishable/lang/pt_br/generic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publishable/lang/pt_br/generic.php b/publishable/lang/pt_br/generic.php index b9a81a33d2..9e79b9a3bc 100644 --- a/publishable/lang/pt_br/generic.php +++ b/publishable/lang/pt_br/generic.php @@ -25,7 +25,7 @@ 'close' => 'Fechar', 'column' => 'Coluna', 'column_first' => 'Primeira Coluna', - 'column_seconf' => 'Segunda Coluna', + 'column_second' => 'Segunda Coluna', 'column_third' => 'Terceira Coluna', 'compass' => 'Bússola', 'created_at' => 'Criado em',