{"version":3,"file":"placeholder.min.js","sources":["https:\/\/moodle.tau.ac.il\/2023\/course\/format\/multitopic\/amd\/src\/courseformat\/courseindex\/placeholder.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 .\n\n\/**\n * Course index placeholder replacer.\n *\n * @module format_multitopic\/courseformat\/courseindex\/placeholder\n * @class format_multitopic\/courseformat\/courseindex\/placeholder\n * @copyright 2022 James Calder and Otago Polytechnic\n * @copyright 2022 Jeremy FitzPatrick and Te W\u0101nanga o Aotearoa\n * @copyright based on work by 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport BaseComponent from 'core_courseformat\/local\/courseindex\/placeholder';\nimport Templates from 'core\/templates';\nimport {getCurrentCourseEditor} from 'core_courseformat\/courseeditor';\n\nexport default class Component extends BaseComponent {\n\n \/**\n * Static method to create a component instance form the mustache template.\n *\n * @param {element|string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @return {Component}\n *\/\n static init(target, selectors) {\n return new this({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n });\n }\n\n \/**\n * Load the course index template.\n *\n * @param {Object} state the initial state\n *\/\n async loadTemplateContent(state) {\n \/\/ Collect section information from the state.\n const exporter = this.reactive.getExporter();\n const data = exporter.course(state);\n data.sectionsnested = this._nestSections(data.sections);\n try {\n \/\/ To render an HTML into our component we just use the regular Templates module.\n const {html, js} = await Templates.renderForPromise(\n 'format_multitopic\/courseformat\/courseindex\/courseindex', \/\/ CHANGED.\n data,\n );\n Templates.replaceNode(this.element, html, js);\n this.pendingContent.resolve();\n\n \/\/ Save the rendered template into the session cache.\n this.reactive.setStorageValue(`courseIndex`, {html, js});\n } catch (error) {\n this.pendingContent.resolve(error);\n throw error;\n }\n }\n\n \/**\n * Nest sections.\n *\n * @param {Array} sections\n * @return {Array}\n *\/\n _nestSections(sections) {\n let topSections = [];\n let parentSection = {};\n let lastParent = {};\n\n \/\/ Let's re-organise our sections.\n for (let i = 0; i < sections.length; i++) {\n let section = sections[i];\n section.subsections = [];\n section.topics = [];\n if (section.indent === 0) {\n parentSection = section;\n lastParent = section;\n topSections.push(section);\n } else if (section.indent === 1) {\n lastParent = section;\n parentSection.subsections.push(section);\n } else if (section.indent === 2) {\n lastParent.topics.push(section);\n }\n }\n return topSections;\n }\n}\n"],"names":["Component","BaseComponent","target","selectors","this","element","document","getElementById","reactive","state","data","getExporter","course","sectionsnested","_nestSections","sections","html","js","Templates","renderForPromise","replaceNode","pendingContent","resolve","setStorageValue","error","topSections","parentSection","lastParent","i","length","section","subsections","topics","indent","push"],"mappings":";;;;;;;;;;2LA8BqBA,kBAAkBC,iCASvBC,OAAQC,kBACT,IAAIC,KAAK,CACZC,QAASC,SAASC,eAAeL,QACjCM,UAAU,0CACVL,UAAAA,sCASkBM,aAGhBC,KADWN,KAAKI,SAASG,cACTC,OAAOH,OAC7BC,KAAKG,eAAiBT,KAAKU,cAAcJ,KAAKK,oBAGpCC,KAACA,KAADC,GAAOA,UAAYC,mBAAUC,iBAC\/B,yDACAT,yBAEMU,YAAYhB,KAAKC,QAASW,KAAMC,SACrCI,eAAeC,eAGfd,SAASe,8BAA+B,CAACP,KAAAA,KAAMC,GAAAA,KACtD,MAAOO,kBACAH,eAAeC,QAAQE,OACtBA,OAUdV,cAAcC,cACNU,YAAc,GACdC,cAAgB,GAChBC,WAAa,OAGZ,IAAIC,EAAI,EAAGA,EAAIb,SAASc,OAAQD,IAAK,KAClCE,QAAUf,SAASa,GACvBE,QAAQC,YAAc,GACtBD,QAAQE,OAAS,GACM,IAAnBF,QAAQG,QACRP,cAAgBI,QAChBH,WAAaG,QACbL,YAAYS,KAAKJ,UACS,IAAnBA,QAAQG,QACfN,WAAaG,QACbJ,cAAcK,YAAYG,KAAKJ,UACL,IAAnBA,QAAQG,QACfN,WAAWK,OAAOE,KAAKJ,gBAGxBL"}