Skip to content

Commit

Permalink
fix multi types
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Jun 30, 2024
1 parent 02fe2df commit d1ba435
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
55 changes: 31 additions & 24 deletions resources/views/pages/media.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
@elseif(str($item->mime_type)->contains('audio'))
<x-icon name="heroicon-o-musical-note" class="w-32 h-32" />
@else
@php $loadTypes = \TomatoPHP\FilamentMediaManager\Facade\FilamentMediaManager::getTypes() @endphp
@foreach($loadTypes as $type)
@if(str($item->file_name)->contains($type->exstantion))
<x-icon :name="$type->icon" class="w-32 h-32" />
@else
<x-icon name="heroicon-o-document" class="w-32 h-32" />
@endif
@endforeach
@php
$hasPreview = false;
$loadTypes = \TomatoPHP\FilamentMediaManager\Facade\FilamentMediaManager::getTypes();
foreach ($loadTypes as $type) {
if(str($item->file_name)->contains($type->exstantion)){
$hasPreview = $type->preview;
}
}
@endphp
@if($hasPreview)
<x-icon :name="$type->icon" class="w-32 h-32" />
@else
<x-icon name="heroicon-o-document" class="w-32 h-32" />
@endif
@endif
</div>
<div>
Expand Down Expand Up @@ -85,22 +91,23 @@
</video>
</a>
@else
@php $loadTypes = \TomatoPHP\FilamentMediaManager\Facade\FilamentMediaManager::getTypes() @endphp
@foreach($loadTypes as $type)
@if(str($item->file_name)->contains($type->exstantion))
@if($type->preview)
@include($type->preview, ['url' => $item->getUrl()])
@else
<a href="{{ $item->getUrl() }}" target="_blank" class="flex flex-col items-center justify-center p-4 h-full border dark:border-gray-700 rounded-lg">
<x-icon :name="$type->icon" class="w-32 h-32" />
</a>
@endif
@else
<a href="{{ $item->getUrl() }}" target="_blank" class="flex flex-col items-center justify-center p-4 h-full border dark:border-gray-700 rounded-lg">
<x-icon name="heroicon-o-document" class="w-32 h-32" />
</a>
@endif
@endforeach
@php
$hasPreview = false;
$loadTypes = \TomatoPHP\FilamentMediaManager\Facade\FilamentMediaManager::getTypes();
foreach ($loadTypes as $type) {
if(str($item->file_name)->contains($type->exstantion)){
$hasPreview = $type->preview;
}
}
@endphp
@if($hasPreview)
@include($hasPreview, ['media' => $item])

@else
<a href="{{ $item->getUrl() }}" target="_blank" class="flex flex-col items-center justify-center p-4 h-full border dark:border-gray-700 rounded-lg">
<x-icon :name="$type->icon" class="w-32 h-32" />
</a>
@endif
@endif
<div class="flex flex-col gap-4 my-4">
@if($item->model)
Expand Down
22 changes: 16 additions & 6 deletions src/Services/Contracts/MediaManagerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class MediaManagerType
public ?string $exstantion = null;
public ?string $icon = null;
public ?string $preview = null;
public ?string $js = null;
public ?string $css = null;
public ?array $js = null;
public ?array $css = null;


public static function make(?string $exstantion=null): static
Expand All @@ -34,15 +34,25 @@ public function preview(?string $preview=null): static
return $this;
}

public function js(?string $js=null): static
public function js(string|array|null $js=null): static
{
$this->js = $js;
if(is_array($js)){
$this->js = $js;
}
else {
$this->js[] = $js;
}
return $this;
}

public function css(?string $css=null): static
public function css(string|array|null $css=null): static
{
$this->css = $css;
if(is_array($css)){
$this->css = $css;
}
else {
$this->css[] = $css;
}
return $this;
}
}
16 changes: 10 additions & 6 deletions src/Services/FilamentMediaManagerServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ public function register(MediaManagerType|array $type)
}
} else {
if($type->js){
FilamentAsset::register([
Js::make($type->exstantion.'_js', $type->js),
]);
foreach ($type->js as $key=>$jsItem){
FilamentAsset::register([
Js::make($type->exstantion.'_js_'.$key, $jsItem),
]);
}
}
if($type->css){
FilamentAsset::register([
Css::make($type->exstantion.'_css', $type->css),
]);
foreach ($type->css as $key=>$cssItem){
FilamentAsset::register([
Css::make($type->exstantion.'_css_'.$key, $cssItem),
]);
}
}

$this->types[] = $type;
Expand Down

0 comments on commit d1ba435

Please sign in to comment.