Prevent student from opening pending lesson
This commit is contained in:
@@ -24,11 +24,11 @@
|
|||||||
import { course, group } from '../../store';
|
import { course, group } from '../../store';
|
||||||
import { updateCourse } from '../../../../utils/services/courses';
|
import { updateCourse } from '../../../../utils/services/courses';
|
||||||
import { profile } from '../../../../utils/store/user';
|
import { profile } from '../../../../utils/store/user';
|
||||||
import People from '../../../../routes/people.svelte';
|
|
||||||
|
|
||||||
// export let lessonId;
|
// export let lessonId;
|
||||||
export let path;
|
export let path;
|
||||||
let show = null;
|
let show = null;
|
||||||
|
let isStudent = null;
|
||||||
|
|
||||||
const { page } = stores();
|
const { page } = stores();
|
||||||
|
|
||||||
@@ -99,7 +99,9 @@
|
|||||||
(member) => member.profile_id === profileId
|
(member) => member.profile_id === profileId
|
||||||
);
|
);
|
||||||
|
|
||||||
return user ? user.role_id !== 3 : false;
|
isStudent = user ? user.role_id === 3 : true;
|
||||||
|
|
||||||
|
return !isStudent;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -153,9 +155,12 @@
|
|||||||
<a
|
<a
|
||||||
class="item flex items-center {(path || $page.path).includes(
|
class="item flex items-center {(path || $page.path).includes(
|
||||||
item.id
|
item.id
|
||||||
) && 'active'} pl-7 py-2 {!item.is_complete &&
|
) && 'active'} pl-7 py-2 {isStudent && !item.is_complete
|
||||||
'cursor-not-allowed'}"
|
? 'cursor-not-allowed'
|
||||||
href={getLessonsRoute($course.id, item.id)}
|
: ''}"
|
||||||
|
href={isStudent && !item.is_complete
|
||||||
|
? $page.path
|
||||||
|
: getLessonsRoute($course.id, item.id)}
|
||||||
>
|
>
|
||||||
<span class="course-counter">
|
<span class="course-counter">
|
||||||
{getLectureNo(index + 1)}
|
{getLectureNo(index + 1)}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import { stores } from '@sapper/app';
|
||||||
import Time24 from 'carbon-icons-svelte/lib/Time24';
|
import Time24 from 'carbon-icons-svelte/lib/Time24';
|
||||||
import Edit24 from 'carbon-icons-svelte/lib/Edit24';
|
import Edit24 from 'carbon-icons-svelte/lib/Edit24';
|
||||||
import Save24 from 'carbon-icons-svelte/lib/Save24';
|
import Save24 from 'carbon-icons-svelte/lib/Save24';
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
import Select from '../../../../components/Form/Select.svelte';
|
import Select from '../../../../components/Form/Select.svelte';
|
||||||
import { fetchCourse } from '../../../../utils/services/courses';
|
import { fetchCourse } from '../../../../utils/services/courses';
|
||||||
import CourseContainer from '../../../../components/CourseContainer/index.svelte';
|
import CourseContainer from '../../../../components/CourseContainer/index.svelte';
|
||||||
|
import { profile } from '../../../../utils/store/user';
|
||||||
import {
|
import {
|
||||||
lessons,
|
lessons,
|
||||||
handleAddLesson,
|
handleAddLesson,
|
||||||
@@ -38,6 +40,9 @@
|
|||||||
|
|
||||||
let lessonEditing;
|
let lessonEditing;
|
||||||
let ref;
|
let ref;
|
||||||
|
let isStudent = true;
|
||||||
|
|
||||||
|
const { page } = stores();
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
const d = new Date(date);
|
const d = new Date(date);
|
||||||
@@ -69,6 +74,16 @@
|
|||||||
const { data } = await fetchCourse(courseId);
|
const { data } = await fetchCourse(courseId);
|
||||||
setCourseData(data);
|
setCourseData(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$: {
|
||||||
|
const user = $group.people.find(
|
||||||
|
(person) => person.profile_id === $profile.id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
isStudent = user.role_id === 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CourseContainer>
|
<CourseContainer>
|
||||||
@@ -92,26 +107,29 @@
|
|||||||
class="group relative m-auto rounded-md border-2 border-gray-100 py-3 px-5 mb-4 flex items-center hover:shadow-2xl shadow-md transition delay-150 duration-300 ease-in-out"
|
class="group relative m-auto rounded-md border-2 border-gray-100 py-3 px-5 mb-4 flex items-center hover:shadow-2xl shadow-md transition delay-150 duration-300 ease-in-out"
|
||||||
>
|
>
|
||||||
<!-- Complete or Not complete icon -->
|
<!-- Complete or Not complete icon -->
|
||||||
<RoleBasedSecurity allowedRoles="[1,2]">
|
<div class="absolute -left-6 -top-6 success">
|
||||||
<div class="absolute -left-6 -top-6 success">
|
<IconButton
|
||||||
<IconButton
|
disabled={isStudent}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
lesson.is_complete = !lesson.is_complete;
|
lesson.is_complete = !lesson.is_complete;
|
||||||
handleSaveLesson(lesson, $course.id);
|
handleSaveLesson(lesson, $course.id);
|
||||||
}}
|
}}
|
||||||
toolTipProps={{
|
toolTipProps={isStudent
|
||||||
title: `Click to ${lesson.is_complete ? 'lock' : 'unlock'}`,
|
? {}
|
||||||
direction: 'right',
|
: {
|
||||||
}}
|
title: `Click to ${lesson.is_complete ? 'lock' : 'unlock'}`,
|
||||||
>
|
direction: 'right',
|
||||||
{#if lesson.is_complete}
|
}}
|
||||||
<CheckmarkFilled24 class="carbon-icon" />
|
>
|
||||||
{:else}
|
{#if lesson.is_complete}
|
||||||
<span class="text-2xl">🔒</span>
|
<CheckmarkFilled24 class="carbon-icon" />
|
||||||
{/if}
|
{:else}
|
||||||
</IconButton>
|
<span class="text-2xl">🔒</span>
|
||||||
</div>
|
{/if}
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<RoleBasedSecurity allowedRoles="[1,2]">
|
||||||
<!-- Edit/Save -->
|
<!-- Edit/Save -->
|
||||||
<div class="absolute top-2 right-0">
|
<div class="absolute top-2 right-0">
|
||||||
{#if lessonEditing === index}
|
{#if lessonEditing === index}
|
||||||
@@ -140,8 +158,13 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<h3 class="text-2xl m-0 flex items-center">
|
<h3 class="text-2xl m-0 flex items-center">
|
||||||
<a
|
<a
|
||||||
href="/courses/{$course.id}/lessons/{lesson.id}"
|
href={isStudent && !lesson.is_complete
|
||||||
class="hover:underline text-black"
|
? $page.path
|
||||||
|
: '/courses/{$course.id}/lessons/{lesson.id}'}
|
||||||
|
class="hover:underline text-black {isStudent &&
|
||||||
|
!lesson.is_complete
|
||||||
|
? 'cursor-not-allowed'
|
||||||
|
: ''}"
|
||||||
>
|
>
|
||||||
{lesson.title}
|
{lesson.title}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user