CLASSROOMIO-T-195: Shuffle options to mix correct answers Merge branch 'main' of https://gitlab.com/thenextgreat/classroomio into CLASSROOMIO-T-195 CLASSROOMIO-T-195: Exercise Templates for JS Co-authored-by: Rotimi Best <[email protected]> Co-authored-by: Tunji Adeyemi <[email protected]> Merge-request: CLASSROOMIO-MR-92 Merged-by: Best Admin <[email protected]>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { HTML_IDS, HTML_TEMPLATES } from './html';
|
|
import { CSS_IDS, CSS_TEMPLATES } from './css';
|
|
import { calculateTotalPoints, shuffleOptions } from './utils';
|
|
import type { ExerciseTemplate } from '$lib/utils/types';
|
|
import { JS_IDS, JS_TEMPLATES } from './js';
|
|
|
|
export const TAGS = {
|
|
HTML: 'HTML',
|
|
CSS: 'CSS',
|
|
JS: 'JS',
|
|
Typescript: 'Typescript',
|
|
ReactJS: 'ReactJS',
|
|
VueJS: 'VueJS'
|
|
};
|
|
|
|
function generateTemplateForTag(
|
|
keys: { [key: string]: string },
|
|
templates: {
|
|
[x: string]: ExerciseTemplate;
|
|
}
|
|
) {
|
|
const template = [];
|
|
|
|
for (const key in keys) {
|
|
const id = keys[key];
|
|
templates[id].questionnaire.questions = templates[id].questionnaire.questions.map((q) => {
|
|
q.options = shuffleOptions(q.options);
|
|
return q;
|
|
});
|
|
template.push({
|
|
id,
|
|
title: templates[id].title,
|
|
questions: templates[id].questionnaire.questions.length,
|
|
points: calculateTotalPoints(templates[id]),
|
|
data: templates[id]
|
|
});
|
|
}
|
|
|
|
return template;
|
|
}
|
|
|
|
export const TEMPLATES = {
|
|
[TAGS.HTML]: generateTemplateForTag(HTML_IDS, HTML_TEMPLATES),
|
|
[TAGS.CSS]: generateTemplateForTag(CSS_IDS, CSS_TEMPLATES),
|
|
[TAGS.JS]: generateTemplateForTag(JS_IDS, JS_TEMPLATES),
|
|
[TAGS.Typescript]: [],
|
|
[TAGS.ReactJS]: [],
|
|
[TAGS.VueJS]: []
|
|
};
|