Optimierung 2.1: Admin-PM-Editoren nutzen Tags-Trait
Admin create/edit nutzen jetzt InteractsWithPressReleaseTags (wie die Customer-Editoren) statt die byte-gleiche addTag/removeTag/tagsArray-Logik lokal zu duplizieren. ~48 Zeilen je Datei entfernt. Tests: 259 PressRelease-Tests gruen. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a5f3ddd0f3
commit
6cc4c2c490
2 changed files with 4 additions and 100 deletions
|
|
@ -19,6 +19,8 @@ use Livewire\Attributes\Title;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component {
|
new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class extends Component {
|
||||||
|
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||||
|
|
||||||
public string $portal = 'presseecho';
|
public string $portal = 'presseecho';
|
||||||
|
|
||||||
public string $language = 'de';
|
public string $language = 'de';
|
||||||
|
|
@ -110,39 +112,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
||||||
$this->resetErrorBag('title');
|
$this->resetErrorBag('title');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addTag(string $tag): void
|
|
||||||
{
|
|
||||||
$tag = trim($tag);
|
|
||||||
|
|
||||||
if ($tag === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$existing = $this->tagsArray();
|
|
||||||
|
|
||||||
if (count($existing) >= 5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($tag, $existing, true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$existing[] = $tag;
|
|
||||||
$this->keywords = implode(', ', $existing);
|
|
||||||
|
|
||||||
unset($this->tags, $this->presubmitChecks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeTag(string $tag): void
|
|
||||||
{
|
|
||||||
$existing = array_values(array_filter($this->tagsArray(), fn(string $existingTag): bool => $existingTag !== $tag));
|
|
||||||
|
|
||||||
$this->keywords = implode(', ', $existing);
|
|
||||||
|
|
||||||
unset($this->tags, $this->presubmitChecks);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single Source of Truth für die Validierungsregeln. Ermöglicht
|
* Single Source of Truth für die Validierungsregeln. Ermöglicht
|
||||||
* Live-Re-Validation via updated()-Hook ohne Duplikation.
|
* Live-Re-Validation via updated()-Hook ohne Duplikation.
|
||||||
|
|
@ -424,23 +393,6 @@ new #[Layout('components.layouts.app'), Title('Neue Pressemitteilung')] class ex
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function tagsArray(): array
|
|
||||||
{
|
|
||||||
if (trim($this->keywords) === '') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return collect(explode(',', $this->keywords))
|
|
||||||
->map(fn(string $tag): string => trim($tag))
|
|
||||||
->filter()
|
|
||||||
->unique()
|
|
||||||
->values()
|
|
||||||
->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function defaultContactIdFor(int $companyId): ?int
|
private function defaultContactIdFor(int $companyId): ?int
|
||||||
{
|
{
|
||||||
if ($companyId <= 0) {
|
if ($companyId <= 0) {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ use Livewire\Attributes\Title;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
|
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
|
||||||
|
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||||
|
|
||||||
#[Locked]
|
#[Locked]
|
||||||
public int $id;
|
public int $id;
|
||||||
|
|
||||||
|
|
@ -159,39 +161,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
||||||
unset($this->presubmitChecks);
|
unset($this->presubmitChecks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addTag(string $tag): void
|
|
||||||
{
|
|
||||||
$tag = trim($tag);
|
|
||||||
|
|
||||||
if ($tag === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$existing = $this->tagsArray();
|
|
||||||
|
|
||||||
if (count($existing) >= 5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array($tag, $existing, true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$existing[] = $tag;
|
|
||||||
$this->keywords = implode(', ', $existing);
|
|
||||||
|
|
||||||
unset($this->tags, $this->presubmitChecks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeTag(string $tag): void
|
|
||||||
{
|
|
||||||
$existing = array_values(array_filter($this->tagsArray(), fn(string $existingTag): bool => $existingTag !== $tag));
|
|
||||||
|
|
||||||
$this->keywords = implode(', ', $existing);
|
|
||||||
|
|
||||||
unset($this->tags, $this->presubmitChecks);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, array<int, mixed>>
|
* @return array<string, array<int, mixed>>
|
||||||
*/
|
*/
|
||||||
|
|
@ -611,23 +580,6 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return list<string>
|
|
||||||
*/
|
|
||||||
private function tagsArray(): array
|
|
||||||
{
|
|
||||||
if (trim($this->keywords) === '') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return collect(explode(',', $this->keywords))
|
|
||||||
->map(fn(string $tag): string => trim($tag))
|
|
||||||
->filter()
|
|
||||||
->unique()
|
|
||||||
->values()
|
|
||||||
->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function defaultContactIdFor(int $companyId): ?int
|
private function defaultContactIdFor(int $companyId): ?int
|
||||||
{
|
{
|
||||||
if ($companyId <= 0) {
|
if ($companyId <= 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue