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.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user