fix: fetch question
This commit is contained in:
@@ -113,23 +113,12 @@ const existingQuestion = reactive({
|
||||
question: '',
|
||||
marks: 0,
|
||||
})
|
||||
|
||||
const question = reactive({
|
||||
question: '',
|
||||
type: 'Choices',
|
||||
marks: 0,
|
||||
})
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: __('Add a new question'),
|
||||
},
|
||||
questionName: {
|
||||
type: String,
|
||||
},
|
||||
})
|
||||
|
||||
const populateFields = () => {
|
||||
let fields = ['option', 'is_correct', 'explanation', 'possibility']
|
||||
let counter = 1
|
||||
@@ -141,17 +130,22 @@ const populateFields = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const questionData = createResource({
|
||||
url: 'frappe.client.get',
|
||||
makeParams(values) {
|
||||
return {
|
||||
doctype: 'LMS Question',
|
||||
name: props.questionName,
|
||||
}
|
||||
populateFields()
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: __('Add a new question'),
|
||||
},
|
||||
auto: false,
|
||||
cache: ['question', props.questionName],
|
||||
onSuccess(data) {
|
||||
questionData: {
|
||||
type: [Object, null],
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
watch(show, () => {
|
||||
let data = props.questionData
|
||||
if (show.value && data) {
|
||||
let counter = 1
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (Object.hasOwn(question, key)) question[key] = data[key]
|
||||
@@ -161,7 +155,7 @@ const questionData = createResource({
|
||||
? true
|
||||
: false
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const questionRow = createResource({
|
||||
@@ -247,17 +241,6 @@ const addQuestionRow = (question, close) => {
|
||||
)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.questionName,
|
||||
async (name) => {
|
||||
console.log('name', name)
|
||||
populateFields()
|
||||
if (name != 'new') {
|
||||
questionData.reload()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const dialogOptions = computed(() => {
|
||||
return {
|
||||
title: __(props.title),
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
</div>
|
||||
<Question
|
||||
v-model="showQuestionModal"
|
||||
:questionName="currentQuestion"
|
||||
:questionData="currentQuestion"
|
||||
v-model:quiz="quizDetails"
|
||||
:title="
|
||||
currentQuestion ? __('Edit the question') : __('Add a new question')
|
||||
@@ -343,10 +343,32 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
const questionData = createResource({
|
||||
url: 'lms.lms.utils.get_question_details',
|
||||
makeParams(values) {
|
||||
return {
|
||||
question: values.question,
|
||||
}
|
||||
},
|
||||
auto: false,
|
||||
cache: ['question', props.questionName],
|
||||
})
|
||||
|
||||
const openQuestionModal = (question = null) => {
|
||||
currentQuestion.value = question
|
||||
showQuestionModal.value = true
|
||||
console.log(currentQuestion.value)
|
||||
if (question) {
|
||||
questionData.reload(
|
||||
{ question },
|
||||
{
|
||||
onSuccess(data) {
|
||||
currentQuestion.value = data
|
||||
showQuestionModal.value = true
|
||||
},
|
||||
}
|
||||
)
|
||||
} else {
|
||||
currentQuestion.value = null
|
||||
showQuestionModal.value = true
|
||||
}
|
||||
}
|
||||
|
||||
const breadcrumbs = computed(() => {
|
||||
|
||||
Reference in New Issue
Block a user