2025-01-19 14:37:00 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\System;
|
|
|
|
|
|
|
|
|
|
use App\Filament\Resources\System\PluginStoreResource\Pages;
|
|
|
|
|
use App\Filament\Resources\System\PluginStoreResource\RelationManagers;
|
|
|
|
|
use App\Livewire\InstallPluginModal;
|
|
|
|
|
use App\Models\Plugin;
|
|
|
|
|
use App\Models\PluginStore;
|
|
|
|
|
use Filament\Forms;
|
|
|
|
|
use Filament\Forms\Form;
|
|
|
|
|
use Filament\Infolists\Infolist;
|
|
|
|
|
use Filament\Resources\Resource;
|
|
|
|
|
use Filament\Support\Enums\FontWeight;
|
|
|
|
|
use Filament\Tables;
|
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
use Filament\Infolists\Components;
|
|
|
|
|
use Filament\Infolists;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
2025-05-05 18:24:17 +07:00
|
|
|
use Illuminate\Support\Facades\App;
|
2025-01-19 14:37:00 +08:00
|
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
|
use Filament\Actions\Action;
|
|
|
|
|
use Livewire\Livewire;
|
|
|
|
|
|
|
|
|
|
class PluginStoreResource extends Resource
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
|
|
|
|
|
|
protected static ?string $navigationGroup = 'System';
|
|
|
|
|
|
2025-05-05 18:24:17 +07:00
|
|
|
protected static ?int $navigationSort = 99;
|
|
|
|
|
|
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
|
|
|
{
|
|
|
|
|
return PluginStore::getHasNewVersionCount();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-19 14:37:00 +08:00
|
|
|
public static function form(Form $form): Form
|
|
|
|
|
{
|
|
|
|
|
return $form
|
|
|
|
|
->schema([
|
|
|
|
|
//
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->columns([
|
|
|
|
|
Tables\Columns\Layout\Stack::make([
|
|
|
|
|
Tables\Columns\Layout\Stack::make([
|
2025-05-05 18:24:17 +07:00
|
|
|
Tables\Columns\TextColumn::make(self::getColumnLabelKey("title"))
|
2025-01-19 14:37:00 +08:00
|
|
|
->weight(FontWeight::Bold)
|
|
|
|
|
,
|
2025-05-05 18:24:17 +07:00
|
|
|
Tables\Columns\TextColumn::make(self::getColumnLabelKey("description")),
|
2025-01-19 14:37:00 +08:00
|
|
|
]),
|
|
|
|
|
Tables\Columns\Layout\Stack::make([
|
|
|
|
|
Tables\Columns\TextColumn::make('version')
|
2025-05-05 18:24:17 +07:00
|
|
|
->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')
|
2025-01-19 14:37:00 +08:00
|
|
|
,
|
|
|
|
|
])
|
|
|
|
|
])->space(3),
|
|
|
|
|
])
|
|
|
|
|
->contentGrid([
|
|
|
|
|
'md' => 2,
|
|
|
|
|
'xl' => 3,
|
|
|
|
|
])
|
|
|
|
|
->filters([
|
|
|
|
|
//
|
|
|
|
|
])
|
|
|
|
|
->actions([
|
|
|
|
|
Tables\Actions\ViewAction::make()
|
2025-05-05 18:24:17 +07:00
|
|
|
->modalHeading(nexus_trans("plugin.labels.introduce"))
|
2025-01-19 14:37:00 +08:00
|
|
|
->modalContent(fn (PluginStore $record) => $record->getFullDescription())
|
|
|
|
|
->extraModalFooterActions([
|
2025-05-05 18:24:17 +07:00
|
|
|
Action::make(nexus_trans("plugin.labels.view_on_blog"))
|
2025-01-19 14:37:00 +08:00
|
|
|
->url(fn (PluginStore $record) => $record->getBlogPostUrl())
|
|
|
|
|
->extraAttributes(['target' => '_blank'])
|
|
|
|
|
,
|
|
|
|
|
])
|
|
|
|
|
,
|
|
|
|
|
Tables\Actions\Action::make("install")
|
2025-05-05 18:24:17 +07:00
|
|
|
->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");
|
|
|
|
|
})
|
2025-05-05 22:07:14 +07:00
|
|
|
->modalHeading(fn (PluginStore $record) => sprintf("%s: %s", nexus_trans("plugin.actions.install_or_update"), data_get($record, self::getColumnLabelKey("title"))))
|
2025-01-19 14:37:00 +08:00
|
|
|
->modalContent(function (PluginStore $record) {
|
|
|
|
|
$infolist = new Infolist();
|
|
|
|
|
$infolist->record = $record;
|
|
|
|
|
$infolist->schema([
|
|
|
|
|
Infolists\Components\TextEntry::make('plugin_id')
|
2025-05-05 18:24:17 +07:00
|
|
|
->label(fn () => nexus_trans("plugin.labels.install_title", ['web_root' => base_path()]))
|
2025-01-19 14:37:00 +08:00
|
|
|
->html(true)
|
|
|
|
|
->formatStateUsing(function (PluginStore $record) {
|
2025-01-19 19:09:16 +08:00
|
|
|
return self::getPluginInstruction($record);
|
2025-01-19 14:37:00 +08:00
|
|
|
})
|
|
|
|
|
,
|
|
|
|
|
]);
|
|
|
|
|
return $infolist;
|
|
|
|
|
})
|
|
|
|
|
->modalFooterActions(fn () => [])
|
2025-05-05 18:24:17 +07:00
|
|
|
->color(fn (PluginStore $record) => $record->hasNewVersion() ? 'danger' : 'primary')
|
2025-01-19 14:37:00 +08:00
|
|
|
,
|
|
|
|
|
])
|
|
|
|
|
->recordAction(null)
|
|
|
|
|
->paginated(false)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 18:24:17 +07:00
|
|
|
private static function getColumnLabelKey($column): string
|
|
|
|
|
{
|
|
|
|
|
$locale = App::getLocale();
|
|
|
|
|
if (in_array($locale, ['zh_CN', 'zh_TW'])) {
|
|
|
|
|
return "$column.zh_CN";
|
|
|
|
|
}
|
|
|
|
|
return "$column.en";
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-19 19:09:16 +08:00
|
|
|
private static function getPluginInstruction(PluginStore $record): string
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
2025-05-05 18:24:17 +07:00
|
|
|
$result[] = nexus_trans("plugin.labels.config_plugin_address");
|
2025-01-19 19:09:16 +08:00
|
|
|
$result[] = sprintf("<code>composer config repositories.%s git %s</code>", $record->plugin_id, $record->remote_url);
|
2025-05-05 18:24:17 +07:00
|
|
|
$result[] = "<br/>" . nexus_trans("plugin.labels.download_specific_version");
|
2025-01-19 19:09:16 +08:00
|
|
|
$result[] = sprintf("<code>composer require %s:%s</code>", $record->package_name, $record->version);
|
2025-05-05 18:24:17 +07:00
|
|
|
$result[] = "<br/>" . nexus_trans("plugin.labels.execute_install");
|
2025-01-19 19:09:16 +08:00
|
|
|
$result[] = sprintf("<code>php artisan plugin install %s</code>", $record->package_name);
|
|
|
|
|
return implode("<br/>", $result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-19 14:37:00 +08:00
|
|
|
public static function getRelations(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
//
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'index' => Pages\ListPluginStores::route('/'),
|
|
|
|
|
// 'create' => Pages\CreatePluginStore::route('/create'),
|
|
|
|
|
// 'edit' => Pages\EditPluginStore::route('/{record}/edit'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|