Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.3 kB
1
Indexable
Never
let 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;
    }

    return 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
    ).then((module) => {
        return module.waitReady();
    }).then(() => {

        // TUTAJ JUZ NIE MAM KONTEKSTU MODULE I NIE MOGĘ GO UŻYĆ


        console.log(module);
        console.log(habababa);
        console.log(this.module);

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

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

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

        return Promise.all([generateAnswerProm, generateEvaluationProm]);
    });
};


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;
});