Skip to content

Commit

Permalink
Merge pull request #121 from GPP-Woo/120-filter-datum-tot-en-met
Browse files Browse the repository at this point in the history
fix: zoek op datum tot en met
  • Loading branch information
nijmra authored Dec 16, 2024
2 parents 93679a7 + b8d5898 commit 2f274ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion odpc.client/src/components/DateRangePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>

<div class="form-group">
<label for="untilDate">Datum tot</label>
<label for="untilDate">Datum tot en met</label>

<input type="date" id="untilDate" ref="untilDateRef" v-model="untilDate" :max="today" />
</div>
Expand Down
24 changes: 19 additions & 5 deletions odpc.client/src/features/publicatie/PublicatiesOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<input type="text" id="zoeken" v-model="searchString" @keydown.enter.prevent="onSearch" />
</div>

<date-range-picker v-model:from-date="fromDate" v-model:until-date="untilDate" />
<date-range-picker v-model:from-date="fromDate" v-model:until-date="untilDateInclusive" />

<div class="form-group-button">
<button
Expand Down Expand Up @@ -128,7 +128,7 @@
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { computed, ref, watch } from "vue";
import SimpleSpinner from "@/components/SimpleSpinner.vue";
import AlertInline from "@/components/AlertInline.vue";
import DateRangePicker from "@/components/DateRangePicker.vue";
Expand All @@ -137,7 +137,12 @@ import { PublicatieStatus, type Publicatie } from "./types";
const searchString = ref("");
const fromDate = ref("");
const untilDate = ref("");
const untilDateInclusive = ref("");
// we zoeken met een datum in een datum-tijd veld, daarom corrigeren we de datum hier
const untilDateExclusive = computed({
get: () => addDays(untilDateInclusive.value, 1),
set: (v) => (untilDateInclusive.value = addDays(v, -1))
});
const sortingOptions = {
officiele_titel: "Title (a-z)",
Expand All @@ -156,6 +161,15 @@ const searchParamsConfig = {
registratiedatumTot: ""
};
const addDays = (dateString: string, days: number) => {
if (!dateString) return dateString;
const date = new Date(dateString);
const nextDateUtc = new Date(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + days)
);
return nextDateUtc.toISOString().substring(0, 10);
};
const { pagedResult, queryParams, pageCount, onNext, onPrev, isFetching, error } = usePagedSearch<
Publicatie,
typeof searchParamsConfig
Expand All @@ -171,7 +185,7 @@ watch(
({ search, registratiedatumVanaf, registratiedatumTot }) => {
searchString.value = search;
fromDate.value = registratiedatumVanaf;
untilDate.value = registratiedatumTot;
untilDateExclusive.value = registratiedatumTot;
},
{ once: true }
);
Expand All @@ -182,7 +196,7 @@ const onSearch = () =>
...queryParams.value,
search: searchString.value,
registratiedatumVanaf: fromDate.value,
registratiedatumTot: untilDate.value
registratiedatumTot: untilDateExclusive.value
});
</script>

Expand Down

0 comments on commit 2f274ca

Please sign in to comment.