Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"process_monitor.min.js","sources":["../src/process_monitor.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Process monitor includer.\n *\n * @module     core/process_monitor\n * @copyright  2022 Ferran Recio <ferran@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport log from 'core/log';\nimport {manager} from 'core/local/process_monitor/manager';\nimport {LoadingProcess} from 'core/local/process_monitor/loadingprocess';\nimport {ProcessQueue} from 'core/local/process_monitor/processqueue';\nimport Templates from 'core/templates';\n\nlet initialized = false;\n\n/**\n * Get the parent container.\n * @private\n * @return {HTMLelement} the process monitor container.\n */\nconst getParentContainer = () => {\n    // The footer pop over depends on the theme.\n    return document.querySelector(`#page`) ?? document.body;\n};\n\nexport const processMonitor = {\n    /**\n     * Adds a new process to the monitor.\n     * @param {Object} definition the process definition\n     * @param {String} definition.name the process name\n     * @param {Number} definition.percentage the current percentage (0 - 100)\n     * @param {String} definition.error the error message if any\n     * @param {String} definition.url possible link url if any\n     * @returns {LoadingProcess} the loading process\n     */\n    addLoadingProcess: function(definition) {\n        this.initProcessMonitor();\n        const process = new LoadingProcess(manager, definition);\n        return process;\n    },\n\n    /**\n     * Remove all processes form the current monitor.\n     */\n    removeAllProcesses: function() {\n        manager.getInitialStatePromise().then(() => {\n            manager.dispatch('removeAllProcesses');\n            return;\n        }).catch(() => {\n            log.error(`Cannot update process monitor.`);\n        });\n    },\n\n    /**\n     * Initialize the process monitor.\n     */\n    initProcessMonitor: async function() {\n        if (initialized) {\n            return;\n        }\n        initialized = true;\n        const container = getParentContainer();\n        if (document.getElementById(`#processMonitor`)) {\n            return;\n        }\n        try {\n            const {html, js} = await Templates.renderForPromise('core/local/process_monitor/monitor', {});\n            Templates.appendNodeContents(container, html, js);\n        } catch (error) {\n            log.error(`Cannot load the process monitor`);\n        }\n    },\n\n    /**\n     * Return the process monitor initial state promise.\n     * @returns {Promise} Promise of the initial state fully loaded\n     */\n    getInitialStatePromise: function() {\n        return manager.getInitialStatePromise();\n    },\n\n    /**\n     * Load the load queue monitor.\n     *\n     * @return {Promise<ProcessQueue>} when the file uploader is ready to be used.\n     */\n    createProcessQueue: async function() {\n        processMonitor.initProcessMonitor();\n        const processQueue = new ProcessQueue(manager);\n        await processMonitor.getInitialStatePromise();\n        return processQueue;\n    }\n};\n"],"names":["initialized","processMonitor","addLoadingProcess","definition","initProcessMonitor","LoadingProcess","manager","removeAllProcesses","getInitialStatePromise","then","dispatch","catch","error","async","container","document","querySelector","body","getElementById","html","js","Templates","renderForPromise","appendNodeContents","createProcessQueue","processQueue","ProcessQueue"],"mappings":";;;;;;;gLA6BIA,aAAc,QAYLC,eAAiB,CAU1BC,kBAAmB,SAASC,iBACnBC,4BACW,IAAIC,+BAAeC,iBAASH,aAOhDI,mBAAoB,4BACRC,yBAAyBC,MAAK,sBAC1BC,SAAS,yBAElBC,OAAM,kBACDC,4CAOZR,mBAAoBS,oBACZb,mBAGJA,aAAc,QACRc,wCAvCHC,SAASC,8EAA0BD,SAASE,KAF5B,8BA0CfF,SAASG,4CAIHC,KAACA,KAADC,GAAOA,UAAYC,mBAAUC,iBAAiB,qCAAsC,uBAChFC,mBAAmBT,UAAWK,KAAMC,IAChD,MAAOR,oBACDA,2CAQZJ,uBAAwB,kBACbF,iBAAQE,0BAQnBgB,mBAAoBX,iBAChBZ,eAAeG,2BACTqB,aAAe,IAAIC,2BAAapB,+BAChCL,eAAeO,yBACdiB"}