Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -46,8 +46,8 @@ export default {
|
||||
if (g == null || g === '') return '—';
|
||||
|
||||
// Altersabhängige, (auf Wunsch) altertümlichere Bezeichnungen
|
||||
const age = Number(this.falukantData?.age);
|
||||
const group = this._getAgeGroupKey(age);
|
||||
const years = this._ageYearsFromWidgetValue(this.falukantData?.age);
|
||||
const group = this._getAgeGroupKey(years);
|
||||
if (group && (g === 'female' || g === 'male')) {
|
||||
const key = `falukant.genderAge.${g}.${group}`;
|
||||
const t = this.$t(key);
|
||||
@@ -62,11 +62,25 @@ export default {
|
||||
falukantAgeLabel() {
|
||||
const ageValue = this.falukantData?.age;
|
||||
if (ageValue == null) return '—';
|
||||
const numAge = Number(ageValue);
|
||||
return `${numAge} ${this.$t('falukant.overview.metadata.years')}`;
|
||||
const years = this._ageYearsFromWidgetValue(ageValue);
|
||||
if (years == null) return '—';
|
||||
return `${years} ${this.$t('falukant.overview.metadata.years')}`;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Backend liefert für Falukant aktuell das Alter als Tage (differenceInDays).
|
||||
* Für die Anzeige und die Age-Groups brauchen wir Jahre.
|
||||
*/
|
||||
_ageYearsFromWidgetValue(ageValue) {
|
||||
const n = Number(ageValue);
|
||||
if (Number.isNaN(n)) return null;
|
||||
|
||||
// Heuristik: >= 365 wird als Tage interpretiert.
|
||||
// Falls das Backend irgendwann auf Jahre umstellt, bleiben Werte < 365 unverändert.
|
||||
const years = n >= 365 ? Math.floor(n / 365) : Math.floor(n);
|
||||
return Number.isFinite(years) ? years : null;
|
||||
},
|
||||
_getAgeGroupKey(age) {
|
||||
const a = Number(age);
|
||||
if (Number.isNaN(a)) return null;
|
||||
|
||||
Reference in New Issue
Block a user