Add all files

This commit is contained in:
root
2025-11-30 11:57:22 +01:00
parent 2ee51cac4f
commit 044271db3d
1476 changed files with 142544 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Admin\Resources\ServerResource\Pages;
use App\Admin\Resources\ServerResource;
use App\Helpers\ExtensionHelper;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
class CreateServer extends CreateRecord
{
protected static string $resource = ServerResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['type'] = 'server';
return $data;
}
protected function handleRecordCreation(array $data): Model
{
$record = static::getModel()::create(\Arr::except($data, ['settings']));
if (!isset($data['settings'])) {
return $record;
}
foreach ($data['settings'] as $key => $value) {
if (is_null($value)) {
continue;
}
$record->settings()->updateOrCreate([
'key' => $key,
], [
'value' => $value,
]);
}
ExtensionHelper::call($record, 'enabled', [$record], mayFail: true);
return $record;
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Admin\Resources\ServerResource\Pages;
use App\Admin\Resources\ServerResource;
use App\Helpers\ExtensionHelper;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
class EditServer extends EditRecord
{
protected static string $resource = ServerResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make()->before(fn ($record) => ExtensionHelper::call($record, 'disabled', [$record], mayFail: true)),
];
}
protected function mutateFormDataBeforeFill(array $data): array
{
foreach ($this->record->settings as $setting) {
$data['settings'][$setting->key] = $setting->value;
}
return $data;
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
$record->update(Arr::except($data, ['settings']));
if (!isset($data['settings'])) {
return $record;
}
$config = ExtensionHelper::getConfig($record->type, $record->extension);
foreach ($config as $option) {
$record->settings()->updateOrCreate([
'key' => $option['name'],
'settingable_id' => $record->id,
'settingable_type' => $record->getMorphClass(),
], [
'type' => $option['database_type'] ?? 'string',
'value' => isset($data['settings'][$option['name']]) ? (is_array($data['settings'][$option['name']]) ? json_encode($data['settings'][$option['name']]) : $data['settings'][$option['name']]) : null,
'encrypted' => $option['encrypted'] ?? false,
]);
}
ExtensionHelper::call($record, 'updated', [$record], mayFail: true);
// Maybe the extension changed the record, so we need to refresh it
return $record->refresh();
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Admin\Resources\ServerResource\Pages;
use App\Admin\Resources\ServerResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListServers extends ListRecords
{
protected static string $resource = ServerResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}