Skip to content

Commit

Permalink
Move walk endTime form field into own component #248
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfausk committed Jan 7, 2025
1 parent 98052db commit e4de5b0
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 304 deletions.
121 changes: 121 additions & 0 deletions web/assets/js/components/Common/Walk/WalkEndTimeField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<script setup lang="ts">
import {computed, ref, watch} from "vue";
import {getViolationsFeedback} from "../../../utils";
import {Walk} from "../../../model";
import DatePicker from "vue2-datepicker";
import 'vue2-datepicker/index.css';
import 'vue2-datepicker/locale/de';
import dayjs from "dayjs";
// const props = defineProps(['modelValue', 'value']); // vue3
// const emit = defineEmits(['update:modelValue']); // vue3
const emit = defineEmits(['input']);
export interface Props {
value: string,
initialWalk?: Walk | null,
description?: string,
error?: any,
isLoading?: boolean
}
const props = withDefaults(defineProps<Props>(), {
description: '',
initialWalk: null,
error: false,
isLoading: false,
});
const endTimeTime = ref(props.value ? dayjs(props.value).toDate() : dayjs().toDate());
const endTimeDate = ref(props.value ? dayjs(props.value).toDate() : dayjs().toDate());
const datePickerLang = ref({
formatLocale: {
firstDayOfWeek: 1,
},
monthBeforeYear: true,
});
const value = computed({
get() {
// return props.modelValue // vue3
return props.value
},
set(value) {
// emit('update:modelValue', value); // vue3
emit('input', value)
}
});
watch(() => props.value, () => {
if (dayjs(endTimeTime.value) !== dayjs(props.value)) {
endTimeTime.value = dayjs(props.value).toDate();
}
if (dayjs(endTimeDate.value) !== dayjs(props.value)) {
endTimeDate.value = dayjs(props.value).toDate();
}
})
watch(() => endTimeTime.value, () => {
let endTimeDate = dayjs(props.value);
let endTime = dayjs(endTimeTime.value);
endTimeDate = endTimeDate.hour(endTime.hour());
endTimeDate = endTimeDate.minute(endTime.minute());
endTimeDate = endTimeDate.endOf('minute');
value.value = endTimeDate.format();
});
watch(() => endTimeDate.value, () => {
const endTimeDateValue = dayjs(endTimeDate.value);
let endTime = dayjs(props.value);
endTime = endTime.year(endTimeDateValue.year());
endTime = endTime.month(endTimeDateValue.month());
endTime = endTime.date(endTimeDateValue.date());
endTime = endTime.endOf('minute');
value.value = endTime.format();
});
const errorMessages = computed(() => {
if (!props.error) {
return ''
}
return getViolationsFeedback(['endTime', 'endTimeBeforeEndTime', 'endTimeBeforeAllWayPoints'], props.error);
})
</script>

<template>
<div>
Rundenendzeit<br>
<date-picker
v-model="endTimeDate"
label="Rundenendzeit"
:disabled="isLoading"
format="DD.MM.YYYY"
title-format="DD.MM.YYYY"
show-week-number
data-test="endTimeDate"
:lang="datePickerLang"
:clearable="false"
/>
<date-picker
v-model="endTimeTime"
type="time"
:disabled="isLoading"
data-test="endTimeTime"
:minute-step="5"
format="HH:mm"
title-format="HH:mm"
:show-second="false"
:lang="datePickerLang"
:clearable="false"
/>
<div class="text-disabeld text-caption">{{ description }}</div>
<v-alert
v-if="!!errorMessages?.length"
type="error"
>
{{ errorMessages }}
</v-alert>
</div>
</template>

<style scoped>
</style>
11 changes: 9 additions & 2 deletions web/assets/js/components/Common/Walk/WalkStartTimeField.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import {computed, ref, watch} from "vue";
import {getViolationsFeedback} from "../../../utils";
import {Team, Walk} from "../../../model";
import {Walk} from "../../../model";
import DatePicker from "vue2-datepicker";
import 'vue2-datepicker/index.css';
import 'vue2-datepicker/locale/de';
Expand Down Expand Up @@ -46,7 +46,14 @@ const value = computed({
}
});
watch(() => props.value, () => {
if (dayjs(startTimeTime.value) !== dayjs(props.value)) {
startTimeTime.value = dayjs(props.value).toDate();
}
if (dayjs(startTimeDate.value) !== dayjs(props.value)) {
startTimeDate.value = dayjs(props.value).toDate();
}
})
watch(() => startTimeTime.value, () => {
let startTimeDate = dayjs(props.value);
let startTime = dayjs(startTimeTime.value);
Expand Down
1 change: 1 addition & 0 deletions web/assets/js/components/Common/Walk/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {default as WalkConceptOfDayField} from './WalkConceptOfDayField.vue';
export {default as WalkEndTimeField} from './WalkEndTimeField.vue';
export {default as WalkGuestNamesField} from './WalkGuestNamesField.vue';
export {default as WalkHolidaysField} from './WalkHolidaysField.vue';
export {default as WalkNameField} from './WalkNameField.vue';
Expand Down
Loading

0 comments on commit e4de5b0

Please sign in to comment.