diff --git a/frontend/src/components/zaehlstelle/optionsmenue/OptionsmenueZaehlstelle.vue b/frontend/src/components/zaehlstelle/optionsmenue/OptionsmenueZaehlstelle.vue index 99465e6be..21262e73c 100644 --- a/frontend/src/components/zaehlstelle/optionsmenue/OptionsmenueZaehlstelle.vue +++ b/frontend/src/components/zaehlstelle/optionsmenue/OptionsmenueZaehlstelle.vue @@ -39,6 +39,7 @@ > (() => { return zaehlstelleStore.getFilteroptions; @@ -177,6 +181,23 @@ const getContentSheetHeight = computed(() => { function setDefaultOptionsForZaehlung() { const optionsCopy = {} as OptionsDTO; Object.assign(optionsCopy, options.value); + const yesterday = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000); + + optionsCopy.zeitraumStartAndEndDate = { + startDate: yesterday, + endDate: yesterday, + isRange: () => true + }; + + const isoStartDate = dateUtils.formatDateToISO( + yesterday + ); + const isoEndDate = dateUtils.formatDateToISO( + yesterday + ); + optionsCopy.zeitraum = [isoStartDate, isoEndDate].filter( + (date) => !isEmpty(date) + ); if (props.zaehlung.zaehldauer === Zaehldauer.DAUER_13_STUNDEN) { optionsCopy.zeitauswahl = Zeitauswahl.BLOCK; @@ -241,6 +262,24 @@ function setDefaultOptionsForZaehlung() { } // Event Methoden für die Zeitauswahl Komponente +function setZeitraumStartAndEndDate(event: StartAndEndDate) { + if (event) { + chosenOptions.value.zeitraumStartAndEndDate = event; + zaehlstelleStore.setZeitraumStartAndEndDate(event); + if (!isNil(chosenOptions.value.zeitraumStartAndEndDate)) { + const isoStartDate = dateUtils.formatDateToISO( + chosenOptions.value.zeitraumStartAndEndDate.startDate + ); + const isoEndDate = dateUtils.formatDateToISO( + chosenOptions.value.zeitraumStartAndEndDate.endDate + ); + chosenOptions.value.zeitraum = [isoStartDate, isoEndDate].filter( + (date) => !isEmpty(date) + ); + } + } +} + function setZeitauswahl(event: string) { chosenOptions.value.zeitauswahl = event; zaehlstelleStore.setZeitauswahl(event); diff --git a/frontend/src/components/zaehlstelle/optionsmenue/panels/ZeitauswahlPanel.vue b/frontend/src/components/zaehlstelle/optionsmenue/panels/ZeitauswahlPanel.vue index 396f646c7..f3755d335 100644 --- a/frontend/src/components/zaehlstelle/optionsmenue/panels/ZeitauswahlPanel.vue +++ b/frontend/src/components/zaehlstelle/optionsmenue/panels/ZeitauswahlPanel.vue @@ -10,13 +10,21 @@ + + - (); const zaehlstelleStore = useZaehlstelleStore(); const zaehlstelleUtils = useZaehlstelleUtils(); +const dateUtils = useDateUtils(); const emits = defineEmits<{ + (e: "zeitraumStartAndEndDate", v: StartAndEndDate): void; (e: "zeitauswahl", v: string): void; (e: "zeitblock", v: string): void; (e: "intervall", v: ZaehldatenIntervall): void; @@ -221,6 +234,39 @@ const activeZaehlung = computed(() => { return zaehlstelleStore.getAktiveZaehlung; }); +const zeitraumStartAndEndDate = computed(() => { + return zaehlstelleStore.getZeitraumStartAndEndDate; +}); + +const minDateDescription = ref(""); +const minDate = ref(); + +watch( + () => [activeZaehlung.value.datum], + () => { + const startdatum = new Date("2006-01-01"); + const realisierungsdatum = new Date( + activeZaehlung.value.datum + ); + if ( + dateUtils.isValidIsoDate(activeZaehlung.value.datum) && + realisierungsdatum >= startdatum + ) { + minDateDescription.value = "Realisierungsdatum"; + minDate.value = realisierungsdatum; + } else { + minDateDescription.value = "frühestmöglichen Datum"; + minDate.value = startdatum; + } + }, + { immediate: true } +); + +const maxDateDescription = ref("gestrigen Datum"); +const maxDate = ref(new Date(new Date().setDate(new Date().getDate() - 1))); + +const auffaelligeTage = ref>([]); + const isZeitauswahlSpitzenstundeOrBlock = computed(() => { return ( zeitauswahl.value === Zeitauswahl.BLOCK || isZeitauswahlSpitzenstunde.value @@ -399,6 +445,15 @@ watch(options, (newOptions: OptionsDTO) => { update(newOptions); }); +watch( + () => [zeitraumStartAndEndDate.value.startDate, zeitraumStartAndEndDate.value.endDate], + () => { + emits("zeitraumStartAndEndDate", zeitraumStartAndEndDate.value); + }, + { immediate: true } +); + + watch(zeitauswahl, () => { emits("zeitauswahl", zeitauswahl.value); }); diff --git a/frontend/src/store/ZaehlstelleStore.ts b/frontend/src/store/ZaehlstelleStore.ts index 6c4511ef4..7448005a9 100644 --- a/frontend/src/store/ZaehlstelleStore.ts +++ b/frontend/src/store/ZaehlstelleStore.ts @@ -12,6 +12,9 @@ import { useUserStore } from "@/store/UserStore"; import LadeKnotenarmComperator from "@/types/zaehlung/LadeKnotenarmComperator"; import LadeZaehlungComperator from "@/types/zaehlung/LadeZaehlungComperator"; import DefaultObjectCreator from "@/util/DefaultObjectCreator"; +import { isNil, isEmpty } from "lodash"; +import type StartAndEndDate from "@/types/common/StartAndEndDate"; +import { useDateUtils } from "@/util/DateUtils"; export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { const route = useRoute(); @@ -23,6 +26,15 @@ export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { const filteroptions = ref( DefaultObjectCreator.createDefaultZaehlstelleOptionsDto() ); + const zeitraumStartAndEndDate = ref( + { + startDate: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), + endDate: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000), + isRange: () => true + } + ); + const dateUtils = useDateUtils(); + const zeitraum = ref([]); const zeitblock = ref(""); const zeitauswahl = ref(""); const history = ref(false); @@ -51,6 +63,10 @@ export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { () => filteroptions.value.differenzdatenDarstellen ); const isBlackprintMode = computed(() => filteroptions.value.blackPrintMode); + const getZeitraumStartAndEndDate = computed( + () => zeitraumStartAndEndDate.value + ); + const getZeitraum = computed(() => zeitraum.value); const getZeitblock = computed(() => zeitblock.value); const getZeitauswahl = computed(() => zeitauswahl.value); const isHistory = computed(() => history.value); @@ -100,6 +116,23 @@ export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { filteroptions.value = payload; history.value = true; } + function setZeitraumStartAndEndDate(payload: StartAndEndDate) { + zeitraumStartAndEndDate.value = payload; + if (!isNil(payload)) { + const isoStartDate = dateUtils.formatDateToISO( + payload.startDate + ); + const isoEndDate = dateUtils.formatDateToISO( + payload.endDate + ); + zeitraum.value = [isoStartDate, isoEndDate].filter( + (date) => !isEmpty(date) + ); + } + } + function setZeitraum(payload: string[]) { + zeitraum.value = payload; + } function setZeitblock(payload: string) { zeitblock.value = payload; } @@ -204,6 +237,8 @@ export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { getFilteroptions, isDifferenzdatenDarstellung, isBlackprintMode, + getZeitraum, + getZeitraumStartAndEndDate, getZeitblock, getZeitauswahl, isHistory, @@ -225,6 +260,8 @@ export const useZaehlstelleStore = defineStore("zaehlstelleStore", () => { setActiveTab, setFilteroptions, setFilteroptionsHistory, + setZeitraum, + setZeitraumStartAndEndDate, setZeitblock, setZeitauswahl, reloadFilteroptions, diff --git a/frontend/src/types/zaehlung/OptionsDTO.ts b/frontend/src/types/zaehlung/OptionsDTO.ts index dc69065e1..0e499cd2a 100644 --- a/frontend/src/types/zaehlung/OptionsDTO.ts +++ b/frontend/src/types/zaehlung/OptionsDTO.ts @@ -1,7 +1,10 @@ import ZaehldatenIntervall from "@/types/enum/ZaehldatenIntervall"; import Zaehldauer from "@/types/enum/Zaehldauer"; +import type StartAndEndDate from "../common/StartAndEndDate"; export default interface OptionsDTO { + zeitraumStartAndEndDate: StartAndEndDate; + zeitraum: string[]; zaehldauer: Zaehldauer; intervall: ZaehldatenIntervall; zeitblock: string; diff --git a/frontend/src/util/DefaultObjectCreator.ts b/frontend/src/util/DefaultObjectCreator.ts index 41b8d94ac..2481c8652 100644 --- a/frontend/src/util/DefaultObjectCreator.ts +++ b/frontend/src/util/DefaultObjectCreator.ts @@ -223,6 +223,8 @@ export default class DefaultObjectCreator { return { beideRichtungen: false, vergleichszaehlungsId: null, + zeitraumStartAndEndDate: new StartAndEndDate(undefined, undefined), + zeitraum: [], zaehldauer: Zaehldauer.DAUER_24_STUNDEN, intervall: ZaehldatenIntervall.STUNDE_VIERTEL, zeitblock: Zeitblock.ZB_00_24,