added enabled/disable to styles
This commit is contained in:
@@ -18,7 +18,7 @@ class InstallPluginPage extends Page implements HasForms
|
||||
|
||||
protected static string $view = 'filament.pages.install-plugin-page';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $title = 'Install Plugin';
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use App\Models\ApiProvider;
|
||||
use Filament\Tables\Actions\Action;
|
||||
|
||||
class ListPlugins extends Page implements HasTable
|
||||
@@ -23,7 +24,7 @@ class ListPlugins extends Page implements HasTable
|
||||
|
||||
protected static string $view = 'filament.pages.list-plugins';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?string $title = 'Plugins';
|
||||
|
||||
@@ -40,7 +41,9 @@ class ListPlugins extends Page implements HasTable
|
||||
|
||||
if (class_exists($class) && in_array(ApiPluginInterface::class, class_implements($class))) {
|
||||
try {
|
||||
$instance = new $class();
|
||||
$apiProvider = ApiProvider::where('plugin', $filename)->first();
|
||||
if(!$apiProvider) continue;
|
||||
$instance = new $class($apiProvider);
|
||||
$plugins->add(new Plugin([
|
||||
'id' => $instance->getIdentifier(),
|
||||
'name' => $instance->getName(),
|
||||
@@ -78,8 +81,10 @@ class ListPlugins extends Page implements HasTable
|
||||
->icon(fn ($record) => $record->enabled ? 'heroicon-o-x-circle' : 'heroicon-o-check-circle')
|
||||
->action(function ($record) {
|
||||
try {
|
||||
$apiProvider = ApiProvider::where('plugin', $record->identifier)->first();
|
||||
if(!$apiProvider) throw new \Exception('ApiProvider not found');
|
||||
$pluginClass = 'App\\Api\\Plugins\\' . $record->identifier;
|
||||
$plugin = new $pluginClass();
|
||||
$plugin = new $pluginClass($apiProvider);
|
||||
if ($record->enabled) {
|
||||
$plugin->disable();
|
||||
} else {
|
||||
@@ -97,6 +102,7 @@ class ListPlugins extends Page implements HasTable
|
||||
->send();
|
||||
}
|
||||
}),
|
||||
|
||||
Action::make('delete')
|
||||
->label('Delete')
|
||||
->icon('heroicon-o-trash')
|
||||
|
||||
@@ -41,8 +41,7 @@ class AiModelResource extends Resource
|
||||
Select::make('apiProviders')
|
||||
->relationship('apiProviders', 'name')
|
||||
->multiple()
|
||||
->label(__('filament.resource.ai_model.form.api_providers'))
|
||||
->options(\App\Models\ApiProvider::pluck('name', 'id')),
|
||||
->label(__('filament.resource.ai_model.form.api_providers')),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,18 @@ class ApiProviderResource extends Resource
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\BulkAction::make('enable')
|
||||
->label(__('filament.resource.api_provider.action.enable_selected'))
|
||||
->icon('heroicon-o-check-circle')
|
||||
->action(function (\Illuminate\Support\Collection $records) {
|
||||
$records->each->update(['enabled' => true]);
|
||||
}),
|
||||
Tables\Actions\BulkAction::make('disable')
|
||||
->label(__('filament.resource.api_provider.action.disable_selected'))
|
||||
->icon('heroicon-o-x-circle')
|
||||
->action(function (\Illuminate\Support\Collection $records) {
|
||||
$records->each->update(['enabled' => false]);
|
||||
}),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
@@ -122,8 +134,9 @@ class ApiProviderResource extends Resource
|
||||
|
||||
$class = 'App\\Api\\Plugins\\' . $filename;
|
||||
if (class_exists($class) && in_array(ApiPluginInterface::class, class_implements($class))) {
|
||||
$instance = new $class();
|
||||
$plugins[$instance->getIdentifier()] = $instance->getName();
|
||||
// Do not instantiate here, just get identifier and name if possible statically or by convention
|
||||
// For now, we'll use filename as identifier and name
|
||||
$plugins[$filename] = $filename;
|
||||
}
|
||||
}
|
||||
return $plugins;
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\StyleResource\Pages;
|
||||
use App\Filament\Resources\StyleResource\RelationManagers;
|
||||
use App\Models\Style;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
|
||||
class StyleResource extends Resource
|
||||
{
|
||||
@@ -76,7 +72,7 @@ class StyleResource extends Resource
|
||||
ImageColumn::make('preview_image')->label(__('filament.resource.style.table.preview_image'))->disk('public'),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('ai_model')
|
||||
SelectFilter::make('ai_model')
|
||||
->relationship('aiModel', 'name')
|
||||
->label(__('filament.resource.style.table.ai_model')),
|
||||
])
|
||||
@@ -85,7 +81,13 @@ class StyleResource extends Resource
|
||||
Tables\Actions\Action::make('duplicate')
|
||||
->label(__('filament.resource.style.action.duplicate'))
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->url(fn (\App\Models\Style $record): string => StyleResource::getUrl('create', ['duplicate_id' => $record->id])),
|
||||
->action(function (\App\Models\Style $record) {
|
||||
$newStyle = $record->replicate();
|
||||
$newStyle->title = $record->title . ' (Kopie)';
|
||||
$newStyle->save();
|
||||
|
||||
return redirect()->to(StyleResource::getUrl('edit', ['record' => $newStyle->id]));
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Filament\Resources\StyleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StyleResource;
|
||||
use App\Models\Style;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
@@ -15,20 +14,4 @@ class CreateStyle extends CreateRecord
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
parent::mount();
|
||||
|
||||
$duplicateId = request()->query('duplicate_id');
|
||||
|
||||
if ($duplicateId) {
|
||||
$originalStyle = Style::find($duplicateId);
|
||||
if ($originalStyle) {
|
||||
$data = $originalStyle->toArray();
|
||||
$data['title'] = $originalStyle->title . ' (Kopie)';
|
||||
$this->form->fill($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user