Skip to content

Commit

Permalink
Merge pull request #123 from lara-zeus/allow-multi-library
Browse files Browse the repository at this point in the history
allow to upload multiple libraries and refactor the views
  • Loading branch information
atmonshi authored Jul 12, 2023
2 parents ab81874 + cadcce5 commit ab80bff
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
23 changes: 5 additions & 18 deletions resources/views/themes/zeus/addons/library-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,10 @@
<span>{{ $item->created_at->format('Y.m/d') }}-{{ $item->created_at->format('h:i a') }}</span>
</p>

@if($item->type === 'IMAGE')
<img class="mx-auto" src="{{ $item->theFile() }}">
@endif

@if($item->type === 'FILE')
<div class="text-center">
<x-filament::button tag="a" target="_blank" href="{{ $item->theFile() }}" class="mx-auto">
{{ __('Show File') }}
</x-filament::button>
</div>
@endif

@if($item->type === 'VIDEO')
<video width="100%" class="w-full" controls>
<source src="{{ $item->theFile() }}">
Your browser does not support HTML video.
</video>
@endif
<div class="grid grid-cols-1 @if($item->getFiles()->count() > 1) sm:grid-cols-2 lg:grid-cols-3 @endif gap-2 justify-items-stretch content-stretch">
@foreach($item->getFiles() as $file)
@include($theme.'.addons.library-types.'.strtolower($item->type))
@endforeach
</div>
</x-filament::card>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<x-filament::button tag="a" target="_blank" href="{{ $file->getFullUrl() }}" class="mx-auto">
{{ __('Show File') }}
</x-filament::button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="{{ $file->getFullUrl() }}" target="_blank">
<img alt="{{ $item->title }}-{{ $file->name }}" class="aspect-video mx-auto" src="{{ $file->getFullUrl() }}">
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<video width="100%" class="w-full" controls>
<source src="{{ $file->getFullUrl() }}">
Your browser does not support HTML video.
</video>
2 changes: 2 additions & 0 deletions src/Filament/Resources/LibraryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public static function form(Form $form): Form

SpatieMediaLibraryFileUpload::make('file_path_upload')
->collection('library')
->multiple()
->enableReordering()
->visible(fn (Closure $get) => $get('upload_or_url') === 'upload')
->label(''),

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/SearchHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait SearchHelpers
{
private function highlightSearchResults(Collection $collection, ?string $search = null): Collection
private function highlightSearchResults(Collection $collection, string $search = null): Collection
{
if (! $search) {
return $collection;
Expand Down
12 changes: 11 additions & 1 deletion src/Models/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection;
use Spatie\Tags\HasTags;
use Spatie\Translatable\HasTranslations;

Expand Down Expand Up @@ -48,12 +49,21 @@ public function getRouteKeyName()
return 'slug';
}

public function theFile()
public function theFile(): ?string
{
if (! $this->getMedia('library')->isEmpty()) {
return $this->getFirstMediaUrl('library');
}

return $this->file_path;
}

public function getFiles(): ?MediaCollection
{
if (! $this->getMedia('library')->isEmpty()) {
return $this->getMedia('library');
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function generateSlug(string $locale): string
return call_user_func($slugger, $this->getTranslation('name', $locale));
}

public static function findBySlug(string $slug, string $type = null, string $locale = null): Model|null
public static function findBySlug(string $slug, string $type = null, string $locale = null): ?Model
{
$locale = $locale ?? static::getLocale();

Expand Down

0 comments on commit ab80bff

Please sign in to comment.