improve plugin store

This commit is contained in:
xiaomlove
2025-05-05 18:24:17 +07:00
parent 5b71976624
commit fb88455323
15 changed files with 282 additions and 55 deletions

View File

@@ -18,6 +18,7 @@ use Filament\Infolists\Components;
use Filament\Infolists;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\App;
use Illuminate\Support\HtmlString;
use Filament\Actions\Action;
use Livewire\Livewire;
@@ -29,6 +30,13 @@ class PluginStoreResource extends Resource
protected static ?string $navigationGroup = 'System';
protected static ?int $navigationSort = 99;
public static function getNavigationBadge(): ?string
{
return PluginStore::getHasNewVersionCount();
}
public static function form(Form $form): Form
{
return $form
@@ -43,15 +51,26 @@ class PluginStoreResource extends Resource
->columns([
Tables\Columns\Layout\Stack::make([
Tables\Columns\Layout\Stack::make([
Tables\Columns\TextColumn::make('title')
Tables\Columns\TextColumn::make(self::getColumnLabelKey("title"))
->weight(FontWeight::Bold)
,
Tables\Columns\TextColumn::make('description'),
Tables\Columns\TextColumn::make(self::getColumnLabelKey("description")),
]),
Tables\Columns\Layout\Stack::make([
Tables\Columns\TextColumn::make('version')
->formatStateUsing(fn (PluginStore $record) => sprintf("版本: %s | 更新时间: %s", $record->version, $record->release_date))
->color('gray')
->formatStateUsing(function (PluginStore $record) {
$installedVersion = $record->installed_version;
$latestVersion = $record->version;
if ($installedVersion) {
return sprintf('%s: %s', nexus_trans("plugin.labels.installed_version"), $installedVersion);
}
return sprintf(
'%s: %s | %s: %s',
nexus_trans("plugin.labels.latest_version"), $latestVersion,
nexus_trans("plugin.labels.release_date"), $record->release_date
);
})
->color(fn ($record) => $record->installed_version ? 'success' : 'gray')
,
])
])->space(3),
@@ -65,24 +84,29 @@ class PluginStoreResource extends Resource
])
->actions([
Tables\Actions\ViewAction::make()
->modalHeading("详细介绍")
->modalHeading(nexus_trans("plugin.labels.introduce"))
->modalContent(fn (PluginStore $record) => $record->getFullDescription())
->extraModalFooterActions([
Action::make("viewOnBlog")
Action::make(nexus_trans("plugin.labels.view_on_blog"))
->url(fn (PluginStore $record) => $record->getBlogPostUrl())
->extraAttributes(['target' => '_blank'])
,
])
,
Tables\Actions\Action::make("install")
->label("安装")
->modalHeading(fn (PluginStore $record) => sprintf("安装插件: %s", $record->title))
->label(function(PluginStore $record) {
if ($record->hasNewVersion()) {
return sprintf('%s(new: %s)', nexus_trans("plugin.actions.update"), $record->version);
}
return nexus_trans("plugin.actions.install");
})
->modalHeading(fn (PluginStore $record) => sprintf("%s: %s", nexus_trans("plugin.actions.install_or_update") ,$record->title))
->modalContent(function (PluginStore $record) {
$infolist = new Infolist();
$infolist->record = $record;
$infolist->schema([
Infolists\Components\TextEntry::make('plugin_id')
->label(fn () => sprintf("进入目录: %s, 以 root 用户的身份依次执行以下命令进行安装: ", base_path()))
->label(fn () => nexus_trans("plugin.labels.install_title", ['web_root' => base_path()]))
->html(true)
->formatStateUsing(function (PluginStore $record) {
return self::getPluginInstruction($record);
@@ -92,6 +116,7 @@ class PluginStoreResource extends Resource
return $infolist;
})
->modalFooterActions(fn () => [])
->color(fn (PluginStore $record) => $record->hasNewVersion() ? 'danger' : 'primary')
,
])
->recordAction(null)
@@ -99,14 +124,23 @@ class PluginStoreResource extends Resource
;
}
private static function getColumnLabelKey($column): string
{
$locale = App::getLocale();
if (in_array($locale, ['zh_CN', 'zh_TW'])) {
return "$column.zh_CN";
}
return "$column.en";
}
private static function getPluginInstruction(PluginStore $record): string
{
$result = [];
$result[] = "配置扩展地址";
$result[] = nexus_trans("plugin.labels.config_plugin_address");
$result[] = sprintf("<code>composer config repositories.%s git %s</code>", $record->plugin_id, $record->remote_url);
$result[] = "<br/>下载扩展. 这里展示的最新版本号, 如果需要安装其他版本(可在查看页面底部获得)自行替换";
$result[] = "<br/>" . nexus_trans("plugin.labels.download_specific_version");
$result[] = sprintf("<code>composer require %s:%s</code>", $record->package_name, $record->version);
$result[] = "<br/>执行安装";
$result[] = "<br/>" . nexus_trans("plugin.labels.execute_install");
$result[] = sprintf("<code>php artisan plugin install %s</code>", $record->package_name);
return implode("<br/>", $result);
}