From 393580369b464126851d2931f98fcee3988b61e3 Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Mon, 20 May 2024 15:59:53 +0200 Subject: [PATCH 01/27] restructured files + first changes patch --- .../create}/body/CreateSubjectBody.vue | 4 +- .../create}/body/SubjectInstructorsCard.vue | 0 .../create}/body/UserSearchCard.vue | 2 +- .../create}/body/UserSearchList.vue | 0 .../header/CreateSubjectHeaderCard.vue | 0 .../header/CreateSubjectHeaderContainer.vue | 4 +- .../header/CreateSubjectHeaderImage.vue | 0 .../subject/modify/patch/PatchSubjectBody.vue | 11 + .../body/SubjectBody.vue | 4 +- .../body/groups/SubjectGroupsPage.vue | 0 .../body/projects/SubjectProjectPage.vue | 0 .../body/projects/SubjectProjectsPage.vue | 4 +- .../projects/list/SubjectProjectsList.vue | 2 +- .../body/projects/list/SubjectTab.vue | 0 .../buttons/RegisterLinkButton.vue | 0 .../header/SubjectHeaderCard.vue | 0 .../header/SubjectHeaderContainer.vue | 4 +- .../header/SubjectHeaderImage.vue | 0 .../body/SubjectCard.vue | 0 .../header/SubjectsHeaderCard.vue | 0 .../header/SubjectsHeaderContainer.vue | 4 +- .../header/SubjectsHeaderImage.vue | 0 frontend/src/router/index.ts | 5 + .../src/views/subject/CreateSubjectView.vue | 4 +- .../src/views/subject/PatchSubjectView.vue | 229 ++++++++++++++++++ frontend/src/views/subject/SubjectView.vue | 6 +- frontend/src/views/subject/SubjectsView.vue | 4 +- 27 files changed, 266 insertions(+), 21 deletions(-) rename frontend/src/components/subject/{createSubjectView => modify/create}/body/CreateSubjectBody.vue (80%) rename frontend/src/components/subject/{createSubjectView => modify/create}/body/SubjectInstructorsCard.vue (100%) rename frontend/src/components/subject/{createSubjectView => modify/create}/body/UserSearchCard.vue (91%) rename frontend/src/components/subject/{createSubjectView => modify/create}/body/UserSearchList.vue (100%) rename frontend/src/components/subject/{createSubjectView => modify/create}/header/CreateSubjectHeaderCard.vue (100%) rename frontend/src/components/subject/{createSubjectView => modify/create}/header/CreateSubjectHeaderContainer.vue (82%) rename frontend/src/components/subject/{createSubjectView => modify/create}/header/CreateSubjectHeaderImage.vue (100%) create mode 100644 frontend/src/components/subject/modify/patch/PatchSubjectBody.vue rename frontend/src/components/subject/{subjectview => subject}/body/SubjectBody.vue (86%) rename frontend/src/components/subject/{subjectview => subject}/body/groups/SubjectGroupsPage.vue (100%) rename frontend/src/components/subject/{subjectview => subject}/body/projects/SubjectProjectPage.vue (100%) rename frontend/src/components/subject/{subjectview => subject}/body/projects/SubjectProjectsPage.vue (92%) rename frontend/src/components/subject/{subjectview => subject}/body/projects/list/SubjectProjectsList.vue (97%) rename frontend/src/components/subject/{subjectview => subject}/body/projects/list/SubjectTab.vue (100%) rename frontend/src/components/subject/{subjectview => subject}/buttons/RegisterLinkButton.vue (100%) rename frontend/src/components/subject/{subjectview => subject}/header/SubjectHeaderCard.vue (100%) rename frontend/src/components/subject/{subjectview => subject}/header/SubjectHeaderContainer.vue (85%) rename frontend/src/components/subject/{subjectview => subject}/header/SubjectHeaderImage.vue (100%) rename frontend/src/components/subject/{subjectsview => subjects}/body/SubjectCard.vue (100%) rename frontend/src/components/subject/{subjectsview => subjects}/header/SubjectsHeaderCard.vue (100%) rename frontend/src/components/subject/{subjectsview => subjects}/header/SubjectsHeaderContainer.vue (82%) rename frontend/src/components/subject/{subjectsview => subjects}/header/SubjectsHeaderImage.vue (100%) create mode 100644 frontend/src/views/subject/PatchSubjectView.vue diff --git a/frontend/src/components/subject/createSubjectView/body/CreateSubjectBody.vue b/frontend/src/components/subject/modify/create/body/CreateSubjectBody.vue similarity index 80% rename from frontend/src/components/subject/createSubjectView/body/CreateSubjectBody.vue rename to frontend/src/components/subject/modify/create/body/CreateSubjectBody.vue index 16f3e330..550bb55a 100644 --- a/frontend/src/components/subject/createSubjectView/body/CreateSubjectBody.vue +++ b/frontend/src/components/subject/modify/create/body/CreateSubjectBody.vue @@ -17,9 +17,9 @@ + + + + diff --git a/frontend/src/components/subject/subjectview/body/SubjectBody.vue b/frontend/src/components/subject/subject/body/SubjectBody.vue similarity index 86% rename from frontend/src/components/subject/subjectview/body/SubjectBody.vue rename to frontend/src/components/subject/subject/body/SubjectBody.vue index bc04c9c6..cae152ea 100644 --- a/frontend/src/components/subject/subjectview/body/SubjectBody.vue +++ b/frontend/src/components/subject/subject/body/SubjectBody.vue @@ -23,8 +23,8 @@ + + diff --git a/frontend/src/views/subject/SubjectView.vue b/frontend/src/views/subject/SubjectView.vue index fb7cffeb..8355c40e 100644 --- a/frontend/src/views/subject/SubjectView.vue +++ b/frontend/src/views/subject/SubjectView.vue @@ -72,12 +72,12 @@ import { useSubjectStudentsQuery, } from "@/queries/Subject"; import BackgroundContainer from "@/components/BackgroundContainer.vue"; -import SubjectHeaderContainer from "@/components/subject/subjectview/header/SubjectHeaderContainer.vue"; -import SubjectBody from "@/components/subject/subjectview/body/SubjectBody.vue"; +import SubjectHeaderContainer from "@/components/subject/subject/header/SubjectHeaderContainer.vue"; +import SubjectBody from "@/components/subject/subject/body/SubjectBody.vue"; import { useCurrentUserQuery } from "@/queries/User"; import useIsTeacher from "@/composables/useIsTeacher"; import useIsAdmin from "@/composables/useIsAdmin"; -import RegisterLinkButton from "@/components/subject/subjectview/buttons/RegisterLinkButton.vue"; +import RegisterLinkButton from "@/components/subject/subject/buttons/RegisterLinkButton.vue"; const props = defineProps<{ subjectId: number; diff --git a/frontend/src/views/subject/SubjectsView.vue b/frontend/src/views/subject/SubjectsView.vue index e15e46ee..91aec9e2 100644 --- a/frontend/src/views/subject/SubjectsView.vue +++ b/frontend/src/views/subject/SubjectsView.vue @@ -52,8 +52,8 @@ From a1244c04d22faedf360ba53219d20d9fb43345a9 Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Tue, 21 May 2024 03:33:08 +0200 Subject: [PATCH 09/27] fixes to form validation --- .../src/views/subject/PatchSubjectView.vue | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/frontend/src/views/subject/PatchSubjectView.vue b/frontend/src/views/subject/PatchSubjectView.vue index 842b82bd..8b8cc53a 100644 --- a/frontend/src/views/subject/PatchSubjectView.vue +++ b/frontend/src/views/subject/PatchSubjectView.vue @@ -73,7 +73,7 @@ import { useCreateSubjectInstructorMutation, useCreateSubjectMutation, useSubjectInstructorsQuery, useSubjectProjectsQuery, - useSubjectQuery + useSubjectQuery, useUpdateSubjectMutation } from "@/queries/Subject"; import type SubjectForm from "@/models/Subject"; import type User from "@/models/User"; @@ -92,10 +92,11 @@ const snackbar = ref(false); const dialog = ref(false); const isFormError = ref(false); const subjectName = ref(null); -const activeAcademicYear = ref(null); +const activeAcademicYear = ref(null); const currentUserAsInstructor = ref(computed(() => isInstructor.value)); const addedInstructors = ref>(new Set()); const removedInstructors = ref>(new Set()); +const subjectChanged = ref(false); const { data: currentUser, @@ -138,7 +139,10 @@ const isInstructor = computed(() => { return shownInstructors.value.some((instructor) => instructor?.uid === currentUser.value?.uid); }); -const createSubjectInstructorMutation = useCreateSubjectInstructorMutation(subjectId); +const name = computed(() => subjectChanged.value ? subjectName.value : subject.value?.name); +const academicYear = computed(() => activeAcademicYear.value || subject.value?.academic_year); + +const {mutateAsync: updateSubject} = useUpdateSubjectMutation(); const router = useRouter(); @@ -178,11 +182,19 @@ const onCurrentUserAsInstructorChanged = (isInstructor: boolean) => { const onSubjectNameUpdated = (name: string) => { subjectName.value = name; + subjectChanged.value = true; isFormError.value = false; }; const validateSubjectName = () => { - return !(!subjectName.value || subjectName.value.trim().length < 3); + if (!subjectChanged.value) { + return true; + } else { + return name.value !== null && name.value.trim().length > 2; + } +}; +const validateSubjectAcademicYear = () => { + return academicYear.value !== null; }; const validateInstructors = () => { @@ -193,41 +205,42 @@ const validateInstructors = () => { }; async function handleSubmit() { - /* + if (!validateSubjectName()) { isFormError.value = true; return; } + if (!validateSubjectAcademicYear()) { + return; + } + if (!validateInstructors()) { snackbar.value = true; return; } - */ - - - const name = subjectName.value || subject.value?.name; const subjectData: SubjectForm = { - name: name.trim().charAt(0).toUpperCase() + name.trim().slice(1), - academic_year: activeAcademicYear.value || subject.value?.academic_year, + name: name.value.trim().charAt(0).toUpperCase() + name.value.trim().slice(1), + academic_year: academicYear.value }; console.log(subjectData) const instructorIds = shownInstructors.value.map((instructor) => instructor.uid); console.log(instructorIds) + /* try { - subjectId.value = await createSubjectMutation.mutateAsync(subjectData); - for (const instructor of instructorIds) { - await createSubjectInstructorMutation.mutateAsync(instructor); - } - - await router.push({name: "subject", params: {subjectId: subjectId.value}}); + await updateSubject({ + subjectId: subjectId.value, + name: subjectData.name, + academic_year: subjectData.academic_year, + }); } catch (error) { - console.error("Error during subject creation:", error); + console.error("Error during subject alteration:", error); } - */ + + */ } From 8d69a5b87d4920231f92577beb0980780e72363b Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Tue, 21 May 2024 04:16:14 +0200 Subject: [PATCH 10/27] adding and removing works --- .../src/views/subject/PatchSubjectView.vue | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/frontend/src/views/subject/PatchSubjectView.vue b/frontend/src/views/subject/PatchSubjectView.vue index 8b8cc53a..81b215a9 100644 --- a/frontend/src/views/subject/PatchSubjectView.vue +++ b/frontend/src/views/subject/PatchSubjectView.vue @@ -95,7 +95,7 @@ const subjectName = ref(null); const activeAcademicYear = ref(null); const currentUserAsInstructor = ref(computed(() => isInstructor.value)); const addedInstructors = ref>(new Set()); -const removedInstructors = ref>(new Set()); +const removedInstructors = ref>(new Set()); const subjectChanged = ref(false); const { @@ -139,6 +139,10 @@ const isInstructor = computed(() => { return shownInstructors.value.some((instructor) => instructor?.uid === currentUser.value?.uid); }); +const isCurrentInstructor = (user: User) => { + return new Set([...(instructors.value || [])].map((instructor) => instructor.uid)).has(user.uid) +} + const name = computed(() => subjectChanged.value ? subjectName.value : subject.value?.name); const academicYear = computed(() => activeAcademicYear.value || subject.value?.academic_year); @@ -146,9 +150,10 @@ const {mutateAsync: updateSubject} = useUpdateSubjectMutation(); const router = useRouter(); + const shownInstructors = computed(() => { - return Array.from(new Set([...(instructors.value || []), ...addedInstructors.value].filter((instructor) => { - return !removedInstructors.value.has(instructor); + return Array.from(new Set([...(instructors.value || []), ...addedInstructors.value].filter((instructor: User) => { + return !removedInstructors.value.has(instructor.uid); }))).sort((a, b) => { if (a?.is_teacher && !b?.is_teacher) { return -1; @@ -160,23 +165,27 @@ const shownInstructors = computed(() => { }) }); -const addInstructor = (user: User) => { - addedInstructors.value.add(user); - removedInstructors.value.delete(user); +const addInstructor = (instructor: User) => { + if (isCurrentInstructor(instructor)) { + removedInstructors.value.delete(instructor.uid); + } else { + addedInstructors.value.add(instructor); + } + }; const removeInstructor = (instructor: User) => { - removedInstructors.value.add(instructor); + if (isCurrentInstructor(instructor)) { + removedInstructors.value.add(instructor.uid); + } addedInstructors.value.delete(instructor); }; -const onCurrentUserAsInstructorChanged = (isInstructor: boolean) => { - if (isInstructor) { - addedInstructors.value.add(currentUser.value); - removedInstructors.value.delete(currentUser.value); +const onCurrentUserAsInstructorChanged = (isCurrentUserInstructor: boolean) => { + if (isCurrentUserInstructor) { + removedInstructors.value.delete(currentUser.value.uid); } else { - addedInstructors.value.delete(currentUser.value); - removedInstructors.value.add(currentUser.value); + removedInstructors.value.add(currentUser.value.uid); } }; @@ -229,6 +238,9 @@ async function handleSubmit() { const instructorIds = shownInstructors.value.map((instructor) => instructor.uid); console.log(instructorIds) + + + /* try { await updateSubject({ From aab3e9ec1a40e54fbab98deae6b8bc0777a8a2b3 Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Tue, 21 May 2024 04:27:34 +0200 Subject: [PATCH 11/27] skeleton for query done --- .../src/views/subject/PatchSubjectView.vue | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/frontend/src/views/subject/PatchSubjectView.vue b/frontend/src/views/subject/PatchSubjectView.vue index 81b215a9..aaf657b5 100644 --- a/frontend/src/views/subject/PatchSubjectView.vue +++ b/frontend/src/views/subject/PatchSubjectView.vue @@ -95,7 +95,7 @@ const subjectName = ref(null); const activeAcademicYear = ref(null); const currentUserAsInstructor = ref(computed(() => isInstructor.value)); const addedInstructors = ref>(new Set()); -const removedInstructors = ref>(new Set()); +const removedInstructorUIDs = ref>(new Set()); const subjectChanged = ref(false); const { @@ -153,7 +153,7 @@ const router = useRouter(); const shownInstructors = computed(() => { return Array.from(new Set([...(instructors.value || []), ...addedInstructors.value].filter((instructor: User) => { - return !removedInstructors.value.has(instructor.uid); + return !removedInstructorUIDs.value.has(instructor.uid); }))).sort((a, b) => { if (a?.is_teacher && !b?.is_teacher) { return -1; @@ -167,7 +167,7 @@ const shownInstructors = computed(() => { const addInstructor = (instructor: User) => { if (isCurrentInstructor(instructor)) { - removedInstructors.value.delete(instructor.uid); + removedInstructorUIDs.value.delete(instructor.uid); } else { addedInstructors.value.add(instructor); } @@ -176,16 +176,16 @@ const addInstructor = (instructor: User) => { const removeInstructor = (instructor: User) => { if (isCurrentInstructor(instructor)) { - removedInstructors.value.add(instructor.uid); + removedInstructorUIDs.value.add(instructor.uid); } addedInstructors.value.delete(instructor); }; const onCurrentUserAsInstructorChanged = (isCurrentUserInstructor: boolean) => { if (isCurrentUserInstructor) { - removedInstructors.value.delete(currentUser.value.uid); + removedInstructorUIDs.value.delete(currentUser.value.uid); } else { - removedInstructors.value.add(currentUser.value.uid); + removedInstructorUIDs.value.add(currentUser.value.uid); } }; @@ -234,12 +234,10 @@ async function handleSubmit() { academic_year: academicYear.value }; - console.log(subjectData) - const instructorIds = shownInstructors.value.map((instructor) => instructor.uid); - console.log(instructorIds) - - + const addedInstructorUIDs = Array.from(addedInstructors.value).map((instructor) => instructor.uid); + console.log(addedInstructorUIDs) + console.log(removedInstructorUIDs.value) /* try { @@ -248,6 +246,18 @@ async function handleSubmit() { name: subjectData.name, academic_year: subjectData.academic_year, }); + + for (const instructor of removedInstructorUIDs) { + await removeSubjectInstructorMutation.mutateAsync(instructor); + } + + for (const instructor of addedInstructorUIDs) { + await createSubjectInstructorMutation.mutateAsync(instructor); + } + + await router.push({name: 'subject', params: {subjectId: subjectId.value}}); + + } catch (error) { console.error("Error during subject alteration:", error); } From 32541d0af5571a3894d5299dd96c9e6b1278caf5 Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Tue, 21 May 2024 04:40:37 +0200 Subject: [PATCH 12/27] small academic year fix --- .../src/views/subject/PatchSubjectView.vue | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/frontend/src/views/subject/PatchSubjectView.vue b/frontend/src/views/subject/PatchSubjectView.vue index aaf657b5..2d4a92af 100644 --- a/frontend/src/views/subject/PatchSubjectView.vue +++ b/frontend/src/views/subject/PatchSubjectView.vue @@ -68,10 +68,9 @@ - - - - diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 32f4a8d8..331cb1a8 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -84,12 +84,12 @@ const router = createRouter({ { path: "/subjects/create", name: "create-subject", - component: () => import("../views/subject/CreateSubjectView.vue"), + component: () => import("../views/subject/modify/CreateSubjectView.vue"), }, { path: "/subjects/:subjectId(\\d+)/edit", name: "edit-subject", - component: () => import("../views/subject/PatchSubjectView.vue"), + component: () => import("../views/subject/modify/PatchSubjectView.vue"), props: (route) => ({ subjectId: Number(route.params.subjectId) }), }, { diff --git a/frontend/src/views/subject/CreateSubjectView.vue b/frontend/src/views/subject/modify/CreateSubjectView.vue similarity index 94% rename from frontend/src/views/subject/CreateSubjectView.vue rename to frontend/src/views/subject/modify/CreateSubjectView.vue index 8d9681bc..f84c52f0 100644 --- a/frontend/src/views/subject/CreateSubjectView.vue +++ b/frontend/src/views/subject/modify/CreateSubjectView.vue @@ -32,7 +32,7 @@
- - - + - +
@@ -76,8 +76,8 @@ import { useCreateSubjectInstructorMutation, useCreateSubjectMutation } from "@/ import type SubjectForm from "@/models/Subject"; import type User from "@/models/User"; import { useCurrentUserQuery } from "@/queries/User"; -import CreateSubjectHeaderContainer from "@/components/subject/modify/create/header/CreateSubjectHeaderContainer.vue"; -import CreateSubjectBody from "@/components/subject/modify/create/body/CreateSubjectBody.vue"; +import ModifySubjectHeaderContainer from "@/components/subject/modify/header/ModifySubjectHeaderContainer.vue"; +import ModifySubjectBody from "@/components/subject/modify/body/ModifySubjectBody.vue"; import { useRouter } from "vue-router"; const snackbar = ref(false); diff --git a/frontend/src/views/subject/PatchSubjectView.vue b/frontend/src/views/subject/modify/PatchSubjectView.vue similarity index 95% rename from frontend/src/views/subject/PatchSubjectView.vue rename to frontend/src/views/subject/modify/PatchSubjectView.vue index 5c1bed09..26349255 100644 --- a/frontend/src/views/subject/PatchSubjectView.vue +++ b/frontend/src/views/subject/modify/PatchSubjectView.vue @@ -32,7 +32,7 @@
- - - + - +
@@ -79,8 +79,8 @@ import type SubjectForm from "@/models/Subject"; import type User from "@/models/User"; import {useCurrentUserQuery} from "@/queries/User"; import {useRouter} from "vue-router"; -import CreateSubjectHeaderContainer from "@/components/subject/modify/create/header/CreateSubjectHeaderContainer.vue"; -import CreateSubjectBody from "@/components/subject/modify/create/body/CreateSubjectBody.vue"; +import ModifySubjectHeaderContainer from "@/components/subject/modify/header/ModifySubjectHeaderContainer.vue"; +import ModifySubjectBody from "@/components/subject/modify/body/ModifySubjectBody.vue"; const props = defineProps<{ subjectId: number; From e6f6f4918f33c24bbd56f438953c51cdb83d6489 Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Tue, 21 May 2024 17:24:29 +0200 Subject: [PATCH 17/27] installed dialog component --- .../modify/extra/ModifySubjectDialog.vue | 45 +++++++++++++++++++ .../modify/extra/ModifySubjectSnackBar.vue | 11 +++++ .../subject/modify/CreateSubjectView.vue | 35 ++++++--------- 3 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 frontend/src/components/subject/modify/extra/ModifySubjectDialog.vue create mode 100644 frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue diff --git a/frontend/src/components/subject/modify/extra/ModifySubjectDialog.vue b/frontend/src/components/subject/modify/extra/ModifySubjectDialog.vue new file mode 100644 index 00000000..a514c71c --- /dev/null +++ b/frontend/src/components/subject/modify/extra/ModifySubjectDialog.vue @@ -0,0 +1,45 @@ + + + + + + + diff --git a/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue b/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue new file mode 100644 index 00000000..85af7153 --- /dev/null +++ b/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/frontend/src/views/subject/modify/CreateSubjectView.vue b/frontend/src/views/subject/modify/CreateSubjectView.vue index f84c52f0..fb33846f 100644 --- a/frontend/src/views/subject/modify/CreateSubjectView.vue +++ b/frontend/src/views/subject/modify/CreateSubjectView.vue @@ -15,22 +15,12 @@ {{ $t("create_subject.error_snackbar") }} - - - - {{ $t("create_subject.cancel_dialog") }} - - - - - {{ $t("default.no_capital") }} - - - {{ $t("default.yes_capital") }} - - - - + +
- - - - diff --git a/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue b/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue deleted file mode 100644 index 85af7153..00000000 --- a/frontend/src/components/subject/modify/extra/ModifySubjectSnackBar.vue +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index 5dda2a65..2de4055e 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -164,6 +164,11 @@ export default { email_invalid: "Provided email is invalid", }, + patch_subject: { + cancel_dialog: "Cancel editing subject?", + edit_subject: "Edit subject", + }, + group: { not_found: "Group not found", not_found2: "No groups found", diff --git a/frontend/src/i18n/locales/nl.ts b/frontend/src/i18n/locales/nl.ts index 7b1e9a72..036b03de 100644 --- a/frontend/src/i18n/locales/nl.ts +++ b/frontend/src/i18n/locales/nl.ts @@ -165,6 +165,11 @@ export default { email_invalid: "Ingevoerde email is ongeldig", }, + patch_subject: { + cancel_dialog: "Wijzigingen annuleren?", + edit_subject: "Wijzig vak", + }, + group: { not_found: "Groep niet gevonden", not_found2: "Geen groepen teruggevonden", diff --git a/frontend/src/views/subject/modify/CreateSubjectView.vue b/frontend/src/views/subject/modify/CreateSubjectView.vue index fb33846f..f84c52f0 100644 --- a/frontend/src/views/subject/modify/CreateSubjectView.vue +++ b/frontend/src/views/subject/modify/CreateSubjectView.vue @@ -15,12 +15,22 @@ {{ $t("create_subject.error_snackbar") }} - - + + + + {{ $t("create_subject.cancel_dialog") }} + + + + + {{ $t("default.no_capital") }} + + + {{ $t("default.yes_capital") }} + + + +
From 7f01ec1c98e8ce867d1a4459a9034d3e63e47fdb Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Wed, 22 May 2024 21:57:36 +0200 Subject: [PATCH 21/27] fixes to broken patch page --- .../views/subject/modify/PatchSubjectView.vue | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/frontend/src/views/subject/modify/PatchSubjectView.vue b/frontend/src/views/subject/modify/PatchSubjectView.vue index 5a537e82..592ab15a 100644 --- a/frontend/src/views/subject/modify/PatchSubjectView.vue +++ b/frontend/src/views/subject/modify/PatchSubjectView.vue @@ -56,8 +56,8 @@ > @@ -68,7 +68,7 @@ {{ $t("default.cancel") }} - + {{ $t("default.confirm") }}
@@ -86,7 +86,7 @@ import { useSubjectQuery, useUpdateSubjectMutation, } from "@/queries/Subject"; -import type { SubjectForm } from "@/models/Subject"; +import type SubjectForm from "@/models/Subject"; import type User from "@/models/User"; import { useCurrentUserQuery } from "@/queries/User"; import { useRouter } from "vue-router"; @@ -108,9 +108,11 @@ const subjectMail = ref(""); const activeAcademicYear = ref(null); const currentUserAsInstructor = ref(computed(() => isInstructor.value)); const addedInstructors = ref>(new Set()); -const removedInstructors = ref>(new Set()); +const removedInstructorUIDs = ref>(new Set()); const subjectNameChanged = ref(false); const subjectMailChanged = ref(false); +const pageUpdating = ref(false); +const tempInstructors = ref([]); const { data: currentUser, @@ -150,9 +152,13 @@ const isCurrentInstructor = (user: User) => { ); }; -const name = computed(() => (subjectNameChanged.value ? subjectName.value : subject.value!.name)); +const name = computed(() => + subjectNameChanged.value ? subjectName.value || "" : subject.value!.name +); const academicYear = computed(() => activeAcademicYear.value || subject.value!.academic_year); -const mail = computed(() => (subjectMailChanged.value ? subjectMail.value : subject.value!.email)); +const mail = computed(() => + subjectMailChanged.value ? subjectMail.value || "" : subject.value!.email || "" +); const router = useRouter(); @@ -160,7 +166,7 @@ const shownInstructors = computed(() => { return Array.from( new Set( [...(instructors.value || []), ...addedInstructors.value].filter((instructor: User) => { - return !removedInstructors.value.has(instructor); + return !removedInstructorUIDs.value.has(instructor.uid); }) ) ).sort((a, b) => { @@ -174,25 +180,30 @@ const shownInstructors = computed(() => { }); }); +const getInstructor = (instructorUID: string) => { + return [...(instructors.value || [])].find((i) => i.uid === instructorUID); +}; + const addInstructor = (instructor: User) => { if (isCurrentInstructor(instructor)) { - removedInstructors.value.delete(instructor); + removedInstructorUIDs.value.delete(instructor.uid); + } else { + addedInstructors.value.add(instructor); } - addedInstructors.value.add(instructor); }; const removeInstructor = (instructor: User) => { if (isCurrentInstructor(instructor)) { - removedInstructors.value.add(instructor); + removedInstructorUIDs.value.add(instructor.uid); } addedInstructors.value.delete(instructor); }; const onCurrentUserAsInstructorChanged = (isCurrentUserInstructor: boolean) => { if (isCurrentUserInstructor) { - removedInstructors.value.delete(currentUser.value!); + removedInstructorUIDs.value.delete(currentUser.value.uid); } else { - removedInstructors.value.add(currentUser.value!); + removedInstructorUIDs.value.add(currentUser.value.uid); } }; @@ -212,14 +223,14 @@ const validateSubjectName = () => { if (!subjectNameChanged.value) { return true; } - return name.value !== null && name.value.trim().length > 2; + return name.value.trim() !== "" && name.value.trim().length > 2; }; const validateSubjectMail = () => { if (!subjectMailChanged.value) { return true; } - return !subjectMail.value || /.+@.+\..+/.test(subjectMail.value); + return subjectMail.value == "" || /.+@.+\..+/.test(subjectMail.value.trim()); }; const validateInstructors = () => { @@ -247,18 +258,23 @@ async function handleSubmit() { const subjectData: SubjectForm = { name: name.value.trim().charAt(0).toUpperCase() + name.value.trim().slice(1), - email: mail.value, + email: mail.value.trim(), academic_year: academicYear.value, }; try { await updateSubject({ subject: subjectData, subjectId: subjectId.value }); - for (let instructor of removedInstructors.value) { - await deleteSubjectInstructor({ - subjectId: subjectId.value, - user: instructor, - }); + pageUpdating.value = true; + tempInstructors.value = [...shownInstructors.value]; + + for (let instructorUID of removedInstructorUIDs.value) { + const instructor = getInstructor(instructorUID); + if (instructor) + await deleteSubjectInstructor({ + subjectId: subjectId.value, + user: instructor, + }); } for (let instructor of addedInstructors.value) { From badcd92886719b5ab6680436203f76cd7f05295b Mon Sep 17 00:00:00 2001 From: mattiscauwel Date: Wed, 22 May 2024 23:48:54 +0200 Subject: [PATCH 22/27] fix broken merge conflicts --- .../subject/subject/header/SubjectHeaderContainer.vue | 4 +++- .../subject/subjects/header/SubjectsHeaderContainer.vue | 2 +- frontend/src/views/subject/SubjectView.vue | 7 ++++--- frontend/src/views/subject/SubjectsView.vue | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/subject/subject/header/SubjectHeaderContainer.vue b/frontend/src/components/subject/subject/header/SubjectHeaderContainer.vue index bb1e50ce..cf4fe3d5 100644 --- a/frontend/src/components/subject/subject/header/SubjectHeaderContainer.vue +++ b/frontend/src/components/subject/subject/header/SubjectHeaderContainer.vue @@ -1,6 +1,7 @@