fix: fetch question

This commit is contained in:
Jannat Patel
2024-08-05 16:29:43 +05:30
parent 27ca13ece6
commit afe7df2989
2 changed files with 42 additions and 37 deletions

View File

@@ -113,23 +113,12 @@ const existingQuestion = reactive({
question: '', question: '',
marks: 0, marks: 0,
}) })
const question = reactive({ const question = reactive({
question: '', question: '',
type: 'Choices', type: 'Choices',
marks: 0, marks: 0,
}) })
const props = defineProps({
title: {
type: String,
default: __('Add a new question'),
},
questionName: {
type: String,
},
})
const populateFields = () => { const populateFields = () => {
let fields = ['option', 'is_correct', 'explanation', 'possibility'] let fields = ['option', 'is_correct', 'explanation', 'possibility']
let counter = 1 let counter = 1
@@ -141,17 +130,22 @@ const populateFields = () => {
}) })
} }
const questionData = createResource({ populateFields()
url: 'frappe.client.get',
makeParams(values) { const props = defineProps({
return { title: {
doctype: 'LMS Question', type: String,
name: props.questionName, default: __('Add a new question'),
}
}, },
auto: false, questionData: {
cache: ['question', props.questionName], type: [Object, null],
onSuccess(data) { required: true,
},
})
watch(show, () => {
let data = props.questionData
if (show.value && data) {
let counter = 1 let counter = 1
Object.keys(data).forEach((key) => { Object.keys(data).forEach((key) => {
if (Object.hasOwn(question, key)) question[key] = data[key] if (Object.hasOwn(question, key)) question[key] = data[key]
@@ -161,7 +155,7 @@ const questionData = createResource({
? true ? true
: false : false
} }
}, }
}) })
const questionRow = createResource({ 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(() => { const dialogOptions = computed(() => {
return { return {
title: __(props.title), title: __(props.title),

View File

@@ -123,7 +123,7 @@
</div> </div>
<Question <Question
v-model="showQuestionModal" v-model="showQuestionModal"
:questionName="currentQuestion" :questionData="currentQuestion"
v-model:quiz="quizDetails" v-model:quiz="quizDetails"
:title=" :title="
currentQuestion ? __('Edit the question') : __('Add a new question') 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) => { const openQuestionModal = (question = null) => {
currentQuestion.value = question if (question) {
showQuestionModal.value = true questionData.reload(
console.log(currentQuestion.value) { question },
{
onSuccess(data) {
currentQuestion.value = data
showQuestionModal.value = true
},
}
)
} else {
currentQuestion.value = null
showQuestionModal.value = true
}
} }
const breadcrumbs = computed(() => { const breadcrumbs = computed(() => {