diff --git a/app/Filament/Pages/Supporto/TicketGestione.php b/app/Filament/Pages/Supporto/TicketGestione.php index 997ed69..2832a10 100644 --- a/app/Filament/Pages/Supporto/TicketGestione.php +++ b/app/Filament/Pages/Supporto/TicketGestione.php @@ -384,7 +384,37 @@ public function closeAttachmentMapPreview(): void */ public function getAttachmentDetails(TicketAttachment $attachment): array { - return $this->parseAttachmentDescription((string) ($attachment->description ?? '')); + $details = $this->parseAttachmentDescription((string) ($attachment->description ?? '')); + $metadata = is_array($attachment->metadata ?? null) ? $attachment->metadata : []; + + $lat = $metadata['gps_decimal']['lat'] ?? null; + $lng = $metadata['gps_decimal']['lng'] ?? null; + if ($details['gps'] === null && is_numeric($lat) && is_numeric($lng)) { + $details['gps'] = [ + 'lat' => (float) $lat, + 'lng' => (float) $lng, + 'label' => number_format((float) $lat, 5, '.', '') . ', ' . number_format((float) $lng, 5, '.', ''), + ]; + $details['maps_embed_url'] = 'https://maps.google.com/maps?q=' . $lat . ',' . $lng . '&z=17&output=embed'; + } + + if ($details['maps_url'] === null && filled($metadata['google_maps_url'] ?? null)) { + $details['maps_url'] = trim((string) $metadata['google_maps_url']); + } + + if ($details['exif_datetime'] === null && filled($metadata['exif_datetime'] ?? null)) { + $details['exif_datetime'] = trim((string) $metadata['exif_datetime']); + } + + if ($details['device'] === null && filled($metadata['device'] ?? null)) { + $details['device'] = trim((string) $metadata['device']); + } + + if ($details['file_label'] === null && filled($metadata['stored_name'] ?? null)) { + $details['file_label'] = trim((string) $metadata['stored_name']); + } + + return $details; } public function getSelectedTicketProperty(): ?Ticket diff --git a/app/Filament/Pages/Supporto/TicketMobile.php b/app/Filament/Pages/Supporto/TicketMobile.php index 6bd8f9c..57cef91 100644 --- a/app/Filament/Pages/Supporto/TicketMobile.php +++ b/app/Filament/Pages/Supporto/TicketMobile.php @@ -683,7 +683,7 @@ public function removeNewTicketFile(int $index): void } /** - * @return array + * @return array}> */ public function getSelectedUploadsProperty(): array { @@ -699,6 +699,10 @@ public function getSelectedUploadsProperty(): array $mime = (string) (method_exists($file, 'getClientMimeType') ? $file->getClientMimeType() : 'application/octet-stream'); $isImage = str_starts_with($mime, 'image/'); $protocol = $this->resolveDraftUploadCode($file, (int) $index, $isImage); + $size = (int) (method_exists($file, 'getSize') ? $file->getSize() : 0); + $metadata = $isImage + ? app(TicketAttachmentUploadService::class)->inspectUpload($file) + : []; $previewUrl = null; if ($isImage && method_exists($file, 'temporaryUrl')) { @@ -718,6 +722,8 @@ public function getSelectedUploadsProperty(): array 'is_image' => $isImage, 'preview_url' => $previewUrl, 'description' => (string) ($this->newTicketAttachmentDescriptions[$index] ?? ''), + 'size' => $size, + 'metadata' => is_array($metadata) ? $metadata : [], ]; } @@ -744,6 +750,7 @@ private function salvaAllegatiTicket(Ticket $ticket, int $userId): int } $saved = 0; + $supportsAttachmentMetadata = Schema::hasColumn('ticket_attachments', 'metadata'); $files = array_merge($this->newTicketCameraShots, $this->newTicketAttachments); @@ -759,7 +766,7 @@ private function salvaAllegatiTicket(Ticket $ticket, int $userId): int 'display_name' => $displayName, ]); - TicketAttachment::query()->create([ + $payload = [ 'ticket_id' => (int) $ticket->id, 'ticket_update_id' => null, 'user_id' => $userId, @@ -773,7 +780,13 @@ private function salvaAllegatiTicket(Ticket $ticket, int $userId): int $stored['original_name'] ?? null, $stored['source_original_name'] ?? null, ), - ]); + ]; + + if ($supportsAttachmentMetadata) { + $payload['metadata'] = is_array($stored['metadata'] ?? null) ? $stored['metadata'] : []; + } + + TicketAttachment::query()->create($payload); $saved++; } catch (Throwable $e) { diff --git a/app/Services/Support/TicketAttachmentUploadService.php b/app/Services/Support/TicketAttachmentUploadService.php index 509cc06..5b6f8ad 100644 --- a/app/Services/Support/TicketAttachmentUploadService.php +++ b/app/Services/Support/TicketAttachmentUploadService.php @@ -9,6 +9,15 @@ class TicketAttachmentUploadService { + /** + * @param UploadedFile|TemporaryUploadedFile $file + * @return array + */ + public function inspectUpload(object $file): array + { + return $this->extractImageMetadataFromFileObject($file); + } + /** * @param UploadedFile|TemporaryUploadedFile $file * @return array{path:string,mime:string,size:int,original_name:string} diff --git a/resources/views/filament/pages/supporto/ticket-mobile.blade.php b/resources/views/filament/pages/supporto/ticket-mobile.blade.php index c5f451b..5e2fd45 100644 --- a/resources/views/filament/pages/supporto/ticket-mobile.blade.php +++ b/resources/views/filament/pages/supporto/ticket-mobile.blade.php @@ -233,11 +233,6 @@ - -