initial import
This commit is contained in:
131
app/Filament/Resources/ApiProviderResource.php
Normal file
131
app/Filament/Resources/ApiProviderResource.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ApiProviderResource\Pages;
|
||||
use App\Filament\Resources\ApiProviderResource\RelationManagers;
|
||||
use App\Models\ApiProvider;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use App\Api\Plugins\ApiPluginInterface;
|
||||
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
|
||||
class ApiProviderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ApiProvider::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
$plugins = self::getAvailablePlugins();
|
||||
|
||||
return $form
|
||||
->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')),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')->label(__('filament.resource.api_provider.table.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(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
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))) {
|
||||
$instance = new $class();
|
||||
$plugins[$instance->getIdentifier()] = $instance->getName();
|
||||
}
|
||||
}
|
||||
return $plugins;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user