another fix for export import templates
This commit is contained in:
parent
b9f66cbfbe
commit
082a637719
|
|
@ -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'];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,23 @@ function handleFileChange(event) {
|
|||
}
|
||||
|
||||
function performImport() {
|
||||
importForm.post(route("importTemplates.import"), {
|
||||
// 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;
|
||||
|
|
@ -271,14 +287,14 @@ const props = defineProps({
|
|||
<AlertDialogCancel @click="cancelDelete" :disabled="deleteForm.processing">
|
||||
Prekliči
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
<Button
|
||||
@click="performDelete"
|
||||
:disabled="deleteForm.processing"
|
||||
class="bg-destructive hover:bg-destructive/90"
|
||||
>
|
||||
<span v-if="deleteForm.processing">Brisanje…</span>
|
||||
<span v-else>Izbriši</span>
|
||||
</AlertDialogAction>
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user