-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathquiz.js
More file actions
80 lines (71 loc) · 1.75 KB
/
quiz.js
File metadata and controls
80 lines (71 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import QuizBlock from '@/components/QuizBlock.vue'
import AssessmentPlugin from '@/components/AssessmentPlugin.vue'
import { createApp, h } from 'vue'
import { usersStore } from '../stores/user'
import translationPlugin from '../translation'
import { CircleHelp } from 'lucide-vue-next'
import { getLmsRoute } from '@/utils/basePath'
import router from '@/router'
export class Quiz {
constructor({ data, api, readOnly }) {
this.data = data
this.readOnly = readOnly
}
static get toolbox() {
const app = createApp({
render: () => h(CircleHelp, { size: 5, strokeWidth: 1.5 }),
})
const div = document.createElement('div')
app.mount(div)
return {
title: __('Quiz'),
icon: div.innerHTML,
}
}
static get isReadOnlySupported() {
return true
}
render() {
this.wrapper = document.createElement('div')
if (Object.keys(this.data).length) {
this.renderQuiz(this.data.quiz)
} else {
this.renderQuizModal()
}
return this.wrapper
}
renderQuiz(quiz) {
if (this.readOnly) {
const quizPath = getLmsRoute(`quiz/${quiz}?fromLesson=1`)
this.wrapper.innerHTML = `<iframe src="${quizPath}" class="w-full h-[700px]"></iframe>`
return
}
this.wrapper.innerHTML = `<div class='border rounded-md p-4 text-center bg-surface-menu-bar mb-4'>
<span class="font-medium">
Quiz: ${quiz}
</span>
</div>`
return
}
renderQuizModal() {
if (this.readOnly) {
return
}
const app = createApp(AssessmentPlugin, {
type: 'quiz',
onAddition: (quiz) => {
this.data.quiz = quiz
this.renderQuiz(quiz)
},
})
app.use(translationPlugin)
app.use(router)
app.mount(this.wrapper)
}
save() {
if (Object.keys(this.data).length === 0) return {}
return {
quiz: this.data.quiz,
}
}
}