mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
add plugin readme
This commit is contained in:
parent
4f00603c59
commit
5057fd9c8f
@ -9,6 +9,7 @@ use Exception;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
@ -81,10 +82,24 @@ class PluginResource extends Resource
|
||||
->recordActions([
|
||||
Action::make('view')
|
||||
->label(trans('filament-actions::view.single.label'))
|
||||
->icon('tabler-eye-share')
|
||||
->icon(fn (Plugin $plugin) => $plugin->getReadme() ? 'tabler-eye' : 'tabler-eye-share')
|
||||
->color('gray')
|
||||
->visible(fn (Plugin $plugin) => $plugin->url)
|
||||
->url(fn (Plugin $plugin) => $plugin->url, true),
|
||||
->visible(fn (Plugin $plugin) => $plugin->getReadme() || $plugin->url)
|
||||
->url(fn (Plugin $plugin) => !$plugin->getReadme() ? $plugin->url : null, true)
|
||||
->slideOver(true)
|
||||
->modalHeading('Readme')
|
||||
->modalSubmitAction(fn (Plugin $plugin) => Action::make('visit_website')
|
||||
->label(trans('admin/plugin.visit_website'))
|
||||
->visible($plugin->url)
|
||||
->url($plugin->url, true)
|
||||
)
|
||||
->modalCancelActionLabel(trans('filament::components/modal.actions.close.label'))
|
||||
->schema(fn (Plugin $plugin) => $plugin->getReadme() ? [
|
||||
TextEntry::make('readme')
|
||||
->hiddenLabel()
|
||||
->markdown()
|
||||
->state(fn (Plugin $plugin) => $plugin->getReadme()),
|
||||
] : null),
|
||||
Action::make('settings')
|
||||
->label(trans('admin/plugin.settings'))
|
||||
->authorize(fn (Plugin $plugin) => auth()->user()->can('update', $plugin))
|
||||
|
||||
@ -402,4 +402,17 @@ class Plugin extends Model implements HasPluginSettings
|
||||
|
||||
return array_map(fn ($provider) => $this->namespace . '\\Console\\Commands\\' . str($provider->getRelativePathname())->remove('.php', false), File::allFiles($path));
|
||||
}
|
||||
|
||||
public function getReadme(): ?string
|
||||
{
|
||||
return cache()->remember("plugins.$this->id.readme", now()->addMinutes(5), function () {
|
||||
$path = plugin_path($this->id, 'README.md');
|
||||
|
||||
if (File::missing($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return File::get($path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ return [
|
||||
'version' => 'Version',
|
||||
'category' => 'Category',
|
||||
'status' => 'Status',
|
||||
'visit_website' => 'Visit Website',
|
||||
'settings' => 'Settings',
|
||||
'install' => 'Install',
|
||||
'update' => 'Update',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user