Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
4.0 kB
2
Indexable
Never
async function renderKlasowkiTask(task, taskIndex, groupIndex) {
    console.log(task);
    console.log(taskIndex);

    let containerTask = document.createElement('div');
    containerTask.className = "container_tasks";

    let { spaceUnderTask, maxPoints } = task.metadata;

    let header = document.createElement('h1');
    header.className = 'numb_exer_title';

    if (pointsInTasks) {
        let spanPoints = document.createElement('span');
        spanPoints.className = "points_block";
        spanPoints.textContent = maxPoints + ' p.';
        header.append(spanPoints);
    }

    header.insertAdjacentText('beforeend', 'Zadanie ' + (taskIndex + 1) + '.');


    containerTask.append(header);

    let div = document.createElement('div');
    div.setAttribute('data-index', taskIndex);
    div.setAttribute('data-code', task.code);

    containerTask.append(div);

    if ((spaceUnderTasks && spaceUnderTask) || task.spaceUnderTaskCustom) {
        spaceUnderTask = spaceUnderTasks ? spaceUnderTask : task.spaceUnderTaskCustom;
        let nameOfImage = "space_under_" + spaceUnderTask;
        let fillField = document.createElement('img');
        fillField.src = imagesMap[nameOfImage];
        fillField.className = "fill_field";
        containerTask.append(fillField);
    }

    groupTasks[groupIndex].append(containerTask);

    let initModuleParams = {};

    if (task.initModuleParams !== undefined) {
        initModuleParams = task.initModuleParams;
    }

    console.log("ZACZYNAM INIT");

    let module = await moduleLoader.initModule(
        task.manifest,
        window.BASE_PATH + task.path,
        div,
        Object.assign({
            locale: 'pl',
            contrastMode: getContrastModeName(0),
            showAnswers: true,
            isLoggedIn: false,
            generatingPrintPdf: false,
            supportInlineTex: true,
            xssAllowTags: ['iframe'],
            xssAllowAttribs: ['style', 'data-action'],
            showCoordinatesEditorTab: true,
            XofYRequireAnswerError: true,
            XofYQuestionScore: true,
            XofYAutonumber: true,
            systemSettings: {
                showCoordinatesEditorTab: true,
                XofYRequireAnswerError: true,
                XofYQuestionScore: true,
                XofYAutonumber: true,
                supportInlineTex: true,
                xssAllowTags: ['iframe'],
                xssAllowAttribs: ['style', 'data-action'],
            },
        }, initModuleParams),
        storageId
    );

    console.log("KONCZE INIT");

    console.log("ZACZYNAM RENDERQ");
    await module.waitReady();

    console.log('Module has been loaded', module);
    await module.resize();

    if (module.canGenerateAnswer()) {
        const blockAnswer = document.getElementById("answer_" + groupIndex + "_" + taskIndex);
        await module.generateAnswer(blockAnswer);
    }

    if (module.canGenerateAnswerEvaluationSchema()) {
        const blockEvaluation = document.getElementById("evaluation_schema_" + groupIndex + "_" + taskIndex);
        await module.generateAnswerEvaluationSchema(blockEvaluation);
    }

    console.log("KONCZE RENDERQ");

};


Promise.all(
    window.TASKS_DATA.map((taskGroup, j) => {

        return Promise.all(taskGroup.map((task, i) => {
            switch (task.type) {
                case taskTypes.klasowki_task:
                    return renderKlasowkiTask(task, i, j);
                    break;
                case taskTypes.custom_task:
                    return renderCustomTask(task, i, j);
                    break;
            }
        }));
    })

).then(() => {
    console.log("MATH TYPESET");
    return window.MathJax.typesetPromise()
}).then(() => {
    console.log("MATH TYPESET FINISH");
}).finally(() => {
    console.log("FINNALY");
    window.ALL_TASKS_READY = true;
});