Refactor FalukantService and update UI components: Removed debug logging from FalukantService, added age requirement messages in i18n files, and improved age validation display in PoliticsView. This enhances user experience and code clarity regarding age eligibility for political applications.
This commit is contained in:
@@ -4409,7 +4409,6 @@ class FalukantService extends BaseService {
|
|||||||
const characterId = character.id;
|
const characterId = character.id;
|
||||||
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
|
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
|
||||||
const canApplyByAge = ageDays >= FalukantService.MIN_AGE_POLITICS_DAYS;
|
const canApplyByAge = ageDays >= FalukantService.MIN_AGE_POLITICS_DAYS;
|
||||||
console.log('[getOpenPolitics] characterId=', characterId, 'birthdate=', character.birthdate, 'ageDays=', ageDays, 'MIN=', FalukantService.MIN_AGE_POLITICS_DAYS, 'canApplyByAge=', canApplyByAge);
|
|
||||||
const rows = await sequelize.query(
|
const rows = await sequelize.query(
|
||||||
FalukantService.RECURSIVE_REGION_SEARCH,
|
FalukantService.RECURSIVE_REGION_SEARCH,
|
||||||
{
|
{
|
||||||
@@ -4485,7 +4484,6 @@ class FalukantService extends BaseService {
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung
|
.filter(election => !election.alreadyApplied); // Nur Positionen ohne bestehende Bewerbung
|
||||||
console.log('[getOpenPolitics] returning', result.length, 'entries, canApplyByAge on first:', result[0]?.canApplyByAge);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4502,9 +4500,7 @@ class FalukantService extends BaseService {
|
|||||||
|
|
||||||
// 2) Mindestalter 16 (Spieljahre = 16 Tage Realzeit)
|
// 2) Mindestalter 16 (Spieljahre = 16 Tage Realzeit)
|
||||||
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
|
const ageDays = character.birthdate ? calcAge(character.birthdate) : 0;
|
||||||
console.log('[applyForElections] characterId=', character.id, 'birthdate=', character.birthdate, 'ageDays=', ageDays, 'MIN=', FalukantService.MIN_AGE_POLITICS_DAYS);
|
|
||||||
if (ageDays < FalukantService.MIN_AGE_POLITICS_DAYS) {
|
if (ageDays < FalukantService.MIN_AGE_POLITICS_DAYS) {
|
||||||
console.log('[applyForElections] rejected: too_young');
|
|
||||||
throw new Error('too_young');
|
throw new Error('too_young');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1029,9 +1029,11 @@
|
|||||||
"region": "Region",
|
"region": "Region",
|
||||||
"date": "Datum",
|
"date": "Datum",
|
||||||
"candidacy": "Kandidatur",
|
"candidacy": "Kandidatur",
|
||||||
|
"candidacyWithAge": "Kandidatur (ab 16 Jahren)",
|
||||||
"none": "Keine offenen Positionen.",
|
"none": "Keine offenen Positionen.",
|
||||||
"apply": "Für ausgewählte Positionen kandidieren",
|
"apply": "Für ausgewählte Positionen kandidieren",
|
||||||
"minAgeHint": "Kandidatur erst ab 16 Jahren möglich."
|
"minAgeHint": "Kandidatur erst ab 16 Jahren möglich.",
|
||||||
|
"ageRequirement": "Für alle politischen Ämter gilt: Kandidatur erst ab 16 Jahren."
|
||||||
},
|
},
|
||||||
"too_young": "Dein Charakter ist noch zu jung. Eine Bewerbung ist erst ab 16 Jahren möglich.",
|
"too_young": "Dein Charakter ist noch zu jung. Eine Bewerbung ist erst ab 16 Jahren möglich.",
|
||||||
"upcoming": {
|
"upcoming": {
|
||||||
|
|||||||
@@ -363,9 +363,11 @@
|
|||||||
"region": "Region",
|
"region": "Region",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"candidacy": "Candidacy",
|
"candidacy": "Candidacy",
|
||||||
|
"candidacyWithAge": "Candidacy (from age 16)",
|
||||||
"none": "No open positions.",
|
"none": "No open positions.",
|
||||||
"apply": "Apply for selected positions",
|
"apply": "Apply for selected positions",
|
||||||
"minAgeHint": "Candidacy is only possible from age 16."
|
"minAgeHint": "Candidacy is only possible from age 16.",
|
||||||
|
"ageRequirement": "All political offices require candidates to be at least 16 years old."
|
||||||
},
|
},
|
||||||
"too_young": "Your character is too young. Applications are only possible from age 16.",
|
"too_young": "Your character is too young. Applications are only possible from age 16.",
|
||||||
"upcoming": {
|
"upcoming": {
|
||||||
|
|||||||
@@ -18,14 +18,14 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="product in products" :key="product.id">
|
<tr v-for="product in products" :key="product.id">
|
||||||
<td>{{ $t(`falukant.product.${product.labelTr}`) }}</td>
|
<td>{{ $t(`falukant.product.${product.labelTr}`) }}</td>
|
||||||
<td>{{ product.knowledges[0].knowledge }} %</td>
|
<td>{{ product.knowledges?.[0]?.knowledge ?? 0 }} %</td>
|
||||||
<td>
|
<td>
|
||||||
<button
|
<button
|
||||||
v-if="ownRunningEducations.length === 0"
|
v-if="ownRunningEducations.length === 0"
|
||||||
@click="learnItem(product.id, 'self')"
|
@click="learnItem(product.id, 'self')"
|
||||||
>
|
>
|
||||||
{{ $t('falukant.education.learn') }}
|
{{ $t('falukant.education.learn') }}
|
||||||
({{ formatCost(getSelfCost(product.knowledges[0].knowledge)) }})
|
({{ formatCost(getSelfCost(product.knowledges?.[0]?.knowledge ?? 0)) }})
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -171,11 +171,23 @@ export default {
|
|||||||
activeChild: null,
|
activeChild: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
activeTab: {
|
||||||
|
async handler(tab) {
|
||||||
|
if (tab === 'director' && this.directors.length === 0) {
|
||||||
|
await this.loadDirectors();
|
||||||
|
}
|
||||||
|
if (tab === 'children' && this.children.length === 0) {
|
||||||
|
await this.loadChildren();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.loadProducts();
|
await this.loadProducts();
|
||||||
await this.loadEducations();
|
await this.loadEducations();
|
||||||
await this.loadDirectors();
|
|
||||||
await this.loadChildren();
|
await this.loadChildren();
|
||||||
|
if (this.activeTab === 'director') await this.loadDirectors();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// Basis-Funktion: lineare Interpolation
|
// Basis-Funktion: lineare Interpolation
|
||||||
@@ -193,7 +205,8 @@ export default {
|
|||||||
return this.computeCost(knowledge, 'one');
|
return this.computeCost(knowledge, 'one');
|
||||||
},
|
},
|
||||||
getSelfAllCost() {
|
getSelfAllCost() {
|
||||||
const avg = this.products.reduce((sum, p) => sum + (p.knowledges[0].knowledge||0), 0) / this.products.length;
|
if (!this.products?.length) return 0;
|
||||||
|
const avg = this.products.reduce((sum, p) => sum + (p.knowledges?.[0]?.knowledge || 0), 0) / this.products.length;
|
||||||
return this.computeCost(avg, 'all');
|
return this.computeCost(avg, 'all');
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -209,12 +222,14 @@ export default {
|
|||||||
},
|
},
|
||||||
getChildrenAllCost(childId) {
|
getChildrenAllCost(childId) {
|
||||||
const child = this.children.find(c => c.id === childId);
|
const child = this.children.find(c => c.id === childId);
|
||||||
const avg = (child.knowledge || []).reduce((s,k) => s + k.knowledge, 0) / (child.knowledge?.length||1);
|
if (!child || !Array.isArray(child.knowledge)) return 0;
|
||||||
|
const avg = child.knowledge.reduce((s, k) => s + (k.knowledge || 0), 0) / (child.knowledge.length || 1);
|
||||||
return this.computeCost(avg, 'all');
|
return this.computeCost(avg, 'all');
|
||||||
},
|
},
|
||||||
childNotInLearning() {
|
childNotInLearning() {
|
||||||
const child = this.children.find(c => c.id === this.activeChild);
|
const child = this.children.find(c => c.id === this.activeChild);
|
||||||
return !this.childrenRunningEducations.some(e => e.learningCharacter.id === child.id);
|
if (!child) return true;
|
||||||
|
return !this.childrenRunningEducations.some(e => e.learningCharacter?.id === child.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
// DIRECTOR
|
// DIRECTOR
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
|
|
||||||
<!-- OPEN Tab: hier zeigen wir 'openPolitics' -->
|
<!-- OPEN Tab: hier zeigen wir 'openPolitics' -->
|
||||||
<div v-else-if="activeTab === 'openPolitics'" class="tab-pane">
|
<div v-else-if="activeTab === 'openPolitics'" class="tab-pane">
|
||||||
|
<p class="politics-age-requirement">{{ $t('falukant.politics.open.ageRequirement') }}</p>
|
||||||
<div v-if="loading.openPolitics" class="loading">{{ $t('loading') }}</div>
|
<div v-if="loading.openPolitics" class="loading">{{ $t('loading') }}</div>
|
||||||
<div v-else class="table-scroll">
|
<div v-else class="table-scroll">
|
||||||
<table class="politics-table">
|
<table class="politics-table">
|
||||||
@@ -65,7 +66,7 @@
|
|||||||
<th>{{ $t('falukant.politics.open.office') }}</th>
|
<th>{{ $t('falukant.politics.open.office') }}</th>
|
||||||
<th>{{ $t('falukant.politics.open.region') }}</th>
|
<th>{{ $t('falukant.politics.open.region') }}</th>
|
||||||
<th>{{ $t('falukant.politics.open.date') }}</th>
|
<th>{{ $t('falukant.politics.open.date') }}</th>
|
||||||
<th>{{ $t('falukant.politics.open.candidacy') }}</th>
|
<th>{{ $t('falukant.politics.open.candidacyWithAge') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -247,10 +248,6 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const { data } = await apiClient.get('/api/falukant/politics/open');
|
const { data } = await apiClient.get('/api/falukant/politics/open');
|
||||||
this.openPolitics = Array.isArray(data) ? data : [];
|
this.openPolitics = Array.isArray(data) ? data : [];
|
||||||
// Debug: Alters-Flag prüfen
|
|
||||||
if (this.openPolitics.length > 0) {
|
|
||||||
console.log('[PoliticsView] loadOpenPolitics: count=', this.openPolitics.length, 'first.canApplyByAge=', this.openPolitics[0].canApplyByAge, 'first.id=', this.openPolitics[0].id);
|
|
||||||
}
|
|
||||||
// Bereits beworbene Positionen vorselektieren, damit die Checkbox
|
// Bereits beworbene Positionen vorselektieren, damit die Checkbox
|
||||||
// sichtbar markiert bleibt.
|
// sichtbar markiert bleibt.
|
||||||
this.selectedApplications = this.openPolitics
|
this.selectedApplications = this.openPolitics
|
||||||
@@ -435,6 +432,13 @@ h2 {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.politics-age-requirement {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin: 0 0 10px 0;
|
||||||
|
font-size: 0.95em;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
.table-scroll {
|
.table-scroll {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user