Neues Modul: Qualitätsmanagement
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m55s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 4m15s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m46s
CI / Build-Artefakte aktuell (pull_request) Successful in 52s

- Kategorien mit farbigen Ordnerkacheln; Farbe und Symbol je Ordner
  (Auswahl oder eigener Upload, SVG bereinigt), an Unterordner vererbt
- Ordnerseite: Einführungstext, Ansprechpartner (Profilfelder wählbar),
  Unterordner, Liste mit Dokument, Version, Stand, Größe, Aktion
- Einträge: Datei (Lesefassung + bearbeitbare Vorlage), Link,
  Online-Formular; neue Fassungen archivieren die bisherigen
- PDF-Betrachter im Portal (pdf.js)
- Eigene Volltextsuche (PDF, Word, Excel, PowerPoint, OpenDocument)
  mit Textausschnitt; optionale Texterkennung per Tesseract
- Rollen-Ausschluss für das ganze Modul, Pflegerecht qm.manage,
  Zielgruppen je Kategorie
- Vorbereitet: Wiedervorlage, Verantwortliche, Lesebestätigungen
- Abhängigkeit smalot/pdfparser

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 15:50:23 +00:00
parent f78cc96be7
commit b3a057e27c
218 changed files with 13478 additions and 358 deletions

View file

@ -0,0 +1,125 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Pages;
use App\Models\Role;
use App\Support\Audit;
use App\Support\Settings;
use BackedEnum;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Text;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\HtmlString;
use Inhaus\Plugins\Qm\Presenter;
use Inhaus\Plugins\Qm\QmAccess;
use Inhaus\Plugins\Qm\Text\Ocr;
use UnitEnum;
class QmSettings extends Page
{
protected string $view = 'filament.pages.settings-form';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedAdjustmentsHorizontal;
protected static string|UnitEnum|null $navigationGroup = 'Qualitätsmanagement';
protected static ?int $navigationSort = 3;
protected static ?string $navigationLabel = 'QM-Einstellungen';
protected static ?string $title = 'QM-Einstellungen';
protected static ?string $slug = 'qm-einstellungen';
/** @var array<string, mixed>|null */
public ?array $data = [];
public static function canAccess(): bool
{
return auth()->user()?->can('qm.manage') ?? false;
}
public function mount(Settings $settings): void
{
$this->form->fill([
'contact_fields' => (array) $settings->get(Presenter::CONTACT_FIELDS, Presenter::DEFAULT_CONTACT_FIELDS),
'excluded_roles' => array_map('strval', (array) $settings->get(QmAccess::EXCLUDED_ROLES, [])),
'ocr_enabled' => (bool) $settings->get(Ocr::SETTING_ENABLED, false),
'ocr_binary' => (string) $settings->get(Ocr::SETTING_BINARY, ''),
]);
}
public function form(Schema $schema): Schema
{
return $schema->statePath('data')->components([
Section::make('Ansprechpartner')
->description('Welche Angaben aus dem Profil bei Ansprechpartnern in den QM-Ordnern erscheinen. Name und Foto werden immer gezeigt.')
->schema([
CheckboxList::make('contact_fields')->hiddenLabel()->columns(3)
->options(fn () => app(Presenter::class)->contactFieldOptions()),
]),
Section::make('Zugang')
->description('Grundsätzlich sehen alle angemeldeten Personen das Qualitätsmanagement; pflegen darf nur, wer das Recht „Qualitätsmanagement pflegen“ hat (ohne Vergabe: die Administration).')
->schema([
Select::make('excluded_roles')->label('Ausgeschlossene Rollen')->multiple()->native(false)
->options(fn () => Role::query()->orderBy('name')->pluck('name', 'id')->mapWithKeys(fn ($name, $id) => [(string) $id => $name])->all())
->helperText('Wer eine dieser Rollen hat, sieht das Modul nicht – weder im Menü noch über Links (z. B. Klient*innen, Gäste). Der Ausschluss geht anderen Rollen vor.'),
]),
Section::make('Texterkennung (OCR) für eingescannte PDFs')
->description('Text aus PDF, Word, Excel und PowerPoint wird immer durchsuchbar gemacht. Eingescannte PDFs ohne Textebene brauchen dafür eine Texterkennung auf dem Server.')
->columns(2)
->schema([
Text::make(fn () => $this->ocrStatus())->columnSpanFull(),
Toggle::make('ocr_enabled')->label('Texterkennung verwenden')
->helperText('Läuft im Hintergrund (Hintergrundaufgaben), einige Dateien je Durchgang.'),
TextInput::make('ocr_binary')->label('Pfad zu Tesseract')->placeholder('tesseract')->maxLength(200)
->regex('#^(/[\w./-]+|[\w.-]+)$#')
->helperText('Nur nötig, wenn das Programm nicht im Suchpfad liegt, z. B. /usr/bin/tesseract.'),
]),
]);
}
public function save(Settings $settings): void
{
$data = $this->form->getState();
$options = app(Presenter::class)->contactFieldOptions();
$settings->setMany([
Presenter::CONTACT_FIELDS => array_values(array_intersect((array) $data['contact_fields'], array_keys($options))),
QmAccess::EXCLUDED_ROLES => array_values(array_map('intval', (array) $data['excluded_roles'])),
Ocr::SETTING_ENABLED => (bool) $data['ocr_enabled'],
Ocr::SETTING_BINARY => trim((string) $data['ocr_binary']),
]);
Audit::log('qm.settings_saved', ['excluded_roles' => count((array) $data['excluded_roles'])]);
Notification::make()->success()->title('Gespeichert')->send();
}
private function ocrStatus(): HtmlString
{
$status = app(Ocr::class)->status();
$pending = DB::table('qm_files')->where('text_status', 'needs_ocr')->whereNull('archived_at')->count();
$ok = fn (bool $v) => $v ? '<span style="color:rgb(22 163 74)">✔</span>' : '<span style="color:rgb(220 38 38)">✘</span>';
return new HtmlString(
'<div style="display:grid;gap:4px;font-size:13px">'
.'<div>'.$ok($status['exec']).' Programme aufrufen erlaubt (PHP-Funktion proc_open)</div>'
.'<div>'.$ok($status['tesseract'] !== null).' Tesseract: '.e($status['tesseract'] ?? 'nicht gefunden')
.($status['languages'] ? ' · Sprachen: '.e(implode(', ', array_slice($status['languages'], 0, 8))) : '').'</div>'
.'<div>'.$ok($status['rasterizer'] !== null).' PDF-Seiten in Bilder umwandeln: '.e($status['rasterizer'] ?? 'weder pdftoppm noch Imagick mit PDF-Unterstützung').'</div>'
.'<div style="margin-top:4px">'.$pending.' eingescannte Datei(en) warten auf Texterkennung.</div>'
.'<div style="margin-top:6px;opacity:.75">Einrichtung auf eigenem Server (Debian/Ubuntu): <code>apt install tesseract-ocr tesseract-ocr-deu poppler-utils</code>. Ein Apache-Modul gibt es dafür nicht; Tesseract ist ein eigenständiges Programm, das PHP aufruft.</div>'
.'</div>'
);
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmCategories\Pages;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ManageRecords;
use Inhaus\Plugins\Qm\Filament\Resources\QmCategories\QmCategoryResource;
use Inhaus\Plugins\Qm\QmTree;
class ManageQmCategories extends ManageRecords
{
protected static string $resource = QmCategoryResource::class;
protected function getHeaderActions(): array
{
return [CreateAction::make()->label('Kategorie anlegen')->after(fn () => QmTree::flush())];
}
}

View file

@ -0,0 +1,73 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmCategories;
use App\Filament\Components\AudienceSection;
use BackedEnum;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Inhaus\Plugins\Qm\Filament\Resources\QmCategories\Pages\ManageQmCategories;
use Inhaus\Plugins\Qm\Models\QmCategory;
use Inhaus\Plugins\Qm\QmTree;
use UnitEnum;
/**
* Kategorien der QM-Startseite (Überschrift mit Trennlinie über den Ordnerkacheln).
*/
class QmCategoryResource extends Resource
{
protected static ?string $model = QmCategory::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
protected static string|UnitEnum|null $navigationGroup = 'Qualitätsmanagement';
protected static ?int $navigationSort = 2;
protected static ?string $modelLabel = 'QM-Kategorie';
protected static ?string $pluralModelLabel = 'Kategorien';
protected static ?string $slug = 'qm-kategorien';
public static function canAccess(): bool
{
return auth()->user()?->can('qm.manage') ?? false;
}
public static function form(Schema $schema): Schema
{
return $schema->columns(2)->components([
TextInput::make('name')->label('Name')->required()->maxLength(120)->placeholder('z. B. Allgemein'),
TextInput::make('sort')->label('Reihenfolge')->numeric()->default(0),
AudienceSection::make('qm_category', 'Wer die Kategorie samt allen Ordnern sieht. Leer lassen = alle, die das QM-Modul sehen.')->columnSpanFull()->collapsed(),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('sort')
->reorderable('sort')
->modifyQueryUsing(fn ($query) => $query->withCount('folders'))
->columns([
TextColumn::make('name')->label('Name')->weight('medium'),
TextColumn::make('folders_count')->label('Ordner'),
])
->recordActions([
EditAction::make()->after(fn () => QmTree::flush()),
DeleteAction::make()->modalDescription('Die Ordner bleiben erhalten und erscheinen unter „Weitere“.'),
]);
}
public static function getPages(): array
{
return ['index' => ManageQmCategories::route('/')];
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages;
use App\Support\Theme\SvgSanitizer;
use Filament\Resources\Pages\CreateRecord;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\QmFolderResource;
use Inhaus\Plugins\Qm\QmTree;
class CreateQmFolder extends CreateRecord
{
protected static string $resource = QmFolderResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['created_by'] = auth()->id();
if (filled($data['parent_id'] ?? null)) {
$data['category_id'] = null;
}
return $data;
}
protected function afterCreate(): void
{
SvgSanitizer::sanitizeFile($this->record->icon_path);
QmTree::flush();
}
protected function getRedirectUrl(): string
{
return QmFolderResource::getUrl('index');
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages;
use App\Support\Theme\SvgSanitizer;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\Facades\Storage;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\QmFolderResource;
use Inhaus\Plugins\Qm\QmTree;
class EditQmFolder extends EditRecord
{
protected static string $resource = QmFolderResource::class;
private ?string $previousIcon = null;
protected function mutateFormDataBeforeSave(array $data): array
{
$this->previousIcon = $this->record->icon_path;
if (filled($data['parent_id'] ?? null)) {
$data['category_id'] = null;
}
return $data;
}
protected function afterSave(): void
{
if ($this->previousIcon && $this->previousIcon !== $this->record->icon_path) {
Storage::disk('uploads')->delete($this->previousIcon);
}
SvgSanitizer::sanitizeFile($this->record->icon_path);
QmTree::flush();
}
protected function getHeaderActions(): array
{
return [
Action::make('open')->label('Im Portal ansehen')->icon(Heroicon::OutlinedEye)->color('gray')
->url(fn () => route('qm.folder', $this->record))->openUrlInNewTab(),
DeleteAction::make()->visible(fn () => ! $this->record->entries()->exists() && ! $this->record->children()->exists()),
];
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
use Filament\Support\Icons\Heroicon;
use Illuminate\Database\Eloquent\Builder;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\QmFolderResource;
use Inhaus\Plugins\Qm\QmTree;
class ListQmFolders extends ListRecords
{
protected static string $resource = QmFolderResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('portal')->label('QM im Portal')->icon(Heroicon::OutlinedEye)->color('gray')->url('/qm')->openUrlInNewTab(),
CreateAction::make()->label('Ordner anlegen'),
];
}
/**
* In Baumreihenfolge: jeder Ordner direkt unter seinem übergeordneten.
*/
protected function applySortingToTableQuery(Builder $query): Builder
{
$order = array_keys(app(QmTree::class)->options());
return $order === [] ? $query : $query->orderByRaw('FIELD(id, '.implode(',', array_map('intval', $order)).')');
}
}

View file

@ -0,0 +1,148 @@
<?php
namespace Inhaus\Plugins\Qm\Filament\Resources\QmFolders;
use App\Support\Icons;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;
use Inhaus\Plugins\Qm\Colors;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages\CreateQmFolder;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages\EditQmFolder;
use Inhaus\Plugins\Qm\Filament\Resources\QmFolders\Pages\ListQmFolders;
use Inhaus\Plugins\Qm\Models\QmCategory;
use Inhaus\Plugins\Qm\Models\QmFolder;
use Inhaus\Plugins\Qm\QmTree;
use UnitEnum;
/**
* QM-Ordner: Struktur, Farbe und Symbol (werden vererbt), Einführungstext und
* Ansprechpartner. Dokumente pflegt das QM-Team direkt im Portal.
*/
class QmFolderResource extends Resource
{
protected static ?string $model = QmFolder::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedFolder;
protected static string|UnitEnum|null $navigationGroup = 'Qualitätsmanagement';
protected static ?int $navigationSort = 1;
protected static ?string $modelLabel = 'QM-Ordner';
protected static ?string $pluralModelLabel = 'Ordner';
protected static ?string $slug = 'qm-ordner';
public static function canAccess(): bool
{
return auth()->user()?->can('qm.manage') ?? false;
}
public static function form(Schema $schema): Schema
{
return $schema->columns(1)->components([
Section::make('Ordner')->columns(2)->schema([
TextInput::make('name')->label('Name')->required()->maxLength(120),
Select::make('parent_id')->label('Übergeordneter Ordner')->placeholder('– oberste Ebene –')->searchable()->native(false)->live()
->options(fn (?QmFolder $record) => collect(app(QmTree::class)->options())
->except($record ? [$record->id, ...app(QmTree::class)->descendantIds([$record->id])] : [])->all()),
Select::make('category_id')->label('Kategorie auf der QM-Startseite')->native(false)
->options(fn () => QmCategory::query()->orderBy('sort')->pluck('name', 'id')->all())
->required(fn (Get $get) => blank($get('parent_id')))
->visible(fn (Get $get) => blank($get('parent_id')))
->helperText('Nur für Ordner der obersten Ebene. Kategorien legen Sie unter „Kategorien“ an.'),
TextInput::make('sort')->label('Reihenfolge')->numeric()->default(0),
]),
Section::make('Farbe und Symbol')
->description('Unterordner übernehmen Farbe und Symbol, solange dort nichts eigenes gewählt ist.')
->columns(2)
->schema([
Select::make('color')->label('Farbe')->native(false)->allowHtml()
->options(Colors::options())
->placeholder(fn (Get $get) => blank($get('parent_id')) ? 'Standard (Blau)' : 'Vom übergeordneten Ordner übernehmen'),
Select::make('icon')->label('Symbol')->native(false)->allowHtml()->searchable()
->options(Icons::options())
->getSearchResultsUsing(fn (string $search) => Icons::search($search))
->getOptionLabelUsing(fn (?string $value) => $value ? Icons::option($value) : null)
->placeholder(fn (Get $get) => blank($get('parent_id')) ? 'Ordner' : 'Vom übergeordneten Ordner übernehmen')
->helperText('Alle 1.800+ Symbole über die Suche (englische Namen).'),
FileUpload::make('icon_path')->label('Oder eigenes Symbol hochladen')
->disk('uploads')->directory('qm-icons')->visibility('public')
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp', 'image/jpeg'])->maxSize(1024)
->helperText('SVG (empfohlen), PNG, WebP oder JPG, quadratisch. Ersetzt das Symbol aus der Auswahl.')
->live(),
Toggle::make('icon_mono')->label('Eigenes Symbol einfarbig darstellen')->default(true)
->helperText('Wie die mitgelieferten Symbole: weiß auf der Kachel. Für farbige Logos ausschalten.')
->visible(fn (Get $get) => filled($get('icon_path'))),
]),
Section::make('Einführungstext')->schema([
RichEditor::make('intro')->hiddenLabel()
->toolbarButtons(['bold', 'italic', 'link', 'bulletList', 'orderedList', 'h3', 'blockquote', 'undo', 'redo']),
]),
Section::make('Ansprechpartner')
->description('Welche Angaben aus dem Profil erscheinen (Telefon, E-Mail …), legen Sie unter „QM-Einstellungen“ fest.')
->schema([
Select::make('contacts')->hiddenLabel()->multiple()->searchable()->preload()
->relationship('contacts', 'name', fn ($query) => $query->where('is_active', true)->orderBy('last_name'))
->getOptionLabelFromRecordUsing(fn ($record) => $record->name.($record->job_title ? ' – '.$record->job_title : '')),
]),
]);
}
public static function table(Table $table): Table
{
$tree = app(QmTree::class);
return $table
->modifyQueryUsing(fn ($query) => $query->withCount('entries'))
->defaultSort('name')
->paginated(false)
->columns([
TextColumn::make('name')->label('Ordner')->weight('medium')->searchable()
->formatStateUsing(function (string $state, QmFolder $record) use ($tree) {
$node = $tree->folder($record->id);
$depth = max(0, count($tree->path($record->id)) - 1);
$hex = Colors::PALETTE[$node['color'] ?? Colors::DEFAULT][1];
return new HtmlString(str_repeat('<span style="display:inline-block;width:20px"></span>', $depth)
.'<span style="display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:8px;background:'.$hex.'"></span>'.e($state));
}),
TextColumn::make('category.name')->label('Kategorie')->placeholder('–'),
TextColumn::make('entries_count')->label('Einträge'),
])
->recordActions([
Action::make('open')->label('Im Portal')->icon(Heroicon::OutlinedArrowTopRightOnSquare)->iconButton()
->url(fn (QmFolder $record) => route('qm.folder', $record))->openUrlInNewTab(),
EditAction::make(),
DeleteAction::make()->visible(fn (QmFolder $record) => $record->entries_count === 0 && ! $record->children()->exists()),
]);
}
public static function getPages(): array
{
return [
'index' => ListQmFolders::route('/'),
'create' => CreateQmFolder::route('/neu'),
'edit' => EditQmFolder::route('/{record}/edit'),
];
}
}