diff --git a/client/src/services/selfEvaluationFeedback.ts b/client/src/services/selfEvaluationFeedback.ts index 784beb63..084d7824 100644 --- a/client/src/services/selfEvaluationFeedback.ts +++ b/client/src/services/selfEvaluationFeedback.ts @@ -2,6 +2,7 @@ import { useCSRFFetch } from "@/fetchHelpers"; import type { User } from "@/types"; import { toValue } from "@vueuse/core"; import { t } from "i18next"; +import log from "loglevel"; import type { Ref } from "vue"; import { computed, onMounted, ref } from "vue"; @@ -24,6 +25,42 @@ export interface Criterion { feedback_assessment: "FAIL" | "SUCCESS" | "UNKNOWN"; } +interface FeedbackSummaryCounts { + pass: number; + fail: number; + unknown: number; +} + +export interface FeedbackSummaryAggregates { + // totals across all learning units in the course session + self_assessment_counts: FeedbackSummaryCounts; + feedback_assessment_counts: FeedbackSummaryCounts; +} + +interface FeedbackAssessmentSummary { + counts: FeedbackSummaryCounts; + submitted_by_provider: boolean; + provider_user: User; +} + +interface SelfAssessmentSummary { + counts: FeedbackSummaryCounts; +} + +export interface LearningUnitSummary { + id: string; + title: string; + circle_id: string; + circle_title: string; + feedback_assessment?: FeedbackAssessmentSummary; + self_assessment: SelfAssessmentSummary; +} + +interface Circle { + id: number; + title: string; +} + /** To keep the backend permissions model simple, we have two endpoints: * 1. /requester/: for the user who requested the feedback * 2. /provider/: for the user who provides the feedback @@ -47,7 +84,7 @@ export function useSelfEvaluationFeedback( error.value = undefined; loading.value = true; - console.log("Fetching feedback for learning unit", learningUnitId); + log.info("Fetching feedback for learning unit", learningUnitId); const { data, statusCode, error: _error } = await useCSRFFetch(url.value).json(); loading.value = false; @@ -126,6 +163,52 @@ export function useSelfEvaluationFeedback( }; } +export function useSelfEvaluationFeedbackSummaries( + courseSessionId: Ref | string +) { + const summaries = ref([]); + const aggregates = ref(); + const circles = ref([]); + const loading = ref(false); + const error = ref(); + + const url = computed( + () => + `/api/self-evaluation-feedback/requester/${courseSessionId}/feedbacks/summaries` + ); + + const fetchFeedbackSummaries = async () => { + error.value = undefined; + loading.value = true; + + log.info("Fetching feedback summaries for course session", courseSessionId); + const { data, error: _error } = await useCSRFFetch(url.value).json(); + loading.value = false; + + if (_error.value) { + error.value = _error; + summaries.value = []; + circles.value = []; + aggregates.value = undefined; + return; + } + + summaries.value = data.value.results; + aggregates.value = data.value.aggregates; + circles.value = data.value.circles; + }; + + onMounted(fetchFeedbackSummaries); + + return { + summaries, + aggregates, + circles, + loading, + error, + }; +} + export const getSmiley = (assessment: "FAIL" | "SUCCESS" | "UNKNOWN") => { switch (assessment) { case "SUCCESS":