Director hiring added
This commit is contained in:
BIN
frontend/dump.rdb
Normal file
BIN
frontend/dump.rdb
Normal file
Binary file not shown.
@@ -75,5 +75,6 @@ export default {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -112,4 +112,16 @@ span.button:hover {
|
||||
|
||||
.font-color-gender-nonbinary {
|
||||
color: #DAA520;
|
||||
}
|
||||
|
||||
main,
|
||||
.contenthidden {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.contentscroll {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
@@ -81,6 +81,7 @@ export default {
|
||||
width: calc(100% + 40px);
|
||||
gap: 2em;
|
||||
margin: -21px -20px 1.5em -20px;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
|
||||
162
frontend/src/dialogues/falukant/NewDirectorDialog.vue
Normal file
162
frontend/src/dialogues/falukant/NewDirectorDialog.vue
Normal file
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<DialogWidget ref="dialog" :title="$t('factset.newdirector.title')" :show-close="true" :buttons="buttons"
|
||||
@close="closeDialog" name="FalukantNewDirector" :modal="true" :isTitleTranslated="true">
|
||||
<div class="director-dialog">
|
||||
<div class="proposal-list">
|
||||
<ul>
|
||||
<li v-for="proposal in proposals" :key="proposal.id" @click="selectProposal(proposal)"
|
||||
:class="{ selected: selectedProposal && selectedProposal.id === proposal.id }">
|
||||
{{ $t('falukant.titles.' + proposal.character.gender + '.' + proposal.character.title) }} {{ proposal.character.name }} ({{ proposal.character.age }} Jahre)
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="proposal-details" v-if="selectedProposal">
|
||||
<h3>{{ selectedProposal.character.name }}</h3>
|
||||
<p><strong>{{ $t('falukant.newdirector.age') }}</strong> {{ selectedProposal.character.age }} Jahre</p>
|
||||
<p><strong>{{ $t('falukant.newdirector.salary') }}</strong> {{ selectedProposal.proposedIncome }} $</p>
|
||||
<h4>{{ $t('falukant.newdirector.skills') }}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.newdirector.product') }}</th>
|
||||
<th>{{ $t('falukant.newdirector.knowledge') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="knowledge in selectedProposal.character.knowledge" :key="knowledge.id">
|
||||
<td>{{ $t('falukant.product.' + knowledge.labelTr) }}</td>
|
||||
<td>{{ mapKnowledgeToText(knowledge.value) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</DialogWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import DialogWidget from '@/components/DialogWidget.vue';
|
||||
import { mapKnowledgeToText } from '@/utils/knowledgeHelper.js';
|
||||
|
||||
export default {
|
||||
name: 'FalukantNewDirector',
|
||||
components: {
|
||||
DialogWidget,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialog: null,
|
||||
proposals: [],
|
||||
selectedProposal: null,
|
||||
products: [],
|
||||
buttons: [
|
||||
{ text: 'Einstellen', action: this.hireDirector },
|
||||
{ text: 'Abbrechen', action: 'close' },
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async open(branchId) {
|
||||
this.dialog.open();
|
||||
await this.loadProposals(branchId);
|
||||
},
|
||||
|
||||
closeDialog() {
|
||||
this.dialog.close();
|
||||
this.proposals = [];
|
||||
this.selectedProposal = null;
|
||||
},
|
||||
|
||||
async loadProposals(branchId) {
|
||||
try {
|
||||
const response = await apiClient.post('/api/falukant/director/proposal', { branchId });
|
||||
this.proposals = response.data.map((proposal) => {
|
||||
return {
|
||||
...proposal,
|
||||
knowledge: proposal.knowledge || [],
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error loading proposals:', error);
|
||||
}
|
||||
},
|
||||
|
||||
selectProposal(proposal) {
|
||||
this.selectedProposal = proposal;
|
||||
},
|
||||
|
||||
async hireDirector() {
|
||||
if (!this.selectedProposal) return;
|
||||
try {
|
||||
await apiClient.post('/api/falukant/director/convertproposal', { proposalId: this.selectedProposal.id });
|
||||
this.closeDialog();
|
||||
this.$emit('directorHired');
|
||||
} catch (error) {
|
||||
console.error('Error hiring director:', error);
|
||||
}
|
||||
},
|
||||
|
||||
mapKnowledgeToText(value) {
|
||||
return mapKnowledgeToText(value, this.$t);
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.dialog = this.$refs.dialog;
|
||||
},
|
||||
|
||||
beforeUnmount() { },
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.director-dialog {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.proposal-list {
|
||||
width: 40%;
|
||||
border-right: 1px solid #ddd;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.proposal-list ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.proposal-list li {
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
border: 1px solid transparent;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.proposal-list li:hover {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.proposal-list li.selected {
|
||||
border-color: #f9a22c;
|
||||
background-color: #fdf1db;
|
||||
}
|
||||
|
||||
.proposal-details {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.proposal-details table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.proposal-details table th,
|
||||
.proposal-details table td {
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
@@ -50,7 +50,7 @@
|
||||
"titles": {
|
||||
"male": {
|
||||
"noncivil": "Leibeigener",
|
||||
"civil": "Bürgerlich",
|
||||
"civil": "Freier Bürger",
|
||||
"sir": "Herr",
|
||||
"townlord": "Stadtherr",
|
||||
"by": "von",
|
||||
@@ -71,7 +71,7 @@
|
||||
},
|
||||
"female": {
|
||||
"noncivil": "Leibeigene",
|
||||
"civil": "Bürgerlich",
|
||||
"civil": "Freie Bürgerin",
|
||||
"sir": "Frau",
|
||||
"townlord": "Stadtherrin",
|
||||
"by": "zu",
|
||||
@@ -106,7 +106,18 @@
|
||||
},
|
||||
"director": {
|
||||
"title": "Direktor-Infos",
|
||||
"info": "Informationen über den Direktor der Niederlassung."
|
||||
"info": "Informationen über den Direktor der Niederlassung.",
|
||||
"actions": {
|
||||
"new": "Direktor einstellen"
|
||||
},
|
||||
"name": "Name",
|
||||
"salary": "Gehalt",
|
||||
"satisfaction": "Zufriedenheit",
|
||||
"fire": "Feuern",
|
||||
"teach": "Weiterbilden",
|
||||
"produce": "Darf produzieren",
|
||||
"sell": "Darf verkaufen",
|
||||
"starttransport": "Darf Transporte veranlassen"
|
||||
},
|
||||
"sale": {
|
||||
"title": "Inventar",
|
||||
@@ -137,7 +148,8 @@
|
||||
"time": "Uhr",
|
||||
"current": "Laufende Produktionen",
|
||||
"product": "Produkt",
|
||||
"remainingTime": "Verbleibende Zeit (Sekunden)"
|
||||
"remainingTime": "Verbleibende Zeit (Sekunden)",
|
||||
"noProductions": "Keine laufenden Produktionen."
|
||||
},
|
||||
"columns": {
|
||||
"city": "Stadt",
|
||||
@@ -155,7 +167,31 @@
|
||||
"perMinute": "Erlös pro Minute",
|
||||
"expand": "Erträge anzeigen",
|
||||
"collapse": "Erträge ausblenden",
|
||||
"knowledge": "Produktwissen"
|
||||
"knowledge": "Produktwissen",
|
||||
"profitAbsolute": "Gesamtgewinn",
|
||||
"profitPerMinute": "Gewinn pro Minute"
|
||||
},
|
||||
"storage": {
|
||||
"title": "Lager",
|
||||
"currentCapacity": "Verwendetes Lager",
|
||||
"stockType": "Lagerart",
|
||||
"totalCapacity": "Vorhanden",
|
||||
"used": "Verwendet",
|
||||
"availableToBuy": "Zum Kauf verfügbar",
|
||||
"buyAmount": "Größe",
|
||||
"buyStorageButton": "Kaufen",
|
||||
"sellAmount": "Größe",
|
||||
"sellStorageButton": "Verkaufen",
|
||||
"selectStockType": "Lagertyp auswählen",
|
||||
"costPerUnit": "Kosten pro Einheit",
|
||||
"buycost": "Kosten",
|
||||
"sellincome": "Einnahmen"
|
||||
},
|
||||
"stocktype": {
|
||||
"wood": "Holzlager",
|
||||
"stone": "Steinlager",
|
||||
"iron": "Eisenlager",
|
||||
"field": "Feldlager"
|
||||
}
|
||||
},
|
||||
"product": {
|
||||
@@ -194,6 +230,38 @@
|
||||
},
|
||||
"regionType": {
|
||||
"city": "Stadt"
|
||||
},
|
||||
"moneyHistory": {
|
||||
"title": "Geldhistorie",
|
||||
"filter": "Filter",
|
||||
"search": "Filter setzen",
|
||||
"activity": "Aktivität",
|
||||
"moneyBefore": "Geld vor der Transaktion",
|
||||
"moneyAfter": "Geld nach der Transaktion",
|
||||
"changeValue": "Wertänderung",
|
||||
"time": "Zeit",
|
||||
"activities": {
|
||||
"Product sale": "Produktverkauf",
|
||||
"Production cost": "Produktionskosten",
|
||||
"Sell all products": "Alle Produkte verkaufen"
|
||||
}
|
||||
},
|
||||
"newdirector": {
|
||||
"title": "Neuer Direktor",
|
||||
"age": "Alter",
|
||||
"salary": "Gehalt",
|
||||
"skills": "Wissen",
|
||||
"product": "Produkt",
|
||||
"knowledge": "Produktwissen"
|
||||
},
|
||||
"skillKnowledges": {
|
||||
"excelent": "Exzellent",
|
||||
"veryhigh": "Sehr gut",
|
||||
"high": "Gut",
|
||||
"medium": "Mittel",
|
||||
"low": "Schlecht",
|
||||
"verylow": "Sehr schlecht",
|
||||
"none": "Kein Wissen"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import BranchView from '../views/falukant/BranchView.vue';
|
||||
import Createview from '../views/falukant/CreateView.vue';
|
||||
import FalukantOverviewView from '../views/falukant/OverviewView.vue';
|
||||
import MoneyHistoryView from '../views/falukant/MoneyHistoryView.vue';
|
||||
|
||||
const falukantRoutes = [
|
||||
{
|
||||
@@ -21,6 +22,12 @@ const falukantRoutes = [
|
||||
component: BranchView,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/falukant/moneyhistory',
|
||||
name: 'MoneyHistoryView',
|
||||
component: MoneyHistoryView,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
];
|
||||
|
||||
export default falukantRoutes;
|
||||
|
||||
@@ -56,7 +56,7 @@ const store = createStore({
|
||||
},
|
||||
clearDaemonSocket(state) {
|
||||
if (state.daemonSocket) {
|
||||
state.daemonSocket.disconnect();
|
||||
state.daemonSocket.close();
|
||||
}
|
||||
state.daemonSocket = null;
|
||||
},
|
||||
@@ -73,6 +73,7 @@ const store = createStore({
|
||||
await dispatch('loadMenu');
|
||||
},
|
||||
logout({ commit }) {
|
||||
console.log('Logging out...');
|
||||
commit('clearSocket');
|
||||
commit('clearDaemonSocket');
|
||||
commit('dologout');
|
||||
@@ -80,35 +81,45 @@ const store = createStore({
|
||||
},
|
||||
initializeSocket({ commit, state }) {
|
||||
if (state.isLoggedIn && state.user) {
|
||||
let currentSocket = state.socket;
|
||||
const connectSocket = () => {
|
||||
if (currentSocket) {
|
||||
currentSocket.disconnect();
|
||||
}
|
||||
const socket = io(import.meta.env.VITE_API_BASE_URL);
|
||||
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Socket.io connected');
|
||||
socket.emit('setUserId', state.user.id);
|
||||
socket.emit('setUserId', state.user.id); // Sende user.id, wenn user vorhanden ist
|
||||
});
|
||||
|
||||
|
||||
socket.on('disconnect', (reason) => {
|
||||
console.warn('Socket.io disconnected:', reason);
|
||||
retryConnection(connectSocket);
|
||||
});
|
||||
|
||||
|
||||
commit('setSocket', socket);
|
||||
};
|
||||
|
||||
|
||||
const retryConnection = (reconnectFn) => {
|
||||
setTimeout(() => {
|
||||
console.log('Retrying Socket.io connection...');
|
||||
reconnectFn();
|
||||
}, 1000); // Retry every second
|
||||
};
|
||||
|
||||
|
||||
connectSocket();
|
||||
} else {
|
||||
console.log("User is not logged in or user data is not available.");
|
||||
}
|
||||
},
|
||||
initializeDaemonSocket({ commit, state }) {
|
||||
if (state.isLoggedIn && state.user) {
|
||||
let currentDaemonSocket = state.daemonSocket;
|
||||
const connectDaemonSocket = () => {
|
||||
if (currentDaemonSocket) {
|
||||
currentDaemonSocket.disconnect();
|
||||
}
|
||||
const daemonSocket = new WebSocket(import.meta.env.VITE_DAEMON_SOCKET);
|
||||
|
||||
daemonSocket.onopen = () => {
|
||||
@@ -127,6 +138,7 @@ const store = createStore({
|
||||
|
||||
daemonSocket.onerror = (error) => {
|
||||
console.error('Daemon WebSocket error:', error);
|
||||
console.log('WebSocket readyState:', daemonSocket.readyState);
|
||||
retryConnection(connectDaemonSocket);
|
||||
};
|
||||
|
||||
@@ -134,7 +146,6 @@ const store = createStore({
|
||||
const message = event.data;
|
||||
console.log(message);
|
||||
if (message === "ping") {
|
||||
console.log("Ping received, sending Pong...");
|
||||
daemonSocket.send("pong");
|
||||
} else {
|
||||
try {
|
||||
|
||||
9
frontend/src/utils/knowledgeHelper.js
Normal file
9
frontend/src/utils/knowledgeHelper.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export function mapKnowledgeToText(value, t) {
|
||||
if (value >= 90) return t('falukant.skillKnowledges.excelent');
|
||||
if (value >= 75) return t('falukant.skillKnowledges.veryhigh');
|
||||
if (value >= 60) return t('falukant.skillKnowledges.high');
|
||||
if (value >= 45) return t('falukant.skillKnowledges.medium');
|
||||
if (value >= 30) return t('falukant.skillKnowledges.low');
|
||||
if (value >= 15) return t('falukant.skillKnowledges.verylow');
|
||||
return t('falukant.skillKnowledges.none');
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
106
frontend/src/views/falukant/MoneyHistoryView.vue
Normal file
106
frontend/src/views/falukant/MoneyHistoryView.vue
Normal file
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>{{ $t('falukant.moneyHistory.title') }}</h2>
|
||||
|
||||
<div class="filter-section">
|
||||
<label>{{ $t('falukant.moneyHistory.filter') }}</label>
|
||||
<input v-model="filter" type="text" />
|
||||
<button @click="fetchMoneyHistory(1)">{{ $t('falukant.moneyHistory.search') }}</button>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.moneyHistory.activity') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.moneyBefore') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.moneyAfter') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.changeValue') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.time') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(entry, index) in moneyHistory.data" :key="index">
|
||||
<td>{{ $t(`falukant.moneyHistory.activities.${entry.activity}`) }}</td>
|
||||
<td>{{ entry.moneyBefore }}</td>
|
||||
<td>{{ entry.moneyAfter }}</td>
|
||||
<td>{{ entry.changeValue }}</td>
|
||||
<td>{{ new Date(entry.time).toLocaleString() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="pagination">
|
||||
<button
|
||||
v-if="moneyHistory.currentPage > 1"
|
||||
@click="fetchMoneyHistory(moneyHistory.currentPage - 1)"
|
||||
>
|
||||
{{ $t('falukant.moneyHistory.prev') }}
|
||||
</button>
|
||||
<span>
|
||||
{{ moneyHistory.currentPage }} / {{ moneyHistory.totalPages }}
|
||||
</span>
|
||||
<button
|
||||
v-if="moneyHistory.currentPage < moneyHistory.totalPages"
|
||||
@click="fetchMoneyHistory(moneyHistory.currentPage + 1)"
|
||||
>
|
||||
{{ $t('falukant.moneyHistory.next') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
|
||||
export default {
|
||||
name: 'MoneyHistoryView',
|
||||
data() {
|
||||
return {
|
||||
filter: '',
|
||||
moneyHistory: {
|
||||
data: [],
|
||||
currentPage: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchMoneyHistory(1);
|
||||
},
|
||||
methods: {
|
||||
async fetchMoneyHistory(page) {
|
||||
try {
|
||||
const response = await apiClient.post('/api/falukant/moneyhistory', {
|
||||
page,
|
||||
filter: this.filter,
|
||||
});
|
||||
this.moneyHistory = response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching money history:', error);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filter-section {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ccc;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -27,16 +27,56 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.productions.title') }}</h3>
|
||||
<table v-if="productions.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.sale.region') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.product') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.quantity') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.ending') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(production, index) in productions" :key="index">
|
||||
<td>{{ production.cityName }}</td>
|
||||
<td>{{ $t(`falukant.product.${production.productName}`) }}</td>
|
||||
<td>{{ production.quantity }}</td>
|
||||
<td>{{ formatDate(production.endTimestamp) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else>{{ $t('falukant.branch.production.noProductions') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.stock.title') }}</h3>
|
||||
<table v-if="allStock.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.sale.region') }}</th>
|
||||
<th>{{ $t('falukant.branch.sale.product') }}</th>
|
||||
<th>{{ $t('falukant.branch.sale.quantity') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in allStock" :key="index">
|
||||
<td>{{ item.regionName }}</td>
|
||||
<td>{{ $t(`falukant.product.${item.productLabelTr}`) }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else>{{ $t('falukant.branch.sale.noInventory') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.branches.title') }}</h3>
|
||||
<table>
|
||||
<tr v-for="branch in falukantUser?.branches">
|
||||
<td><span @click="openBranch(branch.id)" class="link">{{ branch.region.name }}</span></td>
|
||||
<td>{{ $t(`falukant.overview.branches.level.${branch.branchType.labelTr}`) }}</td>
|
||||
<tr v-for="branch in falukantUser?.branches" :key="branch.id">
|
||||
<td>
|
||||
<span @click="openBranch(branch.id)" class="link">{{ branch.region.name }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{ $t(`falukant.overview.branches.level.${branch.branchType.labelTr}`) }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -48,8 +88,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import StatusBar from '@/components/falukant/StatusBar.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import { mapState } from 'vuex';
|
||||
|
||||
const AVATAR_POSITIONS = {
|
||||
male: {
|
||||
@@ -90,26 +131,18 @@ const AVATAR_POSITIONS = {
|
||||
|
||||
export default {
|
||||
name: 'FalukantOverviewView',
|
||||
data() {
|
||||
return {
|
||||
falukantUser: null,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
StatusBar,
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchFalukantUser();
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.socket) {
|
||||
this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
|
||||
}
|
||||
data() {
|
||||
return {
|
||||
falukantUser: null,
|
||||
allStock: [],
|
||||
productions: [],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState(['daemonSocket']),
|
||||
getAvatarStyle() {
|
||||
if (!this.falukantUser) return {};
|
||||
const { gender, age } = this.falukantUser.character;
|
||||
@@ -128,6 +161,38 @@ export default {
|
||||
};
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchFalukantUser();
|
||||
await this.fetchAllStock();
|
||||
await this.fetchProductions();
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.on("production_ready", this.handleProductionReadyEvent);
|
||||
}
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.addEventListener('message', (event) => {
|
||||
console.log('incoming event', event);
|
||||
try {
|
||||
if (event.data === "ping") return;
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.event === 'production_ready') {
|
||||
this.handleProductionReadyEvent(message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing WebSocket message in FalukantOverviewView:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.socket) {
|
||||
this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.off("production_ready", this.handleProductionReadyEvent);
|
||||
}
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.onmessage = null;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getAgeGroup(age) {
|
||||
if (age <= 1) return "0-1";
|
||||
@@ -150,9 +215,41 @@ export default {
|
||||
}
|
||||
this.falukantUser = falukantUser.data;
|
||||
},
|
||||
async fetchAllStock() {
|
||||
const response = await apiClient.get('/api/falukant/stockoverview');
|
||||
const rawData = response.data;
|
||||
const aggregated = {};
|
||||
for (const item of rawData) {
|
||||
const key = `${item.regionName}__${item.productLabelTr}`;
|
||||
if (!aggregated[key]) {
|
||||
aggregated[key] = {
|
||||
regionName: item.regionName,
|
||||
productLabelTr: item.productLabelTr,
|
||||
quantity: 0,
|
||||
};
|
||||
}
|
||||
aggregated[key].quantity += item.quantity;
|
||||
}
|
||||
this.allStock = Object.values(aggregated);
|
||||
},
|
||||
handleProductionReadyEvent() {
|
||||
this.fetchAllStock();
|
||||
this.fetchProductions();
|
||||
},
|
||||
openBranch(branchId) {
|
||||
this.$router.push({ name: 'BranchView', params: { branchId: branchId } });
|
||||
}
|
||||
this.$router.push({ name: 'BranchView', params: { branchId } });
|
||||
},
|
||||
async fetchProductions() {
|
||||
try {
|
||||
const response = await apiClient.get('/api/falukant/productions');
|
||||
this.productions = response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching productions:', error);
|
||||
}
|
||||
},
|
||||
formatDate(timestamp) {
|
||||
return new Date(timestamp).toLocaleString();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user