Prozesskonfigurator: fachliche Prozessblöcke als Hauptansicht, Detailpanel je Block, Entwurf verwerfen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4554af8056
commit
664f00e510
8 files changed
+766
-185
No files matched your search
@@ -20,6 +20,7 @@
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\ConfigurationImpact;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\ProcessBlocks;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessLanes;
|
||||
use App\Process\ProcessProfile;
|
||||
@@ -27,6 +28,7 @@
|
||||
use App\Process\Restriction;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
@@ -62,30 +64,90 @@ class ChannelProcess extends Page
|
||||
/** The landlord confirmed that stored settings the chosen model overrides are removed. */
|
||||
public bool $acknowledge = false;
|
||||
|
||||
/** The business block opened in the detail panel ('' = none). */
|
||||
public string $block = '';
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
$this->record = $this->resolveRecord($record);
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
foreach ($configuration->intakes($this->record) as $intake) {
|
||||
$current = $configuration->current($this->record, $intake);
|
||||
$stored = (array) (($this->record->process_overrides ?? [])[$intake->value] ?? []);
|
||||
// The current (saved or derived) model stays selected even if it is not admissible: the page explains why instead of
|
||||
// switching silently to another one.
|
||||
$model = $current['model'];
|
||||
$this->drafts[$intake->value] = [
|
||||
'model' => $model,
|
||||
'variant' => $current['variant'],
|
||||
'steps' => (array) ($stored['steps'] ?? []),
|
||||
'templates' => (array) ($stored['templates'] ?? []),
|
||||
'settings' => array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, array_intersect_key($stored, array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, ProcessSetting::cases())))),
|
||||
'derived' => $current['derived'],
|
||||
];
|
||||
$this->drafts[$intake->value] = $this->storedDraft($intake);
|
||||
}
|
||||
$this->intake = (string) array_key_first($this->drafts);
|
||||
$this->capabilityDraft = $this->record->isWebsite() ? [] : collect(app(ChannelCapabilities::class)->resolve($this->record))
|
||||
$this->block = '';
|
||||
$this->capabilityDraft = $this->storedCapabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* The draft as it is stored (or derived) now – the reference for "unsaved changes" and for discarding them.
|
||||
* The current (saved or derived) model stays selected even if it is not admissible: the page explains why instead of
|
||||
* switching silently to another one.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function storedDraft(IntakeKind $intake): array
|
||||
{
|
||||
$current = app(ChannelProcessConfiguration::class)->current($this->record, $intake);
|
||||
$stored = (array) (($this->record->process_overrides ?? [])[$intake->value] ?? []);
|
||||
|
||||
return [
|
||||
'model' => $current['model'],
|
||||
'variant' => $current['variant'],
|
||||
'steps' => (array) ($stored['steps'] ?? []),
|
||||
'templates' => (array) ($stored['templates'] ?? []),
|
||||
'settings' => array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, array_intersect_key($stored, array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, ProcessSetting::cases())))),
|
||||
'derived' => $current['derived'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function storedCapabilities(): array
|
||||
{
|
||||
return $this->record->isWebsite() ? [] : collect(app(ChannelCapabilities::class)->resolve($this->record))
|
||||
->map(fn (Capability $capability): string => $capability->value === null ? '' : ($capability->value ? '1' : '0'))->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the draft of the current intake kind differs from what is stored (nothing is saved by looking or selecting).
|
||||
*/
|
||||
public function dirty(): bool
|
||||
{
|
||||
$normalise = fn (array $draft): array => [
|
||||
'model' => $draft['model'],
|
||||
'variant' => $draft['variant'],
|
||||
'steps' => array_filter((array) $draft['steps']),
|
||||
'templates' => (array) $draft['templates'],
|
||||
'settings' => array_filter((array) $draft['settings'], fn (mixed $value): bool => $value !== null && $value !== ''),
|
||||
];
|
||||
|
||||
return $normalise($this->drafts[$this->intake]) != $normalise($this->storedDraft(IntakeKind::from($this->intake)))
|
||||
|| $this->capabilityDraft != $this->storedCapabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws the unsaved changes away and shows the stored configuration again.
|
||||
*/
|
||||
public function discard(): void
|
||||
{
|
||||
$intake = $this->intake;
|
||||
$this->acknowledge = false;
|
||||
$this->mount($this->record->getKey());
|
||||
$this->intake = $intake;
|
||||
}
|
||||
|
||||
public function selectBlock(string $block): void
|
||||
{
|
||||
$this->block = $this->block === $block ? '' : $block;
|
||||
}
|
||||
|
||||
public function updatedIntake(): void
|
||||
{
|
||||
$this->block = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The draft of the current intake kind including the capabilities shown (they decide which models fit).
|
||||
*
|
||||
@@ -338,6 +400,74 @@ public function profile(): ProcessProfile
|
||||
return app(ChannelProcessConfiguration::class)->profileWith($this->record, IntakeKind::from($this->intake), $this->draft());
|
||||
}
|
||||
|
||||
/**
|
||||
* The business blocks of the course with what is effective in each: values and their origin, the template chosen for
|
||||
* its decision, what depends on what (derived from the resolved plan, see {@see ProcessBlocks}), the steps that can
|
||||
* be configured here and the fixed ones (no controls, shown as one line), gaps the template names, open problems.
|
||||
*
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
public function blocks(): array
|
||||
{
|
||||
$intake = IntakeKind::from($this->intake);
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
$profile = $this->profile();
|
||||
$model = $this->model();
|
||||
$rows = $configuration->preview($this->record, $intake, $this->draft());
|
||||
$templates = app(TemplateComposer::class)->classes($configuration->templatesOf($model, $this->draft()));
|
||||
$steps = collect($this->steps())->keyBy('module');
|
||||
$conflicts = collect($this->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all();
|
||||
$problems = $this->problems();
|
||||
|
||||
$blocks = [];
|
||||
foreach (app(ProcessBlocks::class)->of($rows) as $key => $block) {
|
||||
$template = $block['area'] === null ? null : ($templates[$block['area']->value] ?? null);
|
||||
$settings = array_values(array_filter($block['settings'], fn (ProcessSetting $setting): bool => in_array($intake, $setting->channelIntakes(), true)));
|
||||
$blockSteps = array_values(array_filter(array_map(fn (array $row): ?array => $steps[$row['module']] ?? null, $block['modules'])));
|
||||
$configurable = array_values(array_filter($blockSteps, fn (array $step): bool => $step['on'] && ($step['optional'] || $step['mode_setting'] || ($step['performer_setting'] && count($step['performer_options']) > 1) || $step['parameters'] !== [])
|
||||
|| (! $step['on'] && $step['optional'])));
|
||||
$fixed = array_values(array_filter($blockSteps, fn (array $step): bool => $step['on'] && ! in_array($step, $configurable, true)));
|
||||
$blocks[$key] = [...$block,
|
||||
'facts' => array_map(fn (ProcessSetting $setting): array => $this->setting($setting, $profile), $settings),
|
||||
'template' => $template,
|
||||
'extensions' => $template === null ? [] : $template::extensions(),
|
||||
'configurable' => $configurable,
|
||||
'fixed' => $fixed,
|
||||
'off' => array_values(array_filter($blockSteps, fn (array $step): bool => ! $step['on'])),
|
||||
'attention' => count(array_filter($settings, fn (ProcessSetting $setting): bool => in_array($setting->value, $conflicts, true))),
|
||||
'problems' => $this->blockProblems($problems, $block['label'], $template, $settings),
|
||||
];
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* The problems of the draft that concern a block: they name its template or one of its settings.
|
||||
*
|
||||
* @param list<string> $problems
|
||||
* @param class-string<FunctionTemplate>|null $template
|
||||
* @param list<ProcessSetting> $settings
|
||||
* @return list<string>
|
||||
*/
|
||||
private function blockProblems(array $problems, string $label, ?string $template, array $settings): array
|
||||
{
|
||||
return array_values(array_filter($problems, fn (string $problem): bool => ($template !== null && str_contains($problem, $template::label()))
|
||||
|| collect($settings)->contains(fn (ProcessSetting $setting): bool => str_contains($problem, $setting->question()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems of the draft that belong to no block (shown above the blocks).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function problemsOutsideBlocks(): array
|
||||
{
|
||||
$inBlocks = collect($this->blocks())->flatMap(fn (array $block): array => $block['problems'])->all();
|
||||
|
||||
return array_values(array_diff($this->problems(), $inBlocks));
|
||||
}
|
||||
|
||||
/**
|
||||
* The step cards: preview row + controls of each step.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process;
|
||||
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
|
||||
/**
|
||||
* The business blocks of a resolved course (docs/Prozessarchitektur P01–P05) as the configurator's main view shows them:
|
||||
* a grouping of modules for the reader, nothing more. What a block depends on is derived from the hard and soft
|
||||
* dependencies of the modules that are really in the plan and apply (the facts the {@see ProcessRunner} uses, the same
|
||||
* as {@see ProcessLanes}) – there is no hand-written order between blocks and no arrow between merely adjacent phases.
|
||||
* Pure: it reads, it never changes anything.
|
||||
*/
|
||||
final class ProcessBlocks
|
||||
{
|
||||
/**
|
||||
* Grouping of the modules and the settings a block reports. A module that is in no block would show up under "other",
|
||||
* so a new module is never lost (a test keeps the catalogue and this table in step).
|
||||
*
|
||||
* @var array<string, array{label: string, phase: string, area: ?TemplateArea, modules: list<string>, settings: list<ProcessSetting>}>
|
||||
*/
|
||||
public const BLOCKS = [
|
||||
'intake' => ['label' => 'Eingang und Gastdaten', 'phase' => 'P01', 'area' => null,
|
||||
'modules' => ['intake.record', 'guest.details', 'guest.data_request', 'guest.address_check', 'guest.loyalty_status', 'pricing.loyalty_discount'],
|
||||
'settings' => [ProcessSetting::FormRequiresAddress, ProcessSetting::DataRequest, ProcessSetting::DataRequestReminderHours]],
|
||||
'availability' => ['label' => 'Verfügbarkeit und Reservierung', 'phase' => 'P01', 'area' => null,
|
||||
'modules' => ['availability.check', 'hold', 'binding.portal', 'channels.block'],
|
||||
'settings' => [ProcessSetting::PreReservation, ProcessSetting::HoldHours, ProcessSetting::ClarificationHoldAutoMinutes]],
|
||||
'answer' => ['label' => 'Antwort und Angebot', 'phase' => 'P02', 'area' => TemplateArea::InquiryAnswer,
|
||||
'modules' => ['offer.information', 'offer.binding', 'offer.acceptance'],
|
||||
'settings' => [ProcessSetting::InquiryAnswer, ProcessSetting::Processing, ProcessSetting::GuestLinkValidDays]],
|
||||
'portal_wait' => ['label' => 'Bestätigung des Portals', 'phase' => 'P02', 'area' => null,
|
||||
'modules' => ['portal.confirmation'],
|
||||
'settings' => [ProcessSetting::AwaitPortalConfirmation, ProcessSetting::PortalConfirmationWaitHours]],
|
||||
'documents' => ['label' => 'Dokumentation', 'phase' => 'P03', 'area' => TemplateArea::ContractDocuments,
|
||||
'modules' => ['documents.send', 'documents.booking_notice', 'documents.stay_confirmation'],
|
||||
'settings' => [ProcessSetting::Documents, ProcessSetting::ContractDelivery, ProcessSetting::BookingNotice, ProcessSetting::ContractTemplate]],
|
||||
'finance' => ['label' => 'Finanzabwicklung', 'phase' => 'P03', 'area' => TemplateArea::Collection,
|
||||
'modules' => ['payments.monitor', 'payments.internal', 'portal.payout'],
|
||||
'settings' => [ProcessSetting::Payments]],
|
||||
'communication' => ['label' => 'Gastkommunikation und Aufenthalt', 'phase' => 'P04', 'area' => TemplateArea::GuestCommunication,
|
||||
'modules' => ['arrival.details', 'arrival.info', 'stay', 'review.request'],
|
||||
'settings' => [ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoSender, ProcessSetting::ArrivalInfoDaysBefore, ProcessSetting::ReviewRequestSender]],
|
||||
'closure' => ['label' => 'Aufgaben und Abschluss', 'phase' => 'P05', 'area' => null,
|
||||
'modules' => ['case.tasks', 'change.proposal', 'case.closure', 'case.settlement'],
|
||||
'settings' => []],
|
||||
];
|
||||
|
||||
public const OTHER = 'other';
|
||||
|
||||
public function __construct(private ProcessCatalogue $catalogue) {}
|
||||
|
||||
/**
|
||||
* The blocks of the course the preview rows describe. A block without a step in the plan is left out.
|
||||
*
|
||||
* @param list<array{module: string, label: string, on: bool, reason: ?string, template: ?string}> $rows ChannelProcessConfiguration::preview
|
||||
* @return array<string, array{key: string, label: string, phase: string, area: ?TemplateArea, settings: list<ProcessSetting>, modules: list<array{module: string, label: string, on: bool, reason: ?string, template: ?string}>, active: bool, waits_for: list<array{block: string, label: string, steps: list<string>}>, after: list<array{block: string, label: string}>, independent: bool, events: list<string>, scheduled: list<string>, conditional: list<array{label: string, reason: ?string}>, may_wait: list<string>}>
|
||||
*/
|
||||
public function of(array $rows): array
|
||||
{
|
||||
$blockOf = [];
|
||||
foreach (self::BLOCKS as $key => $block) {
|
||||
foreach ($block['modules'] as $module) {
|
||||
$blockOf[$module] = $key;
|
||||
}
|
||||
}
|
||||
$other = ['label' => 'Weitere Schritte', 'phase' => 'P03', 'area' => null, 'modules' => [], 'settings' => []];
|
||||
$blocks = [];
|
||||
foreach ($rows as $row) {
|
||||
$key = $blockOf[$row['module']] ?? self::OTHER;
|
||||
$blocks[$key] ??= [...(self::BLOCKS[$key] ?? $other), 'key' => $key, 'modules' => []];
|
||||
$blocks[$key]['modules'][] = $row;
|
||||
}
|
||||
// Presentation order is the table's, the plan decides which blocks exist.
|
||||
$blocks = array_merge(array_intersect_key(array_flip([...array_keys(self::BLOCKS), self::OTHER]), $blocks), $blocks);
|
||||
|
||||
$active = [];
|
||||
foreach ($rows as $row) {
|
||||
if ($row['on']) {
|
||||
$active[$row['module']] = $row;
|
||||
}
|
||||
}
|
||||
foreach ($blocks as $key => &$block) {
|
||||
$block['active'] = collect($block['modules'])->contains('on', true);
|
||||
$block = [...$block, 'waits_for' => [], 'after' => [], 'events' => [], 'scheduled' => [], 'conditional' => [], 'may_wait' => []];
|
||||
foreach ($block['modules'] as $row) {
|
||||
$definition = $this->catalogue->modules()[$row['module']]::definition();
|
||||
if (! $row['on']) {
|
||||
continue;
|
||||
}
|
||||
foreach ($definition->requires as $dependency) {
|
||||
$targetBlock = $blockOf[$dependency->module] ?? self::OTHER;
|
||||
if ($dependency->module === 'intake.record' || ! isset($active[$dependency->module]) || $targetBlock === $key) {
|
||||
continue;
|
||||
}
|
||||
$list = $dependency->hard ? 'waits_for' : 'after';
|
||||
$label = $blocks[$targetBlock]['label'] ?? self::BLOCKS[$targetBlock]['label'] ?? $other['label'];
|
||||
$entry = $block[$list][$targetBlock] ?? ['block' => $targetBlock, 'label' => $label, 'steps' => []];
|
||||
$entry['steps'][] = $active[$dependency->module]['label'];
|
||||
$block[$list][$targetBlock] = $entry;
|
||||
}
|
||||
if ($definition->toggle === ModuleDefinition::TOGGLE_EVENT_DRIVEN) {
|
||||
$block['events'][] = $row['label'];
|
||||
} elseif ($definition->triggers !== [] && collect($definition->triggers)->every(fn (string $trigger): bool => str_starts_with($trigger, 'schedule:'))) {
|
||||
$block['scheduled'][] = $row['label'];
|
||||
}
|
||||
if ($definition->toggle === ModuleDefinition::TOGGLE_CONDITIONAL) {
|
||||
$block['conditional'][] = ['label' => $row['label'], 'reason' => $definition->condition];
|
||||
}
|
||||
foreach ($definition->waits as $wait) {
|
||||
$block['may_wait'][] = ['guest' => 'den Gast', 'portal' => 'das Portal', 'landlord' => 'Sie', 'time' => 'eine Frist'][$wait] ?? $wait;
|
||||
}
|
||||
}
|
||||
$block['waits_for'] = array_values($block['waits_for']);
|
||||
$block['after'] = array_values($block['after']);
|
||||
$block['may_wait'] = array_values(array_unique($block['may_wait']));
|
||||
$block['independent'] = $block['active'] && $block['waits_for'] === [];
|
||||
}
|
||||
unset($block);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user