Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"monitor.min.js","sources":["../../../src/local/process_monitor/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 * The file upload monitor component.\n *\n * @module     core/local/process_monitor/monitor\n * @class      core/local/process_monitor/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 Templates from 'core/templates';\nimport {BaseComponent} from 'core/reactive';\nimport {manager} from 'core/local/process_monitor/manager';\n\nexport default class extends BaseComponent {\n\n    /**\n     * Constructor hook.\n     */\n    create() {\n        // Optional component name for debugging.\n        this.name = 'process_monitor';\n        // Default query selectors.\n        this.selectors = {\n            QUEUELIST: `[data-for=\"process-list\"]`,\n            CLOSE: `[data-action=\"hide\"]`,\n        };\n        // Default classes to toggle on refresh.\n        this.classes = {\n            HIDE: `d-none`,\n        };\n    }\n\n    /**\n     * Static method to create a component instance form the mustache template.\n     *\n     * @param {string} query the DOM main element query selector\n     * @param {object} selectors optional css selector overrides\n     * @return {this}\n     */\n    static init(query, selectors) {\n        return new this({\n            element: document.querySelector(query),\n            reactive: manager,\n            selectors,\n        });\n    }\n\n    /**\n     * Initial state ready method.\n     *\n     * @param {Object} state the initial state\n     */\n    stateReady(state) {\n        this._updateMonitor({state, element: state.display});\n        this.addEventListener(this.getElement(this.selectors.CLOSE), 'click', this._closeMonitor);\n        state.queue.forEach((element) => {\n            this._createListItem({state, element});\n        });\n    }\n\n    /**\n     * Return the component watchers.\n     *\n     * @returns {Array} of watchers\n     */\n    getWatchers() {\n        return [\n            // State changes that require to reload some course modules.\n            {watch: `queue:created`, handler: this._createListItem},\n            {watch: `display:updated`, handler: this._updateMonitor},\n        ];\n    }\n\n    /**\n     * Create a monitor item.\n     *\n     * @param {object} args the watcher arguments\n     * @param {object} args.element the item state data\n     */\n    async _createListItem({element}) {\n        const {html, js} = await Templates.renderForPromise(\n            'core/local/process_monitor/process',\n            {...element}\n        );\n        const target = this.getElement(this.selectors.QUEUELIST);\n        Templates.appendNodeContents(target, html, js);\n    }\n\n    /**\n     * Create a monitor item.\n     *\n     * @param {object} args the watcher arguments\n     * @param {object} args.element the display state data\n     */\n    _updateMonitor({element}) {\n        this.element.classList.toggle(this.classes.HIDE, element.show !== true);\n    }\n\n    /**\n     * Close the monitor.\n     */\n    _closeMonitor() {\n        this.reactive.dispatch('setShow', false);\n    }\n}\n"],"names":["BaseComponent","create","name","selectors","QUEUELIST","CLOSE","classes","HIDE","query","this","element","document","querySelector","reactive","manager","stateReady","state","_updateMonitor","display","addEventListener","getElement","_closeMonitor","queue","forEach","_createListItem","getWatchers","watch","handler","html","js","Templates","renderForPromise","target","appendNodeContents","classList","toggle","show","dispatch"],"mappings":";;;;;;;;0KA4B6BA,wBAKzBC,cAESC,KAAO,uBAEPC,UAAY,CACbC,sCACAC,mCAGCC,QAAU,CACXC,2BAWIC,MAAOL,kBACR,IAAIM,KAAK,CACZC,QAASC,SAASC,cAAcJ,OAChCK,SAAUC,iBACVX,UAAAA,YASRY,WAAWC,YACFC,eAAe,CAACD,MAAAA,MAAON,QAASM,MAAME,eACtCC,iBAAiBV,KAAKW,WAAWX,KAAKN,UAAUE,OAAQ,QAASI,KAAKY,eAC3EL,MAAMM,MAAMC,SAASb,eACZc,gBAAgB,CAACR,MAAAA,MAAON,QAAAA,aASrCe,oBACW,CAEH,CAACC,sBAAwBC,QAASlB,KAAKe,iBACvC,CAACE,wBAA0BC,QAASlB,KAAKQ,iDAU3BP,QAACA,oBACbkB,KAACA,KAADC,GAAOA,UAAYC,mBAAUC,iBAC/B,qCACA,IAAIrB,UAEFsB,OAASvB,KAAKW,WAAWX,KAAKN,UAAUC,8BACpC6B,mBAAmBD,OAAQJ,KAAMC,IAS/CZ,0BAAeP,QAACA,oBACPA,QAAQwB,UAAUC,OAAO1B,KAAKH,QAAQC,MAAuB,IAAjBG,QAAQ0B,MAM7Df,qBACSR,SAASwB,SAAS,WAAW"}