Add vehicle management features in Falukant
- Introduced vehicle types and transport management in the backend, including new models and associations for vehicles and transports. - Implemented service methods to retrieve vehicle types and handle vehicle purchases, ensuring user validation and transaction management. - Updated the FalukantController and router to expose new endpoints for fetching vehicle types and buying vehicles. - Enhanced the frontend with a new transport tab in BranchView, allowing users to buy vehicles, and added localization for vehicle-related terms. - Included initialization logic for vehicle types in the database setup.
This commit is contained in:
191
frontend/src/dialogues/falukant/BuyVehicleDialog.vue
Normal file
191
frontend/src/dialogues/falukant/BuyVehicleDialog.vue
Normal file
@@ -0,0 +1,191 @@
|
||||
<template>
|
||||
<DialogWidget
|
||||
ref="dialog"
|
||||
name="buy-vehicle"
|
||||
:title="$t('falukant.branch.transport.title')"
|
||||
icon="carriage.png"
|
||||
showClose
|
||||
:buttons="dialogButtons"
|
||||
@close="onClose"
|
||||
>
|
||||
<div class="buy-vehicle-form" v-if="loaded">
|
||||
<p class="hint">
|
||||
{{ $t('falukant.branch.transport.balance') }}:
|
||||
<strong>{{ formattedMoney }}</strong>
|
||||
</p>
|
||||
|
||||
<label class="form-label">
|
||||
{{ $t('falukant.branch.transport.vehicleType') }}
|
||||
<select v-model.number="selectedTypeId" class="form-control">
|
||||
<option v-for="t in vehicleTypes" :key="t.id" :value="t.id">
|
||||
{{ $t(`falukant.branch.vehicles.${t.tr}`) }}
|
||||
({{ formatCost(t.cost) }}, C={{ t.capacity }})
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="form-label">
|
||||
{{ $t('falukant.branch.transport.quantity') }}
|
||||
<input
|
||||
type="number"
|
||||
class="form-control"
|
||||
v-model.number="quantity"
|
||||
min="1"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<p class="total">
|
||||
{{ $t('falukant.branch.transport.totalCost') }}:
|
||||
<strong>{{ formatCost(totalCost) }}</strong>
|
||||
</p>
|
||||
|
||||
<p v-if="totalCost > money" class="warning">
|
||||
{{ $t('falukant.branch.transport.notEnoughMoney') }}
|
||||
</p>
|
||||
</div>
|
||||
<div v-else class="loading">
|
||||
{{ $t('loading') }}
|
||||
</div>
|
||||
</DialogWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import DialogWidget from '@/components/DialogWidget.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
|
||||
export default {
|
||||
name: 'BuyVehicleDialog',
|
||||
components: { DialogWidget },
|
||||
props: {
|
||||
regionId: { type: Number, required: true },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
vehicleTypes: [],
|
||||
selectedTypeId: null,
|
||||
quantity: 1,
|
||||
money: 0,
|
||||
loaded: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
dialogButtons() {
|
||||
return [
|
||||
{ text: this.$t('Cancel'), action: this.close },
|
||||
{
|
||||
text: this.$t('falukant.branch.transport.buy'),
|
||||
action: this.onConfirm,
|
||||
disabled: !this.canBuy,
|
||||
},
|
||||
];
|
||||
},
|
||||
selectedType() {
|
||||
return this.vehicleTypes.find((t) => t.id === this.selectedTypeId) || null;
|
||||
},
|
||||
totalCost() {
|
||||
if (!this.selectedType) return 0;
|
||||
const q = Math.max(1, this.quantity || 0);
|
||||
return this.selectedType.cost * q;
|
||||
},
|
||||
canBuy() {
|
||||
return (
|
||||
this.loaded &&
|
||||
this.selectedType &&
|
||||
this.quantity >= 1 &&
|
||||
this.totalCost > 0 &&
|
||||
this.totalCost <= this.money
|
||||
);
|
||||
},
|
||||
formattedMoney() {
|
||||
return this.formatCost(this.money);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
async open() {
|
||||
this.loaded = false;
|
||||
this.quantity = 1;
|
||||
await Promise.all([this.loadVehicleTypes(), this.loadMoney()]);
|
||||
if (this.vehicleTypes.length && !this.selectedTypeId) {
|
||||
this.selectedTypeId = this.vehicleTypes[0].id;
|
||||
}
|
||||
this.loaded = true;
|
||||
this.$refs.dialog.open();
|
||||
},
|
||||
close() {
|
||||
this.$refs.dialog.close();
|
||||
},
|
||||
onClose() {
|
||||
this.close();
|
||||
this.$emit('close');
|
||||
},
|
||||
async loadVehicleTypes() {
|
||||
const { data } = await apiClient.get('/api/falukant/vehicles/types');
|
||||
this.vehicleTypes = data;
|
||||
},
|
||||
async loadMoney() {
|
||||
const { data } = await apiClient.get('/api/falukant/info');
|
||||
this.money = Number(data.money) || 0;
|
||||
},
|
||||
formatCost(value) {
|
||||
return new Intl.NumberFormat(navigator.language, {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(value);
|
||||
},
|
||||
async onConfirm() {
|
||||
if (!this.canBuy) return;
|
||||
try {
|
||||
await apiClient.post('/api/falukant/vehicles', {
|
||||
vehicleTypeId: this.selectedTypeId,
|
||||
quantity: this.quantity,
|
||||
regionId: this.regionId,
|
||||
});
|
||||
this.$emit('bought');
|
||||
this.close();
|
||||
} catch (err) {
|
||||
console.error('Error buying vehicles', err);
|
||||
this.$emit('error', err);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.buy-vehicle-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
width: 100%;
|
||||
padding: 0.3rem;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.total {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.warning {
|
||||
color: #c62828;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@
|
||||
"director": "Direktor",
|
||||
"inventory": "Inventar",
|
||||
"production": "Produktion",
|
||||
"storage": "Lager"
|
||||
"storage": "Lager",
|
||||
"transport": "Transportmittel"
|
||||
},
|
||||
"selection": {
|
||||
"title": "Niederlassungsauswahl",
|
||||
@@ -203,6 +204,25 @@
|
||||
"buycost": "Kosten",
|
||||
"sellincome": "Einnahmen"
|
||||
},
|
||||
"vehicles": {
|
||||
"cargo_cart": "Lastkarren",
|
||||
"ox_cart": "Ochsenkarren",
|
||||
"small_carriage": "Kleine Pferdekutsche",
|
||||
"large_carriage": "Große Pferdekutsche",
|
||||
"four_horse_carriage": "Vierspänner",
|
||||
"raft": "Floß",
|
||||
"sailing_ship": "Segelschiff"
|
||||
},
|
||||
"transport": {
|
||||
"title": "Transportmittel",
|
||||
"placeholder": "Hier kannst du Transportmittel für deine Region kaufen.",
|
||||
"vehicleType": "Transportmittel",
|
||||
"quantity": "Anzahl",
|
||||
"totalCost": "Gesamtkosten",
|
||||
"notEnoughMoney": "Du hast nicht genug Geld für diesen Kauf.",
|
||||
"buy": "Transportmittel kaufen",
|
||||
"balance": "Kontostand"
|
||||
},
|
||||
"stocktype": {
|
||||
"wood": "Holzlager",
|
||||
"stone": "Steinlager",
|
||||
|
||||
@@ -30,6 +30,17 @@
|
||||
"knowledge": "Knowledge",
|
||||
"hire": "Hire",
|
||||
"noProposals": "No director candidates available."
|
||||
},
|
||||
"branch": {
|
||||
"vehicles": {
|
||||
"cargo_cart": "Cargo cart",
|
||||
"ox_cart": "Ox cart",
|
||||
"small_carriage": "Small horse carriage",
|
||||
"large_carriage": "Large horse carriage",
|
||||
"four_horse_carriage": "Four-horse carriage",
|
||||
"raft": "Raft",
|
||||
"sailing_ship": "Sailing ship"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,21 @@
|
||||
<div v-else-if="activeTab === 'storage'" class="branch-tab-pane">
|
||||
<StorageSection :branchId="selectedBranch.id" ref="storageSection" />
|
||||
</div>
|
||||
|
||||
<!-- Transportmittel -->
|
||||
<div v-else-if="activeTab === 'transport'" class="branch-tab-pane">
|
||||
<p>{{ $t('falukant.branch.transport.placeholder') }}</p>
|
||||
<button @click="openBuyVehicleDialog">
|
||||
{{ $t('falukant.branch.transport.buy') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<BuyVehicleDialog
|
||||
v-if="selectedBranch"
|
||||
ref="buyVehicleDialog"
|
||||
:region-id="selectedBranch?.regionId"
|
||||
@bought="handleVehiclesBought"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -65,6 +79,7 @@ import SaleSection from '@/components/falukant/SaleSection.vue';
|
||||
import ProductionSection from '@/components/falukant/ProductionSection.vue';
|
||||
import StorageSection from '@/components/falukant/StorageSection.vue';
|
||||
import RevenueSection from '@/components/falukant/RevenueSection.vue';
|
||||
import BuyVehicleDialog from '@/dialogues/falukant/BuyVehicleDialog.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import { mapState } from 'vuex';
|
||||
|
||||
@@ -79,8 +94,9 @@ export default {
|
||||
ProductionSection,
|
||||
StorageSection,
|
||||
RevenueSection,
|
||||
BuyVehicleDialog,
|
||||
},
|
||||
|
||||
|
||||
data() {
|
||||
return {
|
||||
branches: [],
|
||||
@@ -92,6 +108,7 @@ export default {
|
||||
{ value: 'inventory', label: 'falukant.branch.tabs.inventory' },
|
||||
{ value: 'director', label: 'falukant.branch.tabs.director' },
|
||||
{ value: 'storage', label: 'falukant.branch.tabs.storage' },
|
||||
{ value: 'transport', label: 'falukant.branch.tabs.transport' },
|
||||
],
|
||||
};
|
||||
},
|
||||
@@ -155,6 +172,7 @@ export default {
|
||||
const result = await apiClient.get('/api/falukant/branches');
|
||||
this.branches = result.data.map(branch => ({
|
||||
id: branch.id,
|
||||
regionId: branch.regionId,
|
||||
cityName: branch.region.name,
|
||||
type: this.$t(`falukant.branch.types.${branch.branchType.labelTr}`),
|
||||
isMainBranch: branch.isMainBranch,
|
||||
@@ -325,6 +343,16 @@ export default {
|
||||
console.error('Error processing daemon message:', error);
|
||||
}
|
||||
},
|
||||
|
||||
openBuyVehicleDialog() {
|
||||
if (!this.selectedBranch) return;
|
||||
this.$refs.buyVehicleDialog?.open();
|
||||
},
|
||||
|
||||
handleVehiclesBought() {
|
||||
// Refresh status bar (for updated money) and potentially other data later
|
||||
this.$refs.statusBar?.fetchStatus();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -333,4 +361,4 @@ export default {
|
||||
h2 {
|
||||
padding-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -7,6 +7,8 @@ import path from 'path';
|
||||
export default defineConfig(({ mode }) => {
|
||||
// Lade Umgebungsvariablen explizit
|
||||
const env = loadEnv(mode, process.cwd(), '');
|
||||
// Kombiniere mit process.env, um auch Shell-Umgebungsvariablen zu berücksichtigen
|
||||
const combinedEnv = { ...env, ...process.env };
|
||||
|
||||
return {
|
||||
plugins: [vue()],
|
||||
@@ -16,18 +18,18 @@ export default defineConfig(({ mode }) => {
|
||||
'import.meta.env.DEV': false,
|
||||
'import.meta.env.PROD': true,
|
||||
'import.meta.env.MODE': '"production"',
|
||||
// Stelle sicher, dass Umgebungsvariablen aus .env.production geladen werden
|
||||
...(env.VITE_DAEMON_SOCKET && {
|
||||
'import.meta.env.VITE_DAEMON_SOCKET': JSON.stringify(env.VITE_DAEMON_SOCKET)
|
||||
// Stelle sicher, dass Umgebungsvariablen aus .env.production oder Shell-Umgebung geladen werden
|
||||
...(combinedEnv.VITE_DAEMON_SOCKET && {
|
||||
'import.meta.env.VITE_DAEMON_SOCKET': JSON.stringify(combinedEnv.VITE_DAEMON_SOCKET)
|
||||
}),
|
||||
...(env.VITE_API_BASE_URL && {
|
||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL)
|
||||
...(combinedEnv.VITE_API_BASE_URL && {
|
||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(combinedEnv.VITE_API_BASE_URL)
|
||||
}),
|
||||
...(env.VITE_CHAT_WS_URL && {
|
||||
'import.meta.env.VITE_CHAT_WS_URL': JSON.stringify(env.VITE_CHAT_WS_URL)
|
||||
...(combinedEnv.VITE_CHAT_WS_URL && {
|
||||
'import.meta.env.VITE_CHAT_WS_URL': JSON.stringify(combinedEnv.VITE_CHAT_WS_URL)
|
||||
}),
|
||||
...(env.VITE_SOCKET_IO_URL && {
|
||||
'import.meta.env.VITE_SOCKET_IO_URL': JSON.stringify(env.VITE_SOCKET_IO_URL)
|
||||
...(combinedEnv.VITE_SOCKET_IO_URL && {
|
||||
'import.meta.env.VITE_SOCKET_IO_URL': JSON.stringify(combinedEnv.VITE_SOCKET_IO_URL)
|
||||
})
|
||||
},
|
||||
optimizeDeps: {
|
||||
|
||||
Reference in New Issue
Block a user