Skip to content

Commit 9a9d0ca

Browse files
committed
improve collection handling and translations
1 parent 1b92f3f commit 9a9d0ca

File tree

4 files changed

+68
-17
lines changed

4 files changed

+68
-17
lines changed

packages/media/resources/views/livewire/media-picker-modal.blade.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class="text-xs text-gray-700 w-full mt-2 overflow-hidden text-ellipsis whitespac
188188
<div class="w-full md:w-2/5 lg:w-1/3 max-w-md flex-shrink-0 border-l pl-4 flex flex-col h-full">
189189
@if(!empty($selectedMediaMeta['id']))
190190
<div class="flex-1">
191-
<x-filament::section>
191+
<x-filament::section columns="2">
192192
<div class="space-y-4">
193193
<div>
194194
<span class="text-sm font-medium text-gray-500">{{ __('media::fields.file_name') }}</span>
@@ -224,11 +224,29 @@ class="text-xs text-gray-700 w-full mt-2 overflow-hidden text-ellipsis whitespac
224224
<span class="text-sm font-medium text-gray-500">{{ __('media::fields.uploaded_by') }}</span>
225225
<p class="mt-1 text-sm text-gray-900">{{ $selectedMediaMeta['uploader_name'] ?? '-' }}</p>
226226
</div>
227+
228+
<div>
229+
<span class="text-sm font-medium text-gray-500">{{ __('media::fields.collection') }}</span>
230+
<div class="mt-1">
231+
<x-filament::input.wrapper>
232+
<x-filament::input.select
233+
wire:model.live="selectedMediaMeta.collection_name"
234+
:disabled="$selectedMediaMeta['write_protected']"
235+
>
236+
@foreach($collectionOptions as $name)
237+
<option value="{{ $name }}">{{ $name === 'default' ? __('media::fields.default_collection') : $name }}</option>
238+
@endforeach
239+
</x-filament::input.select>
240+
</x-filament::input.wrapper>
241+
</div>
242+
</div>
227243
</div>
228244
</x-filament::section>
229245

230-
<x-filament::section class="mt-2">
231-
<h3 class="text-lg font-semibold mb-4">{{ __('media::fields.metadata') }}</h3>
246+
<x-filament::section class="mt-2" collapsible collapsed>
247+
<x-slot name="heading">
248+
<h3 class="text-lg font-semibold mb-4">{{ __('media::fields.metadata') }}</h3>
249+
</x-slot>
232250
<form wire:submit.prevent="saveMetadata">
233251
<x-filament-forms::field-wrapper.label class="block text-sm font-medium text-gray-700 mb-1">
234252
{{ __('media::fields.name') }}
@@ -268,8 +286,10 @@ class="block w-full border-gray-300 rounded-md shadow-sm focus:ring-blue-500 foc
268286
</form>
269287
</x-filament::section>
270288

271-
<x-filament::section class="mt-2">
272-
<h3 class="text-lg font-semibold mb-4">{{ __('media::fields.internal_note') }}</h3>
289+
<x-filament::section class="mt-2" collapsible collapsed>
290+
<x-slot name="heading">
291+
<h3 class="text-lg font-semibold mb-4">{{ __('media::fields.internal_note') }}</h3>
292+
</x-slot>
273293
<form wire:submit.prevent="saveMetadata">
274294
<x-filament::input.wrapper class="mb-4">
275295
<x-filament::input type="text" wire:model.lazy="selectedMediaMeta.internal_note"

packages/media/src/Http/Livewire/MediaPickerModal.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ public function form(Form $form): Form
9696
$collection = Select::make('collection_name')
9797
->label(__('media::fields.collection'))
9898
->options(function () {
99-
return Media::query()
99+
$collections = Media::query()
100100
->distinct()
101-
->pluck('collection_name', 'collection_name')
101+
->pluck('collection_name')
102102
->toArray();
103+
104+
$options = [];
105+
foreach ($collections as $name) {
106+
$options[$name] = $name === 'default' ? __('media::fields.default_collection') : $name;
107+
}
108+
109+
return $options;
103110
})
104111
->searchable()
105112
->required()
@@ -335,13 +342,14 @@ public function toggleMediaSelection(int $mediaId)
335342
'description' => $media->getAttribute('description') ?? '',
336343
'internal_note' => $media->getAttribute('internal_note') ?? '',
337344
'alt' => $media->getAttribute('alt') ?? '',
338-
'mime_type' => $media->mime_type ?? '',
345+
'mime_type' => $media->getReadableMimeType(),
339346
'write_protected' => (bool) $media->getOriginal('write_protected'),
340347
'size' => $media->size,
341348
'dimensions' => $media->getCustomProperty('dimensions', []),
342349
'created_at' => $media->created_at,
343350
'updated_at' => $media->updated_at,
344351
'uploader_name' => $uploaderName,
352+
'collection_name' => $media->collection_name,
345353
];
346354
} else {
347355
$this->selectedMediaMeta = [
@@ -359,6 +367,7 @@ public function toggleMediaSelection(int $mediaId)
359367
'created_at' => null,
360368
'updated_at' => null,
361369
'uploader_name' => '-',
370+
'collection_name' => '',
362371
];
363372
}
364373
}
@@ -400,7 +409,7 @@ public function updatedSelectedMediaMeta($value, $field)
400409
if ($this->selectedMediaMeta['id']) {
401410
$media = Media::where('id', $this->selectedMediaMeta['id'])->first();
402411

403-
if (in_array($field, ['title', 'description', 'internal_note', 'alt', 'name'])) {
412+
if (in_array($field, ['title', 'description', 'internal_note', 'alt', 'name', 'collection_name'])) {
404413
if ($media->getOriginal('write_protected')) {
405414
return;
406415
}

packages/media/src/Resources/MediaResource.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,18 @@ class=\"filament-button filament-button-size-sm inline-flex items-center justify
332332
->label(__('media::fields.collection'))
333333
->disabled(fn($record) => $record?->getOriginal('write_protected'))
334334
->options(function () {
335-
return Media::query()
335+
$collections = Media::query()
336336
->distinct()
337-
->pluck('collection_name', 'collection_name')
337+
->pluck('collection_name')
338+
->filter()
338339
->toArray();
340+
341+
$options = [];
342+
foreach ($collections as $name) {
343+
$options[$name] = $name === 'default' ? __('media::fields.default_collection') : $name;
344+
}
345+
346+
return $options;
339347
})
340348
->default(fn($record) => $record->collection_name)
341349
->afterStateUpdated(function ($state, $record) {
@@ -816,11 +824,18 @@ public static function table(Table $table): Table
816824
SelectFilter::make('collection_name')
817825
->label(__('media::fields.collection'))
818826
->options(function () {
819-
return Media::query()
827+
$collections = Media::query()
820828
->distinct()
821-
->pluck('collection_name', 'collection_name')
829+
->pluck('collection_name')
822830
->filter()
823831
->toArray();
832+
833+
$options = [];
834+
foreach ($collections as $name) {
835+
$options[$name] = $name === 'default' ? __('media::fields.default_collection') : $name;
836+
}
837+
838+
return $options;
824839
})
825840
->query(function (Builder $query, array $data) {
826841
if (!$data['value']) {

packages/media/src/Resources/MediaResource/Pages/ListMedia.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@ public function getHeaderActions(): array
3030
Select::make('collection_name')
3131
->label(__('media::fields.collection'))
3232
->options(function () {
33-
return Media::query()
33+
$collections = Media::query()
3434
->distinct()
35-
->pluck('collection_name', 'collection_name')
35+
->pluck('collection_name')
3636
->toArray();
37+
38+
$options = [];
39+
foreach ($collections as $name) {
40+
$options[$name] = $name === 'default' ? __('media::fields.default_collection') : $name;
41+
}
42+
43+
return $options;
3744
})
3845
->searchable()
39-
->default(__('media::fields.default_collection'))
46+
->default('default')
4047
->required()
4148
->live(),
4249
FileUpload::make('file')
@@ -72,7 +79,7 @@ public function getHeaderActions(): array
7279
}
7380

7481
$processedFiles = session('processed_files', []);
75-
$collection = $get('collection_name') ?? __('media::fields.default_collection');
82+
$collection = $get('collection_name') ?? 'default';
7683

7784
foreach ($state as $key => $tempFile) {
7885
if (in_array($key, $processedFiles)) {

0 commit comments

Comments
 (0)