CLASSROOMIO-T-108: Attendance improvement + complete lms exercise
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
import { marked } from 'marked';
|
||||
export let preview;
|
||||
|
||||
function getTotalPossibleGrade() {
|
||||
return $questionnaire.questions.reduce((acc, question) => {
|
||||
function getTotalPossibleGrade(questions) {
|
||||
return questions.reduce((acc, question) => {
|
||||
acc += parseFloat(question.points, 10);
|
||||
return acc;
|
||||
}, 0);
|
||||
@@ -48,7 +48,7 @@
|
||||
</p>
|
||||
|
|
||||
<p class="dark:text-white mx-2">
|
||||
<strong>{getTotalPossibleGrade()}</strong> points.
|
||||
<strong>{getTotalPossibleGrade($questionnaire.questions)}</strong> points.
|
||||
</p>
|
||||
|
|
||||
<p class="dark:text-white mx-2">All required</p>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
// If last question send to server
|
||||
if (isFinished) {
|
||||
$questionnaireMetaData.status = 1;
|
||||
$questionnaireMetaData.totalPossibleGrade = getTotalPossibleGrade();
|
||||
$questionnaireMetaData.totalPossibleGrade = getTotalPossibleGrade($questionnaire.questions);
|
||||
$questionnaireMetaData.grades = {};
|
||||
submitExercise(
|
||||
$questionnaireMetaData.answers,
|
||||
@@ -87,8 +87,8 @@
|
||||
return Math.round(((currentQuestionIndex - 1) / $questionnaire.questions.length) * 100) || 0;
|
||||
}
|
||||
|
||||
function getTotalPossibleGrade() {
|
||||
return $questionnaire.questions.reduce((acc, question) => {
|
||||
function getTotalPossibleGrade(questions) {
|
||||
return questions.reduce((acc, question) => {
|
||||
acc += parseFloat(question.points, 10);
|
||||
return acc;
|
||||
}, 0);
|
||||
@@ -119,7 +119,7 @@
|
||||
answers: submission.answers
|
||||
});
|
||||
|
||||
$questionnaireMetaData.totalPossibleGrade = getTotalPossibleGrade();
|
||||
$questionnaireMetaData.totalPossibleGrade = getTotalPossibleGrade($questionnaire.questions);
|
||||
|
||||
$questionnaireMetaData.currentQuestionIndex = $questionnaire.questions.length;
|
||||
$questionnaireMetaData.isFinished = true;
|
||||
@@ -192,7 +192,7 @@
|
||||
</p>
|
||||
|
|
||||
<p class="dark:text-white mx-2">
|
||||
<strong>{getTotalPossibleGrade()}</strong> points.
|
||||
<strong>{getTotalPossibleGrade($questionnaire.questions)}</strong> points.
|
||||
</p>
|
||||
|
|
||||
<p class="dark:text-white mx-2">All required</p>
|
||||
|
||||
@@ -218,6 +218,8 @@
|
||||
|
||||
$: addBadgeValueToTab($lesson.materials);
|
||||
|
||||
$: console.log('$lesson.materials', $lesson.materials);
|
||||
|
||||
$: updateNoteByCompletion($completion);
|
||||
|
||||
$: initPlyr(player, $lesson.materials.videos);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { writable } from 'svelte/store';
|
||||
import type { Writable } from 'svelte/store';
|
||||
import { lessons } from './components/Lesson/store/lessons';
|
||||
import { ROLE } from '$lib/utils/constants/roles';
|
||||
import type { Course } from '$lib/utils/types';
|
||||
import type { Course, GroupPerson } from '$lib/utils/types';
|
||||
|
||||
export const course: Writable<Course> = writable({
|
||||
id: '',
|
||||
@@ -16,6 +16,7 @@ export const course: Writable<Course> = writable({
|
||||
is_published: false,
|
||||
created_at: new Date().toDateString(),
|
||||
updated_at: new Date().toDateString(),
|
||||
attendance: [],
|
||||
metadata: {
|
||||
requirements: '',
|
||||
description: '',
|
||||
@@ -61,7 +62,12 @@ export const mockGroupMember = {
|
||||
}
|
||||
};
|
||||
|
||||
export const group = writable({
|
||||
export const group = writable<{
|
||||
id: number | null;
|
||||
tutors: GroupPerson[];
|
||||
students: GroupPerson[];
|
||||
people: GroupPerson[];
|
||||
}>({
|
||||
id: null,
|
||||
tutors: [],
|
||||
students: [],
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="header dark:bg-black bg-white flex items-center justify-between {!disableSticky &&
|
||||
class="header dark:bg-black dark:border-neutral-600 bg-white flex items-center justify-between {!disableSticky &&
|
||||
'sticky'} {paddingClass} {dynamicRootClass}"
|
||||
style={overidableStyle}
|
||||
>
|
||||
|
||||
@@ -24,7 +24,7 @@ export const VARIANTS_CLASS = {
|
||||
[VARIANTS.OUTLINED]:
|
||||
'border border-primary-700 hover:border-black-300 hover:bg-primary-700 text-black dark:text-white',
|
||||
[VARIANTS.NONE]:
|
||||
'border-none hover:border-black-300 hover:bg-gray-200 dark:hover:bg-gray-500 text-black',
|
||||
'border-none hover:border-black-300 hover:bg-gray-200 dark:hover:bg-neutral-800 text-black',
|
||||
[VARIANTS.TEXT]: 'text-black hover:underline',
|
||||
[VARIANTS.LINK]: 'text-primary-500 dark:text-primary-500 hover:underline',
|
||||
[VARIANTS.TEXT_DANGER]:
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<div class="ml-4">
|
||||
{#each options as option}
|
||||
<button
|
||||
class="cursor-pointer text-left my-2 border-2 border-gray-300 rounded-md hover:bg-gray-200 dark:hover:bg-gray-500 w-full {getValidationClassName(
|
||||
class="cursor-pointer text-left my-2 border-2 border-gray-300 rounded-md hover:bg-gray-200 dark:hover:bg-neutral-800 w-full {getValidationClassName(
|
||||
option
|
||||
)}"
|
||||
type="button"
|
||||
@@ -107,9 +107,7 @@
|
||||
variant={VARIANTS.OUTLINED}
|
||||
/>
|
||||
<PrimaryButton
|
||||
variant={nextButtonProps.isActive
|
||||
? VARIANTS.CONTAINED
|
||||
: VARIANTS.OUTLINED}
|
||||
variant={nextButtonProps.isActive ? VARIANTS.CONTAINED : VARIANTS.OUTLINED}
|
||||
type="submit"
|
||||
label={nextButtonProps.label}
|
||||
{name}
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
<div class={!disableOptContainerMargin && 'ml-4'}>
|
||||
{#each options as option}
|
||||
<button
|
||||
class="cursor-pointer text-left my-2 border-2 border-gray-300 rounded-md hover:bg-gray-200 dark:hover:bg-gray-500 w-full {getValidationClassName(
|
||||
class="cursor-pointer text-left my-2 border-2 border-gray-300 rounded-md hover:bg-gray-200 dark:hover:bg-neutral-800 w-full {getValidationClassName(
|
||||
option
|
||||
)}"
|
||||
type="button"
|
||||
|
||||
@@ -7,20 +7,20 @@
|
||||
</script>
|
||||
|
||||
<div class="w-full flex flex-col">
|
||||
<div class="flex items-center border-b-2 w-full overflow-x-auto">
|
||||
<div class="flex items-center border-b w-full overflow-x-auto">
|
||||
{#each tabs as tab}
|
||||
{#if !tab.icon && !tab.badgeValue}
|
||||
<button
|
||||
class="relative {currentTab === tab.value
|
||||
? 'text-primary-700'
|
||||
: 'dark:bg-gray-500 dark:text-white'} dark:bg-transparent font-semibold focus:outline-none w-fit mr-8 text-center py-3"
|
||||
: 'dark:bg-gray-500 dark:text-white'} dark:bg-transparent font-semibold focus:outline-none w-fit mr-4 text-center py-3 px-2"
|
||||
on:click={onChange(tab.value)}
|
||||
>
|
||||
<div class="flex items-center justify-center w-full text-center">
|
||||
{tab.label}
|
||||
</div>
|
||||
<span
|
||||
class="absolute bottom-0 left-0 h-1 bg-primary-700 transition-all ease-in-out duration-500 {currentTab ===
|
||||
class="absolute bottom-0 left-0 h-[2px] bg-primary-700 transition-all ease-in-out duration-500 {currentTab ===
|
||||
tab.value
|
||||
? 'w-full'
|
||||
: 'w-0'}"
|
||||
@@ -30,7 +30,7 @@
|
||||
<button
|
||||
class="relative {currentTab === tab.value
|
||||
? 'text-primary-700'
|
||||
: 'dark:bg-gray-500 dark:text-white'} dark:bg-transparent font-semibold focus:outline-none w-24 text-left py-3 mr-10"
|
||||
: 'dark:bg-gray-500 dark:text-white'} dark:bg-transparent font-semibold focus:outline-none w-24 text-left py-3 mr-8 px-2"
|
||||
on:click={onChange(tab.value)}
|
||||
>
|
||||
<div class="grid grid-cols-5 md:grid-cols-4 gap-5 md:gap-3 items-center">
|
||||
@@ -43,12 +43,12 @@
|
||||
value={tab.badgeValue}
|
||||
size="sm"
|
||||
shape="rounded-full"
|
||||
className=" bg-gray-300 dark:text-black text-xs absolute right-0 px-2"
|
||||
className="bg-gray-300 dark:text-black text-xs absolute right-0 px-2"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<span
|
||||
class="absolute bottom-0 left-0 h-1 bg-primary-700 transition-all ease-in-out duration-500 {currentTab ===
|
||||
class="absolute bottom-0 left-0 h-[2px] bg-primary-700 transition-all ease-in-out duration-500 {currentTab ===
|
||||
tab.value
|
||||
? 'w-full'
|
||||
: 'w-0'}"
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
LessonCompletion
|
||||
} from '$lib/utils/types';
|
||||
import { STATUS } from '$lib/utils/constants/course';
|
||||
import type { PostgrestError, PostgrestSingleResponse } from '@supabase/supabase-js';
|
||||
|
||||
export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']) {
|
||||
let match: { slug?: string; id?: string; status?: string } = {};
|
||||
@@ -22,7 +23,7 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
|
||||
match.status = STATUS[STATUS.ACTIVE];
|
||||
|
||||
const { data, error } = await supabase
|
||||
const response: PostgrestSingleResponse<Course | null> = await supabase
|
||||
.from('course')
|
||||
.select(
|
||||
`
|
||||
@@ -53,6 +54,9 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
|
||||
)
|
||||
.match(match)
|
||||
.single();
|
||||
|
||||
const { data, error } = response;
|
||||
|
||||
console.log(`error`, error);
|
||||
if (!data || error) {
|
||||
console.log(`data`, data);
|
||||
@@ -185,7 +189,6 @@ function isNew(item: any) {
|
||||
return isNaN(item);
|
||||
}
|
||||
|
||||
// TODO: Add questionnaire type
|
||||
export async function upsertExercise(questionnaire: any, exerciseId: Exercise['id']) {
|
||||
const {
|
||||
questions,
|
||||
@@ -214,7 +217,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
const { title, id, name, question_type, options, deleted_at, order, points, is_dirty } =
|
||||
question;
|
||||
|
||||
// DELETE /delete/:questionId - Don't delete if answer already given
|
||||
// "DELETE" /delete/:questionId - Don't delete if answer already given
|
||||
if (deleted_at) {
|
||||
// Delete from server only if this question exists in the database
|
||||
if (!isNew(id)) {
|
||||
@@ -232,7 +235,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
continue;
|
||||
}
|
||||
|
||||
// INSERT or UPDATE /update/:questionId or /insert/:questionId
|
||||
// "INSERT" or "UPDATE" /update/:questionId or /insert/:questionId
|
||||
const newQuestion = {
|
||||
id: isNew(id) ? undefined : id,
|
||||
name: isNew(id) ? undefined : name,
|
||||
@@ -274,7 +277,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
for (const option of options) {
|
||||
const { deleted_at, is_dirty } = option;
|
||||
|
||||
// DELETE /delete/:optionId
|
||||
// "DELETE" /delete/:optionId
|
||||
if (deleted_at) {
|
||||
// if this option exists in the database
|
||||
if (!isNew(option.id)) {
|
||||
@@ -285,7 +288,7 @@ export async function upsertExercise(questionnaire: any, exerciseId: Exercise['i
|
||||
continue;
|
||||
}
|
||||
|
||||
// INSERT and UPDATE
|
||||
// "INSERT" and "UPDATE"
|
||||
const newOption = {
|
||||
...option,
|
||||
is_dirty: undefined,
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import type { PostgrestError } from '@supabase/supabase-js';
|
||||
|
||||
export interface LMSExercise {
|
||||
id: string;
|
||||
title: string;
|
||||
updated_at: string;
|
||||
submission: {
|
||||
status_id: number;
|
||||
updated_at: string;
|
||||
groupmember: {
|
||||
id: string;
|
||||
profile: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
lesson: {
|
||||
id: string;
|
||||
title: string;
|
||||
order: number;
|
||||
course: {
|
||||
id: string;
|
||||
title: string;
|
||||
group: {
|
||||
organisation: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
groupmember: {
|
||||
id: string;
|
||||
profile: {
|
||||
id: string;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface FetchLMSExercisesResponse {
|
||||
exercises: LMSExercise[] | null;
|
||||
error: PostgrestError | null;
|
||||
}
|
||||
|
||||
export async function fetchLMSExercises(
|
||||
profileId: string,
|
||||
orgId: string
|
||||
): Promise<FetchLMSExercisesResponse> {
|
||||
const { data, error } = await supabase
|
||||
.from('exercise')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
title,
|
||||
updated_at,
|
||||
submission (
|
||||
status_id,
|
||||
updated_at,
|
||||
groupmember:submitted_by!inner (
|
||||
id,
|
||||
profile!inner (
|
||||
id
|
||||
)
|
||||
)
|
||||
),
|
||||
lesson!inner (
|
||||
id,
|
||||
title,
|
||||
order,
|
||||
course!inner (
|
||||
id,
|
||||
title,
|
||||
group:group_id!inner (
|
||||
organisation:organization_id!inner (
|
||||
id
|
||||
)
|
||||
),
|
||||
groupmember:group_id!inner(
|
||||
id,
|
||||
profile!inner (
|
||||
id
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
`
|
||||
)
|
||||
.eq('lesson.course.group.organisation.id', orgId)
|
||||
.eq('lesson.course.groupmember.profile.id', profileId)
|
||||
.eq('submission.groupmember.profile.id', profileId);
|
||||
|
||||
return {
|
||||
exercises: data,
|
||||
error
|
||||
};
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const attendance = writable({});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const attendance = writable<{
|
||||
[key: string]: {
|
||||
[key: string]: {
|
||||
is_present: boolean;
|
||||
id: number;
|
||||
};
|
||||
};
|
||||
}>({});
|
||||
@@ -1,6 +1,19 @@
|
||||
export * from './config';
|
||||
export * from './dashboard';
|
||||
|
||||
//===============Custom Type===============
|
||||
export interface GroupPerson {
|
||||
assigned_student_id: number | null;
|
||||
created_at: string;
|
||||
email: string | null;
|
||||
group_id: string;
|
||||
id: string;
|
||||
profile: Profile;
|
||||
profile_id: string;
|
||||
role_id: Role['id'];
|
||||
}
|
||||
//===========================================
|
||||
|
||||
interface CourseMetadata {
|
||||
requirements: string;
|
||||
description: string;
|
||||
@@ -109,6 +122,12 @@ export interface Course {
|
||||
is_published?: boolean;
|
||||
progress_rate?: number;
|
||||
total_lessons?: number;
|
||||
attendance: {
|
||||
student_id: string;
|
||||
lesson_id: string;
|
||||
is_present: boolean;
|
||||
id: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface Groupmember {
|
||||
|
||||
Reference in New Issue
Block a user