From b3ca8b00a62dfba0f6dfa78f262786eaf037b13a Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Mon, 23 Dec 2024 02:31:53 +0100 Subject: [PATCH] chore: disable mark as complete if all exercises are not complete #513 --- .../Lesson/Exercise/ViewMode.svelte | 27 +++++----- .../src/lib/utils/services/courses/index.ts | 12 +++++ .../src/lib/utils/translations/de.json | 3 +- .../src/lib/utils/translations/en.json | 3 +- .../src/lib/utils/translations/es.json | 3 +- .../src/lib/utils/translations/fr.json | 3 +- .../src/lib/utils/translations/hi.json | 3 +- .../src/lib/utils/translations/pt.json | 3 +- .../src/lib/utils/translations/ru.json | 3 +- .../src/lib/utils/translations/vi.json | 3 +- .../lessons/[...lessonParams]/+page.svelte | 47 +++++++++++++----- ...241223012709_validate_mark_as_complete.sql | Bin 0 -> 1050 bytes 12 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 supabase/migrations/20241223012709_validate_mark_as_complete.sql diff --git a/apps/dashboard/src/lib/components/Course/components/Lesson/Exercise/ViewMode.svelte b/apps/dashboard/src/lib/components/Course/components/Lesson/Exercise/ViewMode.svelte index a8565329..de02e73a 100644 --- a/apps/dashboard/src/lib/components/Course/components/Lesson/Exercise/ViewMode.svelte +++ b/apps/dashboard/src/lib/components/Course/components/Lesson/Exercise/ViewMode.svelte @@ -128,6 +128,7 @@ $course.id, getGroupMemberId($group.people, $profile.id) ); + if (response) { submissionResponse = response; } @@ -263,8 +264,8 @@ {:else if !$questionnaire.questions.length} Exercise svg -

No question added for this exercise

-

+

No question added for this exercise

+

Click the Edit button to add. @@ -276,25 +277,25 @@

{$questionnaire.title}

-

+

{$questionnaire.questions.length} questions

| -

+

{getTotalPossibleGrade($questionnaire.questions)} points.

| -

All required

+

All required

{#if $questionnaire.due_by} | -

+

Due by: {new Date($questionnaire.due_by).toLocaleString()}

{/if}
-
+
{@html $questionnaire.description || 'No desription'}
@@ -309,26 +310,26 @@ {:else if $questionnaireMetaData.isFinished} {#if !isLoadingAutoSavedData}
-
+

{$questionnaire.title}

{#if STATUS.GRADED === $questionnaireMetaData.status} {$t('course.navItem.lessons.exercises.all_exercises.view_mode.graded')} {:else if $course.type === COURSE_TYPE.SELF_PACED} {$t('course.navItem.lessons.exercises.all_exercises.view_mode.submitted')} {:else} {$t('course.navItem.lessons.exercises.all_exercises.view_mode.pending')} @@ -337,7 +338,7 @@
{#if STATUS.GRADED === $questionnaireMetaData.status && $course.type !== COURSE_TYPE.SELF_PACED} {$questionnaireMetaData.finalTotalGrade}/{$questionnaireMetaData.totalPossibleGrade} @@ -346,7 +347,7 @@
{#if $questionnaireMetaData.status === STATUS.GRADED && $questionnaireMetaData.comment && $course.type !== COURSE_TYPE.SELF_PACED} -
+
{$questionnaireMetaData.comment}
{/if} diff --git a/apps/dashboard/src/lib/utils/services/courses/index.ts b/apps/dashboard/src/lib/utils/services/courses/index.ts index ceb8b5a0..7a796c54 100644 --- a/apps/dashboard/src/lib/utils/services/courses/index.ts +++ b/apps/dashboard/src/lib/utils/services/courses/index.ts @@ -61,6 +61,18 @@ export async function fetchProfileCourseProgress( return { data, error }; } +export async function checkExercisesComplete( + lessonId: Lesson['id'], + groupMemberId: Groupmember['id'] +) { + const { data, error } = await supabase.rpc('check_if_student_completed_exercises', { + lesson_id_arg: lessonId, + groupmember_id_arg: groupMemberId + }); + + return { data, error }; +} + const SLUG_QUERY = ` id, title, diff --git a/apps/dashboard/src/lib/utils/translations/de.json b/apps/dashboard/src/lib/utils/translations/de.json index 21ac2160..44463d0b 100644 --- a/apps/dashboard/src/lib/utils/translations/de.json +++ b/apps/dashboard/src/lib/utils/translations/de.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Etwas stimmt nicht. Bitte versuchen Sie es später" + "try_later": "Etwas stimmt nicht. Bitte versuchen Sie es später", + "exercise_not_complete": "Schließen Sie alle Übungen ab, um sie als abgeschlossen zu markieren" }, "success": { "complete_marked": "Als abgeschlossen markiert", diff --git a/apps/dashboard/src/lib/utils/translations/en.json b/apps/dashboard/src/lib/utils/translations/en.json index e38ffbd1..69085dcc 100644 --- a/apps/dashboard/src/lib/utils/translations/en.json +++ b/apps/dashboard/src/lib/utils/translations/en.json @@ -1337,7 +1337,8 @@ "version_restored": "Version restored sucessfully" }, "error": { - "try_later": "Something's not right - Please try later" + "try_later": "Something's not right - Please try later", + "exercise_not_complete": "Complete all exercises to mark as complete" } }, diff --git a/apps/dashboard/src/lib/utils/translations/es.json b/apps/dashboard/src/lib/utils/translations/es.json index fe85dd59..2db17866 100644 --- a/apps/dashboard/src/lib/utils/translations/es.json +++ b/apps/dashboard/src/lib/utils/translations/es.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Algo no está bien. Inténtelo más tarde." + "try_later": "Algo no está bien. Inténtelo más tarde.", + "exercise_not_complete": "Completa todos los ejercicios para marcarlos como completos." }, "success": { "complete_marked": "Marcado como completo", diff --git a/apps/dashboard/src/lib/utils/translations/fr.json b/apps/dashboard/src/lib/utils/translations/fr.json index 97bf8dda..1911f4a7 100644 --- a/apps/dashboard/src/lib/utils/translations/fr.json +++ b/apps/dashboard/src/lib/utils/translations/fr.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Quelque chose ne va pas – Veuillez réessayer plus tard" + "try_later": "Quelque chose ne va pas – Veuillez réessayer plus tard", + "exercise_not_complete": "Terminez tous les exercices pour les marquer comme terminés" }, "success": { "complete_marked": "Marqué comme terminé", diff --git a/apps/dashboard/src/lib/utils/translations/hi.json b/apps/dashboard/src/lib/utils/translations/hi.json index deee37a1..0ff209f3 100644 --- a/apps/dashboard/src/lib/utils/translations/hi.json +++ b/apps/dashboard/src/lib/utils/translations/hi.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "कुछ ठीक नहीं है - कृपया बाद में प्रयास करें" + "try_later": "कुछ ठीक नहीं है - कृपया बाद में प्रयास करें", + "exercise_not_complete": "पूर्ण के रूप में चिह्नित करने के लिए सभी अभ्यास पूर्ण करें" }, "success": { "complete_marked": "पूर्ण के रूप में चिह्नित", diff --git a/apps/dashboard/src/lib/utils/translations/pt.json b/apps/dashboard/src/lib/utils/translations/pt.json index 4a1269c6..786e9675 100644 --- a/apps/dashboard/src/lib/utils/translations/pt.json +++ b/apps/dashboard/src/lib/utils/translations/pt.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Algo não está certo - tente mais tarde" + "try_later": "Algo não está certo - tente mais tarde", + "exercise_not_complete": "Conclua todos os exercícios para marcá-los como concluídos" }, "success": { "complete_marked": "Marcado como concluído", diff --git a/apps/dashboard/src/lib/utils/translations/ru.json b/apps/dashboard/src/lib/utils/translations/ru.json index 1218b008..af5094fd 100644 --- a/apps/dashboard/src/lib/utils/translations/ru.json +++ b/apps/dashboard/src/lib/utils/translations/ru.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Что-то не так. Повторите попытку позже." + "try_later": "Что-то не так. Повторите попытку позже.", + "exercise_not_complete": "Выполните все упражнения, чтобы отметить их как выполненные." }, "success": { "complete_marked": "Помечено как завершенное", diff --git a/apps/dashboard/src/lib/utils/translations/vi.json b/apps/dashboard/src/lib/utils/translations/vi.json index 4652311f..7b36c1ee 100644 --- a/apps/dashboard/src/lib/utils/translations/vi.json +++ b/apps/dashboard/src/lib/utils/translations/vi.json @@ -43,7 +43,8 @@ }, "lessons": { "error": { - "try_later": "Đã xảy ra sự cố - Vui lòng thử lại sau" + "try_later": "Đã xảy ra sự cố - Vui lòng thử lại sau", + "exercise_not_complete": "Hoàn thành tất cả các bài tập để đánh dấu là hoàn thành" }, "success": { "complete_marked": "Được đánh dấu là hoàn thành", diff --git a/apps/dashboard/src/routes/courses/[id]/lessons/[...lessonParams]/+page.svelte b/apps/dashboard/src/routes/courses/[id]/lessons/[...lessonParams]/+page.svelte index 993c8a1b..fc7614ef 100644 --- a/apps/dashboard/src/routes/courses/[id]/lessons/[...lessonParams]/+page.svelte +++ b/apps/dashboard/src/routes/courses/[id]/lessons/[...lessonParams]/+page.svelte @@ -3,7 +3,11 @@ import { page } from '$app/stores'; import CourseContainer from '$lib/components/CourseContainer/index.svelte'; import { env } from '$env/dynamic/public'; - import { fetchLesson, updateLessonCompletion } from '$lib/utils/services/courses'; + import { + fetchLesson, + updateLessonCompletion, + checkExercisesComplete + } from '$lib/utils/services/courses'; import CheckmarkOutlineIcon from 'carbon-icons-svelte/lib/CheckmarkOutline.svelte'; import CheckmarkFilledIcon from 'carbon-icons-svelte/lib/CheckmarkFilled.svelte'; import ListChecked from 'carbon-icons-svelte/lib/ListChecked.svelte'; @@ -21,13 +25,14 @@ import Exercises from '$lib/components/Course/components/Lesson/Exercises/index.svelte'; import LessonVersionHistory from '$lib/components/Course/components/Lesson/LessonVersionHistory.svelte'; import MODES from '$lib/utils/constants/mode'; - import { course } from '$lib/components/Course/store'; + import { group, course } from '$lib/components/Course/store'; import Download from 'carbon-icons-svelte/lib/Download.svelte'; import ResultOld from 'carbon-icons-svelte/lib/ResultOld.svelte'; import OverflowMenuVertical from 'carbon-icons-svelte/lib/OverflowMenuVertical.svelte'; import { apps } from '$lib/components/Apps/store'; import APPS_CONSTANTS from '$lib/components/Apps/constants'; import IconButton from '$lib/components/IconButton/index.svelte'; + import { getGroupMemberId } from '$lib/components/Course/function'; import { lesson, lessons, @@ -86,6 +91,22 @@ } async function markLessonComplete(lessonId: string) { + const groupMemberId = getGroupMemberId($group.people, $profile.id); + const { data: areExercisesComplete, error } = await checkExercisesComplete( + lessonId, + groupMemberId + ); + + if (error) { + snackbar.error('snackbar.lessons.error.try_later'); + return; + } + + if (!areExercisesComplete) { + snackbar.error('snackbar.lessons.error.exercise_not_complete'); + return; + } + isMarkingComplete = true; let newCompletion: LessonCompletion = { @@ -351,9 +372,9 @@
{ @@ -413,14 +434,14 @@ {/if} -
+
{#if data.isMaterialsTabActive} {:else} {/if}