finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Settings\GeneralSettings;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GetPrinterSetting extends Command
|
||||
@@ -23,15 +24,21 @@ class GetPrinterSetting extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(GeneralSettings $settings)
|
||||
{
|
||||
$setting = \App\Models\Setting::where('key', 'selected_printer')->first();
|
||||
$value = $settings->selected_printer === '__custom__'
|
||||
? $settings->custom_printer_address
|
||||
: $settings->selected_printer;
|
||||
|
||||
if ($setting) {
|
||||
if ($value) {
|
||||
$this->info('Raw value of \'selected_printer\' setting:');
|
||||
$this->info(json_encode($setting->value, JSON_PRETTY_PRINT)); // Assuming \'value\' column holds the data
|
||||
} else {
|
||||
$this->info('\'selected_printer\' setting not found.');
|
||||
$this->info($value);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$this->info('\'selected_printer\' setting not found.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,27 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Api\Plugins\PluginLoader;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ApiProvider;
|
||||
use App\Models\Style;
|
||||
use App\Models\Image;
|
||||
use App\Models\Style;
|
||||
use App\Settings\GeneralSettings;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Setting;
|
||||
|
||||
class ImageController extends Controller
|
||||
{
|
||||
public function __construct(private GeneralSettings $settings) {}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$publicUploadsPath = public_path('storage/uploads');
|
||||
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!File::exists($publicUploadsPath)) {
|
||||
if (! File::exists($publicUploadsPath)) {
|
||||
File::makeDirectory($publicUploadsPath, 0755, true);
|
||||
}
|
||||
|
||||
@@ -29,7 +31,7 @@ class ImageController extends Controller
|
||||
$diskImagePaths = [];
|
||||
foreach ($diskFiles as $file) {
|
||||
// Store path relative to public/storage/
|
||||
$diskImagePaths[] = 'uploads/' . $file->getFilename();
|
||||
$diskImagePaths[] = 'uploads/'.$file->getFilename();
|
||||
}
|
||||
|
||||
$dbImagePaths = Image::pluck('path')->toArray();
|
||||
@@ -48,7 +50,7 @@ class ImageController extends Controller
|
||||
$query = Image::orderBy('updated_at', 'desc');
|
||||
|
||||
// If user is not authenticated, filter by is_public, but also include their temporary images
|
||||
if (!auth()->check()) {
|
||||
if (! auth()->check()) {
|
||||
$query->where(function ($q) {
|
||||
$q->where('is_public', true)->orWhere('is_temp', true);
|
||||
});
|
||||
@@ -56,10 +58,11 @@ class ImageController extends Controller
|
||||
// If user is authenticated, show all their images
|
||||
}
|
||||
|
||||
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
|
||||
$newImageTimespanMinutes = $this->settings->new_image_timespan_minutes;
|
||||
|
||||
$images = $query->get()->map(function ($image) use ($newImageTimespanMinutes) {
|
||||
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
|
||||
|
||||
return $image;
|
||||
});
|
||||
|
||||
@@ -67,13 +70,14 @@ class ImageController extends Controller
|
||||
foreach ($images as $image) {
|
||||
$formattedImages[] = [
|
||||
'image_id' => $image->id,
|
||||
'path' => asset('storage/' . $image->path),
|
||||
'path' => asset('storage/'.$image->path),
|
||||
'name' => basename($image->path),
|
||||
'is_temp' => (bool) $image->is_temp,
|
||||
'is_public' => (bool) $image->is_public,
|
||||
'is_new' => (bool) $image->is_new,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($formattedImages);
|
||||
}
|
||||
|
||||
@@ -84,16 +88,16 @@ class ImageController extends Controller
|
||||
]);
|
||||
|
||||
$file = $request->file('image');
|
||||
$fileName = uniqid() . '.' . $file->getClientOriginalExtension();
|
||||
$fileName = uniqid().'.'.$file->getClientOriginalExtension();
|
||||
$destinationPath = public_path('storage/uploads');
|
||||
|
||||
// Ensure the directory exists
|
||||
if (!File::exists($destinationPath)) {
|
||||
if (! File::exists($destinationPath)) {
|
||||
File::makeDirectory($destinationPath, 0755, true);
|
||||
}
|
||||
|
||||
$file->move($destinationPath, $fileName);
|
||||
$relativePath = 'uploads/' . $fileName; // Path relative to public/storage/
|
||||
$relativePath = 'uploads/'.$fileName; // Path relative to public/storage/
|
||||
|
||||
$image = Image::create([
|
||||
'path' => $relativePath,
|
||||
@@ -103,7 +107,7 @@ class ImageController extends Controller
|
||||
return response()->json([
|
||||
'message' => __('api.image_uploaded_successfully'),
|
||||
'image_id' => $image->id,
|
||||
'path' => asset('storage/' . $relativePath),
|
||||
'path' => asset('storage/'.$relativePath),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -113,9 +117,9 @@ class ImageController extends Controller
|
||||
\Illuminate\Support\Facades\Log::info('styleChangeRequest called', [
|
||||
'image_id' => $request->image_id,
|
||||
'style_id' => $request->style_id,
|
||||
'all_params' => $request->all()
|
||||
'all_params' => $request->all(),
|
||||
]);
|
||||
|
||||
|
||||
// Same-origin check
|
||||
$appUrl = config('app.url');
|
||||
$referer = $request->headers->get('referer');
|
||||
@@ -123,8 +127,9 @@ class ImageController extends Controller
|
||||
if ($referer && parse_url($referer, PHP_URL_HOST) !== parse_url($appUrl, PHP_URL_HOST)) {
|
||||
\Illuminate\Support\Facades\Log::warning('Unauthorized styleChangeRequest', [
|
||||
'referer' => $referer,
|
||||
'app_url' => $appUrl
|
||||
'app_url' => $appUrl,
|
||||
]);
|
||||
|
||||
return response()->json(['error' => 'Unauthorized: Request must originate from the same domain.'], 403);
|
||||
}
|
||||
|
||||
@@ -142,39 +147,41 @@ class ImageController extends Controller
|
||||
}])->find($request->style_id);
|
||||
} else {
|
||||
// Attempt to get default style from settings
|
||||
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
|
||||
if ($defaultStyleSetting && $defaultStyleSetting->value) {
|
||||
$defaultStyleId = $this->settings->default_style_id;
|
||||
if ($defaultStyleId) {
|
||||
$style = Style::with(['aiModel' => function ($query) {
|
||||
$query->where('enabled', true)->with('primaryApiProvider');
|
||||
}])->find($defaultStyleSetting->value);
|
||||
}])->find($defaultStyleId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$style || !$style->aiModel || !$style->aiModel->primaryApiProvider) {
|
||||
if (! $style || ! $style->aiModel || ! $style->aiModel->primaryApiProvider) {
|
||||
\Illuminate\Support\Facades\Log::warning('Style or provider not found', [
|
||||
'style' => $style ? $style->toArray() : null,
|
||||
'ai_model' => $style && $style->aiModel ? $style->aiModel->toArray() : null
|
||||
'ai_model' => $style && $style->aiModel ? $style->aiModel->toArray() : null,
|
||||
]);
|
||||
|
||||
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
// Use the primary API provider for this AI model
|
||||
$apiProvider = $style->aiModel->primaryApiProvider;
|
||||
if (!$apiProvider) {
|
||||
if (! $apiProvider) {
|
||||
\Illuminate\Support\Facades\Log::error('No API provider found for style', [
|
||||
'style_id' => $style->id,
|
||||
'ai_model_id' => $style->aiModel->id
|
||||
'ai_model_id' => $style->aiModel->id,
|
||||
]);
|
||||
|
||||
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
|
||||
}
|
||||
|
||||
|
||||
\Illuminate\Support\Facades\Log::info('Selected API provider for style change', [
|
||||
'api_provider_id' => $apiProvider->id,
|
||||
'api_provider_name' => $apiProvider->name,
|
||||
'plugin' => $apiProvider->plugin
|
||||
'plugin' => $apiProvider->plugin,
|
||||
]);
|
||||
|
||||
|
||||
$plugin = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
|
||||
$result = $plugin->processImageStyleChange($image, $style);
|
||||
@@ -187,9 +194,9 @@ class ImageController extends Controller
|
||||
// Return the prompt_id for WebSocket tracking
|
||||
\Illuminate\Support\Facades\Log::info('Style change request completed', [
|
||||
'prompt_id' => $result['prompt_id'],
|
||||
'image_uuid' => $image->uuid
|
||||
'image_uuid' => $image->uuid,
|
||||
]);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Style change request sent.',
|
||||
'prompt_id' => $result['prompt_id'],
|
||||
@@ -199,8 +206,9 @@ class ImageController extends Controller
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('Error in styleChangeRequest', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
@@ -213,7 +221,7 @@ class ImageController extends Controller
|
||||
|
||||
$image = Image::find($request->image_id);
|
||||
|
||||
if (!$image) {
|
||||
if (! $image) {
|
||||
return response()->json(['error' => __('api.image_not_found')], 404);
|
||||
}
|
||||
|
||||
@@ -227,8 +235,9 @@ class ImageController extends Controller
|
||||
{
|
||||
try {
|
||||
// Delete from the public/storage directory
|
||||
File::delete(public_path('storage/' . $image->path));
|
||||
File::delete(public_path('storage/'.$image->path));
|
||||
$image->delete();
|
||||
|
||||
return response()->json(['message' => __('api.image_deleted_successfully')]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
@@ -245,13 +254,14 @@ class ImageController extends Controller
|
||||
$image = Image::find($request->image_id);
|
||||
$apiProvider = ApiProvider::where('name', $request->api_provider_name)->first();
|
||||
|
||||
if (!$image || !$apiProvider) {
|
||||
if (! $image || ! $apiProvider) {
|
||||
return response()->json(['error' => __('api.image_or_provider_not_found')], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$plugin = PluginLoader::getPlugin($apiProvider->name);
|
||||
$status = $plugin->getStatus($image->uuid); // Annahme: Image Model hat eine UUID
|
||||
|
||||
return response()->json($status);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
@@ -267,8 +277,9 @@ class ImageController extends Controller
|
||||
$query->with('primaryApiProvider');
|
||||
}])->where('comfyui_prompt_id', $promptId)->first();
|
||||
|
||||
if (!$image) {
|
||||
if (! $image) {
|
||||
Log::warning('fetchStyledImage: Image not found for prompt_id.', ['prompt_id' => $promptId]);
|
||||
|
||||
return response()->json(['error' => __('api.image_not_found')], 404);
|
||||
}
|
||||
|
||||
@@ -276,22 +287,25 @@ class ImageController extends Controller
|
||||
|
||||
// Get the style and API provider associated with the image
|
||||
$style = $image->style;
|
||||
if (!$style) {
|
||||
if (! $style) {
|
||||
Log::warning('fetchStyledImage: Style not found for image.', ['image_id' => $image->id]);
|
||||
|
||||
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
|
||||
}
|
||||
Log::info('fetchStyledImage: Style found.', ['style_id' => $style->id, 'style_name' => $style->title]);
|
||||
|
||||
if (!$style->aiModel) {
|
||||
if (! $style->aiModel) {
|
||||
Log::warning('fetchStyledImage: AI Model not found for style.', ['style_id' => $style->id]);
|
||||
|
||||
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
|
||||
}
|
||||
Log::info('fetchStyledImage: AI Model found.', ['ai_model_id' => $style->aiModel->id, 'ai_model_name' => $style->aiModel->name]);
|
||||
|
||||
// Use the primary API provider for this AI model
|
||||
$apiProvider = $style->aiModel->primaryApiProvider;
|
||||
if (!$apiProvider) {
|
||||
if (! $apiProvider) {
|
||||
Log::warning('fetchStyledImage: No API Provider found for AI Model.', ['ai_model_id' => $style->aiModel->id]);
|
||||
|
||||
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
|
||||
}
|
||||
Log::info('fetchStyledImage: API Provider found.', ['api_provider_id' => $apiProvider->id, 'api_provider_name' => $apiProvider->name]);
|
||||
@@ -303,17 +317,18 @@ class ImageController extends Controller
|
||||
|
||||
if (empty($base64Image)) {
|
||||
Log::error('Received empty base64 image from plugin.', ['prompt_id' => $promptId]);
|
||||
|
||||
return response()->json(['error' => 'Received empty image data.'], 500);
|
||||
}
|
||||
|
||||
Log::info('Base64 image received. Decoding and saving.');
|
||||
$decodedImage = base64_decode(preg_replace('#^data:image/\w+;base64, #i', '', $base64Image));
|
||||
|
||||
$newImageName = 'styled_' . uniqid() . '.png';
|
||||
$newImagePathRelative = 'uploads/' . $newImageName;
|
||||
$newImageFullPath = public_path('storage/' . $newImagePathRelative);
|
||||
$newImageName = 'styled_'.uniqid().'.png';
|
||||
$newImagePathRelative = 'uploads/'.$newImageName;
|
||||
$newImageFullPath = public_path('storage/'.$newImagePathRelative);
|
||||
|
||||
if (!File::exists(public_path('storage/uploads'))) {
|
||||
if (! File::exists(public_path('storage/uploads'))) {
|
||||
File::makeDirectory(public_path('storage/uploads'), 0755, true);
|
||||
Log::info('Created uploads directory.', ['path' => public_path('storage/uploads')]);
|
||||
}
|
||||
@@ -334,12 +349,13 @@ class ImageController extends Controller
|
||||
'message' => 'Styled image fetched successfully',
|
||||
'styled_image' => [
|
||||
'id' => $newImage->id,
|
||||
'path' => asset('storage/' . $newImage->path),
|
||||
'path' => asset('storage/'.$newImage->path),
|
||||
'is_temp' => $newImage->is_temp,
|
||||
],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error in fetchStyledImage: ' . $e->getMessage(), ['exception' => $e]);
|
||||
Log::error('Error in fetchStyledImage: '.$e->getMessage(), ['exception' => $e]);
|
||||
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
@@ -348,15 +364,15 @@ class ImageController extends Controller
|
||||
{
|
||||
$styleId = $request->query('style_id');
|
||||
$imageUuid = $request->query('image_uuid');
|
||||
|
||||
|
||||
$apiProvider = null;
|
||||
|
||||
|
||||
// If style_id is provided, get the API provider for that style
|
||||
if ($styleId) {
|
||||
$style = Style::with(['aiModel' => function ($query) {
|
||||
$query->where('enabled', true)->with('primaryApiProvider');
|
||||
}])->find($styleId);
|
||||
|
||||
|
||||
if ($style && $style->aiModel) {
|
||||
// Use the primary API provider for this AI model
|
||||
$apiProvider = $style->aiModel->primaryApiProvider;
|
||||
@@ -367,7 +383,7 @@ class ImageController extends Controller
|
||||
$image = Image::with(['style.aiModel' => function ($query) {
|
||||
$query->with('primaryApiProvider');
|
||||
}])->where('uuid', $imageUuid)->first();
|
||||
|
||||
|
||||
if ($image && $image->style && $image->style->aiModel) {
|
||||
// Use the primary API provider for this AI model
|
||||
$apiProvider = $image->style->aiModel->primaryApiProvider;
|
||||
@@ -376,25 +392,25 @@ class ImageController extends Controller
|
||||
// Fallback to the old behavior if no style_id or image_uuid is provided
|
||||
else {
|
||||
// Try to get a default style if none is provided
|
||||
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
|
||||
if ($defaultStyleSetting && $defaultStyleSetting->value) {
|
||||
$defaultStyleId = $this->settings->default_style_id;
|
||||
if ($defaultStyleId) {
|
||||
$style = Style::with(['aiModel' => function ($query) {
|
||||
$query->where('enabled', true)->with('primaryApiProvider');
|
||||
}])->find($defaultStyleSetting->value);
|
||||
|
||||
}])->find($defaultStyleId);
|
||||
|
||||
if ($style && $style->aiModel) {
|
||||
// Use the primary API provider for this AI model
|
||||
$apiProvider = $style->aiModel->primaryApiProvider;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If still no API provider, use the first available ComfyUI provider
|
||||
if (!$apiProvider) {
|
||||
if (! $apiProvider) {
|
||||
$apiProvider = ApiProvider::where('plugin', 'ComfyUi')->where('enabled', true)->first();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$apiProvider) {
|
||||
if (! $apiProvider) {
|
||||
return response()->json(['error' => 'No enabled ComfyUI API provider found.'], 404);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Style;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Settings\GeneralSettings;
|
||||
|
||||
class StyleController extends Controller
|
||||
{
|
||||
public function __construct(private GeneralSettings $settings) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$styles = Style::with(['aiModel.primaryApiProvider'])
|
||||
@@ -31,15 +32,15 @@ class StyleController extends Controller
|
||||
|
||||
public function getImageRefreshInterval()
|
||||
{
|
||||
$interval = Setting::where('key', 'image_refresh_interval')->first();
|
||||
|
||||
return response()->json(['interval' => $interval ? (int)$interval->value / 1000 : 5]);
|
||||
return response()->json([
|
||||
'interval' => $this->settings->image_refresh_interval / 1000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMaxNumberOfCopies()
|
||||
{
|
||||
$maxCopies = Setting::where('key', 'max_number_of_copies')->first();
|
||||
|
||||
return response()->json(['max_copies' => $maxCopies ? (int)$maxCopies->value : 10]); // Default to 10 if not set
|
||||
return response()->json([
|
||||
'max_copies' => $this->settings->max_number_of_copies,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DownloadController extends Controller
|
||||
{
|
||||
@@ -14,39 +16,61 @@ class DownloadController extends Controller
|
||||
'image_path' => 'required|string',
|
||||
]);
|
||||
|
||||
$imagePath = $request->input('image_path');
|
||||
|
||||
// Check if it's a relative path and make it absolute
|
||||
if (!filter_var($imagePath, FILTER_VALIDATE_URL)) {
|
||||
$imagePath = public_path(str_replace(url('/'), '', $imagePath));
|
||||
}
|
||||
$resolvedPath = $this->resolveImagePath($request->input('image_path'));
|
||||
|
||||
if (! $resolvedPath || ! File::exists($resolvedPath)) {
|
||||
Log::error("DownloadController: Image file not found at {$resolvedPath}");
|
||||
|
||||
// Validate file exists
|
||||
if (!file_exists($imagePath)) {
|
||||
Log::error("DownloadController: Image file not found at {$imagePath}");
|
||||
return response()->json(['error' => 'Image file not found.'], 404);
|
||||
}
|
||||
|
||||
// Get file info
|
||||
$fileName = basename($imagePath);
|
||||
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||||
$mimeType = $this->getMimeType($fileExtension);
|
||||
$extension = strtolower(File::extension($resolvedPath) ?: 'jpg');
|
||||
$downloadName = $this->buildDownloadName($extension);
|
||||
$mimeType = File::mimeType($resolvedPath) ?: $this->getMimeType($extension);
|
||||
|
||||
try {
|
||||
Log::info("DownloadController: Serving download for {$imagePath}");
|
||||
|
||||
// Return the file with proper headers for download
|
||||
return response()->download($imagePath, $fileName, [
|
||||
Log::info("DownloadController: Serving download for {$resolvedPath}");
|
||||
|
||||
return response()->download($resolvedPath, $downloadName, [
|
||||
'Content-Type' => $mimeType,
|
||||
'Content-Disposition' => 'attachment; filename="' . $fileName . '"',
|
||||
'Content-Disposition' => 'attachment; filename="'.$downloadName.'"',
|
||||
]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("DownloadController: Error serving download: " . $e->getMessage());
|
||||
Log::error('DownloadController: Error serving download: '.$e->getMessage());
|
||||
|
||||
return response()->json(['error' => 'Failed to serve download.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveImagePath(string $path): ?string
|
||||
{
|
||||
if (filter_var($path, FILTER_VALIDATE_URL)) {
|
||||
$parsed = parse_url($path, PHP_URL_PATH);
|
||||
|
||||
return $parsed ? public_path(ltrim($parsed, '/')) : null;
|
||||
}
|
||||
|
||||
if (Str::startsWith($path, ['storage/', 'public/'])) {
|
||||
return public_path(ltrim($path, '/'));
|
||||
}
|
||||
|
||||
if (File::exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$candidate = public_path(ltrim($path, '/'));
|
||||
|
||||
return File::exists($candidate) ? $candidate : null;
|
||||
}
|
||||
|
||||
private function buildDownloadName(string $extension): string
|
||||
{
|
||||
$timestamp = Carbon::now()->format('Ymd_His');
|
||||
|
||||
return sprintf('stylegallery_%s.%s', $timestamp, $extension);
|
||||
}
|
||||
|
||||
private function getMimeType(string $extension): string
|
||||
{
|
||||
$mimeTypes = [
|
||||
@@ -61,4 +85,4 @@ class DownloadController extends Controller
|
||||
|
||||
return $mimeTypes[strtolower($extension)] ?? 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Image;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use App\Settings\GeneralSettings;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function __construct(private GeneralSettings $settings) {}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
@@ -18,12 +19,13 @@ class HomeController extends Controller
|
||||
Lang::get('api', [], $locale),
|
||||
Lang::get('settings', [], $locale)
|
||||
);
|
||||
$galleryHeading = Setting::where('key', 'gallery_heading')->first()->value ?? 'Style Gallery';
|
||||
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
|
||||
$galleryHeading = $this->settings->gallery_heading;
|
||||
$newImageTimespanMinutes = $this->settings->new_image_timespan_minutes;
|
||||
|
||||
$images = Image::all()->map(function ($image) use ($newImageTimespanMinutes) {
|
||||
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
|
||||
$image->path = 'storage/' . $image->path;
|
||||
$image->path = 'storage/'.$image->path;
|
||||
|
||||
return $image;
|
||||
});
|
||||
|
||||
@@ -33,4 +35,4 @@ class HomeController extends Controller
|
||||
'images' => $images,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\PrinterService;
|
||||
use App\Settings\GeneralSettings;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\PrinterService;
|
||||
|
||||
class PrintController extends Controller
|
||||
{
|
||||
public function __construct(private GeneralSettings $settings) {}
|
||||
|
||||
public function printImage(Request $request, PrinterService $printerService)
|
||||
{
|
||||
$request->validate([
|
||||
@@ -17,21 +20,20 @@ class PrintController extends Controller
|
||||
|
||||
$imagePath = public_path(str_replace(url('/'), '', $request->input('image_path')));
|
||||
$quantity = $request->input('quantity');
|
||||
// Retrieve printer name from global settings using standard Eloquent
|
||||
$printerName = \App\Models\Setting::where('key', 'selected_printer')->value('value');
|
||||
|
||||
if (!$printerName) {
|
||||
Log::error("PrintController: Default printer name not found in settings.");
|
||||
$printerName = $this->settings->selected_printer === '__custom__'
|
||||
? $this->settings->custom_printer_address
|
||||
: $this->settings->selected_printer;
|
||||
|
||||
if (! $printerName) {
|
||||
Log::error('PrintController: Default printer name not found in settings.');
|
||||
|
||||
return response()->json(['error' => 'Default printer not configured.'], 500);
|
||||
}
|
||||
|
||||
if (!$printerName) {
|
||||
Log::error("PrintController: Default printer name not found in settings.");
|
||||
return response()->json(['error' => 'Default printer not configured.'], 500);
|
||||
}
|
||||
|
||||
if (!file_exists($imagePath)) {
|
||||
if (! file_exists($imagePath)) {
|
||||
Log::error("PrintController: Image file not found at {$imagePath}");
|
||||
|
||||
return response()->json(['error' => 'Image file not found.'], 404);
|
||||
}
|
||||
|
||||
@@ -39,9 +41,11 @@ class PrintController extends Controller
|
||||
|
||||
if ($printSuccess) {
|
||||
Log::info("PrintController: Successfully sent print command for {$imagePath} (x{$quantity}) to {$printerName}");
|
||||
|
||||
return response()->json(['message' => 'Print command sent successfully.']);
|
||||
} else {
|
||||
Log::error("PrintController: Failed to send print command for {$imagePath} (x{$quantity}) to {$printerName}");
|
||||
|
||||
return response()->json(['error' => 'Failed to send print command.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Settings\GeneralSettings;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
use App\Models\Setting;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
@@ -18,7 +18,7 @@ class HandleInertiaRequests extends Middleware
|
||||
/**
|
||||
* Determine the current asset version.
|
||||
*/
|
||||
public function version(Request $request): string|null
|
||||
public function version(Request $request): ?string
|
||||
{
|
||||
return parent::version($request);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class HandleInertiaRequests extends Middleware
|
||||
'user' => $request->user(),
|
||||
],
|
||||
'locale' => app()->getLocale(),
|
||||
'settings' => Setting::all()->pluck('value', 'key'),
|
||||
'settings' => app(GeneralSettings::class)->toArray(),
|
||||
'translations' => function () use ($request) {
|
||||
$currentLocale = app()->getLocale(); // Store current locale
|
||||
$requestedLocale = $request->input('locale', $currentLocale);
|
||||
@@ -50,6 +50,7 @@ class HandleInertiaRequests extends Middleware
|
||||
];
|
||||
|
||||
app()->setLocale($currentLocale); // Revert to original locale
|
||||
|
||||
return $lang;
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['key', 'value'];
|
||||
}
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
@@ -50,4 +52,9 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Filament\Resources\PluginResource;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
@@ -16,12 +17,9 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
use App\Filament\Resources\StyleResource;
|
||||
use App\Filament\Resources\SettingResource\Pages\Settings;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Filament\Resources\PluginResource;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
@@ -33,8 +31,8 @@ class AdminPanelProvider extends PanelProvider
|
||||
->path('admin')
|
||||
->login()
|
||||
->brandLogo(fn () => new HtmlString(
|
||||
'<img src="' . asset('icon.png') . '" alt="App Icon" style="height: 2.5rem; display: inline-block; vertical-align: middle; margin-right: 0.5rem;" />' .
|
||||
'<span style="vertical-align: middle; font-weight: bold; font-size: 1.25rem;">' . config('app.name') . '</span>'
|
||||
'<img src="'.asset('icon.png').'" alt="App Icon" style="height: 2.5rem; display: inline-block; vertical-align: middle; margin-right: 0.5rem;" />'.
|
||||
'<span style="vertical-align: middle; font-weight: bold; font-size: 1.25rem;">'.config('app.name').'</span>'
|
||||
))
|
||||
->colors([
|
||||
'primary' => Color::Amber,
|
||||
@@ -70,7 +68,7 @@ class AdminPanelProvider extends PanelProvider
|
||||
Authenticate::class,
|
||||
])
|
||||
->plugins([
|
||||
|
||||
|
||||
])
|
||||
->profile();
|
||||
|
||||
@@ -86,4 +84,3 @@ class AdminPanelProvider extends PanelProvider
|
||||
return $panel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
app/Settings/GeneralSettings.php
Normal file
29
app/Settings/GeneralSettings.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Settings;
|
||||
|
||||
use Spatie\LaravelSettings\Settings;
|
||||
|
||||
class GeneralSettings extends Settings
|
||||
{
|
||||
public string $gallery_heading = 'Style Gallery';
|
||||
|
||||
public int $new_image_timespan_minutes = 60;
|
||||
|
||||
public int $image_refresh_interval = 30_000;
|
||||
|
||||
public int $max_number_of_copies = 3;
|
||||
|
||||
public bool $show_print_button = true;
|
||||
|
||||
public ?string $selected_printer = null;
|
||||
|
||||
public ?string $custom_printer_address = null;
|
||||
|
||||
public ?int $default_style_id = null;
|
||||
|
||||
public static function group(): string
|
||||
{
|
||||
return 'general';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user