5ef7b0c6cc
- NextcloudInstance mit Zeilenschutz, Migration 20261002150000 - Bewertung (Ampel) als reine Funktion, status.php-Abruf mit Grenzen, endoflife.date-Zwischenspeicher - API: Liste mit Bewertung, Anlegen und Einzelprüfung nur mit Verwalten - Modulseite mit Kacheln, Registrierung in Seitenleiste, Marktplatz und Symbolen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import type { NextcloudRating, RatingLevel } from '@/lib/nextcloud-status-api';
|
|
|
|
/**
|
|
* Darstellung der Ampel (quick-261002-k67), gemeinsam fuer Modulseite und
|
|
* Dashboard-Kachel. Bewusst vollstaendige, statische Klassenzeichenketten —
|
|
* Tailwind findet Klassen nur, wenn sie woertlich im Quelltext stehen.
|
|
*
|
|
* `fill` = Flaeche (Leiste, Punkt), `pill` = Pille (12 % Flaeche + Textvariante),
|
|
* `text` = Schrift in Statusfarbe.
|
|
*/
|
|
export const RATING_STYLE: Record<RatingLevel, { fill: string; pill: string; text: string }> = {
|
|
green: {
|
|
fill: 'bg-status-ok',
|
|
pill: 'bg-status-ok/12 text-status-ok-fg',
|
|
text: 'text-status-ok-fg',
|
|
},
|
|
yellow: {
|
|
fill: 'bg-status-warn',
|
|
pill: 'bg-status-warn/12 text-status-warn-fg',
|
|
text: 'text-status-warn-fg',
|
|
},
|
|
red: {
|
|
fill: 'bg-status-down',
|
|
pill: 'bg-status-down/12 text-status-down-fg',
|
|
text: 'text-status-down-fg',
|
|
},
|
|
unknown: {
|
|
fill: 'bg-status-idle',
|
|
pill: 'bg-status-idle/12 text-status-idle-fg',
|
|
text: 'text-status-idle-fg',
|
|
},
|
|
};
|
|
|
|
type Translate = (key: string, values?: Record<string, string | number>) => string;
|
|
|
|
/** 'YYYY-MM-DD' als Datum nach Sprache, in UTC (kein Tagesversatz durch die Zeitzone). */
|
|
export function formatEolDate(isoDay: string, locale: string): string {
|
|
const date = new Date(`${isoDay}T00:00:00Z`);
|
|
if (Number.isNaN(date.getTime())) return isoDay;
|
|
return new Intl.DateTimeFormat(locale, {
|
|
timeZone: 'UTC',
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric',
|
|
}).format(date);
|
|
}
|
|
|
|
/**
|
|
* Kurzer Klartext zur Bewertung. `t` ist der Uebersetzer des Namensraums
|
|
* `nextcloudStatus`; die API liefert nur Grundkennung plus Parameter (D-B).
|
|
*/
|
|
export function ratingReasonText(t: Translate, rating: NextcloudRating, locale: string): string {
|
|
switch (rating.reason) {
|
|
case 'current':
|
|
return t('reason.current');
|
|
case 'update-available':
|
|
return t('reason.updateAvailable', { version: rating.updateTo ?? '' });
|
|
case 'eol-soon':
|
|
return t('reason.eolSoon', {
|
|
date: rating.eolDate ? formatEolDate(rating.eolDate, locale) : '',
|
|
});
|
|
case 'eol-passed':
|
|
return rating.eolDate
|
|
? t('reason.eolPassed', { date: formatEolDate(rating.eolDate, locale) })
|
|
: t('reason.eolPassedNoDate');
|
|
case 'unreachable':
|
|
return t('reason.unreachable');
|
|
case 'invalid-response':
|
|
return t('reason.invalidResponse');
|
|
case 'maintenance':
|
|
return t('reason.maintenance');
|
|
case 'needs-db-upgrade':
|
|
return t('reason.needsDbUpgrade');
|
|
case 'no-reference':
|
|
return t('reason.noReference');
|
|
case 'version-unknown':
|
|
return t('reason.versionUnknown');
|
|
case 'not-checked':
|
|
return t('reason.notChecked');
|
|
}
|
|
}
|