EvalueTonSavoir/client/src/components/GiftTemplate/templates/index.ts

90 lines
3.2 KiB
TypeScript
Raw Normal View History

2025-01-25 02:02:18 -05:00
2024-03-29 20:08:34 -04:00
import {
2025-01-25 02:02:18 -05:00
ParsedGIFTQuestion as GIFTQuestion,
// Category as CategoryType,
// Description as DescriptionType,
2025-01-25 02:02:18 -05:00
MultipleChoiceQuestion as MultipleChoiceType,
NumericalQuestion as NumericalType,
ShortAnswerQuestion as ShortAnswerType,
// EssayQuestion as EssayType,
2025-01-25 02:02:18 -05:00
TrueFalseQuestion as TrueFalseType,
// MatchingQuestion as MatchingType,
} from 'gift-pegjs';
import { DisplayOptions } from './types';
// import DescriptionTemplate from './DescriptionTemplate';
// import EssayTemplate from './EssayTemplate';
// import MatchingTemplate from './MatchingTemplate';
2025-01-25 02:02:18 -05:00
import MultipleChoiceTemplate from './MultipleChoiceTemplate';
import NumericalTemplate from './NumericalTemplate';
import ShortAnswerTemplate from './ShortAnswerTemplate';
import TrueFalseTemplate from './TrueFalseTemplate';
import Error from './ErrorTemplate';
// import CategoryTemplate from './CategoryTemplate';
export class UnsupportedQuestionTypeError extends globalThis.Error {
constructor(type: string) {
const userFriendlyType = (type === 'Essay') ? 'Réponse longue (Essay)'
: (type === 'Matching') ? 'Association (Matching)'
: (type === 'Category') ? 'Catégorie (Category)'
: type;
super(`Les questions du type ${userFriendlyType} ne sont pas supportées.`);
this.name = 'UnsupportedQuestionTypeError';
}
}
2024-03-29 20:08:34 -04:00
export const state: DisplayOptions = { preview: true, theme: 'light' };
export default function Template(
{ type, ...keys }: GIFTQuestion,
options?: Partial<DisplayOptions>
): string {
Object.assign(state, options);
switch (type) {
// Category, Description, Essay are not supported?
// case 'Category':
// return Category({ ...(keys as CategoryType) });
// case 'Description':
// return Description({
// ...(keys as DescriptionType)
// });
2024-03-29 20:08:34 -04:00
case 'MC':
2025-01-25 02:02:18 -05:00
return MultipleChoiceTemplate({
2024-03-29 20:08:34 -04:00
...(keys as MultipleChoiceType)
});
case 'Numerical':
2025-01-25 02:02:18 -05:00
return NumericalTemplate({ ...(keys as NumericalType) });
2024-03-29 20:08:34 -04:00
case 'Short':
2025-01-25 02:02:18 -05:00
return ShortAnswerTemplate({
2024-03-29 20:08:34 -04:00
...(keys as ShortAnswerType)
});
// case 'Essay':
// return Essay({ ...(keys as EssayType) });
2024-03-29 20:08:34 -04:00
case 'TF':
2025-01-25 02:02:18 -05:00
return TrueFalseTemplate({ ...(keys as TrueFalseType) });
// case 'Matching':
// return Matching({ ...(keys as MatchingType) });
2024-03-29 20:08:34 -04:00
default:
// convert type to human-readable string
throw new UnsupportedQuestionTypeError(type); }
2024-03-29 20:08:34 -04:00
}
export function ErrorTemplate(questionText: string, errorText: string, options?: Partial<DisplayOptions>): string {
2024-03-29 20:08:34 -04:00
Object.assign(state, options);
return Error(questionText, errorText);
2024-03-29 20:08:34 -04:00
}
export {
// CategoryTemplate,
// DescriptionTemplate as Description,
// EssayTemplate as Essay,
// MatchingTemplate as Matching,
2025-01-25 02:02:18 -05:00
MultipleChoiceTemplate as MultipleChoice,
NumericalTemplate as Numerical,
ShortAnswerTemplate as ShortAnswer,
TrueFalseTemplate as TrueFalse,
2024-03-29 20:08:34 -04:00
Error
};