changeset 31:8dd668020310 codex

started converting too bootstrap, also better support for casts
author Luka Sitas <sitas.luka.97@gmail.com>
date Tue, 19 Aug 2025 20:34:53 -0400
parents 21439512ba69
children 45f384a24553
files src/Generator/Model/stubs/model.stub src/Generator/View/IndexViewGenerator.php src/Generator/View/snippets/index/header.stub src/Generator/View/snippets/input/date.stub src/Generator/View/stubs/create_edit.stub src/Generator/View/stubs/index.stub src/Generator/View/stubs/show.stub src/Replacer/TableReplacer.php
diffstat 8 files changed, 96 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/src/Generator/Model/stubs/model.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/Model/stubs/model.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -3,6 +3,7 @@
 namespace {{ namespace }};
 
 use Illuminate\Database\Eloquent\SoftDeletes;
+use Wizard\Framework\Models\BaseModel;
 
 class {{ class }} extends BaseModel
 {
@@ -25,6 +26,10 @@
 			# {{ atributeInsertPoint }}
     ];
 
+		protected $casts = [
+			# {{ castInsertPoint }}
+		];
+
 		protected $fillable = [
 			# {{ fillableInsertPoint }}
 		];
--- a/src/Generator/View/IndexViewGenerator.php	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/IndexViewGenerator.php	Tue Aug 19 20:34:53 2025 -0400
@@ -118,7 +118,7 @@
 						$replacements['{{value}}'] = '{{ $item->'.$name.'?->format(\'Y-m-d H:i\') ?? "" }}';
 					}
 					//checkbox
-					elseif(in_array($type, ['tinyint'])) {
+					if(in_array($type, ['tinyint'])) {
 						$replacements['{{valueClass}}'] .= ' text-center';
 						$replacements['{{value}}'] = '{{ $item->' . $name . ' ?? "0" }}';
 					}
--- a/src/Generator/View/snippets/index/header.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/snippets/index/header.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -1,1 +1,1 @@
-<th class="{{headerClass}}">{{header}}</th>
+<th scope="col" class="{{headerClass}}">{{header}}</th>
--- a/src/Generator/View/snippets/input/date.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/snippets/input/date.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -1,6 +1,6 @@
 <x-form.date
 	name="{{fieldName}}"
 	label="{{fieldLabel}}"
-	:value="request('{{fieldName}}', $item?->{{fieldName}} ?? '')"
+	:value="request('{{fieldName}}', $item?->{{fieldName}}?->format('Y-m-d') ?? '')"
 	:required="{{required}}"
 ></x-form.date>
--- a/src/Generator/View/stubs/create_edit.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/stubs/create_edit.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -1,25 +1,25 @@
 <x-app-layout>
     <x-slot name="header">
-        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
+        <h2 class="fw-semibold fs-4 text-dark">
             {{ isset($item) ? 'Edit' : 'Create' }} {{ ucfirst('{{ modelVariable }}') }}
         </h2>
     </x-slot>
 
-    <div class="py-12">
-        <div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
-            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
-                <form method="POST" action="{{ isset($item) ? route('{{ tableName }}.update', $item) : route('{{ tableName }}.store') }}">
-                    @csrf
-                    @if(isset($item))
+    <div class="py-5">
+        <div class="container">
+            <div class="bg-white shadow-sm rounded p-4">
+                    <form method="POST" action="{{ isset($item) ? route('{{ tableName }}.update', $item) : route('{{ tableName }}.store') }}">
+										@csrf
+                    @if (isset($item))
                         @method('PUT')
                     @endif
 
 										{{ fieldsInsertPoint }}
-										
 
-                    <div class="flex justify-end">
-                        <a href="{{ route('{{ tableName }}.index') }}" class="mr-2 px-4 py-2 bg-gray-200 rounded hover:bg-gray-300">Back</a>
-                        <button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
+                    <div class="d-flex justify-content-end">
+                        <a href="{{ route('{{ tableName }}.index') }}"
+                            class="btn btn-secondary me-2">Back</a>
+                        <button type="submit" class="btn btn-primary">
                             {{ isset($item) ? 'Update' : 'Create' }}
                         </button>
                     </div>
--- a/src/Generator/View/stubs/index.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/stubs/index.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -1,50 +1,50 @@
 <x-app-layout>
     <x-slot name="header">
-        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
+        <h2 class="fw-semibold fs-4 text-dark">
             All {{ Str::plural(ucfirst('{{ modelVariable }}')) }}
         </h2>
     </x-slot>
 
-    <div class="py-12">
-        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
-            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
-                <div class="flex items-center justify-between mb-4">
-                    <span></span>
-                    <a href="{{ route('{{ tableName }}.create') }}" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
-                        + New {{ ucfirst('{{ modelVariable }}') }}
-                    </a>
-                </div>
-                <table class="w-full text-left border-collapse table-auto">
-                    <thead>
-                        <tr class="border-b">
-														{{ headerInsertPoint }}
-                            <th class=" p-2">Actions</th>
-                        </tr>
-                    </thead>
-                    <tbody>
-                        @forelse ($items as $item)
-                            <tr class="border-b">
-																{{ valueInsertPoint }}
-                                <td class="p-2">
-																	<div class="flex space-x-2"> 
-																		<a href="{{ route('{{ tableName }}.show', $item) }}" class="text-blue-600 hover:underline">View</a>
-                                    <a href="{{ route('{{ tableName }}.edit', $item) }}" class="text-yellow-600 hover:underline">Edit</a>
-                                    <form action="{{ route('{{ tableName }}.destroy', $item) }}" method="POST" class="inline">
-                                        @csrf
-                                        @method('DELETE')
-                                        <button type="submit" class="text-red-600 hover:underline" onclick="return confirm('Delete?')">Delete</button>
-                                    </form>
-																	</div>
-                                </td>
-                            </tr>
-                        @empty
-                            <tr>
-                                <td class="p-2" colspan="{{ colCount }}">No {{ tableName }} found.</td>
-                            </tr>
-                        @endforelse
-                    </tbody>
-                </table>
-            </div>
+    <div class="py-5">
+        <div class="container">
+            <div class="bg-white shadow-sm rounded p-4">
+            	    <div class="d-flex align-items-center justify-content-between mb-3">
+            	        <span></span>
+            	        <a href="{{ route('{{ tableName }}.create') }}" class="btn btn-primary">
+            	            + New {{ ucfirst('{{ modelVariable }}') }}
+            	        </a>
+            	    </div>
+            	    <table class="table table-hover">
+            	        <thead>
+            	            <tr>
+            	                {{ headerInsertPoint }}
+            	                <th scope="col">Actions</th>
+            	            </tr>
+            	        </thead>
+            	        <tbody>
+            	            @forelse ($items as $item)
+            	                <tr>
+            	                    {{ valueInsertPoint }}
+            	                    <td>
+            	                        <div class="d-flex gap-2"> 
+            	                            <a href="{{ route('{{ tableName }}.show', $item) }}" class="text-primary">View</a>
+            	                            <a href="{{ route('{{ tableName }}.edit', $item) }}" class="text-warning">Edit</a>
+            	                            <form action="{{ route('{{ tableName }}.destroy', $item) }}" method="POST" class="d-inline">
+            	                                @csrf
+            	                                @method('DELETE')
+            	                                <button type="submit" class="btn btn-link text-danger p-0" onclick="return confirm('Delete?')">Delete</button>
+            	                            </form>
+            	                        </div>
+            	                    </td>
+            	                </tr>
+            	            @empty
+            	                <tr>
+            	                    <td colspan="{{ colCount }}">No {{ tableName }} found.</td>
+            	                </tr>
+            	            @endforelse
+            	        </tbody>
+            	    </table>
+            	</div>
         </div>
     </div>
 </x-app-layout>
--- a/src/Generator/View/stubs/show.stub	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Generator/View/stubs/show.stub	Tue Aug 19 20:34:53 2025 -0400
@@ -1,24 +1,24 @@
 <x-app-layout>
     <x-slot name="header">
-        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
+        <h2 class="fw-semibold fs-4 text-dark">
             {{ ucfirst('{{ modelVariable }}') }} Details
         </h2>
     </x-slot>
 
-    <div class="py-12">
-        <div class="max-w-2xl mx-auto sm:px-6 lg:px-8">
-            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
-                <div class="space-y-4">
+    <div class="py-5">
+        <div class="container">
+            <div class="bg-white shadow-sm rounded p-4">
+                <div class="mb-3">
                     @foreach($fields as $field)
-                        <div>
-                            <span class="font-semibold">{{ ucfirst($field) }}:</span>
-                            <span class="ml-2">{{ $item->$field }}</span>
+                        <div class="mb-2">
+                            <span class="fw-semibold">{{ ucfirst($field) }}:</span>
+                            <span class="ms-2">{{ $item->$field }}</span>
                         </div>
                     @endforeach
                 </div>
-                <div class="flex justify-end mt-6">
-                    <a href="{{ route('{{ tableName }}.edit', $item) }}" class="mr-2 px-4 py-2 bg-yellow-400 text-white rounded hover:bg-yellow-500">Edit</a>
-                    <a href="{{ route('{{ tableName }}.index') }}" class="px-4 py-2 bg-gray-200 rounded hover:bg-gray-300">Back</a>
+                <div class="d-flex justify-content-end mt-4">
+                    <a href="{{ route('{{ tableName }}.edit', $item) }}" class="me-2 btn btn-warning text-white">Edit</a>
+                    <a href="{{ route('{{ tableName }}.index') }}" class="btn btn-secondary">Back</a>
                 </div>
             </div>
         </div>
--- a/src/Replacer/TableReplacer.php	Wed Jun 18 09:04:59 2025 -0400
+++ b/src/Replacer/TableReplacer.php	Tue Aug 19 20:34:53 2025 -0400
@@ -44,6 +44,30 @@
     /**
      * Get a string representation of table attributes.
      */
+    protected function getCasts(): string
+    {
+        $insert = '';
+        foreach ($this->get_columns() as $column) {
+            if (in_array($column['name'], $this->columns_to_ignore)) {
+                continue;
+            }
+						$type = $column['type_name'];
+						//date
+						if(in_array($type, ['date'])) {
+							$insert .= sprintf("'%s' => 'date:Y-m-d',", $column['name'])."\n";
+						}
+						//time
+						if(in_array($type, ['timestamp'])) {
+							$insert .= sprintf("'%s' => 'date:Y-m-d H:i',", $column['name'])."\n";
+						}
+        }
+
+        return $insert;
+    }
+
+    /**
+     * Get a string representation of table attributes.
+     */
     protected function getAttributes(): string
     {
         $insert = '';
@@ -112,6 +136,7 @@
         return [
             '// {{ valuesForCreation }}' => $this->getValuesForCreation(),
             '# {{ attributeInsertPoint }}' => $this->getAttributes(),
+            '# {{ castInsertPoint }}' => $this->getCasts(),
             '# {{ fillableInsertPoint }}' => $this->getFillable(),
             '// {{ valuesForValidation }}' => $this->getValuesForValidation(),
         ];