feat: resetting order body

This commit is contained in:
2026-01-23 13:42:22 +01:00
parent 1a969731cd
commit 1c93684218
2 changed files with 202 additions and 29 deletions
+5 -29
View File
@@ -25,7 +25,9 @@
> >
<LucidePencil /> <LucidePencil />
{{ $t('order-message.button-update') }} {{ $t('order-message.button-update') }}
<span class="text--accent" v-if="store.chosenLocalOrderId">#{{ store.chosenLocalOrderId.split('-')[1] }} </span> <span class="text--accent" v-if="store.chosenLocalOrderId"
>#{{ store.chosenLocalOrderId.split('-')[1] }}
</span>
</button> </button>
<button class="g-button action icon" @click="resetOrder"> <button class="g-button action icon" @click="resetOrder">
@@ -82,6 +84,7 @@ import orderValidationMixin from '../../mixins/orderValidationMixin';
import { useStore } from '../../store/store'; import { useStore } from '../../store/store';
import { currentFormattedHours, currentFormattedMinutes } from '../../utils/dateUtils'; import { currentFormattedHours, currentFormattedMinutes } from '../../utils/dateUtils';
import { LucideCopy, LucidePencil, LucideRotateCcw, LucideSave } from 'lucide-vue-next'; import { LucideCopy, LucidePencil, LucideRotateCcw, LucideSave } from 'lucide-vue-next';
import { setOrderToDefault } from '../../utils/orderUtils';
export default defineComponent({ export default defineComponent({
name: 'OrderMessage', name: 'OrderMessage',
@@ -242,34 +245,7 @@ export default defineComponent({
}, },
resetOrder() { resetOrder() {
const order = this.store[this.store.chosenOrderType]; setOrderToDefault(this.store[this.store.chosenOrderType]);
// TODO
// Object.keys(store.orderData.header).forEach((k) => {
// store.orderData['header'][k as keyof IOrderHeader] = '';
// });
// Object.keys(store.orderData.footer).forEach((k) => {
// store.orderData['footer'][k as keyof IOrderFooter] = '';
// });
// store.orderData.instructions.forEach((instruction) => {
// instruction.active = false;
// Object.keys(instruction.inputFields).forEach((k) => {
// instruction.inputFields[k] = '';
// });
// if (instruction.listFields) {
// instruction.listFields.forEach((field) => {
// Object.keys(field.values).forEach((k) => {
// field.active = false;
// field.values[k] = '';
// });
// });
// }
// });
} }
} }
}); });
+197
View File
@@ -0,0 +1,197 @@
import { IOrderN, IOrderO, IOrderS, TOrder } from '../types/orderTypes';
import { currentFormattedDate } from './dateUtils';
const orderDefaults = {
orderN: {
header: {
orderNo: '1',
trainNo: '',
date: ''
},
rows: [
{
enabled: false,
from: '',
to: '',
trackNo: '',
trackNo2: ''
},
{
enabled: false,
option1: 'sygnału "Nakaz Jazdy"',
option2: 'lewy',
option3: 'lewy',
signal1: '',
signal2: '',
signal3: '',
signalType: 'wyjazdowego',
checkbox: 'checkbox-2a',
direction1: '',
direction2: '',
trackNoFrom: '',
trackNoTo1: '',
trackNoTo2: ''
},
{
enabled: false,
option1: 'Jazda',
option2: 'pociąg',
direction: '',
toKilometer: '',
trackNo: '',
untilHour: '',
untilMin: ''
},
{
enabled: false,
trackNo: '',
optionStation: 'stację',
stationName: '',
checkbox: 'checkbox-4a',
side: 'lewej'
},
{
enabled: false,
trackNo: '',
direction: '',
stationType: 'stację',
stationName: '',
on: ''
},
{
enabled: false,
content: '',
twoWay: {
enabled: false,
from: '',
to: '',
trackNo: ''
}
}
]
},
orderS: {
header: {
orderNo: '1',
trainNo: '',
for: 'pociągu',
date: ''
},
rows: [
{
enabled: false,
option1: 'sygnału "nakaz jazdy"',
optionSignal: 'wyjazdowego',
radio1: 'radio-1a-1',
signal1: '',
trackNo: ''
},
{
enabled: false,
signalType: 'wyjazdowego',
signal1: '',
signal2: '',
signal3: '',
trackNo: ''
},
{
enabled: false,
from: '',
to: '',
trackNo: '',
trainNo: '',
arrivedTo: '',
hour: ''
},
{
enabled: false,
content: '',
w5: {
enabled: false,
maxHour: '',
borderType: 'wskaźnik przetaczania W5',
tmName: '',
maxKm: '',
returnWay: 'sygnał ręczny "Do mnie"',
trackNo: ''
}
}
]
},
orderO: {
header: {
orderNo: '1',
trainNo: '',
date: ''
},
orderList: [
{
name: '',
from: '',
to: '',
vmax: '',
jo: false,
reason: ''
},
{
name: '',
from: '',
to: '',
vmax: '',
jo: false,
reason: ''
},
{
name: '',
from: '',
to: '',
vmax: '',
jo: false,
reason: ''
},
{
name: '',
from: '',
to: '',
vmax: '',
jo: false,
reason: ''
},
{
name: '',
from: '',
to: '',
vmax: '',
jo: false,
reason: ''
}
],
other: ''
}
};
export function getOrderType(order: IOrderN | IOrderO | IOrderS): TOrder {
if ('rows' in order && 'for' in order.header) return 'orderS';
else if ('rows' in order) return 'orderN';
return 'orderO';
}
export function setOrderToDefault(order: IOrderN | IOrderO | IOrderS) {
const orderType = getOrderType(order);
const defaultOrderObjectCopy = JSON.parse(JSON.stringify(orderDefaults[orderType]));
Object.assign(order, defaultOrderObjectCopy);
// Update date in the header
order.header.date = currentFormattedDate();
}