AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"process.min.js","sources":["../../../src/local/process_monitor/process.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 motnitor's process reactive component.\n *\n * @module core/local/process_monitor/process\n * @class core/local/process_monitor/process\n * @copyright 2022 Ferran Recio <ferran@m
oodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\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_process';\n // Default query selectors.\n this.selectors = {\n CLOSE: `[data-action=\"closeProcess\"]`,\n ERROR: `[data-for=\"error\"]`,\n PROGRESSBAR: `progress`,\n NAME: `[data-for=\"name\"]`,\n };\n // Default classes to toggle on refresh.\n this.classes = {\n HIDE: `d-none`,\n };\n this.id = this.element.dataset.id;\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} sel
ectors 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._refreshItem({state, element: state.queue.get(this.id)});\n this.addEventListener(this.getElement(this.selectors.CLOSE), 'click', this._removeProcess);\n }\n\n /**\n * Return the component watchers.\n *\n * @returns {Array} of watchers\n */\n getWatchers() {\n return [\n {watch: `queue[${this.id}]:updated`, handler: this._refreshItem},\n {watch: `queue[${this.id}]:deleted`, handler: this.remove},\n ];\n }\n\n /**\n * Create a monitor item.\n *\n * @param {object} args the watcher arguments\n * @param {object} arg
s.element the item state data\n */\n async _refreshItem({element}) {\n const name = this.getElement(this.selectors.NAME);\n name.innerHTML = element.name;\n\n const progressbar = this.getElement(this.selectors.PROGRESSBAR);\n progressbar.classList.toggle(this.classes.HIDE, element.finished);\n progressbar.value = element.percentage;\n\n const close = this.getElement(this.selectors.CLOSE);\n close.classList.toggle(this.classes.HIDE, !element.error);\n\n const error = this.getElement(this.selectors.ERROR);\n error.innerHTML = element.error;\n error.classList.toggle(this.classes.HIDE, !element.error);\n }\n\n /**\n * Close the process.\n */\n _removeProcess() {\n this.reactive.dispatch('removeProcess', this.id);\n }\n}\n"],"names":["BaseComponent","create","name","selectors","CLOSE","ERROR","PROGRESSBAR","NAME","classes","HIDE","id","this","element","dataset","query","document","querySelector","reactive","man
ager","stateReady","state","_refreshItem","queue","get","addEventListener","getElement","_removeProcess","getWatchers","watch","handler","remove","innerHTML","progressbar","classList","toggle","finished","value","percentage","error","dispatch"],"mappings":";;;;;;;;;uBA2B6BA,wBAKzBC,cAESC,KAAO,+BAEPC,UAAY,CACbC,qCACAC,2BACAC,uBACAC,+BAGCC,QAAU,CACXC,oBAECC,GAAKC,KAAKC,QAAQC,QAAQH,eAUvBI,MAAOX,kBACR,IAAIQ,KAAK,CACZC,QAASG,SAASC,cAAcF,OAChCG,SAAUC,iBACVf,UAAAA,YASRgB,WAAWC,YACFC,aAAa,CAACD,MAAAA,MAAOR,QAASQ,MAAME,MAAMC,IAAIZ,KAAKD,WACnDc,iBAAiBb,KAAKc,WAAWd,KAAKR,UAAUC,OAAQ,QAASO,KAAKe,gBAQ/EC,oBACW,CACH,CAACC,sBAAgBjB,KAAKD,gBAAemB,QAASlB,KAAKU,cACnD,CAACO,sBAAgBjB,KAAKD,gBAAemB,QAASlB,KAAKmB,sCAUxClB,QAACA,cACHD,KAAKc,WAAWd,KAAKR,UAAUI,MACvCwB,UAAYnB,QAAQV,WAEnB8B,YAAcrB,KAAKc,WAAWd,KAAKR,UAAUG,aACnD0B,YAAYC,UAAUC,OAAOvB,KAAKH,QAAQC,KAAMG,QAAQuB,UACxDH,YAAYI,MAAQxB,QAAQyB,WAEd1B,KAAKc,WAAWd,KAAKR,UAAUC,OACvC6B,UAAUC,OAAOvB,KAAKH,QAAQC,MAAOG,QAAQ0B,aAE7CA,MAAQ3B,KAAKc,WAAWd,KAAKR,UAAUE,OAC7CiC,MAAMP,UAAYnB,QAA
Q0B,MAC1BA,MAAML,UAAUC,OAAOvB,KAAKH,QAAQC,MAAOG,QAAQ0B,OAMvDZ,sBACST,SAASsB,SAAS,gBAAiB5B,KAAKD"}