Take attendance + fix point count
This commit is contained in:
@@ -67,6 +67,8 @@
|
|||||||
// If last question send to server
|
// If last question send to server
|
||||||
if (isFinished) {
|
if (isFinished) {
|
||||||
$questionnaireMetaData.status = 1;
|
$questionnaireMetaData.status = 1;
|
||||||
|
$questionnaireMetaData.totalPossibleGrade = getTotalPossibleGrade();
|
||||||
|
$questionnaireMetaData.grades = {};
|
||||||
submitExercise(
|
submitExercise(
|
||||||
$questionnaireMetaData.answers,
|
$questionnaireMetaData.answers,
|
||||||
questions,
|
questions,
|
||||||
@@ -95,7 +97,7 @@
|
|||||||
|
|
||||||
function getTotalPossibleGrade() {
|
function getTotalPossibleGrade() {
|
||||||
return $questionnaire.questions.reduce((acc, question) => {
|
return $questionnaire.questions.reduce((acc, question) => {
|
||||||
acc += question.points;
|
acc += parseInt(question.points, 10);
|
||||||
return acc;
|
return acc;
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import { SNACKBAR_SEVERITY, SNACKBAR_SEVERITY_COLOR } from './constants';
|
import { SNACKBAR_SEVERITY, SNACKBAR_SEVERITY_COLOR } from './constants';
|
||||||
import { snackbarStore } from './store';
|
import { snackbarStore } from './store';
|
||||||
|
|
||||||
let severityColor = SNACKBAR_SEVERITY_COLOR[$snackbarStore.severity];
|
let severityColor;
|
||||||
|
|
||||||
function handleClose() {
|
function handleClose() {
|
||||||
if (typeof $snackbarStore.handleClose === 'number') {
|
if (typeof $snackbarStore.handleClose === 'number') {
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: handleOpen($snackbarStore.open);
|
$: handleOpen($snackbarStore.open);
|
||||||
|
$: severityColor = SNACKBAR_SEVERITY_COLOR[$snackbarStore.severity];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $snackbarStore.open}
|
{#if $snackbarStore.open}
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
<script context="module">
|
<script context="module">
|
||||||
import { fetchCourse } from '../../../utils/services/courses';
|
export async function preload({ params }) {
|
||||||
|
return { courseId: params.id };
|
||||||
export async function preload({ params }, session) {
|
|
||||||
if (process.browser) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
data,
|
|
||||||
// error
|
|
||||||
} = await fetchCourse(params.id, session);
|
|
||||||
|
|
||||||
return { courseData: data };
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -20,16 +9,140 @@
|
|||||||
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
||||||
import PageNav from '../../../components/PageNav/index.svelte';
|
import PageNav from '../../../components/PageNav/index.svelte';
|
||||||
import PageBody from '../../../components/PageBody/index.svelte';
|
import PageBody from '../../../components/PageBody/index.svelte';
|
||||||
import { setCourseData } from '../../../components/Course/store';
|
import {
|
||||||
|
course,
|
||||||
|
group,
|
||||||
|
setCourseData,
|
||||||
|
} from '../../../components/Course/store';
|
||||||
|
import { getLectureNo } from '../../../components/Course/function';
|
||||||
|
import { fetchCourse } from '../../../utils/services/courses';
|
||||||
|
import { lessons } from '../../../components/Course/components/Lesson/store/lessons';
|
||||||
|
import { ROLE } from '../../../utils/constants/roles';
|
||||||
|
import { takeAttendance } from '../../../utils/services/attendance';
|
||||||
|
import { snackbarStore } from '../../../components/Snackbar/store';
|
||||||
|
import { SNACKBAR_SEVERITY } from '../../../components/Snackbar/constants';
|
||||||
|
import { attendance } from '../../../utils/store/attendance';
|
||||||
|
|
||||||
export let courseData = {};
|
export let courseId;
|
||||||
|
|
||||||
onMount(() => {
|
let borderBottomGrey = 'border-r-0 border-b border-l-0 border-gray-300';
|
||||||
setCourseData(courseData);
|
let students = [];
|
||||||
|
|
||||||
|
function setAttendance(courseData) {
|
||||||
|
for (const attendanceItem of courseData.attendance) {
|
||||||
|
const { student_id, lesson_id, is_present, id } = attendanceItem;
|
||||||
|
|
||||||
|
if (!$attendance[student_id]) {
|
||||||
|
$attendance[student_id] = {
|
||||||
|
[lesson_id]: {
|
||||||
|
id,
|
||||||
|
is_present,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
$attendance[student_id] = {
|
||||||
|
...$attendance[student_id],
|
||||||
|
[lesson_id]: {
|
||||||
|
id,
|
||||||
|
is_present,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
if ($course.id) return;
|
||||||
|
|
||||||
|
const { data } = await fetchCourse(courseId);
|
||||||
|
setCourseData(data);
|
||||||
|
setAttendance(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$: students = $group.people.filter(
|
||||||
|
(person) => !!person.profile && person.role_id === ROLE.STUDENT
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CourseContainer>
|
<CourseContainer>
|
||||||
<PageNav title="Attendance" />
|
<PageNav title="Attendance" />
|
||||||
<PageBody />
|
<PageBody>
|
||||||
|
<div class="table rounded-md border border-gray-300 w-full">
|
||||||
|
<div
|
||||||
|
class="flex items-center font-bold border-t-0 {borderBottomGrey} p-3"
|
||||||
|
>
|
||||||
|
<p class="w-1/4">Student</p>
|
||||||
|
{#each $lessons as lesson, index}
|
||||||
|
<p class="col" title={lesson.title}>
|
||||||
|
{getLectureNo(index + 1)}
|
||||||
|
</p>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#each students as student}
|
||||||
|
<div
|
||||||
|
class="flex relative items-center p-3 cursor-pointer {borderBottomGrey}"
|
||||||
|
>
|
||||||
|
<div class="w-1/4 flex items-center">
|
||||||
|
<img
|
||||||
|
alt="Student avatar"
|
||||||
|
src={student.profile.avatar_url}
|
||||||
|
class="w-8 h-8 rounded-full mr-2"
|
||||||
|
/>
|
||||||
|
<div class="text-sm">
|
||||||
|
<p class="font-semibold">{student.profile.fullname}</p>
|
||||||
|
<p>{`#${student.assigned_student_id}` || '-'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#each $lessons as lesson}
|
||||||
|
<p class="col">
|
||||||
|
<input
|
||||||
|
class="form-radio"
|
||||||
|
type="checkbox"
|
||||||
|
checked={$attendance[student.id]
|
||||||
|
? $attendance[student.id][lesson.id]
|
||||||
|
? $attendance[student.id][lesson.id].is_present
|
||||||
|
: false
|
||||||
|
: false}
|
||||||
|
on:change={(e) => {
|
||||||
|
const attendanceItem = $attendance[student.id]
|
||||||
|
? $attendance[student.id][lesson.id] || {}
|
||||||
|
: {};
|
||||||
|
const data = {
|
||||||
|
id: attendanceItem.id,
|
||||||
|
student_id: student.id,
|
||||||
|
is_present: e.target.checked,
|
||||||
|
lesson_id: lesson.id,
|
||||||
|
course_id: courseId,
|
||||||
|
};
|
||||||
|
|
||||||
|
takeAttendance(data).then((res) => {
|
||||||
|
if (res.error) {
|
||||||
|
console.error(`res.error`, res.error);
|
||||||
|
$snackbarStore.open = true;
|
||||||
|
$snackbarStore.severity = SNACKBAR_SEVERITY.ERROR;
|
||||||
|
$snackbarStore.message = "Something isn't right.";
|
||||||
|
} else {
|
||||||
|
console.log('res', res);
|
||||||
|
const { id, is_present } = res.data[0];
|
||||||
|
$attendance[student.id][lesson.id] = {
|
||||||
|
id,
|
||||||
|
is_present,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</PageBody>
|
||||||
</CourseContainer>
|
</CourseContainer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.col {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { supabase } from '../../functions/supabase';
|
||||||
|
|
||||||
|
export async function takeAttendance(update) {
|
||||||
|
return supabase.from('group_attendance').upsert(update);
|
||||||
|
}
|
||||||
@@ -36,7 +36,8 @@ export async function fetchCourse(courseId, session) {
|
|||||||
lessons:lesson(
|
lessons:lesson(
|
||||||
id, title,public, lesson_at, call_url, is_complete,created_at,
|
id, title,public, lesson_at, call_url, is_complete,created_at,
|
||||||
profile:teacher_id(id, avatar_url, fullname)
|
profile:teacher_id(id, avatar_url, fullname)
|
||||||
)
|
),
|
||||||
|
attendance:group_attendance(*)
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
.match({ id: courseId })
|
.match({ id: courseId })
|
||||||
@@ -45,7 +46,8 @@ export async function fetchCourse(courseId, session) {
|
|||||||
if (!data || error) {
|
if (!data || error) {
|
||||||
console.log(`data`, data);
|
console.log(`data`, data);
|
||||||
console.log(`fetchCourse => error`, error);
|
console.log(`fetchCourse => error`, error);
|
||||||
return this.redirect(301, '/courses');
|
// return this.redirect(301, '/courses');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const attendance = writable({});
|
||||||
Reference in New Issue
Block a user