Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"loadingprocess.min.js","sources":["../../../src/local/process_monitor/loadingprocess.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 * The process wrapper class.\n *\n * This module is used to update a process in the process monitor.\n *\n * @module     core/local/process_monitor/loadingprocess\n * @class      LoadingProcess\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';\n\nexport class LoadingProcess {\n\n    /** @var {Map} editorUpdates the courses pending to be updated. */\n    processData = null;\n\n    /** @var {Object} extraData any extra process information to store. */\n    extraData = null;\n\n    /** @var {ProcessMonitorManager} manager the page monitor. */\n    manager = null;\n\n    /** @var {Function} finishedCallback the finished callback if any. */\n    finishedCallback = null;\n\n    /** @var {Function} removedCallback the removed callback if any. */\n    removedCallback = null;\n\n    /** @var {Function} errorCallback the error callback if any. */\n    errorCallback = null;\n\n    /**\n     * Class constructor\n     * @param {ProcessMonitorManager} manager the monitor manager\n     * @param {Object} definition the process definition data\n     */\n    constructor(manager, definition) {\n        this.manager = manager;\n        // Add defaults.\n        this.processData = {\n            id: manager.generateProcessId(),\n            name: '',\n            percentage: 0,\n            url: null,\n            error: null,\n            finished: false,\n            ...definition,\n        };\n        // Create a new entry.\n        this._dispatch('addProcess', this.processData);\n    }\n\n    /**\n     * Execute a monitor manager mutation when the state is ready.\n     *\n     * @private\n     * @param {String} action the mutation to dispatch\n     * @param {*} params the mutaiton params\n     */\n    _dispatch(action, params) {\n        this.manager.getInitialStatePromise().then(() => {\n            this.manager.dispatch(action, params);\n            return;\n        }).catch(() => {\n            log.error(`Cannot update process monitor.`);\n        });\n    }\n\n    /**\n     * Define a finished process callback function.\n     * @param {Function} callback the callback function\n     */\n    onFinish(callback) {\n        this.finishedCallback = callback;\n    }\n\n    /**\n     * Define a removed from monitor process callback function.\n     * @param {Function} callback the callback function\n     */\n    onRemove(callback) {\n        this.removedCallback = callback;\n    }\n\n    /**\n     * Define a error process callback function.\n     * @param {Function} callback the callback function\n     */\n    onError(callback) {\n        this.errorCallback = callback;\n    }\n\n    /**\n     * Set the process percentage.\n     * @param {Number} percentage\n     */\n    setPercentage(percentage) {\n        this.processData.percentage = percentage;\n        this._dispatch('updateProcess', this.processData);\n    }\n\n    /**\n     * Stores extra information to the process.\n     *\n     * This method is used to add information like the course, the user\n     * or any other needed information.\n     *\n     * @param {Object} extraData any extra process information to store\n     */\n    setExtraData(extraData) {\n        this.extraData = extraData;\n    }\n\n    /**\n     * Set the process error string.\n     *\n     * Note: set the error message will mark the process as finished.\n     *\n     * @param {String} error the string message\n     */\n    setError(error) {\n        this.processData.error = error;\n        if (this.errorCallback !== null) {\n            this.errorCallback(this);\n        }\n        this.processData.finished = true;\n        if (this.finishedCallback !== null) {\n            this.finishedCallback(this);\n        }\n        this._dispatch('updateProcess', this.processData);\n    }\n\n    /**\n     * Rename the process\n     * @param {String} name the new process name\n     */\n    setName(name) {\n        this.processData.name = name;\n        this._dispatch('updateProcess', this.processData);\n    }\n\n    /**\n     * Mark the process as finished.\n     */\n    finish() {\n        this.processData.finished = true;\n        if (this.finishedCallback !== null) {\n            this.finishedCallback(this);\n        }\n        this._dispatch('updateProcess', this.processData);\n    }\n\n    /**\n     * Remove the process from the monitor.\n     */\n    remove() {\n        if (this.removedCallback !== null) {\n            this.removedCallback(this);\n        }\n        this._dispatch('removeProcess', this.processData.id);\n    }\n\n    /**\n     * Returns the current rpocess data.\n     * @returns {Object} the process data\n     */\n    getData() {\n        return {...this.processData};\n    }\n\n    /**\n     * Return the process name\n     * @return {String}\n     */\n    get name() {\n        return this.processData.name;\n    }\n\n    /**\n     * Return the process internal id\n     * @return {Number}\n     */\n    get id() {\n        return this.processData.id;\n    }\n\n    /**\n     * Return the process extra data.\n     * @return {*} whatever is in extra data\n     */\n    get data() {\n        return this.extraData;\n    }\n}\n"],"names":["constructor","manager","definition","processData","id","generateProcessId","name","percentage","url","error","finished","_dispatch","this","action","params","getInitialStatePromise","then","dispatch","catch","onFinish","callback","finishedCallback","onRemove","removedCallback","onError","errorCallback","setPercentage","setExtraData","extraData","setError","setName","finish","remove","getData","data"],"mappings":"sbAqDIA,YAAYC,QAASC,+CAtBP,uCAGF,qCAGF,8CAGS,6CAGD,2CAGF,WAQPD,QAAUA,aAEVE,YAAc,CACfC,GAAIH,QAAQI,oBACZC,KAAM,GACNC,WAAY,EACZC,IAAK,KACLC,MAAO,KACPC,UAAU,KACPR,iBAGFS,UAAU,aAAcC,KAAKT,aAUtCQ,UAAUE,OAAQC,aACTb,QAAQc,yBAAyBC,MAAK,UAClCf,QAAQgB,SAASJ,OAAQC,WAE/BI,OAAM,kBACDT,2CAQZU,SAASC,eACAC,iBAAmBD,SAO5BE,SAASF,eACAG,gBAAkBH,SAO3BI,QAAQJ,eACCK,cAAgBL,SAOzBM,cAAcnB,iBACLJ,YAAYI,WAAaA,gBACzBI,UAAU,gBAAiBC,KAAKT,aAWzCwB,aAAaC,gBACJA,UAAYA,UAUrBC,SAASpB,YACAN,YAAYM,MAAQA,MACE,OAAvBG,KAAKa,oBACAA,cAAcb,WAElBT,YAAYO,UAAW,EACE,OAA1BE,KAAKS,uBACAA,iBAAiBT,WAErBD,UAAU,gBAAiBC,KAAKT,aAOzC2B,QAAQxB,WACCH,YAAYG,KAAOA,UACnBK,UAAU,gBAAiBC,KAAKT,aAMzC4B,cACS5B,YAAYO,UAAW,EACE,OAA1BE,KAAKS,uBACAA,iBAAiBT,WAErBD,UAAU,gBAAiBC,KAAKT,aAMzC6B,SACiC,OAAzBpB,KAAKW,sBACAA,gBAAgBX,WAEpBD,UAAU,gBAAiBC,KAAKT,YAAYC,IAOrD6B,gBACW,IAAIrB,KAAKT,aAOhBG,kBACOM,KAAKT,YAAYG,KAOxBF,gBACOQ,KAAKT,YAAYC,GAOxB8B,kBACOtB,KAAKgB"}