Implement church career information retrieval and update related components: Add a new method in FalukantService to fetch church career details for characters, including current and approved office levels. Enhance DashboardWidget, StatusBar, and ChurchView components to handle new church-related socket events and display relevant information. Update localization files for church-related terms and error messages in English, German, and Spanish.
This commit is contained in:
@@ -3,6 +3,25 @@
|
||||
<StatusBar />
|
||||
<div class="church-content">
|
||||
<h2>{{ $t('falukant.church.title') }}</h2>
|
||||
<div class="church-summary">
|
||||
<div class="church-summary-card">
|
||||
<div class="church-summary-label">{{ $t('falukant.church.summary.highestCurrentOffice') }}</div>
|
||||
<div class="church-summary-value">{{ highestCurrentOfficeLabel }}</div>
|
||||
</div>
|
||||
<div class="church-summary-card">
|
||||
<div class="church-summary-label">{{ $t('falukant.church.summary.availableApplications') }}</div>
|
||||
<div class="church-summary-value">{{ availablePositions.length }}</div>
|
||||
</div>
|
||||
<div class="church-summary-card">
|
||||
<div class="church-summary-label">{{ $t('falukant.church.summary.supervisedApplications') }}</div>
|
||||
<div class="church-summary-value">{{ supervisedApplications.length }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="church-guidance">
|
||||
<p>{{ $t('falukant.church.summary.guidance') }}</p>
|
||||
</div>
|
||||
|
||||
<SimpleTabs v-model="activeTab" :tabs="tabs" />
|
||||
|
||||
<div class="tab-content">
|
||||
@@ -87,6 +106,7 @@
|
||||
<th>{{ $t('falukant.church.available.office') }}</th>
|
||||
<th>{{ $t('falukant.church.available.region') }}</th>
|
||||
<th>{{ $t('falukant.church.available.supervisor') }}</th>
|
||||
<th>{{ $t('falukant.church.available.decision') }}</th>
|
||||
<th>{{ $t('falukant.church.available.seats') }}</th>
|
||||
<th>{{ $t('falukant.church.available.action') }}</th>
|
||||
</tr>
|
||||
@@ -101,6 +121,7 @@
|
||||
</span>
|
||||
<span v-else>—</span>
|
||||
</td>
|
||||
<td>{{ decisionModeLabel(pos.decisionMode) }}</td>
|
||||
<td>{{ pos.availableSeats }}</td>
|
||||
<td>
|
||||
<button @click="applyForPosition(pos)" :disabled="pos.availableSeats === 0">
|
||||
@@ -109,7 +130,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!availablePositions.length">
|
||||
<td colspan="5">{{ $t('falukant.church.available.none') }}</td>
|
||||
<td colspan="6">{{ $t('falukant.church.available.none') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -166,6 +187,7 @@ import MessageDialog from '@/dialogues/standard/MessageDialog.vue'
|
||||
import ErrorDialog from '@/dialogues/standard/ErrorDialog.vue'
|
||||
import apiClient from '@/utils/axios.js'
|
||||
import SimpleTabs from '@/components/SimpleTabs.vue'
|
||||
import { mapState } from 'vuex'
|
||||
|
||||
export default {
|
||||
name: 'ChurchView',
|
||||
@@ -196,9 +218,37 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(['socket', 'daemonSocket', 'user']),
|
||||
highestCurrentOffice() {
|
||||
if (!this.currentPositions.length) {
|
||||
return null;
|
||||
}
|
||||
return [...this.currentPositions]
|
||||
.filter(pos => this.isOwnPosition(pos))
|
||||
.sort((a, b) => this.officeRank(b.officeType?.name) - this.officeRank(a.officeType?.name))[0] || null;
|
||||
},
|
||||
highestCurrentOfficeLabel() {
|
||||
if (!this.highestCurrentOffice?.officeType?.name) {
|
||||
return this.$t('falukant.church.summary.none');
|
||||
}
|
||||
return this.$t(`falukant.church.offices.${this.highestCurrentOffice.officeType.name}`);
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.loadNotBaptisedChildren();
|
||||
await this.loadOwnCharacterId();
|
||||
await Promise.all([
|
||||
this.loadCurrentPositions(),
|
||||
this.loadAvailablePositions(),
|
||||
this.loadSupervisedApplications()
|
||||
]);
|
||||
this.setupSocketEvents();
|
||||
this.setupDaemonListeners();
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.teardownSocketEvents();
|
||||
this.teardownDaemonListeners();
|
||||
},
|
||||
watch: {
|
||||
activeTab(newTab) {
|
||||
@@ -212,6 +262,90 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
matchesCurrentUser(eventData) {
|
||||
if (eventData?.user_id == null) {
|
||||
return true;
|
||||
}
|
||||
const currentIds = [this.user?.id, this.user?.hashedId]
|
||||
.filter(Boolean)
|
||||
.map((value) => String(value));
|
||||
return currentIds.includes(String(eventData.user_id));
|
||||
},
|
||||
setupSocketEvents() {
|
||||
this.teardownSocketEvents();
|
||||
if (!this.socket) {
|
||||
setTimeout(() => this.setupSocketEvents(), 1000);
|
||||
return;
|
||||
}
|
||||
this._statusSocketHandler = (data) => this.handleEvent({ event: 'falukantUpdateStatus', ...data });
|
||||
this._churchSocketHandler = (data) => this.handleEvent({ event: 'falukantUpdateChurch', ...data });
|
||||
this.socket.on('falukantUpdateStatus', this._statusSocketHandler);
|
||||
this.socket.on('falukantUpdateChurch', this._churchSocketHandler);
|
||||
},
|
||||
teardownSocketEvents() {
|
||||
if (!this.socket) return;
|
||||
if (this._statusSocketHandler) this.socket.off('falukantUpdateStatus', this._statusSocketHandler);
|
||||
if (this._churchSocketHandler) this.socket.off('falukantUpdateChurch', this._churchSocketHandler);
|
||||
},
|
||||
setupDaemonListeners() {
|
||||
this.teardownDaemonListeners();
|
||||
if (!this.daemonSocket) return;
|
||||
this._daemonChurchHandler = (event) => {
|
||||
if (event.data === 'ping') return;
|
||||
try {
|
||||
const message = JSON.parse(event.data);
|
||||
if (['falukantUpdateStatus', 'falukantUpdateChurch'].includes(message.event)) {
|
||||
this.handleEvent(message);
|
||||
}
|
||||
} catch (_) {}
|
||||
};
|
||||
this.daemonSocket.addEventListener('message', this._daemonChurchHandler);
|
||||
},
|
||||
teardownDaemonListeners() {
|
||||
if (this.daemonSocket && this._daemonChurchHandler) {
|
||||
this.daemonSocket.removeEventListener('message', this._daemonChurchHandler);
|
||||
this._daemonChurchHandler = null;
|
||||
}
|
||||
},
|
||||
queueChurchRefresh({ current = true, available = true, applications = true } = {}) {
|
||||
if (this._pendingChurchRefresh) {
|
||||
clearTimeout(this._pendingChurchRefresh);
|
||||
}
|
||||
this._pendingChurchRefresh = setTimeout(async () => {
|
||||
this._pendingChurchRefresh = null;
|
||||
const tasks = [];
|
||||
if (current) tasks.push(this.loadCurrentPositions());
|
||||
if (available) tasks.push(this.loadAvailablePositions());
|
||||
if (applications) tasks.push(this.loadSupervisedApplications());
|
||||
await Promise.all(tasks);
|
||||
}, 120);
|
||||
},
|
||||
handleEvent(eventData) {
|
||||
if (!this.matchesCurrentUser(eventData)) {
|
||||
return;
|
||||
}
|
||||
switch (eventData.event) {
|
||||
case 'falukantUpdateStatus':
|
||||
this.queueChurchRefresh();
|
||||
break;
|
||||
case 'falukantUpdateChurch':
|
||||
switch (eventData.reason) {
|
||||
case 'applications':
|
||||
this.queueChurchRefresh({ current: false, available: false, applications: true });
|
||||
break;
|
||||
case 'npc_decision':
|
||||
this.queueChurchRefresh({ current: true, available: true, applications: true });
|
||||
break;
|
||||
case 'appointment':
|
||||
case 'vacancy_fill':
|
||||
case 'promotion':
|
||||
default:
|
||||
this.queueChurchRefresh({ current: true, available: true, applications: false });
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
async loadNotBaptisedChildren() {
|
||||
try {
|
||||
const { data } = await apiClient.get('/api/falukant/family/notbaptised')
|
||||
@@ -292,6 +426,24 @@ export default {
|
||||
}
|
||||
return pos.character.id === this.ownCharacterId;
|
||||
},
|
||||
officeRank(name) {
|
||||
const ranks = {
|
||||
'lay-preacher': 0,
|
||||
'village-priest': 1,
|
||||
'parish-priest': 2,
|
||||
dean: 3,
|
||||
archdeacon: 4,
|
||||
bishop: 5,
|
||||
archbishop: 6,
|
||||
cardinal: 7,
|
||||
pope: 8
|
||||
};
|
||||
return ranks[name] ?? -1;
|
||||
},
|
||||
decisionModeLabel(mode) {
|
||||
const key = `falukant.church.available.decisionType.${mode || 'interim'}`;
|
||||
return this.$te(key) ? this.$t(key) : mode || '—';
|
||||
},
|
||||
async applyForPosition(position) {
|
||||
try {
|
||||
const regionId = position.regionId || position.region?.id;
|
||||
@@ -310,7 +462,7 @@ export default {
|
||||
} catch (err) {
|
||||
console.error('Error applying for position', err);
|
||||
const errorMsg = err.response?.data?.message || 'falukant.church.available.applyError';
|
||||
this.$root.$refs.errorDialog?.open(`tr:${errorMsg}`);
|
||||
this.$root.$refs.errorDialog?.open(errorMsg.startsWith('falukant.') ? `tr:${errorMsg}` : `tr:falukant.church.available.applyError`);
|
||||
}
|
||||
},
|
||||
async decideOnApplication(applicationId, decision) {
|
||||
@@ -370,6 +522,35 @@ h2 {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.church-summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 0.75rem;
|
||||
margin: 1rem 0 0.75rem;
|
||||
}
|
||||
|
||||
.church-summary-card,
|
||||
.church-guidance {
|
||||
border: 1px solid #ddd;
|
||||
background: #fff;
|
||||
padding: 0.85rem 1rem;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.church-summary-label {
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.church-summary-value {
|
||||
margin-top: 0.25rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.church-guidance {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
width: 140px;
|
||||
margin-right: 0.5rem;
|
||||
|
||||
@@ -455,6 +455,7 @@ export default {
|
||||
'falukantUpdateStatus',
|
||||
'falukantUpdateFamily',
|
||||
'children_update',
|
||||
'falukantUpdateChurch',
|
||||
'familychanged',
|
||||
'falukant_family_scandal_hint'
|
||||
].includes(message.event)) {
|
||||
@@ -513,7 +514,7 @@ export default {
|
||||
} else if (eventData.reason === 'lover_birth') {
|
||||
showInfo(this, this.$t('falukant.family.notifications.loverBirth'));
|
||||
}
|
||||
this.queueFamilyRefresh({ reloadCharacter: eventData.reason === 'monthly' || eventData.reason === 'daily' });
|
||||
this.queueFamilyRefresh({ reloadCharacter: ['monthly', 'daily', 'lover_installment'].includes(eventData.reason) });
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -356,6 +356,7 @@ export default {
|
||||
this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.off("falukantUpdateStatus");
|
||||
this.socket.off("falukantUpdateFamily");
|
||||
this.socket.off("falukantUpdateChurch");
|
||||
this.socket.off("falukantUpdateProductionCertificate");
|
||||
this.socket.off("children_update");
|
||||
this.socket.off("falukantBranchUpdate");
|
||||
@@ -372,6 +373,9 @@ export default {
|
||||
this.socket.on("falukantUpdateFamily", (data) => {
|
||||
this.handleEvent({ event: 'falukantUpdateFamily', ...data });
|
||||
});
|
||||
this.socket.on("falukantUpdateChurch", (data) => {
|
||||
this.handleEvent({ event: 'falukantUpdateChurch', ...data });
|
||||
});
|
||||
this.socket.on("falukantUpdateProductionCertificate", (data) => {
|
||||
this.handleEvent({ event: 'falukantUpdateProductionCertificate', ...data });
|
||||
});
|
||||
@@ -441,6 +445,7 @@ export default {
|
||||
switch (eventData.event) {
|
||||
case 'falukantUpdateStatus':
|
||||
case 'falukantUpdateFamily':
|
||||
case 'falukantUpdateChurch':
|
||||
case 'falukantUpdateProductionCertificate':
|
||||
case 'children_update':
|
||||
case 'falukantBranchUpdate':
|
||||
|
||||
Reference in New Issue
Block a user