refactor: update migration paths and add image support to proposal attachment viewer

This commit is contained in:
Yoga Pangestu 2026-04-23 09:52:53 +07:00
parent d681080dc3
commit 2447d0b037
2 changed files with 48 additions and 5 deletions

View File

@ -278,7 +278,7 @@ private function importOfferFile(int $proposalId, object $legacy): void
}
// Adjust path based on where these files are stored in S3
$sourcePath = 'old-data/proposals/'.$legacyPath;
$sourcePath = 'old-data/mediacooperations/'.$legacyPath;
$fileName = basename($sourcePath);
$legacyDir = dirname($sourcePath);
@ -286,7 +286,7 @@ private function importOfferFile(int $proposalId, object $legacy): void
'model_type' => CooperationProposal::class,
'model_id' => $proposalId,
'uuid' => (string) Str::uuid(),
'collection_name' => 'proposals',
'collection_name' => 'cooperations',
'name' => pathinfo($fileName, PATHINFO_FILENAME),
'file_name' => $fileName,
'mime_type' => $this->guessMime($fileName),
@ -295,8 +295,9 @@ private function importOfferFile(int $proposalId, object $legacy): void
'size' => 0,
'manipulations' => '[]',
'custom_properties' => json_encode([
'feature' => 'proposals',
'feature' => 'cooperations',
'date' => Carbon::parse($legacy->created_at ?? now())->toDateString(),
'doc_type' => 'proposal-attachment',
'legacy_dir' => $legacyDir,
]),
'generated_conversions' => '[]',

View File

@ -155,11 +155,53 @@ public function infolist(Schema $infolist): Schema
->label('Deskripsi')
->columnSpanFull(),
PdfViewerEntry::make('proposal_attachment')
PdfViewerEntry::make('proposal_attachment_pdf')
->label('Lampiran Proposal')
->getStateUsing(fn (CooperationProposal $record): ?string => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
->visible(function (CooperationProposal $record): bool {
$media = $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first();
return $media && str_contains($media->mime_type ?? '', 'pdf');
})
->getStateUsing(fn (CooperationProposal $record): ?string => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first())->getUrl())
->disk(config('filesystems.default')),
TextEntry::make('proposal_attachment_image')
->label('Lampiran Proposal')
->html()
->visible(function (CooperationProposal $record): bool {
$media = $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first();
return $media && str_contains($media->mime_type ?? '', 'image');
})
->getStateUsing(function (CooperationProposal $record): string {
$media = $record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first();
if (! $media) {
return '';
}
$url = $media->getUrl();
$downloadUrl = $url;
if (in_array($media->disk, ['s3', 'minio'])) {
$downloadUrl = $media->getTemporaryUrl(now()->addMinutes(30), '', [
'ResponseContentDisposition' => 'attachment; filename="'.$media->file_name.'"',
]);
}
$downloadLink = '<a href="'.$downloadUrl.'" download="dokumen" class="mt-2 flex items-center gap-1 text-sm font-medium text-primary-600 transition hover:text-primary-500">
<svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
</svg>
Unduh Dokumen
</a>';
return '<div class="flex flex-col">'.
'<img src="'.$url.'" alt="Dokumen" style="max-width: 100%; height: auto; border-radius: 0.5rem;" />'.
$downloadLink.
'</div>';
}),
TextEntry::make('rejectionReasons.reason')
->label('Alasan Penolakan')
->listWithLineBreaks()