From f67e3f5a1a54bba4bb556f8cd8fd8f64e1e5a7e1 Mon Sep 17 00:00:00 2001 From: Joyelle Ndagijimana Date: Sat, 17 May 2025 18:50:18 +0200 Subject: [PATCH] feat: deadline is editeerbaar --- .../assignments/DeadlineSelector.vue | 8 +- frontend/src/i18n/locale/en.json | 8 +- frontend/src/utils/assignment-rules.ts | 24 +- .../views/assignments/CreateAssignment.vue | 251 +++++++++--------- .../views/assignments/TeacherAssignment.vue | 17 +- 5 files changed, 163 insertions(+), 145 deletions(-) diff --git a/frontend/src/components/assignments/DeadlineSelector.vue b/frontend/src/components/assignments/DeadlineSelector.vue index 304c544c..13ac96ca 100644 --- a/frontend/src/components/assignments/DeadlineSelector.vue +++ b/frontend/src/components/assignments/DeadlineSelector.vue @@ -2,15 +2,21 @@ import { ref, watch } from "vue"; import { deadlineRules } from "@/utils/assignment-rules.ts"; - const emit = defineEmits<(e: "update:deadline", value: Date) => void>(); + const emit = defineEmits<(e: "update:deadline", value: Date | null) => void>(); + const props = defineProps<{ deadline: Date | null }>(); const datetime = ref(""); + datetime.value = props.deadline ? new Date(props.deadline).toISOString().slice(0, 16) : "" + + // Watch the datetime value and emit the update watch(datetime, (val) => { const newDate = new Date(val); if (!isNaN(newDate.getTime())) { emit("update:deadline", newDate); + } else { + emit("update:deadline", null); } }); diff --git a/frontend/src/i18n/locale/en.json b/frontend/src/i18n/locale/en.json index a9307b6e..bf74fc32 100644 --- a/frontend/src/i18n/locale/en.json +++ b/frontend/src/i18n/locale/en.json @@ -166,5 +166,11 @@ "pathContainsNonExistingLearningObjects": "At least one of the learning objects referenced in this path does not exist.", "targetAgesMandatory": "Target ages must be specified.", "hintRemoveIfUnconditionalTransition": "(remove this if this should be an unconditional transition)", - "hintKeywordsSeparatedBySpaces": "Keywords separated by spaces" + "hintKeywordsSeparatedBySpaces": "Keywords separated by spaces", + "title-required": "Title cannot be empty.", + "class-required": "You must select at least one class.", + "deadline-invalid": "Invalid date or time.", + "deadline-past": "The deadline must be in the future.", + "lp-required": "You must select a learning path.", + "lp-invalied": "The selected learning path doesn't exist." } diff --git a/frontend/src/utils/assignment-rules.ts b/frontend/src/utils/assignment-rules.ts index 51380960..4fdde0d7 100644 --- a/frontend/src/utils/assignment-rules.ts +++ b/frontend/src/utils/assignment-rules.ts @@ -1,3 +1,7 @@ +import {useI18n} from "vue-i18n"; + +const { t } = useI18n(); + /** * Validation rule for the assignment title. * @@ -8,7 +12,7 @@ export const assignmentTitleRules = [ if (value?.length >= 1) { return true; } // Title must not be empty - return "Title cannot be empty."; + return t("title-required"); }, ]; @@ -23,7 +27,7 @@ export const classRules = [ if (value) { return true; } - return "You must select at least one class."; + return t("class-required"); }, ]; @@ -34,30 +38,18 @@ export const classRules = [ */ export const deadlineRules = [ (value: string): string | boolean => { - if (!value) { - return "You must set a deadline."; - } const selectedDateTime = new Date(value); const now = new Date(); if (isNaN(selectedDateTime.getTime())) { - return "Invalid date or time."; + return t("deadline-invalid"); } if (selectedDateTime <= now) { - return "The deadline must be in the future."; + return t("deadline-past"); } return true; }, ]; - -export const descriptionRules = [ - (value: string): string | boolean => { - if (!value || value.trim() === "") { - return "Description cannot be empty."; - } - return true; - }, -]; diff --git a/frontend/src/views/assignments/CreateAssignment.vue b/frontend/src/views/assignments/CreateAssignment.vue index 0e7f7124..ef07c443 100644 --- a/frontend/src/views/assignments/CreateAssignment.vue +++ b/frontend/src/views/assignments/CreateAssignment.vue @@ -1,91 +1,101 @@