From 08e8cc7d088c47379ecdc91f047eeb041618ac45 Mon Sep 17 00:00:00 2001 From: albert1413 Date: Tue, 10 Dec 2024 19:15:08 +0100 Subject: [PATCH 1/4] feat: CRUD elementTypes --- .../Admin/ElementTypeController.php | 81 +++++++++++++++++++ app/src/app/Models/ElementType.php | 32 ++++++++ .../app/Views/Admin/ElementType/Create.php | 40 +++++++++ app/src/app/Views/Admin/ElementType/Edit.php | 66 +++++++++++++++ app/src/app/Views/Admin/ElementTypes.php | 62 ++++++++++++++ app/src/routes/admin.php | 33 ++++++++ 6 files changed, 314 insertions(+) create mode 100644 app/src/app/Controllers/Admin/ElementTypeController.php create mode 100644 app/src/app/Models/ElementType.php create mode 100644 app/src/app/Views/Admin/ElementType/Create.php create mode 100644 app/src/app/Views/Admin/ElementType/Edit.php create mode 100644 app/src/app/Views/Admin/ElementTypes.php diff --git a/app/src/app/Controllers/Admin/ElementTypeController.php b/app/src/app/Controllers/Admin/ElementTypeController.php new file mode 100644 index 00000000..2cba192b --- /dev/null +++ b/app/src/app/Controllers/Admin/ElementTypeController.php @@ -0,0 +1,81 @@ + 'Admin/ElementTypes', + 'title' => 'Manage Elements Types', + 'layout' => 'Admin/AdminLayout', + 'data' => ['elementTypes' => $elementTypes], + ]); + } + + public function create($queryParams) + { + //$elements = Element::findAll(); + View::render([ + 'view' => 'Admin/ElementType/Create', + 'title' => 'Add Element Type', + 'layout' => 'Admin/AdminLayout', + 'data' => [ + //'elements' => $elements, + ], + ]); + } + + public function store($postData) + { + $elementType = new ElementType(); + $elementType->name = $postData['name']; + $elementType->description = $postData['description']; + + $elementType->save(); + + Session::set('success', 'Element-Type created successfully'); + + header('Location: /admin/elementTypes'); + } + + public function edit($id, $queryParams) + { + $elementType = ElementType::find($id); + View::render([ + 'view' => 'Admin/ElementType/Edit', + 'title' => 'Edit Element Type', + 'layout' => 'Admin/AdminLayout', + 'data' => ['elementType' => $elementType], + ]); + } + + public function update($id, $postData) + { + $elementType = ElementType::find($id); + $elementType->name = $postData['name']; + $elementType->description = $postData['description']; + $elementType->save(); + + Session::set('success', 'Element-Type updated successfully'); + + header('Location: /admin/elementTypes'); + } + + public function destroy($id, $queryParams) + { + $elementType = ElementType::find($id); + $elementType->delete(); + + Session::set('success', 'Element-Type deleted successfully'); + + header('Location: /admin/elementTypes'); + } +} diff --git a/app/src/app/Models/ElementType.php b/app/src/app/Models/ElementType.php new file mode 100644 index 00000000..c5071c4f --- /dev/null +++ b/app/src/app/Models/ElementType.php @@ -0,0 +1,32 @@ +id = $data['id']; + $elementType->name = $data['name']; + $elementType->description = $data['description']; + $elementType->created_at = $data['created_at']; + + return $elementType; + } + + //public function element(): Element + //{ + // return $this->belongsTo(Element::class, 'element_id'); + //} + +} diff --git a/app/src/app/Views/Admin/ElementType/Create.php b/app/src/app/Views/Admin/ElementType/Create.php new file mode 100644 index 00000000..e9a1cb57 --- /dev/null +++ b/app/src/app/Views/Admin/ElementType/Create.php @@ -0,0 +1,40 @@ +
+ + + + + + Return to Element-Types + +
+ +
+

Create Element Type

+
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+
+
diff --git a/app/src/app/Views/Admin/ElementType/Edit.php b/app/src/app/Views/Admin/ElementType/Edit.php new file mode 100644 index 00000000..52ab9183 --- /dev/null +++ b/app/src/app/Views/Admin/ElementType/Edit.php @@ -0,0 +1,66 @@ +
+ + + + + + Return to Elements + +
+ +
+

Edit Element

+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+
+
diff --git a/app/src/app/Views/Admin/ElementTypes.php b/app/src/app/Views/Admin/ElementTypes.php new file mode 100644 index 00000000..0ee80015 --- /dev/null +++ b/app/src/app/Views/Admin/ElementTypes.php @@ -0,0 +1,62 @@ + + + + + + +
+ + Create Element Type + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
IDNameDescriptionActions
+ getId(); ?> + name; ?> + description; ?> + + + + + + + + + + + + +
+
diff --git a/app/src/routes/admin.php b/app/src/routes/admin.php index 81f96ffc..a6062126 100644 --- a/app/src/routes/admin.php +++ b/app/src/routes/admin.php @@ -3,6 +3,7 @@ use App\Controllers\Admin\ContractController; use App\Controllers\Admin\DashboardController; use App\Controllers\Admin\ElementController; +use App\Controllers\Admin\ElementTypeController; use App\Controllers\Admin\IncidenceController; use App\Controllers\Admin\TaskTypeController; use App\Controllers\Admin\TreeTypeController; @@ -137,6 +138,27 @@ 'method' => 'destroy', 'middlewares' => [AdminMiddleware::class], ], + // ElementType + '/admin/elementTypes' => [ + 'controller' => ElementTypeController::class, + 'method' => 'index', + 'middlewares' => [AdminMiddleware::class], + ], + '/admin/elementType/create' => [ + 'controller' => ElementTypeController::class, + 'method' => 'create', + 'middlewares' => [AdminMiddleware::class], + ], + '/admin/elementType/:id/edit' => [ + 'controller' => ElementTypeController::class, + 'method' => 'edit', + 'middlewares' => [AdminMiddleware::class], + ], + '/admin/elementType/:id/delete' => [ + 'controller' => ElementTypeController::class, + 'method' => 'destroy', + 'middlewares' => [AdminMiddleware::class], + ], // === TaskTypes GET Routes '/admin/task-types' => [ 'controller' => TaskTypeController::class, @@ -202,6 +224,17 @@ 'method' => 'update', 'middlewares' => [AdminMiddleware::class], ], + // === Element-Types POST Routes + '/admin/elementType/store' => [ + 'controller' => ElementTypeController::class, + 'method' => 'store', + 'middlewares' => [AdminMiddleware::class], + ], + '/admin/elementType/:id/update' => [ + 'controller' => ElementTypeController::class, + 'method' => 'update', + 'middlewares' => [AdminMiddleware::class], + ], // === WorkOrders POST Routes '/admin/work-order/store' => [ 'controller' => WorkOrderController::class, From 00492f810978520ec3bdfcf35e68cd4c35e20dcb Mon Sep 17 00:00:00 2001 From: albert1413 Date: Tue, 10 Dec 2024 21:21:15 +0100 Subject: [PATCH 2/4] feat: update ElementType --- .../app/Views/Admin/ElementType/Create.php | 8 ++-- app/src/app/Views/Admin/ElementType/Edit.php | 41 ++++--------------- app/src/app/Views/Admin/ElementTypes.php | 6 +-- 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/app/src/app/Views/Admin/ElementType/Create.php b/app/src/app/Views/Admin/ElementType/Create.php index e9a1cb57..2bbe93ee 100644 --- a/app/src/app/Views/Admin/ElementType/Create.php +++ b/app/src/app/Views/Admin/ElementType/Create.php @@ -1,5 +1,5 @@
- @@ -11,7 +11,7 @@ class="bg-blue-500 hover:bg-blue-600 text-white font-medium py-2 px-4 rounded-lg

Create Element Type

-
+
@@ -23,8 +23,8 @@ class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none foc
- - Description +
diff --git a/app/src/app/Views/Admin/ElementType/Edit.php b/app/src/app/Views/Admin/ElementType/Edit.php index 52ab9183..1d0278e8 100644 --- a/app/src/app/Views/Admin/ElementType/Edit.php +++ b/app/src/app/Views/Admin/ElementType/Edit.php @@ -1,5 +1,5 @@
-

Edit Element

+

Edit Element Type

- +
- - -
- - -
- - -
- - -
- - -
- - -
- - Description +
+