diff --git a/app/Http/Controllers/Api/PbgTaskController.php b/app/Http/Controllers/Api/PbgTaskController.php new file mode 100644 index 0000000..9fcb780 --- /dev/null +++ b/app/Http/Controllers/Api/PbgTaskController.php @@ -0,0 +1,90 @@ + $request->input("step1Form.uuid"), + "name" => $request->input("step1Form.name"), + "owner_name" => $request->input("step1Form.owner_name"), + "application_type" => $request->input("step1Form.application_type"), + "application_type_name" => $request->input("step1Form.application_type_name"), + "condition" => $request->input("step1Form.condition"), + "registration_number" => $request->input("step1Form.registration_number"), + "document_number" => $request->input("step1Form.document_number"), + "address" => $request->input("step1Form.address"), + "status" => $request->input("step1Form.status"), + "status_name" => $request->input("step1Form.status_name"), + "slf_status" => $request->input("step1Form.slf_status"), + "slf_status_name" => $request->input("step1Form.slf_status_name"), + "function_type" => $request->input("step1Form.function_type"), + "consultation_type" => $request->input("step1Form.consultation_type"), + "due_date" => $request->input("step1Form.due_date"), + "land_certificate_phase" => $request->input("step1Form.land_certificate_phase"), + "task_created_at" => $request->input("step1Form.task_created_at"), + ]); + + return response()->json([ + "success" => true, + "message" => "Step 1 berhasil disimpan!", + "data" => $data + ], 201); + } catch (\Exception $e) { + return response()->json([ + "success" => false, + "message" => "Gagal menyimpan data", + "error" => $e->getMessage() + ], 500); + } + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } + + protected function validatePbgTask(Request $request){ + return $request->validate([ + "uuid" => $request->input("step1Form.uuid"), + ]); + } +} diff --git a/app/Http/Controllers/Api/RequestAssignmentController.php b/app/Http/Controllers/Api/RequestAssignmentController.php index 10d4319..20d3754 100644 --- a/app/Http/Controllers/Api/RequestAssignmentController.php +++ b/app/Http/Controllers/Api/RequestAssignmentController.php @@ -14,7 +14,7 @@ class RequestAssignmentController extends Controller */ public function index(Request $request) { - $query = PbgTask::query(); + $query = PbgTask::query()->orderBy('id', 'desc'); if($request->has('search') && !empty($request->get("search"))){ $query->where('name', 'LIKE', '%'.$request->get('search').'%'); } diff --git a/app/Http/Controllers/RequestAssignment/PbgTaskController.php b/app/Http/Controllers/RequestAssignment/PbgTaskController.php index 395ca33..d2e0cdf 100644 --- a/app/Http/Controllers/RequestAssignment/PbgTaskController.php +++ b/app/Http/Controllers/RequestAssignment/PbgTaskController.php @@ -12,7 +12,7 @@ class PbgTaskController extends Controller */ public function index() { - return view('request-assignment.index'); + return view('pbg_task.index'); } /** @@ -20,7 +20,7 @@ class PbgTaskController extends Controller */ public function create() { - // + return view("pbg_task.create"); } /** @@ -28,7 +28,7 @@ class PbgTaskController extends Controller */ public function store(Request $request) { - // + } /** @@ -36,7 +36,7 @@ class PbgTaskController extends Controller */ public function show(string $id) { - // + return view("pbg_task.show"); } /** @@ -44,7 +44,7 @@ class PbgTaskController extends Controller */ public function edit(string $id) { - // + return view("pbg_task.edit"); } /** diff --git a/app/Http/Requests/PbgTaskMultiStepRequest.php b/app/Http/Requests/PbgTaskMultiStepRequest.php new file mode 100644 index 0000000..e76af85 --- /dev/null +++ b/app/Http/Requests/PbgTaskMultiStepRequest.php @@ -0,0 +1,62 @@ +|string> + */ + public function rules() + { + return [ + // rules step 1 + "step1Form.uuid" => "required", + "step1Form.name" => "nullable|string|max:255", + "step1Form.owner_name" => "nullable|string|max:255", + "step1Form.application_type" => "nullable|string|max:255", + "step1Form.application_type_name" => "nullable|string|max:255", + "step1Form.condition" => "nullable|string|max:255", + "step1Form.registration_number" => "nullable|string|max:255", + "step1Form.document_number" => "nullable|string|max:255", + "step1Form.address" => "nullable|string|max:255", + "step1Form.status" => "nullable|integer", + "step1Form.status_name" => "nullable|string|max:255", + "step1Form.slf_status" => "nullable|string|max:255", + "step1Form.slf_status_name" => "nullable|string|max:255", + "step1Form.function_type" => "nullable|string|max:255", + "step1Form.consultation_type" => "nullable|string|max:255", + "step1Form.due_date" => "nullable|date", + "step1Form.land_certificate_phase" => "nullable|boolean", + "step1Form.task_created_at" => "nullable|date", + ]; + } + + public function messages() + { + return [ + // message step 1 + "step1Form.uuid.required" => "UUID wajib diisi.", + "step1Form.uuid.uuid" => "Format UUID tidak valid.", + "step1Form.name.max" => "Nama tidak boleh lebih dari 255 karakter.", + "step1Form.owner_name.max" => "Nama pemilik tidak boleh lebih dari 255 karakter.", + "step1Form.registration_number.max" => "Nomor registrasi tidak boleh lebih dari 255 karakter.", + "step1Form.document_number.max" => "Nomor dokumen tidak boleh lebih dari 255 karakter.", + "step1Form.status.integer" => "Status harus berupa angka.", + "step1Form.due_date.date" => "Tanggal jatuh tempo tidak valid.", + "step1Form.land_certificate_phase.boolean" => "Fase sertifikat tanah harus berupa true/false.", + ]; + } +} diff --git a/resources/js/pbg-task/create.js b/resources/js/pbg-task/create.js new file mode 100644 index 0000000..ff984d4 --- /dev/null +++ b/resources/js/pbg-task/create.js @@ -0,0 +1,132 @@ +import GlobalConfig from "../global-config.js"; + +class MultiFormCreatePBG { + constructor() { + this.currentStep = 1; + this.totalSteps = 4; + this.formData = {}; // Menyimpan data dari semua langkah + } + + init() { + document + .getElementById("nextStep") + .addEventListener("click", () => this.nextStep()); + + document + .getElementById("prevStep") + .addEventListener("click", () => this.prevStep()); + } + + nextStep() { + if (!this.validateStep()) return; + + this.saveStepData(); + + if (this.currentStep < this.totalSteps) { + document + .getElementById(`step${this.currentStep}`) + .classList.add("d-none"); + + this.currentStep++; + document + .getElementById(`step${this.currentStep}`) + .classList.remove("d-none"); + + document.getElementById( + "stepTitle" + ).innerText = `Step ${this.currentStep}`; + document.getElementById("prevStep").disabled = false; + document.getElementById("nextStep").innerText = + this.currentStep === this.totalSteps ? "Submit" : "Next →"; + } else { + this.submitForm(); // Submit ke API jika sudah step terakhir + } + } + + prevStep() { + if (this.currentStep > 1) { + document + .getElementById(`step${this.currentStep}`) + .classList.add("d-none"); + + this.currentStep--; + document + .getElementById(`step${this.currentStep}`) + .classList.remove("d-none"); + + document.getElementById( + "stepTitle" + ).innerText = `Step ${this.currentStep}`; + document.getElementById("prevStep").disabled = + this.currentStep === 1; + document.getElementById("nextStep").innerText = "Next →"; + } + } + + saveStepData() { + const stepForm = document.querySelector(`#step${this.currentStep}Form`); + const formDataObj = new FormData(stepForm); + + if (!this.formData) { + this.formData = {}; + } + + const stepKey = `step${this.currentStep}Form`; + this.formData[stepKey] = {}; + + for (const [key, value] of formDataObj.entries()) { + this.formData[stepKey][key] = value; + } + + console.log("form data", this.formData); + } + + validateStep() { + const stepForm = document.querySelector(`#step${this.currentStep}Form`); + const inputs = stepForm.querySelectorAll( + "input[required], select[required]" + ); + let isValid = true; + + inputs.forEach((input) => { + if (!input.value) { + input.classList.add("is-invalid"); + isValid = false; + } else { + input.classList.remove("is-invalid"); + } + }); + + return isValid; + } + + async submitForm() { + try { + const response = await fetch( + `${GlobalConfig.apiHost}/api/api-pbg-task`, + { + method: "POST", + headers: { + Authorization: `Bearer ${ + document.querySelector("meta[name='api-token']") + .content + }`, + "Content-Type": "application/json", + }, + body: JSON.stringify(this.formData), + } + ); + + const result = await response.json(); + alert(result.message); + window.location.href = "/pbg-task"; + } catch (error) { + console.error("Error submitting form:", error); + alert("Terjadi kesalahan saat mengirim data."); + } + } +} + +document.addEventListener("DOMContentLoaded", function () { + new MultiFormCreatePBG().init(); +}); diff --git a/resources/js/pbg-task/index.js b/resources/js/pbg-task/index.js new file mode 100644 index 0000000..56dc6d5 --- /dev/null +++ b/resources/js/pbg-task/index.js @@ -0,0 +1,69 @@ +import { Grid } from "gridjs/dist/gridjs.umd.js"; +import "gridjs/dist/gridjs.umd.js"; +import GlobalConfig from "../global-config"; + +class PbgTasks { + init() { + this.initTableRequestAssignment(); + } + + initTableRequestAssignment() { + new Grid({ + columns: [ + "ID", + { name: "Name", width: "15%" }, + { name: "Condition", width: "7%" }, + "Registration Number", + "Document Number", + { name: "Address", width: "30%" }, + "Status", + "Function Type", + "Consultation Type", + { name: "Due Date", width: "7%" }, + ], + search: { + server: { + url: (prev, keyword) => `${prev}?search=${keyword}`, + }, + }, + pagination: { + limit: 15, + server: { + url: (prev, page) => + `${prev}${prev.includes("?") ? "&" : "?"}page=${ + page + 1 + }`, + }, + }, + sort: true, + server: { + url: `${GlobalConfig.apiHost}/api/request-assignments`, + credentials: "include", + headers: { + Authorization: `Bearer ${document + .querySelector('meta[name="api-token"]') + .getAttribute("content")}`, + "Content-Type": "application/json", + }, + then: (data) => + data.data.map((item) => [ + item.id, + item.name, + item.condition, + item.registration_number, + item.document_number, + item.address, + item.status_name, + item.function_type, + item.consultation_type, + item.due_date, + ]), + total: (data) => data.meta.total, + }, + }).render(document.getElementById("table-pbg-tasks")); + } +} + +document.addEventListener("DOMContentLoaded", function (e) { + new PbgTasks().init(); +}); diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index 07160cd..3b545d0 100644 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -106,7 +106,7 @@