Runware/ComfyUI fixes, dashboard links, import action, Leonardo plugin, widget, added status field and test connection button
This commit is contained in:
@@ -11,10 +11,12 @@ use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
@@ -38,12 +40,23 @@ class AiModelResource extends Resource
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Hinweise zu Model-Parametern')
|
||||
->description('Parameter werden je nach Plugin unterschiedlich verwendet: Runware/ComfyUI als JSON für Workflow/Model-Settings, Leonardo v2 akzeptiert z. B. width/height/style_ids/prompt_enhance. Prüfe die Plugin-Doku; Felder, die nicht zum Plugin passen, werden ignoriert.')
|
||||
->columns(1)
|
||||
->collapsible()
|
||||
->schema([]),
|
||||
TextInput::make('name')
|
||||
->required(),
|
||||
TextInput::make('model_id')
|
||||
->required(),
|
||||
TextInput::make('model_type')
|
||||
->nullable(),
|
||||
Select::make('api_provider_id')
|
||||
->label('API Provider')
|
||||
->relationship('primaryApiProvider', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Toggle::make('enabled')
|
||||
->default(true),
|
||||
Textarea::make('parameters')
|
||||
|
||||
@@ -9,6 +9,7 @@ use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
@@ -38,6 +39,12 @@ class ApiProviderResource extends Resource
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
Placeholder::make('provider_dashboard')
|
||||
->label('Provider Dashboard')
|
||||
->content(fn (?ApiProvider $record) => $record?->getDashboardUrl() ? '<a href="'.$record->getDashboardUrl().'" target="_blank" class="text-primary-600 underline">'.$record->getDashboardUrl().'</a>' : '—')
|
||||
->disableLabel(false)
|
||||
->columnSpanFull()
|
||||
->visible(fn (?ApiProvider $record) => (bool) $record?->getDashboardUrl()),
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Filament\Resources\ApiProviders\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiProviders\ApiProviderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
@@ -19,8 +18,14 @@ class CreateApiProvider extends CreateRecord
|
||||
$this->testResultState = $result;
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
// No record yet, so no dashboard link; keep header clean.
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Filament\Resources\ApiProviders\Pages;
|
||||
|
||||
use App\Api\Plugins\PluginLoader;
|
||||
use App\Filament\Resources\ApiProviders\ApiProviderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
@@ -22,6 +25,34 @@ class EditApiProvider extends EditRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('test_connection')
|
||||
->label('Verbindung testen')
|
||||
->icon('heroicon-o-bolt')
|
||||
->color('gray')
|
||||
->action(function (): void {
|
||||
try {
|
||||
$provider = $this->record;
|
||||
$plugin = PluginLoader::getPlugin($provider->plugin, $provider);
|
||||
$plugin->testConnection($provider->toArray());
|
||||
|
||||
Notification::make()
|
||||
->title('Verbindung erfolgreich')
|
||||
->success()
|
||||
->send();
|
||||
} catch (\Throwable $e) {
|
||||
Notification::make()
|
||||
->title('Verbindung fehlgeschlagen')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}),
|
||||
Action::make('dashboard')
|
||||
->label('Provider Dashboard')
|
||||
->icon('heroicon-o-arrow-top-right-on-square')
|
||||
->visible(fn () => $this->record?->getDashboardUrl())
|
||||
->url(fn () => $this->record?->getDashboardUrl())
|
||||
->openUrlInNewTab(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
@@ -30,4 +61,4 @@ class EditApiProvider extends EditRecord
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources\Styles;
|
||||
use App\Models\Style;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\Action\Step;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
@@ -25,6 +26,7 @@ use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Spatie\SimpleExcel\SimpleExcelReader;
|
||||
|
||||
class StyleResource extends Resource
|
||||
{
|
||||
@@ -107,6 +109,79 @@ class StyleResource extends Resource
|
||||
->relationship('aiModel', 'name'),
|
||||
])
|
||||
->deferFilters(false)
|
||||
->headerActions([
|
||||
Action::make('import_styles')
|
||||
->label('Import Styles (CSV)')
|
||||
->icon('heroicon-o-arrow-up-on-square-stack')
|
||||
->steps([
|
||||
Step::make('Datei')
|
||||
->schema([
|
||||
FileUpload::make('import_file')
|
||||
->label('CSV-Datei (Titel,Prompt,[Beschreibung])')
|
||||
->acceptedFileTypes([
|
||||
'text/csv',
|
||||
'text/plain',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
])
|
||||
->directory('imports/styles')
|
||||
->visibility('private')
|
||||
->required(),
|
||||
]),
|
||||
Step::make('Zuordnung')
|
||||
->schema([
|
||||
Select::make('ai_model_id')
|
||||
->label('AI Modell')
|
||||
->relationship('aiModel', 'name')
|
||||
->required(),
|
||||
]),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$path = storage_path('app/'.$data['import_file']);
|
||||
|
||||
if (! file_exists($path)) {
|
||||
throw new \RuntimeException('Import-Datei nicht gefunden.');
|
||||
}
|
||||
|
||||
$rows = self::parseImportFile($path);
|
||||
|
||||
if (empty($rows)) {
|
||||
throw new \RuntimeException('Keine gültigen Zeilen gefunden.');
|
||||
}
|
||||
|
||||
$created = 0;
|
||||
foreach ($rows as $row) {
|
||||
$title = $row['title'] ?? null;
|
||||
$prompt = $row['prompt'] ?? null;
|
||||
$description = $row['description'] ?? null;
|
||||
|
||||
if (! $title || ! $prompt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Style::create([
|
||||
'title' => $title,
|
||||
'prompt' => $prompt,
|
||||
'description' => $description ?? '',
|
||||
'preview_image' => '', // user must set later
|
||||
'ai_model_id' => $data['ai_model_id'],
|
||||
'enabled' => true,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
$created++;
|
||||
}
|
||||
|
||||
if ($created === 0) {
|
||||
throw new \RuntimeException('Es wurden keine Styles importiert.');
|
||||
}
|
||||
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Import abgeschlossen')
|
||||
->body($created.' Styles importiert. Bitte Vorschau-Bilder ergänzen.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
Action::make('duplicate')
|
||||
@@ -149,6 +224,24 @@ class StyleResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
protected static function parseImportFile(string $path): array
|
||||
{
|
||||
return SimpleExcelReader::create($path)->getRows()->map(function (array $row) {
|
||||
$normalized = [];
|
||||
foreach ($row as $key => $value) {
|
||||
$normalized[strtolower(trim($key))] = is_string($value) ? trim($value) : $value;
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $normalized['title'] ?? $normalized['titel'] ?? null,
|
||||
'prompt' => $normalized['prompt'] ?? null,
|
||||
'description' => $normalized['description'] ?? $normalized['beschreibung'] ?? null,
|
||||
];
|
||||
})->filter(function (array $row) {
|
||||
return ! empty($row['title']) && ! empty($row['prompt']);
|
||||
})->values()->all();
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user