Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to allow and implement randomization of sections. #12278

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ export const Quiz = {
type: Number,
default: getRandomInt(),
},
// Default to sections being shown in a fixed order
learners_see_fixed_order: {
type: Boolean,
default: true,
},
};
11 changes: 6 additions & 5 deletions kolibri/plugins/coach/assets/src/views/common/QuizStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
:layout8="{ span: 4 }"
:layout12="{ span: 12 }"
>
{{ $tr('questionOrderLabel') }}
{{ sectionOrderLabel$() }}
</KGridItem>
<KGridItem
:layout4="{ span: 4 }"
Expand Down Expand Up @@ -265,6 +265,7 @@
import Lockr from 'lockr';
import { QUIZ_REPORT_VISIBILITY_MODAL_DISMISSED } from 'kolibri.coreVue.vuex.constants';
import { mapActions } from 'vuex';
import { enhancedQuizManagementStrings } from 'kolibri-common/strings/enhancedQuizManagementStrings';
import { coachStringsMixin } from './commonCoachStrings';
import Score from './Score';
import Recipients from './Recipients';
Expand All @@ -275,6 +276,10 @@
name: 'QuizStatus',
components: { Score, Recipients, ElapsedTime, StatusElapsedTime, AverageScoreTooltip },
mixins: [coachStringsMixin, commonCoreStrings],
setup() {
const { sectionOrderLabel$ } = enhancedQuizManagementStrings;
return { sectionOrderLabel$ };
},
props: {
className: {
type: String,
Expand Down Expand Up @@ -454,10 +459,6 @@
context:
'The label for a switch that will toggle whether or not learners can view their quiz report.',
},
questionOrderLabel: {
message: 'Question order',
context: 'A label for the place where the question order is shown.',
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<KRadioButton
v-model="learners_see_fixed_order"
:label="randomizedLabel$()"
:buttonValue="true"
:buttonValue="false"
:description="randomizedOptionDescription$()"
/>
</KGridItem>
Expand All @@ -101,7 +101,7 @@
<KRadioButton
v-model="learners_see_fixed_order"
:label="fixedLabel$()"
:buttonValue="false"
:buttonValue="true"
:description="fixedOptionDescription$()"
/>
</KGridItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
@update="updateQuiz"
/>

<div v-if="quizInitialized">
<h5 class="section-order-header">
{{ sectionOrderLabel$() }}
</h5>
<KGrid>
<KGridItem
:layout12="{ span: 6 }"
:layout8="{ span: 4 }"
:layout4="{ span: 2 }"
>
<KRadioButton
:currentValue="quiz.learners_see_fixed_order"
:label="randomizedLabel$()"
:buttonValue="false"
:description="randomizedSectionOptionDescription$()"
@input="value => updateQuiz({ learners_see_fixed_order: value })"
/>
</KGridItem>
<KGridItem
:layout12="{ span: 6 }"
:layout8="{ span: 4 }"
:layout4="{ span: 2 }"
>
<KRadioButton
:currentValue="quiz.learners_see_fixed_order"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something going on here with the saving/setting current value that is changing the saved value on edit, that I'm pretty sure is a bug although I can't see on code read through where precisely it's happening (see screenshot in overall PR comment)

:label="fixedLabel$()"
:buttonValue="true"
:description="fixedSectionOptionDescription$()"
@input="value => updateQuiz({ learners_see_fixed_order: value })"
/>
</KGridItem>
</KGrid>
</div>

<CreateQuizSection v-if="quizInitialized && quiz.draft" />

<BottomAppBar>
Expand Down Expand Up @@ -92,7 +126,15 @@
const showError = ref(false);
const quizInitialized = ref(false);

const { saveAndClose$, allSectionsEmptyWarning$ } = enhancedQuizManagementStrings;
const {
saveAndClose$,
allSectionsEmptyWarning$,
sectionOrderLabel$,
randomizedLabel$,
fixedLabel$,
randomizedSectionOptionDescription$,
fixedSectionOptionDescription$,
} = enhancedQuizManagementStrings;

return {
classId,
Expand All @@ -106,6 +148,11 @@
allSectionsEmpty,
allSectionsEmptyWarning$,
saveAndClose$,
sectionOrderLabel$,
randomizedLabel$,
fixedLabel$,
randomizedSectionOptionDescription$,
fixedSectionOptionDescription$,
};
},
provide() {
Expand Down Expand Up @@ -212,4 +259,9 @@
margin-right: 8px;
}

.section-order-header {
margin-top: 0;
margin-bottom: 0.5em;
}

</style>
11 changes: 8 additions & 3 deletions kolibri/plugins/learn/assets/src/modules/examViewer/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ export function showExam(store, params, alreadyOnQuiz) {
store.commit('classAssignments/SET_CURRENT_CLASSROOM', classroom);
fetchExamWithContent(exam).then(({ exam: converted, exercises: contentNodes }) => {
if (shouldResolve()) {
const { question_sources } = converted;
let { question_sources } = converted;

// When necessary, randomize the questions for the learner.
// Seed based on the user ID so they see a consistent order each time.
question_sources.forEach(section => {
for (const section of question_sources) {
if (!section.learners_see_fixed_order) {
section.questions = shuffled(section.questions, store.state.core.session.user_id);
}
});
}
// When necessary randomize the order of the sections
// Seed based on the user ID so they see a consistent order each time.
if (!converted.learners_see_fixed_order) {
question_sources = shuffled(question_sources, store.state.core.session.user_id);
}
// If necessary, convert the question source info
const allQuestions = question_sources.reduce((acc, section) => {
acc = [...acc, ...section.questions];
Expand Down
10 changes: 10 additions & 0 deletions packages/kolibri-common/strings/enhancedQuizManagementStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag
message:
'Please choose a different resource or decrease the number of questions to be replaced.',
},
sectionOrderLabel: {
message: 'Section order',
context: 'A label for the place where the section order option is shown.',
},
questionOrder: {
message: 'Question order',
},
Expand All @@ -130,12 +134,18 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag
randomizedOptionDescription: {
message: 'Each learner sees a different question order',
},
randomizedSectionOptionDescription: {
message: 'Each learner sees a different section order',
},
fixedLabel: {
message: 'Fixed',
},
fixedOptionDescription: {
message: 'Each learner sees the same question order',
},
fixedSectionOptionDescription: {
message: 'Each learner sees the same section order',
},
questionEditedSuccessfully: {
message: 'Question edited successfully',
},
Expand Down