tenant admin startseite schicker gestaltet und super-admin und tenant admin (filament) aufgesplittet.
Es gibt nun task collections und vordefinierte tasks für alle. Onboarding verfeinert und webseite-carousel gefixt (logging später entfernen!)
This commit is contained in:
@@ -18,15 +18,27 @@ class TaskResource extends JsonResource
|
||||
? $this->assignedEvents->count()
|
||||
: $this->assignedEvents()->count();
|
||||
|
||||
$titleTranslations = $this->normalizeTranslations($this->title);
|
||||
$descriptionTranslations = $this->normalizeTranslations($this->description, allowNull: true);
|
||||
$exampleTranslations = $this->normalizeTranslations($this->example_text, allowNull: true);
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'tenant_id' => $this->tenant_id,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'slug' => $this->slug,
|
||||
'title' => $this->translatedText($titleTranslations, 'Untitled task'),
|
||||
'title_translations' => $titleTranslations,
|
||||
'description' => $descriptionTranslations ? $this->translatedText($descriptionTranslations, '') : null,
|
||||
'description_translations' => $descriptionTranslations ?? [],
|
||||
'example_text' => $exampleTranslations ? $this->translatedText($exampleTranslations, '') : null,
|
||||
'example_text_translations' => $exampleTranslations ?? [],
|
||||
'priority' => $this->priority,
|
||||
'difficulty' => $this->difficulty,
|
||||
'due_date' => $this->due_date?->toISOString(),
|
||||
'is_completed' => (bool) $this->is_completed,
|
||||
'collection_id' => $this->collection_id,
|
||||
'source_task_id' => $this->source_task_id,
|
||||
'source_collection_id' => $this->source_collection_id,
|
||||
'assigned_events_count' => $assignedEventsCount,
|
||||
'assigned_events' => $this->whenLoaded(
|
||||
'assignedEvents',
|
||||
@@ -36,5 +48,60 @@ class TaskResource extends JsonResource
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>|null
|
||||
*/
|
||||
protected function normalizeTranslations(mixed $value, bool $allowNull = false): ?array
|
||||
{
|
||||
if ($allowNull && ($value === null || $value === '')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$filtered = array_filter(
|
||||
$value,
|
||||
static fn ($text) => is_string($text) && $text !== ''
|
||||
);
|
||||
|
||||
return ! empty($filtered)
|
||||
? $filtered
|
||||
: ($allowNull ? null : []);
|
||||
}
|
||||
|
||||
if (is_string($value) && $value !== '') {
|
||||
$locale = app()->getLocale() ?: 'de';
|
||||
|
||||
return [
|
||||
$locale => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $allowNull ? null : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $translations
|
||||
*/
|
||||
protected function translatedText(array $translations, string $fallback): string
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
$locales = array_filter([
|
||||
$locale,
|
||||
$locale && str_contains($locale, '-') ? explode('-', $locale)[0] : null,
|
||||
'de',
|
||||
'en',
|
||||
]);
|
||||
|
||||
foreach ($locales as $code) {
|
||||
if ($code && isset($translations[$code]) && $translations[$code] !== '') {
|
||||
return $translations[$code];
|
||||
}
|
||||
}
|
||||
|
||||
$first = reset($translations);
|
||||
|
||||
return $first !== false ? $first : $fallback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user