feat(politics): enhance office application feedback with required title details
This commit is contained in:
@@ -7197,6 +7197,27 @@ class FalukantService extends BaseService {
|
|||||||
const nameToId = new Map(allTypes.map((t) => [t.name, t.id]));
|
const nameToId = new Map(allTypes.map((t) => [t.name, t.id]));
|
||||||
const titleId = character.titleOfNobility ?? character.nobleTitle?.id;
|
const titleId = character.titleOfNobility ?? character.nobleTitle?.id;
|
||||||
const allowedOfficeNames = await getAllowedOfficeTypeNamesByTitle(titleId);
|
const allowedOfficeNames = await getAllowedOfficeTypeNamesByTitle(titleId);
|
||||||
|
const [titles, officeEligibilityBenefits] = await Promise.all([
|
||||||
|
TitleOfNobility.findAll({ attributes: ['id', 'labelTr', 'level'] }),
|
||||||
|
TitleBenefit.findAll({
|
||||||
|
where: { benefitType: 'office_eligibility' },
|
||||||
|
attributes: ['titleId', 'parameters']
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
const titleById = new Map(titles.map((title) => [Number(title.id), title]));
|
||||||
|
const minimumTitleByOfficeName = new Map();
|
||||||
|
for (const benefit of officeEligibilityBenefits) {
|
||||||
|
const officeNames = benefit.parameters?.officeTypeNames;
|
||||||
|
const title = titleById.get(Number(benefit.titleId));
|
||||||
|
if (!Array.isArray(officeNames) || !title) continue;
|
||||||
|
|
||||||
|
for (const officeName of officeNames) {
|
||||||
|
const currentMinimum = minimumTitleByOfficeName.get(officeName);
|
||||||
|
if (!currentMinimum || title.level < currentMinimum.level) {
|
||||||
|
minimumTitleByOfficeName.set(officeName, title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allTypes.map((typeRow) => {
|
return allTypes.map((typeRow) => {
|
||||||
const type = typeRow.get({ plain: true });
|
const type = typeRow.get({ plain: true });
|
||||||
@@ -7213,6 +7234,7 @@ class FalukantService extends BaseService {
|
|||||||
const prerequisitesMet = requiredOfficeNames.length === 0 || matchedOfficeNames.length > 0;
|
const prerequisitesMet = requiredOfficeNames.length === 0 || matchedOfficeNames.length > 0;
|
||||||
const titleEligible = allowedOfficeNames.size === 0 || allowedOfficeNames.has(type.name);
|
const titleEligible = allowedOfficeNames.size === 0 || allowedOfficeNames.has(type.name);
|
||||||
const canApplyNow = canApplyByAge && titleEligible && prerequisitesMet;
|
const canApplyNow = canApplyByAge && titleEligible && prerequisitesMet;
|
||||||
|
const requiredTitle = minimumTitleByOfficeName.get(type.name);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
officeTypeId: type.id,
|
officeTypeId: type.id,
|
||||||
@@ -7225,6 +7247,8 @@ class FalukantService extends BaseService {
|
|||||||
matchedOfficeNames,
|
matchedOfficeNames,
|
||||||
prerequisitesMet,
|
prerequisitesMet,
|
||||||
titleEligible,
|
titleEligible,
|
||||||
|
requiredTitleLabelTr: requiredTitle?.labelTr ?? null,
|
||||||
|
characterGender: character.gender,
|
||||||
canApplyByAge,
|
canApplyByAge,
|
||||||
canApplyNow
|
canApplyNow
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1611,7 +1611,8 @@
|
|||||||
"yes": "Ja",
|
"yes": "Ja",
|
||||||
"no": "Nein",
|
"no": "Nein",
|
||||||
"blockedByAge": "Mindestalter nicht erreicht",
|
"blockedByAge": "Mindestalter nicht erreicht",
|
||||||
"blockedByTitle": "Standesvoraussetzung nicht erfüllt",
|
"blockedByTitle": "Benötigter Stand: mindestens {title}",
|
||||||
|
"unknownRequiredTitle": "unbekannt",
|
||||||
"blockedByPrerequisites": "Vorherige Ämter fehlen"
|
"blockedByPrerequisites": "Vorherige Ämter fehlen"
|
||||||
},
|
},
|
||||||
"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.",
|
||||||
|
|||||||
@@ -797,7 +797,8 @@
|
|||||||
"yes": "Yes",
|
"yes": "Yes",
|
||||||
"no": "No",
|
"no": "No",
|
||||||
"blockedByAge": "Minimum age not met",
|
"blockedByAge": "Minimum age not met",
|
||||||
"blockedByTitle": "Title requirement not met",
|
"blockedByTitle": "Required title: at least {title}",
|
||||||
|
"unknownRequiredTitle": "unknown",
|
||||||
"blockedByPrerequisites": "Required prior offices missing"
|
"blockedByPrerequisites": "Required prior offices missing"
|
||||||
},
|
},
|
||||||
"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.",
|
||||||
|
|||||||
@@ -180,7 +180,11 @@
|
|||||||
: $t('falukant.politics.officesTab.no') }}
|
: $t('falukant.politics.officesTab.no') }}
|
||||||
<template v-if="!office.canApplyNow">
|
<template v-if="!office.canApplyNow">
|
||||||
<span v-if="!office.canApplyByAge"> · {{ $t('falukant.politics.officesTab.blockedByAge') }}</span>
|
<span v-if="!office.canApplyByAge"> · {{ $t('falukant.politics.officesTab.blockedByAge') }}</span>
|
||||||
<span v-if="!office.titleEligible"> · {{ $t('falukant.politics.officesTab.blockedByTitle') }}</span>
|
<span v-if="!office.titleEligible">
|
||||||
|
· {{ $t('falukant.politics.officesTab.blockedByTitle', {
|
||||||
|
title: formatRequiredTitle(office.requiredTitleLabelTr, office.characterGender)
|
||||||
|
}) }}
|
||||||
|
</span>
|
||||||
<span v-if="!office.prerequisitesMet"> · {{ $t('falukant.politics.officesTab.blockedByPrerequisites') }}</span>
|
<span v-if="!office.prerequisitesMet"> · {{ $t('falukant.politics.officesTab.blockedByPrerequisites') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</span>
|
</span>
|
||||||
@@ -364,6 +368,10 @@ export default {
|
|||||||
await this.loadCurrentPositions();
|
await this.loadCurrentPositions();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
formatRequiredTitle(titleLabelTr, gender) {
|
||||||
|
if (!titleLabelTr) return this.$t('falukant.politics.officesTab.unknownRequiredTitle');
|
||||||
|
return this.$t(`falukant.titles.${gender === 'female' ? 'female' : 'male'}.${titleLabelTr}`);
|
||||||
|
},
|
||||||
formatPoliticalCharacterName(character) {
|
formatPoliticalCharacterName(character) {
|
||||||
const firstName = character?.definedFirstName?.name || '';
|
const firstName = character?.definedFirstName?.name || '';
|
||||||
const lastName = character?.definedLastName?.name || '';
|
const lastName = character?.definedLastName?.name || '';
|
||||||
|
|||||||
Reference in New Issue
Block a user