2023-10-04 08:18:33 +01:00
|
|
|
import { HTML_IDS, HTML_TEMPLATES } from './html';
|
2023-10-07 02:14:51 +00:00
|
|
|
import { CSS_IDS, CSS_TEMPLATES } from './css';
|
2023-10-07 05:27:11 +00:00
|
|
|
import { calculateTotalPoints, shuffleOptions } from './utils';
|
2023-10-06 09:06:03 +00:00
|
|
|
import type { ExerciseTemplate } from '$lib/utils/types';
|
2023-10-07 05:27:11 +00:00
|
|
|
import { JS_IDS, JS_TEMPLATES } from './js';
|
2023-10-10 06:09:39 +00:00
|
|
|
import { NODE_IDS, NODE_TEMPLATES } from './node';
|
2023-10-09 16:23:16 +00:00
|
|
|
import { REACT_IDS, REACT_TEMPLATES } from './react';
|
2023-10-09 16:21:26 +00:00
|
|
|
import { TS_IDS, TS_TEMPLATES } from './typescript';
|
2023-10-10 06:39:23 +00:00
|
|
|
import { PHP_IDS, PHP_TEMPLATES } from './php';
|
2023-10-04 08:18:33 +01:00
|
|
|
|
|
|
|
|
export const TAGS = {
|
|
|
|
|
HTML: 'HTML',
|
|
|
|
|
CSS: 'CSS',
|
|
|
|
|
JS: 'JS',
|
|
|
|
|
Typescript: 'Typescript',
|
|
|
|
|
ReactJS: 'ReactJS',
|
2023-10-10 06:09:39 +00:00
|
|
|
VueJS: 'VueJS',
|
2023-10-10 06:39:23 +00:00
|
|
|
NodeJS: 'NodeJS',
|
|
|
|
|
PHP: 'PHP'
|
2023-10-04 08:18:33 +01:00
|
|
|
};
|
|
|
|
|
|
2023-10-06 09:06:03 +00:00
|
|
|
function generateTemplateForTag(
|
|
|
|
|
keys: { [key: string]: string },
|
|
|
|
|
templates: {
|
|
|
|
|
[x: string]: ExerciseTemplate;
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
const template = [];
|
|
|
|
|
|
|
|
|
|
for (const key in keys) {
|
|
|
|
|
const id = keys[key];
|
2023-10-07 05:27:11 +00:00
|
|
|
templates[id].questionnaire.questions = templates[id].questionnaire.questions.map((q) => {
|
|
|
|
|
q.options = shuffleOptions(q.options);
|
|
|
|
|
return q;
|
|
|
|
|
});
|
2023-10-06 09:06:03 +00:00
|
|
|
template.push({
|
|
|
|
|
id,
|
|
|
|
|
title: templates[id].title,
|
|
|
|
|
questions: templates[id].questionnaire.questions.length,
|
|
|
|
|
points: calculateTotalPoints(templates[id]),
|
|
|
|
|
data: templates[id]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return template;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 08:18:33 +01:00
|
|
|
export const TEMPLATES = {
|
2023-10-06 09:06:03 +00:00
|
|
|
[TAGS.HTML]: generateTemplateForTag(HTML_IDS, HTML_TEMPLATES),
|
2023-10-07 02:14:51 +00:00
|
|
|
[TAGS.CSS]: generateTemplateForTag(CSS_IDS, CSS_TEMPLATES),
|
2023-10-07 05:27:11 +00:00
|
|
|
[TAGS.JS]: generateTemplateForTag(JS_IDS, JS_TEMPLATES),
|
2023-10-09 16:21:26 +00:00
|
|
|
[TAGS.Typescript]: generateTemplateForTag(TS_IDS, TS_TEMPLATES),
|
2023-10-09 16:23:16 +00:00
|
|
|
[TAGS.ReactJS]: generateTemplateForTag(REACT_IDS, REACT_TEMPLATES),
|
2023-10-10 06:09:39 +00:00
|
|
|
[TAGS.VueJS]: [],
|
2023-10-10 06:39:23 +00:00
|
|
|
[TAGS.NodeJS]: generateTemplateForTag(NODE_IDS, NODE_TEMPLATES),
|
|
|
|
|
[TAGS.PHP]: generateTemplateForTag(PHP_IDS, PHP_TEMPLATES)
|
2023-10-04 08:18:33 +01:00
|
|
|
};
|