fix: fetch question details
This commit is contained in:
@@ -49,10 +49,11 @@
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup>
|
||||
import { Dialog, FormControl, TextEditor } from 'frappe-ui'
|
||||
import { computed, onMounted, reactive } from 'vue'
|
||||
import { Dialog, FormControl, TextEditor, createResource } from 'frappe-ui'
|
||||
import { computed, onMounted, reactive, inject } from 'vue'
|
||||
|
||||
const show = defineModel()
|
||||
const user = inject('$user')
|
||||
const question = reactive({
|
||||
question: '',
|
||||
type: 'Choices',
|
||||
@@ -60,7 +61,19 @@ const question = reactive({
|
||||
|
||||
onMounted(() => {
|
||||
populateFields()
|
||||
populateQuestionDetail()
|
||||
console.log(props.questionName)
|
||||
if (
|
||||
props.questionName == 'new' &&
|
||||
!user.data?.is_moderator &&
|
||||
!user.data?.is_instructor
|
||||
) {
|
||||
router.push({ name: 'Courses' })
|
||||
}
|
||||
|
||||
if (props.courseName !== 'new') {
|
||||
questionDoc.reload()
|
||||
}
|
||||
window.addEventListener('keydown', keyboardShortcut)
|
||||
})
|
||||
|
||||
const props = defineProps({
|
||||
@@ -68,9 +81,29 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: __('Add a Question'),
|
||||
},
|
||||
questionDetail: {
|
||||
type: Object,
|
||||
default: {},
|
||||
questionName: {
|
||||
type: String,
|
||||
},
|
||||
})
|
||||
|
||||
const questionDoc = createResource({
|
||||
url: 'frappe.client.get',
|
||||
makeParams: (values) => {
|
||||
return {
|
||||
doctype: 'LMS Question',
|
||||
name: props.questionName,
|
||||
}
|
||||
},
|
||||
onSuccess(data) {
|
||||
let counter = 1
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (Object.hasOwn(question, key)) question[key] = data[key]
|
||||
})
|
||||
while (counter <= 4) {
|
||||
question[`is_correct_${counter}`] = question[`is_correct_${counter}`]
|
||||
? true
|
||||
: false
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -85,13 +118,14 @@ const populateFields = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const populateQuestionDetail = () => {
|
||||
if (Object.keys(props.questionDetail).length) {
|
||||
Object.keys(props.questionDetail).forEach((key) => {
|
||||
if (Object.hasOwn(question, key)) {
|
||||
question[key] = props.questionDetail[key]
|
||||
}
|
||||
})
|
||||
const keyboardShortcut = (e) => {
|
||||
if (
|
||||
e.key === 's' &&
|
||||
(e.ctrlKey || e.metaKey) &&
|
||||
!e.target.classList.contains('ProseMirror')
|
||||
) {
|
||||
submitQuestion()
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
row-key="name"
|
||||
:options="{
|
||||
showTooltip: false,
|
||||
onRowClick: (row) => emit('openQuestionModal', row.name),
|
||||
}"
|
||||
>
|
||||
<ListHeader
|
||||
@@ -88,9 +87,16 @@
|
||||
:row="row"
|
||||
v-slot="{ idx, column, item }"
|
||||
v-for="row in quiz.questions"
|
||||
@click="openQuestionModal(row.question)"
|
||||
>
|
||||
<ListRowItem :item="item">
|
||||
<div class="text-xs">
|
||||
<div
|
||||
v-if="column.key == 'question_detail'"
|
||||
class="text-xs truncate"
|
||||
>
|
||||
{{ item }}
|
||||
</div>
|
||||
<div v-else class="text-xs">
|
||||
{{ item }}
|
||||
</div>
|
||||
</ListRowItem>
|
||||
@@ -99,7 +105,7 @@
|
||||
</ListView>
|
||||
</div>
|
||||
</div>
|
||||
<Question v-model="showQuestionModal" :question="currentQuestion" />
|
||||
<Question v-model="showQuestionModal" :questionName="currentQuestion" />
|
||||
</template>
|
||||
<script setup>
|
||||
import {
|
||||
@@ -144,7 +150,7 @@ const quizDetails = createDocumentResource({
|
||||
doctype: 'LMS Quiz',
|
||||
name: props.quizID,
|
||||
auto: true,
|
||||
cache: ['quiz', props.quiz],
|
||||
cache: ['quiz', props.quizID],
|
||||
onSuccess(data) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (Object.hasOwn(quiz, key)) quiz[key] = data[key]
|
||||
@@ -162,29 +168,29 @@ const quizDetails = createDocumentResource({
|
||||
},
|
||||
})
|
||||
|
||||
console.log(quizDetails)
|
||||
|
||||
const questionColumns = computed(() => {
|
||||
return [
|
||||
{
|
||||
label: __('ID'),
|
||||
key: 'question',
|
||||
width: 1,
|
||||
width: '25%',
|
||||
},
|
||||
{
|
||||
label: __('Question'),
|
||||
key: __('question_detail'),
|
||||
width: 3,
|
||||
width: '60%',
|
||||
},
|
||||
{
|
||||
label: __('Marks'),
|
||||
key: 'marks',
|
||||
width: 0.5,
|
||||
width: '10%',
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
const openQuestionModal = (question = {}) => {
|
||||
const openQuestionModal = (question = null) => {
|
||||
console.log('called')
|
||||
console.log(question)
|
||||
currentQuestion.value = question
|
||||
showQuestionModal.value = true
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ class LMSCertificateRequest(Document):
|
||||
self.validate_if_existing_requests()
|
||||
self.validate_evaluation_end_date()
|
||||
|
||||
def after_insert(self):
|
||||
self.send_notification()
|
||||
|
||||
def set_evaluator(self):
|
||||
if not self.evaluator:
|
||||
self.evaluator = get_evaluator(self.course, self.batch_name)
|
||||
@@ -107,6 +110,35 @@ class LMSCertificateRequest(Document):
|
||||
)
|
||||
)
|
||||
|
||||
def send_notification(self):
|
||||
outgoing_email_account = frappe.get_cached_value(
|
||||
"Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, "name"
|
||||
)
|
||||
if outgoing_email_account or frappe.conf.get("mail_login"):
|
||||
subject = _("Your evaluation slot has been booked")
|
||||
template = "certificate_request_notification"
|
||||
|
||||
args = {
|
||||
"course": frappe.db.get_value("LMS Course", self.course, "title"),
|
||||
"timezone": frappe.db.get_value("LMS Batch", self.batch_name, "timezone")
|
||||
if self.batch_name
|
||||
else "",
|
||||
"date": format_date(self.date, "medium"),
|
||||
"member_name": self.member_name,
|
||||
"start_time": format_time(self.start_time, "short"),
|
||||
"evaluator": frappe.db.get_value("User", self.evaluator, "full_name"),
|
||||
}
|
||||
|
||||
frappe.sendmail(
|
||||
recipients=[self.member],
|
||||
cc=[self.evaluator],
|
||||
subject=subject,
|
||||
template=template,
|
||||
args=args,
|
||||
header=[subject, "green"],
|
||||
retry=3,
|
||||
)
|
||||
|
||||
|
||||
def schedule_evals():
|
||||
if frappe.db.get_single_value("LMS Settings", "send_calendar_invite_for_evaluations"):
|
||||
|
||||
@@ -195,7 +195,8 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-05-24 16:12:26.331351",
|
||||
"make_attachments_public": 1,
|
||||
"modified": "2024-08-01 12:53:22.540990",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Question",
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
"docstatus": 0,
|
||||
"doctype": "Notification",
|
||||
"document_type": "LMS Certificate Request",
|
||||
"enabled": 1,
|
||||
"enabled": 0,
|
||||
"event": "New",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"message": "{% set title = frappe.db.get_value(\"LMS Course\", doc.course, \"title\") %}\n{% set timezone = frappe.db.get_value(\"LMS Batch\", doc.batch, \"timezone\") %}\n{% set timezone = timezone if timezone else '' %}\n{% set evaluator_name = frappe.db.get_value(\"User\", doc.evaluator, \"full_name\") %}\n\n<p> {{ _(\"Hey {0}\").format(doc.member_name) }} </p>\n<p> {{ _('Your evaluation for the course {0} has been scheduled on {1} at {2} {3}.').format(title, frappe.utils.format_date(doc.date, \"medium\"), frappe.utils.format_time(doc.start_time, \"short\"), timezone) }}</p>\n<p> {{ _(\"Your evaluator is {0}\").format(evaluator_name) }}\n<p> {{ _(\"Please prepare well and be on time for the evaluations.\") }} </p>\n",
|
||||
"message": "{% set title = frappe.db.get_value(\"LMS Course\", doc.course, \"title\") %}\n{% set timezone = frappe.db.get_value(\"LMS Batch\", doc.batch, \"timezone\") %}\n{% set timezone = timezone if timezone else '' %}\n{% set evaluator_name = frappe.db.get_value(\"User\", doc.evaluator, \"full_name\") %}\n\n<p> {{ _(\"Hey {0}\").format(doc.member_name) }} </p>\n<p> {{ _('Your evaluation for the course {0} has been scheduled on {1} at {2} {3}.').format(title, frappe.utils.format_date(doc.date, \"medium\"), frappe.utils.format_time(doc.start_time, \"short\"), timezone) }}</p>\n<p> {{ _(\"Your evaluator is {0}\").format(evaluator_name) }} </p>\n<p> {{ _(\"Please prepare well and be on time for the evaluations.\") }} </p>\n",
|
||||
"message_type": "HTML",
|
||||
"modified": "2024-07-10 15:51:03.429317",
|
||||
"modified_by": "sayali@erpnext.com",
|
||||
"modified": "2024-08-01 12:17:40.647724",
|
||||
"modified_by": "jannat@frappe.io",
|
||||
"module": "LMS",
|
||||
"name": "Certificate Request Creation",
|
||||
"owner": "Administrator",
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<p> {{ _("Hey {0}").format(member_name) }} </p>
|
||||
<p> {{ _('Your evaluation for the course {0} has been scheduled on {1} at {2} {3}.').format(title, date, start_time, timezone) }}</p>
|
||||
<p> {{ _("Your evaluator is {0}").format(evaluator) }} </p>
|
||||
<p> {{ _("Please prepare well and be on time for the evaluations.") }} </p>
|
||||
Reference in New Issue
Block a user