Optimierung 2.4: Kanonische Pre-Submit-Checkliste
presubmitChecks() der vier Editoren in ProvidesPressReleasePresubmitChecks zentralisiert (war 4x dupliziert mit Drift). Kanonische Version uebernimmt die bessere Customer-Variante: Firmenname statt leerer Hinweis in der company-Zeile. Dafuer erhalten die Admin-Editoren ein selectedCompany() (Company::withoutGlobalScopes find), das auch in with() genutzt wird; Customer behaelt seine user-gescopte Aufloesung via CustomerCompanyContext. Tests: volle Suite gruen (794 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1ee6710d0f
commit
5ed60c171c
5 changed files with 86 additions and 192 deletions
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Concerns;
|
||||
|
||||
use App\Services\PressRelease\PressReleaseHtmlSanitizer;
|
||||
use Livewire\Attributes\Computed;
|
||||
|
||||
/**
|
||||
* Kanonische Pre-Submit-Checkliste der PM-Editoren (Admin + Customer).
|
||||
*
|
||||
* Vorher in allen vier Editoren dupliziert und leicht auseinandergedriftet
|
||||
* (Firmenname vs. leer, trans_choice vs. statischer Text). Diese Version ist
|
||||
* die Single Source of Truth.
|
||||
*
|
||||
* Die nutzende Komponente muss bereitstellen: die Properties `$title`,
|
||||
* `$text`, `$companyId`, `$categoryId`, `$contactId`, die Tag-Helfer aus
|
||||
* [[InteractsWithPressReleaseTags]] (`tagsArray()`) sowie `selectedCompany()`.
|
||||
*/
|
||||
trait ProvidesPressReleasePresubmitChecks
|
||||
{
|
||||
/**
|
||||
* @return array<int, array{key: string, status: string, label: string, sub: string}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function presubmitChecks(): array
|
||||
{
|
||||
$titleLen = mb_strlen(trim($this->title));
|
||||
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
||||
$tagsCount = count($this->tagsArray());
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'title',
|
||||
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
||||
'label' => __('Titel vorhanden'),
|
||||
'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'),
|
||||
],
|
||||
[
|
||||
'key' => 'text',
|
||||
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
||||
'label' => __('Mindestlänge Fließtext erreicht'),
|
||||
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
||||
],
|
||||
[
|
||||
'key' => 'company',
|
||||
'status' => $this->companyId ? 'ok' : 'err',
|
||||
'label' => __('Firma zugeordnet'),
|
||||
'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'),
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'status' => $this->categoryId ? 'ok' : 'err',
|
||||
'label' => __('Kategorie gewählt'),
|
||||
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
||||
],
|
||||
[
|
||||
'key' => 'contact',
|
||||
'status' => $this->contactId ? 'ok' : 'warn',
|
||||
'label' => __('Pressekontakt zugeordnet'),
|
||||
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
||||
],
|
||||
[
|
||||
'key' => 'tags',
|
||||
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
||||
'label' => __('Themen-Tags vergeben'),
|
||||
'sub' => $tagsCount >= 1
|
||||
? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount])
|
||||
: __('empfohlen für SEO & Auffindbarkeit'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks;
|
||||
|
||||
public string $portal = 'presseecho';
|
||||
|
||||
|
|
@ -183,7 +184,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
->limit(50)
|
||||
->get(['id', 'name']);
|
||||
|
||||
$selectedCompany = $this->companyId ? Company::withoutGlobalScopes()->find((int) $this->companyId) : null;
|
||||
$selectedCompany = $this->selectedCompany();
|
||||
|
||||
return [
|
||||
'companies' => $companies,
|
||||
|
|
@ -201,51 +202,11 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function presubmitChecks(): array
|
||||
private function selectedCompany(): ?Company
|
||||
{
|
||||
$titleLen = mb_strlen(trim($this->title));
|
||||
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
||||
$tagsCount = count($this->tagsArray());
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'title',
|
||||
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
||||
'label' => __('Titel vorhanden'),
|
||||
'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'),
|
||||
],
|
||||
[
|
||||
'key' => 'text',
|
||||
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
||||
'label' => __('Mindestlänge Fließtext erreicht'),
|
||||
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
||||
],
|
||||
[
|
||||
'key' => 'company',
|
||||
'status' => $this->companyId ? 'ok' : 'err',
|
||||
'label' => __('Firma zugeordnet'),
|
||||
'sub' => $this->companyId ? '' : __('Keine Firma gewählt'),
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'status' => $this->categoryId ? 'ok' : 'err',
|
||||
'label' => __('Kategorie gewählt'),
|
||||
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
||||
],
|
||||
[
|
||||
'key' => 'contact',
|
||||
'status' => $this->contactId ? 'ok' : 'warn',
|
||||
'label' => __('Pressekontakt zugeordnet'),
|
||||
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
||||
],
|
||||
[
|
||||
'key' => 'tags',
|
||||
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
||||
'label' => __('Themen-Tags vergeben'),
|
||||
'sub' => $tagsCount >= 1 ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) : __('empfohlen für SEO & Auffindbarkeit'),
|
||||
],
|
||||
];
|
||||
return $this->companyId
|
||||
? Company::withoutGlobalScopes()->find((int) $this->companyId)
|
||||
: null;
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks;
|
||||
|
||||
#[Locked]
|
||||
public int $id;
|
||||
|
|
@ -369,7 +370,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
$statusEnum = PressReleaseStatus::tryFrom($this->currentStatus);
|
||||
|
||||
$selectedCompany = $this->companyId ? Company::withoutGlobalScopes()->find((int) $this->companyId) : null;
|
||||
$selectedCompany = $this->selectedCompany();
|
||||
|
||||
return [
|
||||
'companies' => $companies,
|
||||
|
|
@ -390,51 +391,11 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function presubmitChecks(): array
|
||||
private function selectedCompany(): ?Company
|
||||
{
|
||||
$titleLen = mb_strlen(trim($this->title));
|
||||
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
||||
$tagsCount = count($this->tagsArray());
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'title',
|
||||
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
||||
'label' => __('Titel vorhanden'),
|
||||
'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'),
|
||||
],
|
||||
[
|
||||
'key' => 'text',
|
||||
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
||||
'label' => __('Mindestlänge Fließtext erreicht'),
|
||||
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
||||
],
|
||||
[
|
||||
'key' => 'company',
|
||||
'status' => $this->companyId ? 'ok' : 'err',
|
||||
'label' => __('Firma zugeordnet'),
|
||||
'sub' => $this->companyId ? '' : __('Keine Firma gewählt'),
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'status' => $this->categoryId ? 'ok' : 'err',
|
||||
'label' => __('Kategorie gewählt'),
|
||||
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
||||
],
|
||||
[
|
||||
'key' => 'contact',
|
||||
'status' => $this->contactId ? 'ok' : 'warn',
|
||||
'label' => __('Pressekontakt zugeordnet'),
|
||||
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
||||
],
|
||||
[
|
||||
'key' => 'tags',
|
||||
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
||||
'label' => __('Themen-Tags vergeben'),
|
||||
'sub' => $tagsCount >= 1 ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) : __('empfohlen für SEO & Auffindbarkeit'),
|
||||
],
|
||||
];
|
||||
return $this->companyId
|
||||
? Company::withoutGlobalScopes()->find((int) $this->companyId)
|
||||
: null;
|
||||
}
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks;
|
||||
|
||||
public string $portal = 'presseecho';
|
||||
|
||||
|
|
@ -414,58 +415,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function presubmitChecks(): array
|
||||
{
|
||||
$titleLen = mb_strlen(trim($this->title));
|
||||
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
||||
$tagsCount = count($this->tagsArray());
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'title',
|
||||
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
||||
'label' => __('Titel vorhanden'),
|
||||
'sub' => $titleLen > 0
|
||||
? trans_choice('{0}Noch leer|{1}:n Zeichen|[2,*]:n Zeichen', $titleLen, ['n' => $titleLen])
|
||||
: __('Noch leer'),
|
||||
],
|
||||
[
|
||||
'key' => 'text',
|
||||
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
||||
'label' => __('Mindestlänge Fließtext erreicht'),
|
||||
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
||||
],
|
||||
[
|
||||
'key' => 'company',
|
||||
'status' => $this->companyId ? 'ok' : 'err',
|
||||
'label' => __('Firma zugeordnet'),
|
||||
'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'),
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'status' => $this->categoryId ? 'ok' : 'err',
|
||||
'label' => __('Kategorie gewählt'),
|
||||
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
||||
],
|
||||
[
|
||||
'key' => 'contact',
|
||||
'status' => $this->contactId ? 'ok' : 'warn',
|
||||
'label' => __('Pressekontakt zugeordnet'),
|
||||
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
||||
],
|
||||
[
|
||||
'key' => 'tags',
|
||||
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
||||
'label' => __('Themen-Tags vergeben'),
|
||||
'sub' => $tagsCount >= 1
|
||||
? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount])
|
||||
: __('empfohlen für SEO & Auffindbarkeit'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleaseFormRules;
|
||||
use \App\Livewire\Concerns\ProvidesPressReleasePresubmitChecks;
|
||||
|
||||
#[Locked]
|
||||
public int $id;
|
||||
|
|
@ -397,56 +398,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
return $this->tagsArray();
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function presubmitChecks(): array
|
||||
{
|
||||
$titleLen = mb_strlen(trim($this->title));
|
||||
$textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text);
|
||||
$tagsCount = count($this->tagsArray());
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'title',
|
||||
'status' => $titleLen >= 5 ? 'ok' : 'err',
|
||||
'label' => __('Titel vorhanden'),
|
||||
'sub' => $titleLen > 0 ? __(':n Zeichen', ['n' => $titleLen]) : __('Noch leer'),
|
||||
],
|
||||
[
|
||||
'key' => 'text',
|
||||
'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'),
|
||||
'label' => __('Mindestlänge Fließtext erreicht'),
|
||||
'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]),
|
||||
],
|
||||
[
|
||||
'key' => 'company',
|
||||
'status' => $this->companyId ? 'ok' : 'err',
|
||||
'label' => __('Firma zugeordnet'),
|
||||
'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'),
|
||||
],
|
||||
[
|
||||
'key' => 'category',
|
||||
'status' => $this->categoryId ? 'ok' : 'err',
|
||||
'label' => __('Kategorie gewählt'),
|
||||
'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'),
|
||||
],
|
||||
[
|
||||
'key' => 'contact',
|
||||
'status' => $this->contactId ? 'ok' : 'warn',
|
||||
'label' => __('Pressekontakt zugeordnet'),
|
||||
'sub' => $this->contactId ? '' : __('empfohlen — Journalisten greifen direkt zum Hörer'),
|
||||
],
|
||||
[
|
||||
'key' => 'tags',
|
||||
'status' => $tagsCount >= 1 ? 'ok' : 'warn',
|
||||
'label' => __('Themen-Tags vergeben'),
|
||||
'sub' => $tagsCount >= 1
|
||||
? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount])
|
||||
: __('empfohlen für SEO & Auffindbarkeit'),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function defaultContactIdFor(int $companyId): ?int
|
||||
{
|
||||
return $this->companyContacts($companyId)->first()?->id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue