components([
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Stack::make([
Stack::make([
TextColumn::make(self::getColumnLabelKey("title"))
->weight(FontWeight::Bold)
,
TextColumn::make(self::getColumnLabelKey("description")),
]),
Stack::make([
TextColumn::make('version')
->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),
])
->contentGrid([
'md' => 2,
'xl' => 3,
])
->filters([
//
])
->recordActions([
ViewAction::make()
->modalHeading(nexus_trans("plugin.labels.introduce"))
->modalContent(fn (PluginStore $record) => $record->getFullDescription())
->extraModalFooterActions([
Action::make(nexus_trans("plugin.labels.view_on_blog"))
->url(fn (PluginStore $record) => $record->getBlogPostUrl())
->extraAttributes(['target' => '_blank'])
,
])
,
Action::make("install")
->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"), data_get($record, self::getColumnLabelKey("title"))))
->modalContent(function (PluginStore $record) {
$infolist = new Schema();
$infolist->record = $record;
$infolist->components([
TextEntry::make('plugin_id')
->label(fn () => nexus_trans("plugin.labels.install_title", ['web_root' => base_path()]))
->html(true)
->formatStateUsing(function (PluginStore $record) {
return self::getPluginInstruction($record);
})
,
]);
return $infolist;
})
->modalFooterActions(fn () => [])
->color(fn (PluginStore $record) => $record->hasNewVersion() ? 'danger' : 'primary')
,
])
->recordAction(null)
->paginated(false)
;
}
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[] = nexus_trans("plugin.labels.config_plugin_address");
$result[] = sprintf("composer config repositories.%s vcs %s", $record->plugin_id, $record->remote_url);
$result[] = "
" . nexus_trans("plugin.labels.download_specific_version");
$result[] = sprintf("composer require %s:%s", $record->package_name, $record->version);
$result[] = "
" . nexus_trans("plugin.labels.execute_install");
$result[] = sprintf("php artisan plugin install %s", $record->package_name);
return implode("
", $result);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListPluginStores::route('/'),
// 'create' => Pages\CreatePluginStore::route('/create'),
// 'edit' => Pages\EditPluginStore::route('/{record}/edit'),
];
}
}