diff --git a/app/Http/Controllers/ImportTemplateController.php b/app/Http/Controllers/ImportTemplateController.php index 4ed9f21..4bb9c49 100644 --- a/app/Http/Controllers/ImportTemplateController.php +++ b/app/Http/Controllers/ImportTemplateController.php @@ -28,7 +28,7 @@ public function index() ->join('person', 'person.id', '=', 'clients.person_id') ->orderBy('person.full_name') ->get(['clients.uuid', DB::raw('person.full_name as name')]); - + $segments = Segment::query()->orderBy('name')->get(['id', 'name']); $decisions = Decision::query()->orderBy('name')->get(['id', 'name']); $actions = Action::query()->orderBy('name')->get(['id', 'name']); @@ -693,7 +693,7 @@ public function export(ImportTemplate $template) 'is_active' => $template->is_active, 'reactivate' => $template->reactivate, 'meta' => $template->meta, - 'mappings' => $template->mappings->map(fn($m) => [ + 'mappings' => $template->mappings->map(fn ($m) => [ 'source_column' => $m->source_column, 'entity' => $m->entity, 'target_field' => $m->target_field, @@ -704,10 +704,10 @@ public function export(ImportTemplate $template) ])->values()->toArray(), ]; - $filename = Str::slug($template->name) . '-' . now()->format('Y-m-d') . '.json'; + $filename = Str::slug($template->name).'-'.now()->format('Y-m-d').'.json'; return response()->json($data) - ->header('Content-Disposition', 'attachment; filename="' . $filename . '"'); + ->header('Content-Disposition', 'attachment; filename="'.$filename.'"'); } // Import template from JSON file @@ -756,25 +756,25 @@ public function import(Request $request) } $clientId = null; - if (!empty($data['client_uuid'])) { + if (! empty($data['client_uuid'])) { $clientId = Client::where('uuid', $data['client_uuid'])->value('id'); } // Replace IDs in meta if provided $meta = $json['meta'] ?? []; - if (!empty($data['segment_id'])) { + if (! empty($data['segment_id'])) { $meta['segment_id'] = $data['segment_id']; } - if (!empty($data['decision_id'])) { + if (! empty($data['decision_id'])) { $meta['decision_id'] = $data['decision_id']; } - if (!empty($data['action_id'])) { + if (! empty($data['action_id'])) { $meta['action_id'] = $data['action_id']; } - if (!empty($data['activity_action_id'])) { + if (! empty($data['activity_action_id'])) { $meta['activity_action_id'] = $data['activity_action_id']; } - if (!empty($data['activity_decision_id'])) { + if (! empty($data['activity_decision_id'])) { $meta['activity_decision_id'] = $data['activity_decision_id']; } diff --git a/app/Models/ImportTemplate.php b/app/Models/ImportTemplate.php index b63ac8f..ae83ff3 100644 --- a/app/Models/ImportTemplate.php +++ b/app/Models/ImportTemplate.php @@ -22,6 +22,11 @@ class ImportTemplate extends Model 'reactivate' => 'boolean', ]; + public function getRouteKeyName(): string + { + return 'uuid'; + } + public function user(): BelongsTo { return $this->belongsTo(User::class); diff --git a/resources/js/Pages/Imports/Templates/Index.vue b/resources/js/Pages/Imports/Templates/Index.vue index 09b01b6..9ecad35 100644 --- a/resources/js/Pages/Imports/Templates/Index.vue +++ b/resources/js/Pages/Imports/Templates/Index.vue @@ -125,14 +125,30 @@ function handleFileChange(event) { } function performImport() { - importForm.post(route("importTemplates.import"), { - preserveScroll: true, - onSuccess: () => { - importModalOpen.value = false; - importForm.reset(); - importedData.value = null; - }, - }); + // Convert string IDs to integers before submitting + const formData = { + ...importForm.data(), + segment_id: importForm.segment_id ? parseInt(importForm.segment_id) : null, + decision_id: importForm.decision_id ? parseInt(importForm.decision_id) : null, + action_id: importForm.action_id ? parseInt(importForm.action_id) : null, + activity_action_id: importForm.activity_action_id + ? parseInt(importForm.activity_action_id) + : null, + activity_decision_id: importForm.activity_decision_id + ? parseInt(importForm.activity_decision_id) + : null, + }; + + importForm + .transform(() => formData) + .post(route("importTemplates.import"), { + preserveScroll: true, + onSuccess: () => { + importModalOpen.value = false; + importForm.reset(); + importedData.value = null; + }, + }); } const props = defineProps({ @@ -271,14 +287,14 @@ const props = defineProps({ Prekliči - Brisanje… Izbriši - +