diff --git a/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js b/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js index 5b66c01049a..1fae7eb924d 100644 --- a/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js +++ b/kolibri/plugins/coach/assets/src/composables/useQuizCreation.js @@ -51,6 +51,9 @@ export default function useQuizCreation() { /** @type {ref} A counter for use in naming new sections */ const _sectionLabelCounter = ref(1); + /** @type {ref} A list of all Question objects selected for replacement */ + const replacements = ref([]); + // ------------------ // Section Management // ------------------ @@ -163,6 +166,16 @@ export default function useQuizCreation() { }); } + function handleReplacement() { + const questionsNotSelectedToBeReplaced = activeQuestions.value.filter( + question => !selectedActiveQuestions.value.includes(question.id) + ); + updateSection({ + section_id: activeSection.value.section_id, + questions: [...questionsNotSelectedToBeReplaced, ...replacements.value], + }); + } + /** * @description Selects random questions from the active section's `resource_pool` - no side * effects @@ -481,6 +494,7 @@ export default function useQuizCreation() { provide('saveQuiz', saveQuiz); provide('updateSection', updateSection); + provide('handleReplacement', handleReplacement); provide('replaceSelectedQuestions', replaceSelectedQuestions); provide('addSection', addSection); provide('removeSection', removeSection); @@ -491,6 +505,7 @@ export default function useQuizCreation() { provide('removeQuestionFromSelection', removeQuestionFromSelection); provide('clearSelectedQuestions', clearSelectedQuestions); provide('channels', channels); + provide('replacements', replacements); provide('quiz', quiz); provide('allSections', allSections); provide('activeSection', activeSection); @@ -511,6 +526,7 @@ export default function useQuizCreation() { // Methods saveQuiz, updateSection, + handleReplacement, replaceSelectedQuestions, addSection, removeSection, @@ -523,6 +539,7 @@ export default function useQuizCreation() { // Computed channels, + replacements, quiz, allSections, activeSection, @@ -552,6 +569,7 @@ export default function useQuizCreation() { export function injectQuizCreation() { const saveQuiz = inject('saveQuiz'); const updateSection = inject('updateSection'); + const handleReplacement = inject('handleReplacement'); const replaceSelectedQuestions = inject('replaceSelectedQuestions'); const addSection = inject('addSection'); const removeSection = inject('removeSection'); @@ -562,6 +580,7 @@ export function injectQuizCreation() { const removeQuestionFromSelection = inject('removeQuestionFromSelection'); const clearSelectedQuestions = inject('clearSelectedQuestions'); const channels = inject('channels'); + const replacements = inject('replacements'); const quiz = inject('quiz'); const allSections = inject('allSections'); const activeSection = inject('activeSection'); @@ -584,6 +603,7 @@ export function injectQuizCreation() { deleteActiveSelectedQuestions, selectAllQuestions, updateSection, + handleReplacement, replaceSelectedQuestions, addSection, removeSection, @@ -599,6 +619,7 @@ export function injectQuizCreation() { allQuestionsSelected, selectAllIsIndeterminate, channels, + replacements, quiz, allSections, activeSection, diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ReplaceQuestions.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ReplaceQuestions.vue index f68cb80d6bf..0cfb4c8646c 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ReplaceQuestions.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ReplaceQuestions.vue @@ -132,7 +132,7 @@ :cancelText="coreString('cancelAction')" :title="replaceQuestions$()" @cancel="showReplacementConfirmation = false" - @submit="handleReplacement" + @submit="submitReplacement" >
{{ replaceQuestionsExplaination$() }}
@@ -188,7 +188,6 @@ } = enhancedQuizManagementStrings; const { // Computed - activeQuestions, activeSection, selectedActiveQuestions, activeResourceMap, @@ -199,6 +198,8 @@ replaceSelectedQuestions, toggleQuestionInSelection, updateSection, + handleReplacement, + replacements, } = injectQuizCreation(); const showCloseConfirmation = ref(false); @@ -208,17 +209,9 @@ context.emit('closePanel'); } - const replacements = ref([]); - - function handleReplacement() { + function submitReplacement() { + handleReplacement(); const count = replacements.value.length; - const questionsNotSelectedToBeReplaced = activeQuestions.value.filter( - question => !selectedActiveQuestions.value.includes(question.id) - ); - updateSection({ - section_id: activeSection.value.section_id, - questions: [...questionsNotSelectedToBeReplaced, ...replacements.value], - }); router.replace({ name: PageNames.EXAM_CREATION_ROOT, query: { @@ -263,8 +256,6 @@ return { toggleInReplacements, - handleReplacement, - replacements, activeSection, selectAllReplacementQuestions, selectedActiveQuestions, @@ -283,6 +274,8 @@ isItemExpanded, toggleQuestionInSelection, updateSection, + submitReplacement, + replacements, replaceQuestions$, deleteSectionLabel$, replaceAction$,