-
{{ t('datepicker.date') }}:
-
-
-
- {{ t('datepicker.error', { start: formatDate(startYear), end: formatDate(endYear) }) }}
-
-
+ :start-date="startYear"
+ :end-date="endYear"
+ />
import { defineComponent, onMounted, ref, watch } from 'vue';
import type { DatePickerInstance } from '@vuepic/vue-datepicker';
-import VueDatePicker from '@vuepic/vue-datepicker';
import {
days,
endDate,
@@ -66,7 +37,8 @@ import { RouteLocationRaw } from 'vue-router';
import { addTestDataEnrichment } from '@/utils/test-enrichments';
import { resetAllSelectorValues } from '@/utils/time-search-utils';
import { useI18n } from 'vue-i18n';
-import { updateSelectedDate } from '@/utils/datepicker-utils';
+import { updateDate } from '@/utils/datepicker-utils';
+import TimePicker from '../TimePicker.vue';
interface MonthYearEvent {
instance: number;
@@ -77,13 +49,13 @@ interface MonthYearEvent {
export default defineComponent({
name: 'DayPicker',
components: {
- VueDatePicker,
+ TimePicker,
},
setup() {
let inputTimer: ReturnType | null = null;
const singleDatePicker = ref();
- const selectedDate = ref(new Date(2015, 0, 1, 0, 0, 0));
+ const selectedDate = ref(undefined);
const singleDayStartDate = ref(new Date(2015, 0, 1, 0, 0, 0)); // January 1, 2015, 00:00:00
const singleDayEndDate = ref(new Date(2015, 0, 1, 23, 59, 59)); // January 1, 2015, 23:59:59
@@ -126,26 +98,18 @@ export default defineComponent({
if (inputTimer !== null) {
clearTimeout(inputTimer);
}
- updateSeeMoreLink();
+ updateDate(inputTimer, validDate, selectedDate, updateSeeMoreLink);
},
+ { deep: true },
);
- const setupInputTimer = (e: Event) => {
+ const setupInputTimer = () => {
if (inputTimer !== null) {
clearTimeout(inputTimer);
}
inputTimer = setTimeout(() => {
- updateSelectedDate(e, inputTimer, validDate, selectedDate, updateSeeMoreLink);
- }, 750); // 750 milliseconds (0.75 second) delay
- };
-
- const formatDate = (date: Date) => {
- if (!(date instanceof Date)) return '';
- return date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear();
- };
-
- const textInputOptions = {
- format: 'd-M-yyyy',
+ updateDate(inputTimer, validDate, selectedDate, updateSeeMoreLink);
+ }, 1000); // 1000 milliseconds (1 second) delay
};
const specificDayLink = ref({
@@ -159,7 +123,12 @@ export default defineComponent({
});
const moveToSearchPage = () => {
- if (selectedDate.value !== null && startDate.value !== null && endDate.value !== null) {
+ if (
+ selectedDate.value !== null &&
+ startDate.value !== null &&
+ endDate.value !== null &&
+ selectedDate.value !== undefined
+ ) {
startDate.value.setFullYear(selectedDate.value.getFullYear());
startDate.value.setMonth(selectedDate.value.getMonth());
startDate.value.setDate(selectedDate.value.getDate());
@@ -175,8 +144,8 @@ export default defineComponent({
window.scrollTo({ top: 0, behavior: 'smooth' });
};
- const executeUpdate = (e: Event) => {
- updateSelectedDate(e, inputTimer, validDate, selectedDate, updateSeeMoreLink); // Pass .value here as well
+ const executeUpdate = () => {
+ updateDate(inputTimer, validDate, selectedDate, updateSeeMoreLink); // Pass .value here as well
};
const updateSeeMoreLink = () => {
@@ -239,13 +208,11 @@ export default defineComponent({
moveToSearchPage,
HandleMonthYear,
locale,
- textInputOptions,
- updateSelectedDate,
+ updateDate,
setupInputTimer,
inputTimer,
validDate,
executeUpdate,
- formatDate,
t,
};
},
@@ -259,38 +226,6 @@ export default defineComponent({
justify-content: center;
}
-.date-span {
- width: 320px;
- position: relative;
- display: block;
-}
-
-.error-container {
- width: 50%;
- position: absolute;
- height: fit-content;
- left: 0px;
- top: 55px;
- color: white;
- padding: 5px;
- background-color: rgb(184, 0, 0);
- box-sizing: border-box;
-}
-
-.error-container:before {
- content: '';
- display: block;
- width: 0;
- height: 0;
- border-left: 7px solid transparent;
- border-right: 7px solid transparent;
- border-bottom: 7px solid rgb(184, 0, 0);
- top: -7px;
- position: absolute;
- left: 50%;
- transform: translate(-50%, 0%);
-}
-
.picker-container {
display: flex;
flex-direction: column;
@@ -377,8 +312,8 @@ export default defineComponent({
justify-content: space-around;
flex-direction: column;
align-items: center;
- padding-top: 20px;
- width: 320px;
+ padding-top: 0px;
+ width: 300px;
align-items: flex-end;
padding-left: 8px;
padding-right: 8px;
diff --git a/src/components/common/timeSearch/TimeSearchInitValues.ts b/src/components/common/timeSearch/TimeSearchInitValues.ts
index 801b7405..59de99ac 100644
--- a/src/components/common/timeSearch/TimeSearchInitValues.ts
+++ b/src/components/common/timeSearch/TimeSearchInitValues.ts
@@ -6,8 +6,8 @@ const initStartDate = ref(new Date(2015, 0, 1, 0, 0, 0)); // January 1, 20
const initEndDate = ref(new Date(2015, 11, 31, 23, 59, 59)); // December 31, 2015, 23:59:59
const timeSliderValues = ref(initSliderValues.value);
-const startDate = ref(initStartDate.value); // January 1, 2015, 00:00:00
-const endDate = ref(initEndDate.value); // December 31, 2015, 23:59:59
+const startDate = ref(initStartDate.value); // January 1, 2015, 00:00:00
+const endDate = ref(initEndDate.value); // December 31, 2015, 23:59:59
/* these are just the preset values. Should be updated when we got the new index in solr */
const startYear = ref(new Date(2006, 0, 1, 0, 0, 0));
diff --git a/src/locales/da.json b/src/locales/da.json
index 806c3858..82771098 100644
--- a/src/locales/da.json
+++ b/src/locales/da.json
@@ -543,5 +543,13 @@
"maybeYouWantTo":"Eller måske vil du hellere:",
"restoreFilters":"Gendanne filtre fra sidste søgning",
"GoToFrontpage":"Til forsiden af DR-arkivet"
+ },
+ "calendar": {
+ "open":"Åben kalender",
+ "close": "Luk kalender",
+ "explanation": "Skriv en dato i formatet DD-MM-ÅÅÅÅ eller vælg fra kalenderen.",
+ "select": "Vælg dato",
+ "nextMonth": "Næste måned",
+ "prevMonth":"Forrige måned"
}
}
diff --git a/src/locales/en.json b/src/locales/en.json
index 448d9fbf..e997fa75 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -548,5 +548,13 @@
"maybeYouWantTo":"Or maybe you would rather:",
"restoreFilters":"Restore filters from previous search",
"GoToFrontpage":"Go to the front page of DR-arkivet"
+ },
+ "calendar": {
+ "open":"Open calendar",
+ "close": "Close calendar",
+ "explanation": "Type a date in format DD-MM-YYYY or pick from the calendar.",
+ "select": "Select date",
+ "nextMonth": "Next month",
+ "prevMonth":"Previous month"
}
}
\ No newline at end of file
diff --git a/src/types/CalendarTypes.ts b/src/types/CalendarTypes.ts
new file mode 100644
index 00000000..b4a18d6a
--- /dev/null
+++ b/src/types/CalendarTypes.ts
@@ -0,0 +1,8 @@
+export interface CalendarDay {
+ date: Date;
+ label: number;
+ inMonth: boolean;
+ key: string;
+ disabled: boolean;
+ ariaLabel: string;
+}
diff --git a/src/utils/datepicker-utils.ts b/src/utils/datepicker-utils.ts
index aadc4b46..4fd117f5 100644
--- a/src/utils/datepicker-utils.ts
+++ b/src/utils/datepicker-utils.ts
@@ -1,11 +1,58 @@
import { endYear, startYear } from '@/components/common/timeSearch/TimeSearchInitValues';
import { Ref } from 'vue';
+const updateDate = (
+ timer: ReturnType | null,
+ isDateValid: Ref,
+ inputVar: Ref,
+ updateLink: () => void,
+) => {
+ if (timer) {
+ clearTimeout(timer);
+ }
+ if (inputVar.value === undefined || inputVar.value === null) {
+ return;
+ }
+ isDateValid.value = false;
+
+ const constructedDate =
+ inputVar.value.getDate() + '/' + Number(inputVar.value.getMonth() + 1) + '/' + inputVar.value.getFullYear();
+ const dateInput = constructedDate.replace(/[.-]/g, '/');
+ const splitDateInput = dateInput.split('/');
+ if (splitDateInput.length === 3) {
+ const [day, month, yearInitial] = splitDateInput.map(Number);
+ let year = yearInitial;
+ // Validate if day, month, and year are numbers
+ if (!isNaN(day) && !isNaN(month) && !isNaN(year)) {
+ // Months in JavaScript Date are 0-indexed, so subtract 1 from the month
+ if (year.toString().length === 2) {
+ if (year < Number(new Date().getFullYear().toString().slice(-2))) {
+ year = Number(`20${year}`);
+ } else {
+ year = Number(`19${year}`);
+ }
+ }
+ const setDate = new Date(year, month - 1, day);
+ // Ensure the date is valid
+ if (setDate.getDate() === day && setDate.getMonth() === month - 1 && setDate.getFullYear() === year) {
+ // Validate if the date is within the range
+ const minDate = new Date(startYear.value);
+ const maxDate = new Date(endYear.value);
+
+ if (setDate >= minDate && setDate <= maxDate) {
+ updateLink();
+ isDateValid.value = true;
+ }
+ }
+ }
+ }
+};
+
const updateSelectedDate = (
e: Event,
timer: ReturnType | null,
isDateValid: Ref,
- inputVar: Ref,
+ inputVar: Ref,
updateLink: () => void,
) => {
if (timer) {
@@ -54,4 +101,4 @@ const updateSelectedDate = (
}
};
-export { updateSelectedDate };
+export { updateSelectedDate, updateDate };