Neues Plugin IT-Service (OpenNIT); Abteilung bei „Geschrieben von“
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m35s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 20:05:41 +00:00
parent c713194a83
commit c1117829c3
139 changed files with 2455 additions and 398 deletions

View file

@ -0,0 +1,135 @@
<?php
namespace Inhaus\Plugins\ItService\Filament\Pages;
use App\Support\Audit;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Inhaus\Plugins\ItService\OpenNit\Client;
use Inhaus\Plugins\ItService\OpenNit\OpenNitException;
use Inhaus\Plugins\ItService\OpenNit\Settings;
use UnitEnum;
class ItServiceSettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedLifebuoy;
protected static string|UnitEnum|null $navigationGroup = 'Portal';
protected static ?int $navigationSort = 60;
protected static ?string $navigationLabel = 'IT-Service';
protected static ?string $title = 'IT-Service (OpenNIT)';
protected static ?string $slug = 'it-service';
/** @var array<string, mixed>|null */
public ?array $data = [];
public static function canAccess(): bool
{
return auth()->user()?->can('it-service.manage') ?? false;
}
public function mount(Settings $settings): void
{
$this->form->fill([
'url' => $settings->url(),
'token' => null,
'secret' => null,
'auto_reserve' => match ($settings->autoReserve()) {
true => 'yes', false => 'no', null => 'default'
},
'intro' => $settings->intro(),
]);
}
public function form(Schema $schema): Schema
{
$settings = app(Settings::class);
return $schema->statePath('data')->components([
Section::make('Verbindung zu OpenNIT')
->description('Token und Signing-Secret erzeugen Sie in OpenNIT unter /admin/api (Token-Verwaltung) mit den Scopes „tickets“, „assets“ und „loans“. Beide werden verschlüsselt gespeichert. Die Zuordnung zu Personen erfolgt über die E-Mail-Adresse im Portal.')
->schema([
TextInput::make('url')
->label('API-Adresse')
->placeholder('https://itdoku.example.de/api/ex')
->url()
->required()
->regex('#^https://#i')
->validationMessages(['regex' => 'Die API ist nur über HTTPS erreichbar.']),
TextInput::make('token')
->label('Token')
->password()
->revealable()
->placeholder($settings->token() !== '' ? '•••••••• (gespeichert – leer lassen, um ihn zu behalten)' : '')
->required(fn () => $settings->token() === ''),
TextInput::make('secret')
->label('Signing-Secret')
->password()
->revealable()
->placeholder($settings->secret() !== '' ? '•••••••• (gespeichert – leer lassen, um es zu behalten)' : '')
->required(fn () => $settings->secret() === ''),
]),
Section::make('Leihgeräte')
->schema([
Select::make('auto_reserve')
->label('Anfragen aus dem Portal')
->options([
'default' => 'Wie in OpenNIT eingestellt',
'no' => 'Immer als Anfrage – die IT bestätigt',
'yes' => 'Sofort fest reservieren',
])
->selectablePlaceholder(false)
->default('default'),
]),
Section::make('Hinweistext')
->description('Erscheint oben auf „Meine IT“, z. B. Telefonnummer der IT-Hotline oder Servicezeiten.')
->schema([
RichEditor::make('intro')->hiddenLabel()->toolbarButtons([['bold', 'italic', 'link'], ['bulletList'], ['undo', 'redo']]),
]),
]);
}
public function save(Settings $settings): void
{
$data = $this->form->getState();
$settings->save($data);
Audit::log('it-service.settings', ['url' => $settings->url()]);
Notification::make()->success()->title('IT-Service gespeichert')->send();
$this->mount($settings);
}
protected function getHeaderActions(): array
{
return [
Action::make('test')
->label('Verbindung testen')
->icon(Heroicon::OutlinedSignal)
->color('gray')
->action(function (Client $client) {
try {
$categories = count((array) ($client->get('/ticket-categories')['categories'] ?? []));
$types = count((array) ($client->get('/device-types')['types'] ?? []));
Notification::make()->success()->title('Verbindung klappt')->body("{$categories} Ticket-Kategorien und {$types} Gerätetypen gefunden.")->send();
} catch (OpenNitException $e) {
Notification::make()->danger()->title('Keine Verbindung')->body($e->getMessage().($e->status ? " (HTTP {$e->status})" : ''))->persistent()->send();
}
}),
Action::make('portal')->label('Meine IT ansehen')->icon(Heroicon::OutlinedEye)->color('gray')->url('/it-service')->openUrlInNewTab(),
];
}
}