Files
pleno-vue/src/components/session/token/SessionUser/Objects/Bookings.vue
T
Jeppe Bundgaard fd8b86987f Localize objects and enhance i18n integration
- Replaced hardcoded labels in `Bookings.vue`, `Orders.vue`, and `Vehicles.vue` with dynamic translations using `i18n`.
- Added comprehensive translation keys for `objects` in `en.json` and `da.json`.
- Improved multilingual support for objects metadata, columns, and labels.
2026-02-17 12:56:40 +01:00

292 lines
7.1 KiB
Vue

<script>
import Swal from "sweetalert2";
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
import { SessionUser } from "@/components/session/token/SessionUser.vue";
import {ref} from "vue";
import i18n from '@/i18n';
const t = (key) => i18n.global.t(key);
/**
* The Bookings object
*/
export const Bookings = {
get meta() {
return {
title: t('objects.bookings.title'),
icon: "fas fa-list",
description: t('objects.bookings.description'),
endpoint: "/bookings",
labels: {
single: t('objects.bookings.single'),
multiple: t('objects.bookings.multiple'),
fields: {
names: {
customer_number: {
label: t('objects.bookings.columns.economic_customer_number'),
},
},
},
},
};
},
get columns() {
return {
id: {
label: t('objects.columns.id'),
type: "number",
sortable: true,
creation: {
required: false
}
},
customer_number: {
label: t('objects.columns.customer_number'),
type: "number",
sortable: true,
creation: {
required: true
},
},
wash_type: {
label: t('objects.bookings.columns.wash_type'),
type: "string",
sortable: true,
creation: {
required: true
},
},
contact_email: {
label: t('objects.bookings.columns.contact_email'),
type: "string",
sortable: true,
creation: {
required: true
},
},
reference_number: {
label: t('objects.columns.reference'),
type: "string",
sortable: true,
creation: {
required: true
},
},
regNrTraekker: {
label: t('objects.bookings.columns.reg_1'),
type: "string",
sortable: true,
creation: {
required: true
},
},
regNrTrailer: {
label: t('objects.bookings.columns.reg_2'),
type: "string",
sortable: true,
creation: {
required: false
},
},
washCertificateEmail: {
label: t('objects.bookings.columns.wash_certificate_email'),
type: "string",
sortable: true,
creation: {
required: false
},
},
date: {
label: t('objects.columns.date'),
type: "string",
sortable: true,
creation: {
required: true
},
},
department: {
label: t('objects.columns.department'),
type: "select",
sortable: true,
creation: {
required: true
},
options: async () => {
return SessionUser.objects.department_notification_sms.columns.department.options()
}
},
pickup_bool: {
label: t('objects.bookings.columns.pickup'),
type: "boolean",
sortable: true,
creation: {
required: false
},
},
notes: {
label: t('objects.columns.notes'),
type: "string",
sortable: true,
creation: {
required: false
},
},
washCertificateStatus: {
label: t('objects.bookings.columns.wash_certificate_status'),
type: "select",
sortable: true,
creation: {
required: false
},
options: async () => {
return [
{ id: 'pending', name: "Afventer" },
{ id: 'cancelled', name: "Annulleret" },
{ id: 'completed', name: "Færdig" },
];
}
},
washCertificateUrl: {
label: t('objects.bookings.columns.wash_certificate_url'),
type: "string",
sortable: true,
creation: {
required: false
},
},
status: {
label: t('objects.columns.status'),
type: "select",
sortable: true,
creation: {
required: true
},
options: async () => {
return [
{ id: 'pending', name: "Afventer" },
{ id: 'cancelled', name: "Annulleret" },
{ id: 'completed', name: "Færdig" },
];
}
},
data: {
label: t('objects.columns.data'),
type: "string",
sortable: false,
creation: {
required: false
},
},
wash_certificate_pdf: {
label: t('objects.bookings.columns.wash_certificate_pdf'),
type: "string",
sortable: false,
creation: {
required: false
},
},
created_at: {
label: t('objects.columns.created'),
type: "string",
sortable: true,
creation: {
required: false
},
},
deleted_at: {
label: t('objects.columns.deleted'),
type: "string",
sortable: true,
creation: {
required: false
},
},
};
},
set: {
reference_number: async (id, reference) => {
return ObjectsGlobal.set.column(
Bookings.meta.endpoint,
id,
"reference_number",
reference
)
},
},
get: {
single: async (identifier) => {
return ObjectsGlobal.get.object(Bookings.meta.endpoint, identifier, {authenticated: SessionUser.functions.hasToken()});
},
},
functions: {
submit: async (form) => {
console.warn(form);
return ObjectsGlobal.add.object(Bookings.meta.endpoint, form, {authenticated: SessionUser.functions.hasToken()});
},
download: async (id) => {
return SessionUser.request(
'/bookings/download_pdf',
'GET',
{
id: id
}
);
},
getDepartmentBookingsToday: async (department) => {
/**
* https://api.truckwash.dk/bookings?filters=department:2,status:pending,date-date_from:2025-09-01,date-date_to:2025-09-01&limit=1&page=1
*/
return SessionUser.request(
'/bookings',
'GET',
{
filters: `department:${department},status:pending,date-date_from:${new Date().toISOString().split('T')[0]},date-date_to:${new Date().toISOString().split('T')[0]}`,
limit: 100,
page: 1
}
);
},
isBookingCompleted: async (id) => {
let booking = await Bookings.get.single(id)
.then(response => {
console.warn("Booking:", response);
return response;
})
.catch(error => {
console.error("Error fetching booking:", error);
return null;
});
if (booking) {
console.warn("Booking status:", booking.status);
return booking.status === 'completed';
}
}
},
/**
* Show the create object form
* @param onAfterSubmit
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
*/
showCreateObjectForm: (onAfterSubmit = null) => {
return ObjectsGlobal.showCreateObjectForm(Bookings, onAfterSubmit);
},
/**
* Show the edit object field form
* @param id
* @param column
* @param value
* @param onAfterSubmit
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
*/
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
return ObjectsGlobal.showEditObjectFieldForm(
Bookings,
id,
column,
value,
onAfterSubmit
);
}
};
</script>