Skip to content

Commit

Permalink
fix: fetch question details
Browse files Browse the repository at this point in the history
  • Loading branch information
pateljannat committed Aug 1, 2024
1 parent b8c3bdc commit 471e7d9
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 28 deletions.
60 changes: 47 additions & 13 deletions frontend/src/components/Modals/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,61 @@
</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',
})
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({
title: {
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
}
},
})
Expand All @@ -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()
}
}
Expand Down
26 changes: 16 additions & 10 deletions frontend/src/pages/QuizCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
row-key="name"
:options="{
showTooltip: false,
onRowClick: (row) => emit('openQuestionModal', row.name),
}"
>
<ListHeader
Expand All @@ -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>
Expand All @@ -99,7 +105,7 @@
</ListView>
</div>
</div>
<Question v-model="showQuestionModal" :question="currentQuestion" />
<Question v-model="showQuestionModal" :questionName="currentQuestion" />
</template>
<script setup>
import {
Expand Down Expand Up @@ -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]
Expand All @@ -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
}
Expand Down
32 changes: 32 additions & 0 deletions lms/lms/doctype/lms_certificate_request/lms_certificate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def validate(self):
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)
Expand Down Expand Up @@ -107,6 +110,35 @@ def validate_evaluation_end_date(self):
)
)

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"):
Expand Down
3 changes: 2 additions & 1 deletion lms/lms/doctype/lms_question/lms_question.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"modified": "2024-08-01 12:17:40.647724",
"modified_by": "[email protected]",
"module": "LMS",
"name": "Certificate Request Creation",
"owner": "Administrator",
Expand Down
4 changes: 4 additions & 0 deletions lms/templates/emails/certificate_request_notification.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 471e7d9

Please sign in to comment.