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:
@@ -181,6 +181,12 @@ class FalukantController {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.getVehicleTypes = this._wrapWithUser((userId) => this.service.getVehicleTypes(userId));
|
||||||
|
this.buyVehicles = this._wrapWithUser(
|
||||||
|
(userId, req) => this.service.buyVehicles(userId, req.body),
|
||||||
|
{ successStatus: 201 }
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ import PoliticalOfficeHistory from './falukant/log/political_office_history.js';
|
|||||||
import ElectionHistory from './falukant/log/election_history.js';
|
import ElectionHistory from './falukant/log/election_history.js';
|
||||||
import Underground from './falukant/data/underground.js';
|
import Underground from './falukant/data/underground.js';
|
||||||
import UndergroundType from './falukant/type/underground.js';
|
import UndergroundType from './falukant/type/underground.js';
|
||||||
|
import VehicleType from './falukant/type/vehicle.js';
|
||||||
|
import Vehicle from './falukant/data/vehicle.js';
|
||||||
|
import Transport from './falukant/data/transport.js';
|
||||||
import Blog from './community/blog.js';
|
import Blog from './community/blog.js';
|
||||||
import BlogPost from './community/blog_post.js';
|
import BlogPost from './community/blog_post.js';
|
||||||
import Campaign from './match3/campaign.js';
|
import Campaign from './match3/campaign.js';
|
||||||
@@ -421,6 +424,71 @@ export default function setupAssociations() {
|
|||||||
PromotionalGiftLog.belongsTo(FalukantCharacter, { foreignKey: 'recipientCharacterId', as: 'recipient' });
|
PromotionalGiftLog.belongsTo(FalukantCharacter, { foreignKey: 'recipientCharacterId', as: 'recipient' });
|
||||||
FalukantCharacter.hasMany(PromotionalGiftLog, { foreignKey: 'recipientCharacterId', as: 'giftlogs' });
|
FalukantCharacter.hasMany(PromotionalGiftLog, { foreignKey: 'recipientCharacterId', as: 'giftlogs' });
|
||||||
|
|
||||||
|
// Vehicles & Transports
|
||||||
|
|
||||||
|
VehicleType.hasMany(Vehicle, {
|
||||||
|
foreignKey: 'vehicleTypeId',
|
||||||
|
as: 'vehicles',
|
||||||
|
});
|
||||||
|
Vehicle.belongsTo(VehicleType, {
|
||||||
|
foreignKey: 'vehicleTypeId',
|
||||||
|
as: 'type',
|
||||||
|
});
|
||||||
|
|
||||||
|
FalukantUser.hasMany(Vehicle, {
|
||||||
|
foreignKey: 'falukantUserId',
|
||||||
|
as: 'vehicles',
|
||||||
|
});
|
||||||
|
Vehicle.belongsTo(FalukantUser, {
|
||||||
|
foreignKey: 'falukantUserId',
|
||||||
|
as: 'owner',
|
||||||
|
});
|
||||||
|
|
||||||
|
RegionData.hasMany(Vehicle, {
|
||||||
|
foreignKey: 'regionId',
|
||||||
|
as: 'vehicles',
|
||||||
|
});
|
||||||
|
Vehicle.belongsTo(RegionData, {
|
||||||
|
foreignKey: 'regionId',
|
||||||
|
as: 'region',
|
||||||
|
});
|
||||||
|
|
||||||
|
Transport.belongsTo(RegionData, {
|
||||||
|
foreignKey: 'sourceRegionId',
|
||||||
|
as: 'sourceRegion',
|
||||||
|
});
|
||||||
|
Transport.belongsTo(RegionData, {
|
||||||
|
foreignKey: 'targetRegionId',
|
||||||
|
as: 'targetRegion',
|
||||||
|
});
|
||||||
|
|
||||||
|
RegionData.hasMany(Transport, {
|
||||||
|
foreignKey: 'sourceRegionId',
|
||||||
|
as: 'outgoingTransports',
|
||||||
|
});
|
||||||
|
RegionData.hasMany(Transport, {
|
||||||
|
foreignKey: 'targetRegionId',
|
||||||
|
as: 'incomingTransports',
|
||||||
|
});
|
||||||
|
|
||||||
|
Transport.belongsTo(ProductType, {
|
||||||
|
foreignKey: 'productId',
|
||||||
|
as: 'productType',
|
||||||
|
});
|
||||||
|
ProductType.hasMany(Transport, {
|
||||||
|
foreignKey: 'productId',
|
||||||
|
as: 'transports',
|
||||||
|
});
|
||||||
|
|
||||||
|
Transport.belongsTo(Vehicle, {
|
||||||
|
foreignKey: 'vehicleId',
|
||||||
|
as: 'vehicle',
|
||||||
|
});
|
||||||
|
Vehicle.hasMany(Transport, {
|
||||||
|
foreignKey: 'vehicleId',
|
||||||
|
as: 'transports',
|
||||||
|
});
|
||||||
|
|
||||||
PromotionalGift.hasMany(PromotionalGiftCharacterTrait, { foreignKey: 'gift_id', as: 'characterTraits' });
|
PromotionalGift.hasMany(PromotionalGiftCharacterTrait, { foreignKey: 'gift_id', as: 'characterTraits' });
|
||||||
PromotionalGift.hasMany(PromotionalGiftMood, { foreignKey: 'gift_id', as: 'promotionalgiftmoods' });
|
PromotionalGift.hasMany(PromotionalGiftMood, { foreignKey: 'gift_id', as: 'promotionalgiftmoods' });
|
||||||
|
|
||||||
|
|||||||
41
backend/models/falukant/data/transport.js
Normal file
41
backend/models/falukant/data/transport.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Model, DataTypes } from 'sequelize';
|
||||||
|
import { sequelize } from '../../../utils/sequelize.js';
|
||||||
|
|
||||||
|
class Transport extends Model {}
|
||||||
|
|
||||||
|
Transport.init(
|
||||||
|
{
|
||||||
|
sourceRegionId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
targetRegionId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
productId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
vehicleId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
modelName: 'Transport',
|
||||||
|
tableName: 'transport',
|
||||||
|
schema: 'falukant_data',
|
||||||
|
timestamps: true,
|
||||||
|
underscored: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Transport;
|
||||||
|
|
||||||
|
|
||||||
33
backend/models/falukant/data/vehicle.js
Normal file
33
backend/models/falukant/data/vehicle.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { Model, DataTypes } from 'sequelize';
|
||||||
|
import { sequelize } from '../../../utils/sequelize.js';
|
||||||
|
|
||||||
|
class Vehicle extends Model {}
|
||||||
|
|
||||||
|
Vehicle.init(
|
||||||
|
{
|
||||||
|
vehicleTypeId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
falukantUserId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
regionId: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
modelName: 'Vehicle',
|
||||||
|
tableName: 'vehicle',
|
||||||
|
schema: 'falukant_data',
|
||||||
|
timestamps: true,
|
||||||
|
underscored: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Vehicle;
|
||||||
|
|
||||||
|
|
||||||
46
backend/models/falukant/type/vehicle.js
Normal file
46
backend/models/falukant/type/vehicle.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Model, DataTypes } from 'sequelize';
|
||||||
|
import { sequelize } from '../../../utils/sequelize.js';
|
||||||
|
|
||||||
|
class VehicleType extends Model {}
|
||||||
|
|
||||||
|
VehicleType.init(
|
||||||
|
{
|
||||||
|
tr: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
cost: {
|
||||||
|
// base purchase cost of the vehicle
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
capacity: {
|
||||||
|
// transport capacity (e.g. in units of goods)
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
transportMode: {
|
||||||
|
// e.g. 'land', 'water', 'air'
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
speed: {
|
||||||
|
// abstract speed value, higher = faster
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
modelName: 'VehicleType',
|
||||||
|
tableName: 'vehicle',
|
||||||
|
schema: 'falukant_type',
|
||||||
|
timestamps: false,
|
||||||
|
underscored: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default VehicleType;
|
||||||
|
|
||||||
|
|
||||||
@@ -113,6 +113,9 @@ import PoliticalOfficeHistory from './falukant/log/political_office_history.js';
|
|||||||
import ElectionHistory from './falukant/log/election_history.js';
|
import ElectionHistory from './falukant/log/election_history.js';
|
||||||
import UndergroundType from './falukant/type/underground.js';
|
import UndergroundType from './falukant/type/underground.js';
|
||||||
import Underground from './falukant/data/underground.js';
|
import Underground from './falukant/data/underground.js';
|
||||||
|
import VehicleType from './falukant/type/vehicle.js';
|
||||||
|
import Vehicle from './falukant/data/vehicle.js';
|
||||||
|
import Transport from './falukant/data/transport.js';
|
||||||
|
|
||||||
import Room from './chat/room.js';
|
import Room from './chat/room.js';
|
||||||
import ChatUser from './chat/user.js';
|
import ChatUser from './chat/user.js';
|
||||||
@@ -207,6 +210,9 @@ const models = {
|
|||||||
Credit,
|
Credit,
|
||||||
DebtorsPrism,
|
DebtorsPrism,
|
||||||
HealthActivity,
|
HealthActivity,
|
||||||
|
VehicleType,
|
||||||
|
Vehicle,
|
||||||
|
Transport,
|
||||||
PoliticalOfficeType,
|
PoliticalOfficeType,
|
||||||
PoliticalOfficeRequirement,
|
PoliticalOfficeRequirement,
|
||||||
PoliticalOfficeBenefitType,
|
PoliticalOfficeBenefitType,
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ router.post('/politics/elections', falukantController.vote);
|
|||||||
router.get('/politics/open', falukantController.getOpenPolitics);
|
router.get('/politics/open', falukantController.getOpenPolitics);
|
||||||
router.post('/politics/open', falukantController.applyForElections);
|
router.post('/politics/open', falukantController.applyForElections);
|
||||||
router.get('/cities', falukantController.getRegions);
|
router.get('/cities', falukantController.getRegions);
|
||||||
|
router.get('/vehicles/types', falukantController.getVehicleTypes);
|
||||||
|
router.post('/vehicles', falukantController.buyVehicles);
|
||||||
router.get('/underground/types', falukantController.getUndergroundTypes);
|
router.get('/underground/types', falukantController.getUndergroundTypes);
|
||||||
router.get('/notifications', falukantController.getNotifications);
|
router.get('/notifications', falukantController.getNotifications);
|
||||||
router.get('/notifications/all', falukantController.getAllNotifications);
|
router.get('/notifications/all', falukantController.getAllNotifications);
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import UndergroundType from '../models/falukant/type/underground.js';
|
|||||||
import Notification from '../models/falukant/log/notification.js';
|
import Notification from '../models/falukant/log/notification.js';
|
||||||
import PoliticalOffice from '../models/falukant/data/political_office.js';
|
import PoliticalOffice from '../models/falukant/data/political_office.js';
|
||||||
import Underground from '../models/falukant/data/underground.js';
|
import Underground from '../models/falukant/data/underground.js';
|
||||||
|
import VehicleType from '../models/falukant/type/vehicle.js';
|
||||||
|
import Vehicle from '../models/falukant/data/vehicle.js';
|
||||||
|
|
||||||
function calcAge(birthdate) {
|
function calcAge(birthdate) {
|
||||||
const b = new Date(birthdate); b.setHours(0, 0);
|
const b = new Date(birthdate); b.setHours(0, 0);
|
||||||
@@ -448,6 +450,55 @@ class FalukantService extends BaseService {
|
|||||||
return FalukantStock.findAll({ where: { regionId: b.regionId, userId: u.id } });
|
return FalukantStock.findAll({ where: { regionId: b.regionId, userId: u.id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getVehicleTypes(hashedUserId) {
|
||||||
|
// Validate user existence, but we don't filter by user here
|
||||||
|
await getFalukantUserOrFail(hashedUserId);
|
||||||
|
return VehicleType.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
async buyVehicles(hashedUserId, { vehicleTypeId, quantity, regionId }) {
|
||||||
|
const user = await getFalukantUserOrFail(hashedUserId);
|
||||||
|
const qty = Math.max(1, parseInt(quantity, 10) || 0);
|
||||||
|
|
||||||
|
const type = await VehicleType.findByPk(vehicleTypeId);
|
||||||
|
if (!type) {
|
||||||
|
throw new Error('Vehicle type not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalCost = type.cost * qty;
|
||||||
|
if (user.money < totalCost) {
|
||||||
|
throw new PreconditionError('insufficientFunds');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the region exists (and is part of Falukant map)
|
||||||
|
const region = await RegionData.findByPk(regionId);
|
||||||
|
if (!region) {
|
||||||
|
throw new Error('Region not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update money and create vehicles in a transaction
|
||||||
|
await sequelize.transaction(async (tx) => {
|
||||||
|
await updateFalukantUserMoney(
|
||||||
|
user.id,
|
||||||
|
-totalCost,
|
||||||
|
'buy_vehicles',
|
||||||
|
user.id
|
||||||
|
);
|
||||||
|
|
||||||
|
const records = [];
|
||||||
|
for (let i = 0; i < qty; i++) {
|
||||||
|
records.push({
|
||||||
|
vehicleTypeId: type.id,
|
||||||
|
falukantUserId: user.id,
|
||||||
|
regionId: region.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await Vehicle.bulkCreate(records, { transaction: tx });
|
||||||
|
});
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
async createStock(hashedUserId, branchId, stockData) {
|
async createStock(hashedUserId, branchId, stockData) {
|
||||||
const u = await getFalukantUserOrFail(hashedUserId);
|
const u = await getFalukantUserOrFail(hashedUserId);
|
||||||
const b = await getBranchOrFail(u.id, branchId);
|
const b = await getBranchOrFail(u.id, branchId);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import TitleOfNobility from "../../models/falukant/type/title_of_nobility.js";
|
|||||||
import PartyType from "../../models/falukant/type/party.js";
|
import PartyType from "../../models/falukant/type/party.js";
|
||||||
import MusicType from "../../models/falukant/type/music.js";
|
import MusicType from "../../models/falukant/type/music.js";
|
||||||
import BanquetteType from "../../models/falukant/type/banquette.js";
|
import BanquetteType from "../../models/falukant/type/banquette.js";
|
||||||
|
import VehicleType from "../../models/falukant/type/vehicle.js";
|
||||||
import LearnRecipient from "../../models/falukant/type/learn_recipient.js";
|
import LearnRecipient from "../../models/falukant/type/learn_recipient.js";
|
||||||
import PoliticalOfficeType from "../../models/falukant/type/political_office_type.js";
|
import PoliticalOfficeType from "../../models/falukant/type/political_office_type.js";
|
||||||
import PoliticalOfficeBenefitType from "../../models/falukant/type/political_office_benefit_type.js";
|
import PoliticalOfficeBenefitType from "../../models/falukant/type/political_office_benefit_type.js";
|
||||||
@@ -41,6 +42,7 @@ export const initializeFalukantTypes = async () => {
|
|||||||
await initializePoliticalOfficeTypes();
|
await initializePoliticalOfficeTypes();
|
||||||
await initializePoliticalOfficePrerequisites();
|
await initializePoliticalOfficePrerequisites();
|
||||||
await initializeUndergroundTypes();
|
await initializeUndergroundTypes();
|
||||||
|
await initializeVehicleTypes();
|
||||||
};
|
};
|
||||||
|
|
||||||
const regionTypes = [];
|
const regionTypes = [];
|
||||||
@@ -273,6 +275,16 @@ const learnerTypes = [
|
|||||||
{ tr: 'director', },
|
{ tr: 'director', },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const vehicleTypes = [
|
||||||
|
{ tr: 'cargo_cart', name: 'Lastkarren', cost: 100, capacity: 20, transportMode: 'land', speed: 1 },
|
||||||
|
{ tr: 'ox_cart', name: 'Ochsenkarren', cost: 200, capacity: 50, transportMode: 'land', speed: 2 },
|
||||||
|
{ tr: 'small_carriage', name: 'kleine Pferdekutsche', cost: 300, capacity: 35, transportMode: 'land', speed: 3 },
|
||||||
|
{ tr: 'large_carriage', name: 'große Pferdekutsche', cost: 1000, capacity: 100, transportMode: 'land', speed: 3 },
|
||||||
|
{ tr: 'four_horse_carriage', name: 'Vierspänner', cost: 5000, capacity: 200, transportMode: 'land', speed: 4 },
|
||||||
|
{ tr: 'raft', name: 'Floß', cost: 100, capacity: 25, transportMode: 'water', speed: 1 },
|
||||||
|
{ tr: 'sailing_ship', name: 'Segelschiff', cost: 500, capacity: 200, transportMode: 'water', speed: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
const politicalOfficeBenefitTypes = [
|
const politicalOfficeBenefitTypes = [
|
||||||
{ tr: 'salary' },
|
{ tr: 'salary' },
|
||||||
{ tr: 'reputation' },
|
{ tr: 'reputation' },
|
||||||
@@ -883,6 +895,21 @@ export const initializeLearnerTypes = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const initializeVehicleTypes = async () => {
|
||||||
|
for (const v of vehicleTypes) {
|
||||||
|
await VehicleType.findOrCreate({
|
||||||
|
where: { tr: v.tr },
|
||||||
|
defaults: {
|
||||||
|
tr: v.tr,
|
||||||
|
cost: v.cost,
|
||||||
|
capacity: v.capacity,
|
||||||
|
transportMode: v.transportMode,
|
||||||
|
speed: v.speed,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const initializePoliticalOfficeBenefitTypes = async () => {
|
export const initializePoliticalOfficeBenefitTypes = async () => {
|
||||||
for (const benefitType of politicalOfficeBenefitTypes) {
|
for (const benefitType of politicalOfficeBenefitTypes) {
|
||||||
await PoliticalOfficeBenefitType.findOrCreate({
|
await PoliticalOfficeBenefitType.findOrCreate({
|
||||||
|
|||||||
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",
|
"director": "Direktor",
|
||||||
"inventory": "Inventar",
|
"inventory": "Inventar",
|
||||||
"production": "Produktion",
|
"production": "Produktion",
|
||||||
"storage": "Lager"
|
"storage": "Lager",
|
||||||
|
"transport": "Transportmittel"
|
||||||
},
|
},
|
||||||
"selection": {
|
"selection": {
|
||||||
"title": "Niederlassungsauswahl",
|
"title": "Niederlassungsauswahl",
|
||||||
@@ -203,6 +204,25 @@
|
|||||||
"buycost": "Kosten",
|
"buycost": "Kosten",
|
||||||
"sellincome": "Einnahmen"
|
"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": {
|
"stocktype": {
|
||||||
"wood": "Holzlager",
|
"wood": "Holzlager",
|
||||||
"stone": "Steinlager",
|
"stone": "Steinlager",
|
||||||
|
|||||||
@@ -30,6 +30,17 @@
|
|||||||
"knowledge": "Knowledge",
|
"knowledge": "Knowledge",
|
||||||
"hire": "Hire",
|
"hire": "Hire",
|
||||||
"noProposals": "No director candidates available."
|
"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">
|
<div v-else-if="activeTab === 'storage'" class="branch-tab-pane">
|
||||||
<StorageSection :branchId="selectedBranch.id" ref="storageSection" />
|
<StorageSection :branchId="selectedBranch.id" ref="storageSection" />
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
<BuyVehicleDialog
|
||||||
|
v-if="selectedBranch"
|
||||||
|
ref="buyVehicleDialog"
|
||||||
|
:region-id="selectedBranch?.regionId"
|
||||||
|
@bought="handleVehiclesBought"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -65,6 +79,7 @@ import SaleSection from '@/components/falukant/SaleSection.vue';
|
|||||||
import ProductionSection from '@/components/falukant/ProductionSection.vue';
|
import ProductionSection from '@/components/falukant/ProductionSection.vue';
|
||||||
import StorageSection from '@/components/falukant/StorageSection.vue';
|
import StorageSection from '@/components/falukant/StorageSection.vue';
|
||||||
import RevenueSection from '@/components/falukant/RevenueSection.vue';
|
import RevenueSection from '@/components/falukant/RevenueSection.vue';
|
||||||
|
import BuyVehicleDialog from '@/dialogues/falukant/BuyVehicleDialog.vue';
|
||||||
import apiClient from '@/utils/axios.js';
|
import apiClient from '@/utils/axios.js';
|
||||||
import { mapState } from 'vuex';
|
import { mapState } from 'vuex';
|
||||||
|
|
||||||
@@ -79,8 +94,9 @@ export default {
|
|||||||
ProductionSection,
|
ProductionSection,
|
||||||
StorageSection,
|
StorageSection,
|
||||||
RevenueSection,
|
RevenueSection,
|
||||||
|
BuyVehicleDialog,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
branches: [],
|
branches: [],
|
||||||
@@ -92,6 +108,7 @@ export default {
|
|||||||
{ value: 'inventory', label: 'falukant.branch.tabs.inventory' },
|
{ value: 'inventory', label: 'falukant.branch.tabs.inventory' },
|
||||||
{ value: 'director', label: 'falukant.branch.tabs.director' },
|
{ value: 'director', label: 'falukant.branch.tabs.director' },
|
||||||
{ value: 'storage', label: 'falukant.branch.tabs.storage' },
|
{ 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');
|
const result = await apiClient.get('/api/falukant/branches');
|
||||||
this.branches = result.data.map(branch => ({
|
this.branches = result.data.map(branch => ({
|
||||||
id: branch.id,
|
id: branch.id,
|
||||||
|
regionId: branch.regionId,
|
||||||
cityName: branch.region.name,
|
cityName: branch.region.name,
|
||||||
type: this.$t(`falukant.branch.types.${branch.branchType.labelTr}`),
|
type: this.$t(`falukant.branch.types.${branch.branchType.labelTr}`),
|
||||||
isMainBranch: branch.isMainBranch,
|
isMainBranch: branch.isMainBranch,
|
||||||
@@ -325,6 +343,16 @@ export default {
|
|||||||
console.error('Error processing daemon message:', error);
|
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>
|
</script>
|
||||||
@@ -333,4 +361,4 @@ export default {
|
|||||||
h2 {
|
h2 {
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import path from 'path';
|
|||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
// Lade Umgebungsvariablen explizit
|
// Lade Umgebungsvariablen explizit
|
||||||
const env = loadEnv(mode, process.cwd(), '');
|
const env = loadEnv(mode, process.cwd(), '');
|
||||||
|
// Kombiniere mit process.env, um auch Shell-Umgebungsvariablen zu berücksichtigen
|
||||||
|
const combinedEnv = { ...env, ...process.env };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
@@ -16,18 +18,18 @@ export default defineConfig(({ mode }) => {
|
|||||||
'import.meta.env.DEV': false,
|
'import.meta.env.DEV': false,
|
||||||
'import.meta.env.PROD': true,
|
'import.meta.env.PROD': true,
|
||||||
'import.meta.env.MODE': '"production"',
|
'import.meta.env.MODE': '"production"',
|
||||||
// Stelle sicher, dass Umgebungsvariablen aus .env.production geladen werden
|
// Stelle sicher, dass Umgebungsvariablen aus .env.production oder Shell-Umgebung geladen werden
|
||||||
...(env.VITE_DAEMON_SOCKET && {
|
...(combinedEnv.VITE_DAEMON_SOCKET && {
|
||||||
'import.meta.env.VITE_DAEMON_SOCKET': JSON.stringify(env.VITE_DAEMON_SOCKET)
|
'import.meta.env.VITE_DAEMON_SOCKET': JSON.stringify(combinedEnv.VITE_DAEMON_SOCKET)
|
||||||
}),
|
}),
|
||||||
...(env.VITE_API_BASE_URL && {
|
...(combinedEnv.VITE_API_BASE_URL && {
|
||||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL)
|
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(combinedEnv.VITE_API_BASE_URL)
|
||||||
}),
|
}),
|
||||||
...(env.VITE_CHAT_WS_URL && {
|
...(combinedEnv.VITE_CHAT_WS_URL && {
|
||||||
'import.meta.env.VITE_CHAT_WS_URL': JSON.stringify(env.VITE_CHAT_WS_URL)
|
'import.meta.env.VITE_CHAT_WS_URL': JSON.stringify(combinedEnv.VITE_CHAT_WS_URL)
|
||||||
}),
|
}),
|
||||||
...(env.VITE_SOCKET_IO_URL && {
|
...(combinedEnv.VITE_SOCKET_IO_URL && {
|
||||||
'import.meta.env.VITE_SOCKET_IO_URL': JSON.stringify(env.VITE_SOCKET_IO_URL)
|
'import.meta.env.VITE_SOCKET_IO_URL': JSON.stringify(combinedEnv.VITE_SOCKET_IO_URL)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
|
|||||||
Reference in New Issue
Block a user