AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"stored_progress.min.js","sources":["../src/stored_progress.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 * Script to update stored_progress progress bars on the screen.\n *\n * @module core/stored_progress\n * @copyright 2023 onwards Catalyst IT {@link http://www.catalyst-eu.net/}\n * @license http://www.gnu.o
rg/copyleft/gpl.html GNU GPL v3 or later\n * @author Conn Warwicker <conn.warwicker@catalyst-eu.net>\n */\n\n/* global updateProgressBar */\n\nimport * as Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\n/**\n * @var bool This AMD script is loaded multiple times, for each progress bar on a page.\n * So this stops it running multiple times.\n * */\nvar STORED_PROGRESS_LOADED = false;\n\n/**\n * Poll a given stored progress record.\n *\n * @param {array} ids\n * @param {integer} timeout\n */\nfunction poll(ids, timeout) {\n\n // Call AJAX request.\n let promise = Ajax.call([{\n methodname: 'core_output_poll_stored_progress', args: {'ids': ids}\n }]);\n\n let repollids = [];\n\n // When AJAX request returns, handle the results.\n promise[0].then(function(results) {\n\n results.forEach(function(data) {\n\n // Update the progress bar percentage and message using the core method from the javascript-static.js.\n updateProgressBar(data
.uniqueid, data.progress, data.message, data.estimated, data.error);\n\n // Add the bar for re-polling if it's not completed.\n if (data.progress < 100 && !data.error) {\n repollids.push(data.id);\n }\n\n // If a different timeout came back from the script, use that instead.\n if (data.timeout && data.timeout > 0) {\n timeout = data.timeout;\n }\n\n });\n\n // If we still want to poll any of them, do it again.\n if (repollids.length > 0) {\n return setTimeout(() => poll(repollids, timeout), timeout * 1000);\n }\n\n return false;\n\n }).catch(Notification.exception);\n\n}\n\n/**\n * Initialise the polling process.\n *\n * @param {integer} timeout Timeout to use (seconds).\n */\nexport const init = (timeout) => {\n\n if (STORED_PROGRESS_LOADED === false) {\n\n let ids = [];\n\n // Find any stored progress bars we want to poll.\n document.queryS
electorAll('.stored-progress-bar').forEach(el => {\n\n // Get its id and add to array.\n let id = el.dataset.recordid;\n ids.push(id);\n\n });\n\n // Poll for updates from these IDs.\n poll(ids, timeout);\n\n // Script has run, we don't want it to run again.\n STORED_PROGRESS_LOADED = true;\n\n }\n\n};"],"names":["STORED_PROGRESS_LOADED","poll","ids","timeout","promise","Ajax","call","methodname","args","repollids","then","results","forEach","data","updateProgressBar","uniqueid","progress","message","estimated","error","push","id","length","setTimeout","catch","Notification","exception","document","querySelectorAll","el","dataset","recordid"],"mappings":";;;;;;;;oFAiCIA,wBAAyB,WAQpBC,KAAKC,IAAKC,aAGXC,QAAUC,KAAKC,KAAK,CAAC,CACrBC,WAAY,mCAAoCC,KAAM,KAAQN,QAG9DO,UAAY,GAGhBL,QAAQ,GAAGM,MAAK,SAASC,gBAErBA,QAAQC,SAAQ,SAASC,MAGrBC,kBAAkBD,KAAKE,SAAUF,KAAKG,SAAUH,KAAKI,QAASJ,KAAKK,UAAWL,KAAKM,OAG/EN,KAAKG,SAAW,MAAQH,KAAKM,OAC7BV,UAAUW,KAAKP,KAAK
Q,IAIpBR,KAAKV,SAAWU,KAAKV,QAAU,IAC/BA,QAAUU,KAAKV,YAMnBM,UAAUa,OAAS,GACZC,YAAW,IAAMtB,KAAKQ,UAAWN,UAAoB,IAAVA,YAKvDqB,MAAMC,sBAAaC,yBASLvB,cAEc,IAA3BH,uBAAkC,KAE9BE,IAAM,GAGVyB,SAASC,iBAAiB,wBAAwBhB,SAAQiB,SAGlDR,GAAKQ,GAAGC,QAAQC,SACpB7B,IAAIkB,KAAKC,OAKbpB,KAAKC,IAAKC,SAGVH,wBAAyB"}