-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BucketResource\Pages; | ||
|
||
use App\Filament\Resources\BucketResource; | ||
use Filament\Resources\Pages\Page; | ||
use Filament\Tables\Table; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
|
||
class Files extends Page | ||
{ | ||
protected static string $resource = BucketResource::class; | ||
|
||
protected static string $view = 'filament.resources.bucket-resource.pages.files'; | ||
|
||
protected ?Model $record = null; | ||
|
||
public array $directories = []; | ||
|
||
public array $files = []; | ||
|
||
public array $breadcrumbs = []; | ||
|
||
public string $path = ''; | ||
|
||
public function mount(int | string $record): void | ||
{ | ||
$this->record = $this->resolveRecord($record); | ||
$this->path = (string) request()->input('path', ''); | ||
|
||
if (Str::of($this->path)->contains('..')) { | ||
abort(403); | ||
} | ||
|
||
$parentPath = dirname($this->path); | ||
if ($parentPath === '.') { | ||
$parentPath = ''; | ||
} | ||
|
||
if (! empty($this->path)) { | ||
$this->breadcrumbs = collect(explode('/', $this->path))->map(function ($part, $index) { | ||
return (object)[ | ||
'name' => $part, | ||
'path' => implode('/', array_slice(explode('/', $this->path), 0, $index + 1)), | ||
]; | ||
})->toArray(); | ||
} | ||
|
||
$directories = Storage::directories(bucket_relative_path($this->record->name.'/'.$this->path)); | ||
|
||
foreach ($directories as $key => $directory) { | ||
$directories[$key] = (object) [ | ||
'name' => basename($directory), | ||
'path' => Str::of($directory)->after(bucket_relative_path($this->record->name))->trim('/')->__toString(), | ||
]; | ||
} | ||
|
||
$this->directories = array_merge([(object) ['name' => '..', 'path' => $parentPath]], $directories); | ||
|
||
$files = Storage::files(bucket_relative_path($this->record->name.'/'.$this->path)); | ||
|
||
foreach ($files as $key => $file) { | ||
$files[$key] = (object) [ | ||
'name' => basename($file), | ||
'path' => Str::of($file)->after(bucket_relative_path($this->record->name))->trim('/')->__toString(), | ||
'size' => format_filesize(Storage::size($file), 2), | ||
'last_modified' => Carbon::createFromTimestamp(Storage::lastModified($file))->format(Table::$defaultDateTimeDisplayFormat), | ||
]; | ||
} | ||
|
||
$this->files = $files; | ||
} | ||
|
||
protected function resolveRecord(int | string $key): Model | ||
{ | ||
$record = static::getResource()::resolveRecordRouteBinding($key); | ||
|
||
if ($record === null) { | ||
throw (new ModelNotFoundException())->setModel($this->getModel(), [$key]); | ||
} | ||
|
||
return $record; | ||
} | ||
|
||
public function getRecord(): Model | ||
{ | ||
return $this->record; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
resources/views/filament/resources/bucket-resource/pages/files.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<x-filament-panels::page> | ||
|
||
<div class="fi-ta-ctn divide-y divide-gray-200 overflow-hidden rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:divide-white/10 dark:bg-gray-900 dark:ring-white/10"> | ||
<div class="fi-ta-content divide-y divide-gray-200 overflow-x-auto dark:divide-white/10 dark:border-t-white/10"> | ||
|
||
<div class="fi-ta-header flex gap-1.5 p-4 text-sm"> | ||
<x-filament::link color="gray" href="?path="> | ||
{{ $this->getRecord()->name }} | ||
</x-filament::link> | ||
|
||
@foreach($breadcrumbs as $breadcrumb) | ||
<span class="text-gray-400">></span> | ||
<x-filament::link color="gray" href="?path={{ $breadcrumb->path }}"> | ||
{{ $breadcrumb->name }} | ||
</x-filament::link> | ||
@endforeach | ||
</div> | ||
|
||
<x-filament-tables::table> | ||
<x-slot name="header"> | ||
<x-filament-tables::header-cell>Name</x-filament-tables::header-cell> | ||
<x-filament-tables::header-cell>Size</x-filament-tables::header-cell> | ||
<x-filament-tables::header-cell>Last Modified</x-filament-tables::header-cell> | ||
</x-slot> | ||
|
||
@foreach($directories as $directory) | ||
<tr class="fi-ta-row [@media(hover:hover)]:transition [@media(hover:hover)]:duration-75 hover:bg-gray-50 dark:hover:bg-white/5"> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-name"> | ||
<div class="fi-ta-col-wrp flex items-center"> | ||
<x-filament::icon | ||
icon="heroicon-o-folder" | ||
class="h-6 w-6 text-gray-400 dark:text-gray-500" | ||
/> | ||
<a href="?path={{ $directory->path }}" class="fi-ta-text inline-block w-full px-3 py-3 text-sm">{{ $directory->name }}</a> | ||
</div> | ||
</td> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-user.name"> | ||
<div class="fi-ta-col-wrp"> | ||
|
||
</div> | ||
</td> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-visibility"> | ||
<div class="fi-ta-col-wrp"> | ||
|
||
</div> | ||
</td> | ||
</tr> | ||
@endforeach | ||
|
||
@foreach($files as $file) | ||
<tr class="fi-ta-row [@media(hover:hover)]:transition [@media(hover:hover)]:duration-75 hover:bg-gray-50 dark:hover:bg-white/5"> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-name"> | ||
<div class="fi-ta-col-wrp flex items-center"> | ||
<x-filament::icon | ||
icon="heroicon-o-document" | ||
class="h-6 w-6 text-gray-400 dark:text-gray-500" | ||
/> | ||
<span class="fi-ta-text text-sm inline-block px-3 py-3">{{ $file->name }}</span> | ||
</div> | ||
</td> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-user.name"> | ||
<div class="fi-ta-col-wrp"> | ||
<span class="fi-ta-text text-sm inline-block px-3 py-3">{{ $file->size }}</span> | ||
</div> | ||
</td> | ||
<td class="fi-ta-cell p-0 first-of-type:ps-1 last-of-type:pe-1 sm:first-of-type:ps-3 sm:last-of-type:pe-3 fi-table-cell-visibility"> | ||
<div class="fi-ta-col-wrp"> | ||
<span class="fi-ta-text text-sm inline-block px-3 py-3">{{ $file->last_modified }}</span> | ||
</div> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</x-filament-tables::table> | ||
|
||
</div> | ||
</div> | ||
|
||
</x-filament-panels::page> |