finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!
This commit is contained in:
@@ -2,41 +2,44 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Services\PrinterService;
|
||||
use App\Settings\GeneralSettings;
|
||||
use BackedEnum;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Arr;
|
||||
use UnitEnum;
|
||||
|
||||
class GlobalSettings extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
||||
protected static string $view = 'filament.pages.global-settings';
|
||||
protected static ?string $navigationGroup = 'Admin';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cog';
|
||||
|
||||
protected string $view = 'filament.pages.global-settings';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
public function mount(GeneralSettings $settings): void
|
||||
{
|
||||
$settings = Setting::all()->pluck('value', 'key')->toArray();
|
||||
$this->form->fill($settings);
|
||||
$this->form->fill($settings->toArray());
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
$printerService = new PrinterService();
|
||||
$printerService = new PrinterService;
|
||||
$printers = $printerService->getPrinters();
|
||||
$printerOptions = array_merge($printers, ['__custom__' => __('filament.resource.setting.form.custom_printer')]);
|
||||
|
||||
return $form
|
||||
return $schema
|
||||
->schema([
|
||||
TextInput::make('gallery_heading')
|
||||
->label(__('filament.resource.setting.form.gallery_heading'))
|
||||
@@ -66,18 +69,21 @@ class GlobalSettings extends Page implements HasForms
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
public function save(GeneralSettings $settings): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
|
||||
// if a non-custom printer is selected, clear the custom address
|
||||
if (Arr::get($data, 'selected_printer') !== '__custom__') {
|
||||
$data['custom_printer_address'] = '';
|
||||
$data['custom_printer_address'] = null;
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
Setting::where('key', $key)->update(['value' => $value]);
|
||||
}
|
||||
$data['new_image_timespan_minutes'] = (int) Arr::get($data, 'new_image_timespan_minutes', 0);
|
||||
$data['image_refresh_interval'] = (int) Arr::get($data, 'image_refresh_interval', 0);
|
||||
$data['max_number_of_copies'] = (int) Arr::get($data, 'max_number_of_copies', 0);
|
||||
$data['show_print_button'] = (bool) Arr::get($data, 'show_print_button', false);
|
||||
$data['custom_printer_address'] = $data['custom_printer_address'] ?: null;
|
||||
|
||||
$settings->fill($data)->save();
|
||||
|
||||
Notification::make()
|
||||
->title(__('settings.saved_successfully'))
|
||||
|
||||
@@ -2,23 +2,25 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use UnitEnum;
|
||||
|
||||
class InstallPluginPage extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
|
||||
protected static string $view = 'filament.pages.install-plugin-page';
|
||||
protected string $view = 'filament.pages.install-plugin-page';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $title = 'Install Plugin';
|
||||
|
||||
@@ -29,9 +31,9 @@ class InstallPluginPage extends Page implements HasForms
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
return $schema
|
||||
->schema([
|
||||
FileUpload::make('plugin_file')
|
||||
->label('Plugin File (.php)')
|
||||
@@ -59,10 +61,10 @@ class InstallPluginPage extends Page implements HasForms
|
||||
|
||||
$uploadedFile = $data['plugin_file'];
|
||||
$filename = File::basename($uploadedFile);
|
||||
$destinationPath = app_path('Api/Plugins/' . $filename);
|
||||
$destinationPath = app_path('Api/Plugins/'.$filename);
|
||||
|
||||
try {
|
||||
File::move(storage_path('app/temp_plugins/' . $filename), $destinationPath);
|
||||
File::move(storage_path('app/temp_plugins/'.$filename), $destinationPath);
|
||||
|
||||
Notification::make()
|
||||
->title('Plugin installed successfully')
|
||||
|
||||
@@ -2,30 +2,31 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use App\Models\Plugin;
|
||||
use BackedEnum;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class Plugins extends Page
|
||||
class Plugins extends Page implements Tables\Contracts\HasTable
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-puzzle-piece';
|
||||
use Tables\Concerns\InteractsWithTable;
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-puzzle-piece';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $navigationLabel = 'Plugin List';
|
||||
|
||||
protected static ?string $title = 'Plugins';
|
||||
|
||||
protected static string $view = 'filament.pages.plugins';
|
||||
protected string $view = 'filament.pages.plugins';
|
||||
|
||||
protected static ?string $slug = 'list-plugins';
|
||||
|
||||
public $plugins;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->plugins = Plugin::getAllPlugins();
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('filament.navigation.groups.plugins');
|
||||
@@ -35,4 +36,29 @@ class Plugins extends Page
|
||||
{
|
||||
return __('filament.navigation.plugin_list');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('identifier')
|
||||
->label(__('Identifier'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->label(__('Enabled'))
|
||||
->boolean(),
|
||||
IconColumn::make('configured')
|
||||
->label(__('Configured'))
|
||||
->boolean(),
|
||||
])
|
||||
->records(fn () => Plugin::getAllPlugins())
|
||||
->paginated(false)
|
||||
->emptyStateHeading(__('No plugins found'))
|
||||
->emptyStateDescription(__('Drop PHP plugin files into app/Api/Plugins (excluding ApiPluginInterface.php).'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\AiModels;
|
||||
|
||||
use App\Filament\Resources\AiModelResource\Pages;
|
||||
use App\Filament\Resources\AiModelResource\RelationManagers;
|
||||
use BackedEnum;
|
||||
use App\Filament\Resources\AiModels\Pages;
|
||||
use App\Filament\Resources\AiModels\RelationManagers;
|
||||
use App\Models\AiModel;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas\Schema;
|
||||
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\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\ApiProvider;
|
||||
use App\Api\Plugins\PluginLoader;
|
||||
use App\Api\Plugins\ApiPluginInterface;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
|
||||
class AiModelResource extends Resource
|
||||
{
|
||||
protected static ?string $model = AiModel::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
// protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make()
|
||||
->schema([
|
||||
Select::make('api_provider_id')
|
||||
->label(__('filament.resource.ai_model.form.api_provider'))
|
||||
->relationship('primaryApiProvider', 'name')
|
||||
->live()
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('model_search_result', null);
|
||||
}),
|
||||
Select::make('model_search_result')
|
||||
->label(__('filament.resource.ai_model.form.search_model'))
|
||||
->searchable()
|
||||
->live()
|
||||
->hidden(fn (callable $get) => !static::canSearchModels($get('api_provider_id')))
|
||||
->getSearchResultsUsing(function (string $search, callable $get) {
|
||||
$apiProviderId = $get('api_provider_id');
|
||||
if (!$apiProviderId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$pluginInstance = static::getPluginInstance($apiProviderId);
|
||||
if ($pluginInstance && method_exists($pluginInstance, 'searchModels')) {
|
||||
$models = $pluginInstance->searchModels($search);
|
||||
$options = [];
|
||||
foreach ($models as $model) {
|
||||
$options[json_encode(['name' => $model['name'], 'id' => $model['id'], 'type' => $model['type'] ?? null, 'api_provider_id' => $apiProviderId])] = $model['name'] . ' (' . $model['id'] . ')';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
->getOptionLabelUsing(function ($value) {
|
||||
$decoded = json_decode($value, true);
|
||||
return $decoded['name'] . ' (' . $decoded['id'] . ')';
|
||||
})
|
||||
->afterStateUpdated(function (callable $set, $state) {
|
||||
if ($state) {
|
||||
$selectedModel = json_decode($state, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return; // Stop if JSON is invalid
|
||||
}
|
||||
$set('name', $selectedModel['name']);
|
||||
$set('model_id', $selectedModel['id']);
|
||||
$set('model_type', $selectedModel['type'] ?? null);
|
||||
}
|
||||
}),
|
||||
TextInput::make('name')
|
||||
->label(__('filament.resource.ai_model.form.name'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(),
|
||||
TextInput::make('model_id')
|
||||
->label(__('filament.resource.ai_model.form.model_id'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(),
|
||||
TextInput::make('model_type')
|
||||
->nullable()
|
||||
->maxLength(255)
|
||||
->live(),
|
||||
Forms\Components\Toggle::make('enabled')
|
||||
->label(__('filament.resource.ai_model.form.enabled'))
|
||||
->default(true),
|
||||
Forms\Components\Textarea::make('parameters')
|
||||
->label(__('filament.resource.ai_model.form.parameters'))
|
||||
->nullable()
|
||||
->rows(15)
|
||||
->json(JSON_PRETTY_PRINT)
|
||||
->helperText(__('filament.resource.ai_model.form.parameters_help'))
|
||||
])
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required(),
|
||||
TextInput::make('model_id')
|
||||
->required(),
|
||||
TextInput::make('model_type')
|
||||
->nullable(),
|
||||
Toggle::make('enabled')
|
||||
->default(true),
|
||||
Textarea::make('parameters')
|
||||
->nullable()
|
||||
->rows(15),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected static function canSearchModelsWithAnyProvider(?array $apiProviderIds): bool
|
||||
{
|
||||
if (empty($apiProviderIds)) {
|
||||
@@ -166,33 +113,32 @@ class AiModelResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.ai_model.table.name'))->searchable()->sortable(),
|
||||
TextColumn::make('model_id')->label(__('filament.resource.ai_model.table.model_id'))->searchable()->sortable(),
|
||||
TextColumn::make('model_type')->label(__('filament.resource.ai_model.table.model_type'))->searchable()->sortable(),
|
||||
Tables\Columns\IconColumn::make('enabled')
|
||||
->label(__('filament.resource.ai_model.table.enabled'))
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
TextColumn::make('model_id')->searchable()->sortable(),
|
||||
TextColumn::make('model_type')->searchable()->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->boolean(),
|
||||
TextColumn::make('primaryApiProvider.name')->label(__('filament.resource.ai_model.table.api_provider'))->searchable()->sortable()->limit(50),
|
||||
TextColumn::make('primaryApiProvider.name')->searchable()->sortable()->limit(50),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
EditAction::make(),
|
||||
Action::make('duplicate')
|
||||
->label(__('filament.resource.style.action.duplicate'))
|
||||
->label('Duplicate')
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->action(function (AiModel $record, $livewire) {
|
||||
$livewire->redirect(AiModelResource::getUrl('create', ['sourceRecord' => $record->id]));
|
||||
->action(function (Model $record, $livewire) {
|
||||
$livewire->redirect(static::getUrl('create', ['sourceRecord' => $record->id]));
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AiModelResource\Pages;
|
||||
namespace App\Filament\Resources\AiModels\Pages;
|
||||
|
||||
use App\Filament\Resources\AiModelResource;
|
||||
use App\Filament\Resources\AiModels\AiModelResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AiModelResource\Pages;
|
||||
namespace App\Filament\Resources\AiModels\Pages;
|
||||
|
||||
use App\Filament\Resources\AiModelResource;
|
||||
use App\Filament\Resources\AiModels\AiModelResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AiModelResource\Pages;
|
||||
namespace App\Filament\Resources\AiModels\Pages;
|
||||
|
||||
use App\Filament\Resources\AiModelResource;
|
||||
use App\Filament\Resources\AiModels\AiModelResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\ApiProviders;
|
||||
|
||||
use App\Filament\Resources\ApiProviderResource\Pages;
|
||||
use App\Filament\Resources\ApiProviderResource\RelationManagers;
|
||||
use App\Filament\Resources\ApiProviders\Pages;
|
||||
use App\Filament\Resources\ApiProviders\RelationManagers;
|
||||
use App\Models\ApiProvider;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
@@ -19,210 +23,102 @@ use Illuminate\Support\Facades\File;
|
||||
use App\Api\Plugins\ApiPluginInterface;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Api\Plugins\PluginLoader;
|
||||
use BackedEnum;
|
||||
|
||||
class ApiProviderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ApiProvider::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
$plugins = self::getAvailablePlugins();
|
||||
$livewire = $form->getLivewire();
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('filament.resource.api_provider.form.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Toggle::make('enabled')
|
||||
->label(__('filament.resource.api_provider.form.enabled'))
|
||||
->default(true),
|
||||
TextInput::make('api_url')
|
||||
->label(__('filament.resource.api_provider.form.api_url'))
|
||||
->required()
|
||||
->url()
|
||||
->maxLength(255),
|
||||
TextInput::make('username')
|
||||
->label(__('filament.resource.api_provider.form.username'))
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
TextInput::make('password')
|
||||
->label(__('filament.resource.api_provider.form.password'))
|
||||
->password()
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
TextInput::make('token')
|
||||
->label(__('filament.resource.api_provider.form.token'))
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
Select::make('plugin')
|
||||
->options($plugins)
|
||||
->nullable()
|
||||
->label(__('filament.resource.api_provider.form.plugin')),
|
||||
Actions::make([
|
||||
Action::make('test_connection')
|
||||
->label(__('filament.resource.api_provider.action.test_connection'))
|
||||
->icon(function (\Livewire\Component $livewire) {
|
||||
return match ($livewire->testResultState) {
|
||||
'success' => 'heroicon-o-check-circle',
|
||||
'failed' => 'heroicon-o-x-circle',
|
||||
default => 'heroicon-o-link',
|
||||
};
|
||||
})
|
||||
->color(function (\Livewire\Component $livewire) {
|
||||
return match ($livewire->testResultState) {
|
||||
'success' => 'success',
|
||||
'failed' => 'danger',
|
||||
default => 'gray',
|
||||
};
|
||||
})
|
||||
->action(function (array $data, Forms\Components\Component $component, \Livewire\Component $livewire) {
|
||||
$formData = $component->getLivewire()->form->getState();
|
||||
$apiUrl = str_replace('127.0.0.1', 'localhost', $formData['api_url'] ?? null);
|
||||
$pluginName = $formData['plugin'] ?? null;
|
||||
$token = $formData['token'] ?? null;
|
||||
|
||||
if (!$pluginName) {
|
||||
Notification::make()
|
||||
->title(__('filament.resource.api_provider.notification.connection_failed'))
|
||||
->body('Please select a plugin first.')
|
||||
->danger()
|
||||
->send();
|
||||
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Create a dummy ApiProvider model for the test
|
||||
$dummyApiProvider = new \App\Models\ApiProvider();
|
||||
$dummyApiProvider->api_url = $apiUrl;
|
||||
$dummyApiProvider->token = $token;
|
||||
|
||||
// Load the specific plugin using the PluginLoader
|
||||
$pluginInstance = PluginLoader::getPlugin($pluginName, $dummyApiProvider);
|
||||
|
||||
// Call the testConnection method of the plugin
|
||||
$testResult = $pluginInstance->testConnection([
|
||||
'api_url' => $apiUrl,
|
||||
'token' => $token,
|
||||
'username' => $formData['username'] ?? null,
|
||||
'password' => $formData['password'] ?? null,
|
||||
]);
|
||||
|
||||
if ($testResult) {
|
||||
Notification::make()
|
||||
->title(__('filament.resource.api_provider.notification.connection_successful'))
|
||||
->success()
|
||||
->send();
|
||||
$component->getLivewire()->dispatch('testConnectionFinished', result: 'success');
|
||||
} else {
|
||||
Notification::make()
|
||||
->title(__('filament.resource.api_provider.notification.connection_failed'))
|
||||
->body('Plugin reported connection failed. Check logs for details.')
|
||||
->danger()
|
||||
->send();
|
||||
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Plugin test connection failed: An unexpected error occurred.', [
|
||||
'api_url' => $apiUrl,
|
||||
'plugin' => $pluginName,
|
||||
'error_message' => $e->getMessage(),
|
||||
]);
|
||||
Notification::make()
|
||||
->title(__('filament.resource.api_provider.notification.connection_failed'))
|
||||
->body('An unexpected error occurred during plugin test: ' . $e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
$component->getLivewire()->dispatch('testConnectionFinished', result: 'failed');
|
||||
}
|
||||
}),
|
||||
]),
|
||||
])
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Toggle::make('enabled')
|
||||
->default(true),
|
||||
TextInput::make('api_url')
|
||||
->required()
|
||||
->url()
|
||||
->maxLength(255),
|
||||
TextInput::make('username')
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
TextInput::make('password')
|
||||
->password()
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
TextInput::make('token')
|
||||
->nullable()
|
||||
->maxLength(255),
|
||||
Select::make('plugin')
|
||||
->options($plugins)
|
||||
->nullable(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.api_provider.table.name'))->searchable()->sortable(),
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->label(__('filament.resource.api_provider.table.enabled'))
|
||||
->boolean(),
|
||||
TextColumn::make('api_url')->label(__('filament.resource.api_provider.table.api_url'))->searchable(),
|
||||
TextColumn::make('plugin')->label(__('filament.resource.api_provider.table.plugin'))->searchable()->sortable(),
|
||||
TextColumn::make('api_url')->searchable(),
|
||||
TextColumn::make('plugin')->searchable()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->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]);
|
||||
}),
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListApiProviders::route('/'),
|
||||
'create' => Pages\CreateApiProvider::route('/create'),
|
||||
'edit' => Pages\EditApiProvider::route('/{record}/edit'),
|
||||
];
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListApiProviders::route('/'),
|
||||
'create' => Pages\CreateApiProvider::route('/create'),
|
||||
'edit' => Pages\EditApiProvider::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
protected static function getAvailablePlugins(): array
|
||||
{
|
||||
$plugins = [];
|
||||
$path = app_path('Api/Plugins');
|
||||
$files = File::files($path);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filename = $file->getFilenameWithoutExtension();
|
||||
if (in_array($filename, ['ApiPluginInterface', 'PluginLoader'])) {
|
||||
continue;
|
||||
}
|
||||
$class = "App\Api\Plugins\\" . $filename;
|
||||
if (class_exists($class) && in_array(ApiPluginInterface::class, class_implements($class))) {
|
||||
// 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;
|
||||
|
||||
protected static function getAvailablePlugins(): array
|
||||
{
|
||||
$plugins = [];
|
||||
$path = app_path('Api/Plugins');
|
||||
$files = File::files($path);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filename = $file->getFilenameWithoutExtension();
|
||||
if (in_array($filename, ['ApiPluginInterface', 'PluginLoader'])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $plugins;
|
||||
}
|
||||
}
|
||||
$class = "App\Api\Plugins\\" . $filename;
|
||||
if (class_exists($class) && in_array(ApiPluginInterface::class, class_implements($class))) {
|
||||
$plugins[$filename] = $filename;
|
||||
}
|
||||
}
|
||||
return $plugins;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiProviderResource\Pages;
|
||||
namespace App\Filament\Resources\ApiProviders\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiProviderResource;
|
||||
use App\Filament\Resources\ApiProviders\ApiProviderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiProviderResource\Pages;
|
||||
namespace App\Filament\Resources\ApiProviders\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiProviderResource;
|
||||
use App\Filament\Resources\ApiProviders\ApiProviderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ApiProviderResource\Pages;
|
||||
namespace App\Filament\Resources\ApiProviders\Pages;
|
||||
|
||||
use App\Filament\Resources\ApiProviderResource;
|
||||
use App\Filament\Resources\ApiProviders\ApiProviderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\Images;
|
||||
|
||||
use App\Filament\Resources\ImageResource\Pages;
|
||||
use App\Filament\Resources\ImageResource\RelationManagers;
|
||||
use BackedEnum;
|
||||
use App\Filament\Resources\Images\Pages;
|
||||
use App\Filament\Resources\Images\RelationManagers;
|
||||
use App\Models\Image;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
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\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
class ImageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Image::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
return $schema
|
||||
->components([
|
||||
FileUpload::make('path')
|
||||
->label(__('filament.resource.image.form.path'))
|
||||
->required()
|
||||
->image()
|
||||
->directory('uploads'),
|
||||
Forms\Components\Toggle::make('is_public')
|
||||
->label(__('Publicly Visible'))
|
||||
->directory('uploads')
|
||||
->disk('public'),
|
||||
Toggle::make('is_public')
|
||||
->default(false),
|
||||
]);
|
||||
}
|
||||
@@ -41,19 +46,23 @@ class ImageResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('path')->label(__('filament.resource.image.table.path'))->searchable()->sortable(),
|
||||
Tables\Columns\ImageColumn::make('path')->label(__('filament.resource.image.table.image')),
|
||||
TextColumn::make('path')->searchable()->sortable(),
|
||||
ImageColumn::make('path')
|
||||
->disk('public'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -71,4 +80,4 @@ class ImageResource extends Resource
|
||||
'edit' => Pages\EditImage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ImageResource\Pages;
|
||||
namespace App\Filament\Resources\Images\Pages;
|
||||
|
||||
use App\Filament\Resources\ImageResource;
|
||||
use App\Filament\Resources\Images\ImageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ImageResource\Pages;
|
||||
namespace App\Filament\Resources\Images\Pages;
|
||||
|
||||
use App\Filament\Resources\ImageResource;
|
||||
use App\Filament\Resources\Images\ImageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RoleResource\Pages;
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\RoleResource;
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RoleResource\Pages;
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\RoleResource;
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RoleResource\Pages;
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\RoleResource;
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\Roles;
|
||||
|
||||
use App\Filament\Resources\RoleResource\Pages;
|
||||
use App\Filament\Resources\RoleResource\RelationManagers;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\Roles\Pages;
|
||||
use App\Filament\Resources\Roles\RelationManagers;
|
||||
use App\Models\Role;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
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\Tables\Columns\TextColumn;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
class RoleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Role::class;
|
||||
|
||||
protected static ?string $navigationGroup = 'User Management';
|
||||
protected static UnitEnum|string|null $navigationGroup = 'User Management';
|
||||
protected static ?string $navigationLabel = 'User Roles';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label(__('filament.resource.role.form.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
@@ -37,21 +40,21 @@ class RoleResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.role.table.name'))->searchable()->sortable(),
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -70,4 +73,4 @@ class RoleResource extends Resource
|
||||
'edit' => Pages\EditRole::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StyleResource\Pages;
|
||||
namespace App\Filament\Resources\Styles\Pages;
|
||||
|
||||
use App\Filament\Resources\StyleResource;
|
||||
use App\Filament\Resources\Styles\StyleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StyleResource\Pages;
|
||||
namespace App\Filament\Resources\Styles\Pages;
|
||||
|
||||
use App\Filament\Resources\StyleResource;
|
||||
use App\Filament\Resources\Styles\StyleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StyleResource\Pages;
|
||||
namespace App\Filament\Resources\Styles\Pages;
|
||||
|
||||
use App\Filament\Resources\StyleResource;
|
||||
use App\Filament\Resources\Styles\StyleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Tables\Concerns\CanReorderRecords;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\Styles;
|
||||
|
||||
use App\Filament\Resources\StyleResource\Pages;
|
||||
use BackedEnum;
|
||||
use App\Filament\Resources\Styles\Pages;
|
||||
use App\Models\Style;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
@@ -17,70 +18,68 @@ use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
class StyleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Style::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
->columns('full')
|
||||
->schema([
|
||||
Forms\Components\Tabs::make('Style Details')
|
||||
return $schema
|
||||
->columns(1)
|
||||
->components([
|
||||
Tabs::make('Style Details')
|
||||
->tabs([
|
||||
Forms\Components\Tabs\Tab::make('General')
|
||||
->schema([
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
Tab::make('General')
|
||||
->components([
|
||||
Grid::make(2)
|
||||
->columnSpanFull()
|
||||
->components([
|
||||
TextInput::make('title')
|
||||
->label(__('filament.resource.style.form.title'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Toggle::make('enabled')
|
||||
->label(__('filament.resource.style.form.enabled'))
|
||||
->default(true),
|
||||
]),
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Toggle::make('enabled')
|
||||
->default(true),
|
||||
]),
|
||||
Grid::make(2)
|
||||
->columnSpanFull()
|
||||
->components([
|
||||
Textarea::make('prompt')
|
||||
->label(__('filament.resource.style.form.prompt'))
|
||||
->required()
|
||||
->rows(5),
|
||||
Textarea::make('description')
|
||||
->label(__('filament.resource.style.form.description'))
|
||||
->required()
|
||||
->rows(5),
|
||||
]),
|
||||
]),
|
||||
Select::make('ai_model_id')
|
||||
->relationship('aiModel', 'name')
|
||||
->label(__('filament.resource.style.form.ai_model'))
|
||||
->required(),
|
||||
FileUpload::make('preview_image')
|
||||
->label(__('filament.resource.style.form.preview_image'))
|
||||
->disk('public')
|
||||
->directory('style_previews')
|
||||
->image()
|
||||
->imageEditor()
|
||||
->required()
|
||||
->rules(['mimes:jpeg,png,bmp,gif,webp']),
|
||||
->required(),
|
||||
]),
|
||||
Forms\Components\Tabs\Tab::make('Details')
|
||||
->schema([
|
||||
|
||||
Forms\Components\TextInput::make('sort_order')
|
||||
Tab::make('Details')
|
||||
->components([
|
||||
TextInput::make('sort_order')
|
||||
->numeric()
|
||||
->default(0)
|
||||
->label(__('filament.resource.style.form.sort_order')),
|
||||
->default(0),
|
||||
Textarea::make('parameters')
|
||||
->label(__('filament.resource.style.form.parameters'))
|
||||
->nullable()
|
||||
->rows(15)
|
||||
->json()
|
||||
->helperText(__('filament.resource.style.form.parameters_help'))
|
||||
->formatStateUsing(fn (?array $state): ?string => $state ? json_encode($state, JSON_PRETTY_PRINT) : null),
|
||||
->rows(15),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
@@ -90,45 +89,42 @@ class StyleResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->defaultSort('sort_order')
|
||||
->reorderable('sort_order')
|
||||
->columns([
|
||||
TextColumn::make('title')->label(__('filament.resource.style.table.title'))->searchable()->sortable(),
|
||||
TextColumn::make('title')->searchable()->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->label(__('filament.resource.style.table.enabled'))
|
||||
->boolean(),
|
||||
TextColumn::make('aiModel.name')->label(__('filament.resource.style.table.ai_model'))->searchable()->sortable(),
|
||||
ImageColumn::make('preview_image')->label(__('filament.resource.style.table.preview_image'))->disk('public'),
|
||||
TextColumn::make('sort_order')->label(__('filament.resource.style.table.sort_order'))->sortable(),
|
||||
TextColumn::make('aiModel.name')->searchable()->sortable(),
|
||||
ImageColumn::make('preview_image')->disk('public'),
|
||||
TextColumn::make('sort_order')->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('ai_model')
|
||||
->relationship('aiModel', 'name')
|
||||
->label(__('filament.resource.style.table.ai_model')),
|
||||
->relationship('aiModel', 'name'),
|
||||
])
|
||||
->deferFilters(false)
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('duplicate')
|
||||
->label(__('filament.resource.style.action.duplicate'))
|
||||
EditAction::make(),
|
||||
Action::make('duplicate')
|
||||
->label('Duplicate')
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->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]));
|
||||
return redirect()->to(\App\Filament\Resources\Styles\StyleResource::getUrl('edit', ['record' => $newStyle->id]));
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\BulkAction::make('enable')
|
||||
->label(__('filament.resource.style.action.enable_selected'))
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
BulkAction::make('enable')
|
||||
->label('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.style.action.disable_selected'))
|
||||
BulkAction::make('disable')
|
||||
->label('Disable Selected')
|
||||
->icon('heroicon-o-x-circle')
|
||||
->action(function (\Illuminate\Support\Collection $records) {
|
||||
$records->each->update(['enabled' => false]);
|
||||
@@ -136,7 +132,7 @@ class StyleResource extends Resource
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -155,4 +151,4 @@ class StyleResource extends Resource
|
||||
'edit' => Pages\EditStyle::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\UserResource\Pages;
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
|
||||
@@ -1,45 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
namespace App\Filament\Resources\Users;
|
||||
|
||||
use App\Filament\Resources\UserResource\Pages;
|
||||
use App\Filament\Resources\UserResource\RelationManagers;
|
||||
use UnitEnum;
|
||||
use App\Filament\Resources\Users\Pages;
|
||||
use App\Filament\Resources\Users\RelationManagers;
|
||||
use App\Models\User;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Schemas;
|
||||
use Filament\Schemas\Schema;
|
||||
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\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static ?string $navigationGroup = 'User Management';
|
||||
protected static ?string $navigationLabel = 'User Roles';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'User Management';
|
||||
protected static ?string $navigationLabel = 'Users';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make('User Details')
|
||||
->schema([
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('User Details')
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label(__('filament.resource.user.form.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('email')
|
||||
->label(__('filament.resource.user.form.email'))
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('password')
|
||||
->label(__('filament.resource.user.form.password'))
|
||||
->password()
|
||||
->dehydrateStateUsing(fn (string $state): string => bcrypt($state))
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
@@ -47,30 +50,28 @@ class UserResource extends Resource
|
||||
->maxLength(255),
|
||||
Select::make('role_id')
|
||||
->relationship('role', 'name')
|
||||
->label(__('filament.resource.user.form.role'))
|
||||
->required(),
|
||||
])->columns(2),
|
||||
])->columns(2)
|
||||
->columnSpanFull(),
|
||||
|
||||
Forms\Components\Section::make('Preferences')
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('email_notifications_enabled')
|
||||
->label(__('Email Notifications'))
|
||||
Section::make('Preferences')
|
||||
->components([
|
||||
Toggle::make('email_notifications_enabled')
|
||||
->default(true),
|
||||
Select::make('theme_preference')
|
||||
->label(__('Theme'))
|
||||
->options([
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
])
|
||||
->default('light'),
|
||||
Select::make('locale')
|
||||
->label(__('Language'))
|
||||
->options([
|
||||
'en' => 'English',
|
||||
'de' => 'Deutsch',
|
||||
])
|
||||
->default('en'),
|
||||
])->columns(2),
|
||||
])->columns(2)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -78,23 +79,23 @@ class UserResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.user.table.name'))->searchable()->sortable(),
|
||||
TextColumn::make('email')->label(__('filament.resource.user.table.email'))->searchable()->sortable(),
|
||||
TextColumn::make('role.name')->label(__('filament.resource.user.table.role'))->searchable()->sortable(),
|
||||
TextColumn::make('name')->searchable()->sortable(),
|
||||
TextColumn::make('email')->searchable()->sortable(),
|
||||
TextColumn::make('role.name')->searchable()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -123,4 +124,4 @@ class UserResource extends Resource
|
||||
{
|
||||
return __('filament.navigation.user_roles');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user