{"version":3,"file":"exporter.min.js","sources":["https:\/\/moodle-test3.univ-paris1.fr\/course\/format\/amd\/src\/local\/courseeditor\/exporter.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 * A configuration to provide to the modal.\n *\n * @typedef {Object} courseItem\n *\n * @property {String} type The type of element (section, cm).\n * @property {Number} id Element ID.\n * @property {String} url Element URL.\n *\/\n\n\/**\n * Module to export parts of the state and transform them to be used in templates\n * and as draggable data.\n *\n * @module core_courseformat\/local\/courseeditor\/exporter\n * @class core_courseformat\/local\/courseeditor\/exporter\n * @copyright 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\nexport default class {\n\n \/**\n * Class constructor.\n *\n * @param {CourseEditor} reactive the course editor object\n *\/\n constructor(reactive) {\n this.reactive = reactive;\n\n \/\/ Completions states are defined in lib\/completionlib.php. There are 4 different completion\n \/\/ state values, however, the course index uses the same state for complete and complete_pass.\n \/\/ This is the reason why completed appears twice in the array.\n this.COMPLETIONS = ['incomplete', 'complete', 'complete', 'fail'];\n }\n\n \/**\n * Generate the course export data from the state.\n *\n * @param {Object} state the current state.\n * @returns {Object}\n *\/\n course(state) {\n \/\/ Collect section information from the state.\n const data = {\n sections: [],\n editmode: this.reactive.isEditing,\n highlighted: state.course.highlighted ?? '',\n };\n const sectionlist = this.listedSectionIds(state);\n sectionlist.forEach(sectionid => {\n const sectioninfo = state.section.get(sectionid) ?? {};\n const section = this.section(state, sectioninfo);\n data.sections.push(section);\n });\n data.hassections = (data.sections.length != 0);\n\n return data;\n }\n\n \/**\n * Get the IDs of the sections that are listed as regular sections.\n * @param {Object} state the current state.\n * @returns {Number[]} the list of section ids that are listed.\n *\/\n listedSectionIds(state) {\n const fullSectionList = state.course.sectionlist ?? [];\n return fullSectionList.filter(sectionid => {\n const sectioninfo = state.section.get(sectionid) ?? {};\n \/\/ Delegated sections (controlled by a component) are not listed in course.\n return sectioninfo.component === null;\n });\n }\n\n \/**\n * Generate a section export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} sectioninfo the section state data.\n * @returns {Object}\n *\/\n section(state, sectioninfo) {\n const section = {\n ...sectioninfo,\n highlighted: state.course.highlighted ?? '',\n cms: [],\n };\n const cmlist = sectioninfo.cmlist ?? [];\n cmlist.forEach(cmid => {\n const cminfo = state.cm.get(cmid);\n const cm = this.cm(state, cminfo);\n section.cms.push(cm);\n });\n section.hascms = (section.cms.length != 0);\n\n return section;\n }\n\n \/**\n * Generate a cm export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} cminfo the course module state data.\n * @returns {Object}\n *\/\n cm(state, cminfo) {\n const cm = {\n ...cminfo,\n isactive: false,\n sectioninfo: false, \/\/ Init to false to prevent mustache recursion loops.\n };\n if (cminfo.hasdelegatedsection) {\n const sectioninfo = state.section.get(cminfo.delegatesectionid);\n cm.sectioninfo = this.section(state, sectioninfo);\n }\n return cm;\n }\n\n \/**\n * Generate a dragable cm data structure.\n *\n * This method is used by any draggable course module element to generate drop data\n * for its reactive\/dragdrop instance.\n *\n * @param {*} state the state object\n * @param {*} cmid the cours emodule id\n * @returns {Object|null}\n *\/\n cmDraggableData(state, cmid) {\n const cminfo = state.cm.get(cmid);\n if (!cminfo) {\n return null;\n }\n\n \/\/ Drop an activity over the next activity is the same as doing anything.\n let nextcmid;\n const section = state.section.get(cminfo.sectionid);\n const currentindex = section?.cmlist.indexOf(cminfo.id);\n if (currentindex !== undefined) {\n nextcmid = section?.cmlist[currentindex + 1];\n }\n\n return {\n type: 'cm',\n id: cminfo.id,\n name: cminfo.name,\n sectionid: cminfo.sectionid,\n hasdelegatedsection: cminfo.hasdelegatedsection,\n nextcmid,\n };\n }\n\n \/**\n * Generate a dragable cm data structure.\n *\n * This method is used by any draggable section element to generate drop data\n * for its reactive\/dragdrop instance.\n *\n * @param {*} state the state object\n * @param {*} sectionid the cours section id\n * @returns {Object|null}\n *\/\n sectionDraggableData(state, sectionid) {\n const sectioninfo = state.section.get(sectionid);\n if (!sectioninfo) {\n return null;\n }\n return {\n type: 'section',\n id: sectioninfo.id,\n name: sectioninfo.name,\n number: sectioninfo.number,\n };\n }\n\n \/**\n * Generate a file draggable structure.\n *\n * This method is used when files are dragged on the browser.\n *\n * @param {*} state the state object\n * @param {*} dataTransfer the current data tranfer data\n * @returns {Object|null}\n *\/\n fileDraggableData(state, dataTransfer) {\n const files = [];\n \/\/ Browsers do not provide the file list until the drop event.\n if (dataTransfer.files?.length > 0) {\n dataTransfer.files.forEach(file => {\n files.push(file);\n });\n }\n return {\n type: 'files',\n files,\n };\n }\n\n \/**\n * Generate a completion export data from the cm element.\n *\n * @param {Object} state the current state.\n * @param {Object} cminfo the course module state data.\n * @returns {Object}\n *\/\n cmCompletion(state, cminfo) {\n const data = {\n statename: '',\n state: 'NaN',\n };\n if (cminfo.completionstate !== undefined) {\n data.state = cminfo.completionstate;\n data.hasstate = true;\n let statename = this.COMPLETIONS[cminfo.completionstate] ?? 'NaN';\n if (cminfo.isoverallcomplete !== undefined && cminfo.isoverallcomplete === true) {\n statename = 'complete';\n }\n data[`is${statename}`] = true;\n }\n return data;\n }\n\n \/**\n * Return a sorted list of all sections and cms items in the state.\n *\n * @param {Object} state the current state.\n * @returns {courseItem[]} all sections and cms items in the state.\n *\/\n allItemsArray(state) {\n const items = [];\n const sectionlist = state.course.sectionlist ?? [];\n \/\/ Add sections.\n sectionlist.forEach(sectionid => {\n const sectioninfo = state.section.get(sectionid);\n \/\/ Skip delegated sections because components are responsible for them.\n if (sectioninfo.component !== null) {\n return;\n }\n\n items.push({\n type: 'section',\n id: sectioninfo.id,\n url: sectioninfo.sectionurl\n });\n \/\/ Add cms.\n const cmlist = sectioninfo.cmlist ?? [];\n cmlist.forEach(cmid => {\n const cmInfo = state.cm.get(cmid);\n items.push(...this.cmItemsArray(state, cmInfo));\n });\n });\n return items;\n }\n\n \/**\n * Return a list of all items associated with an activity.\n *\n * @private\n * @param {Object} state the full current state.\n * @param {Object} cmInfo the course module state data.\n * @return {courseItem[]} the items array associated with that cm.\n *\/\n cmItemsArray(state, cmInfo) {\n \/\/ Activities with delegated sections are exported as sections.\n if (cmInfo.hasdelegatedsection) {\n const items = [];\n const delegatedsection = state.section.get(cmInfo.delegatesectionid);\n items.push({\n type: 'section',\n id: delegatedsection.id,\n url: delegatedsection.sectionurl\n });\n const delegatedCmlist = delegatedsection.cmlist ?? [];\n delegatedCmlist.forEach(cmid => {\n const cmInfo = state.cm.get(cmid);\n items.push({\n type: 'cm',\n id: cmInfo.id,\n url: cmInfo.url\n });\n });\n return items;\n }\n\n return [\n {type: 'cm', id: cmInfo.id, url: cmInfo.url},\n ];\n }\n\n \/**\n * Check is some activities of a list can be stealth.\n *\n * @param {Object} state the current state.\n * @param {Number[]} cmIds the module ids to check\n * @returns {Boolean} if any of the activities can be stealth.\n *\/\n canUseStealth(state, cmIds) {\n return cmIds.some(cmId => {\n const cminfo = state.cm.get(cmId);\n return cminfo?.allowstealth ?? false;\n });\n }\n}\n"],"names":["constructor","reactive","COMPLETIONS","course","state","data","sections","editmode","this","isEditing","highlighted","listedSectionIds","forEach","sectionid","sectioninfo","section","get","push","hassections","length","sectionlist","filter","component","cms","cmlist","cmid","cminfo","cm","hascms","isactive","hasdelegatedsection","delegatesectionid","cmDraggableData","nextcmid","currentindex","indexOf","id","undefined","type","name","sectionDraggableData","number","fileDraggableData","dataTransfer","files","file","cmCompletion","statename","completionstate","hasstate","isoverallcomplete","allItemsArray","items","url","sectionurl","cmInfo","cmItemsArray","delegatedsection","canUseStealth","cmIds","some","cmId","allowstealth"],"mappings":";;;;;;;;;;MAyCIA,YAAYC,eACHA,SAAWA,cAKXC,YAAc,CAAC,aAAc,WAAY,WAAY,QAS9DC,OAAOC,uCAEGC,KAAO,CACTC,SAAU,GACVC,SAAUC,KAAKP,SAASQ,UACxBC,0CAAaN,MAAMD,OAAOO,mEAAe,WAEzBF,KAAKG,iBAAiBP,OAC9BQ,SAAQC,yCACVC,uCAAcV,MAAMW,QAAQC,IAAIH,4DAAc,GAC9CE,QAAUP,KAAKO,QAAQX,MAAOU,aACpCT,KAAKC,SAASW,KAAKF,YAEvBV,KAAKa,YAAuC,GAAxBb,KAAKC,SAASa,OAE3Bd,KAQXM,iBAAiBP,sEACWA,MAAMD,OAAOiB,mEAAe,IAC7BC,QAAOR,2CAGO,oCAFbT,MAAMW,QAAQC,IAAIH,8DAAc,IAEjCS,aAW3BP,QAAQX,MAAOU,kEACLC,QAAU,IACTD,YACHJ,2CAAaN,MAAMD,OAAOO,qEAAe,GACzCa,IAAK,uCAEMT,YAAYU,0DAAU,IAC9BZ,SAAQa,aACLC,OAAStB,MAAMuB,GAAGX,IAAIS,MACtBE,GAAKnB,KAAKmB,GAAGvB,MAAOsB,QAC1BX,QAAQQ,IAAIN,KAAKU,OAErBZ,QAAQa,OAAgC,GAAtBb,QAAQQ,IAAIJ,OAEvBJ,QAUXY,GAAGvB,MAAOsB,cACAC,GAAK,IACJD,OACHG,UAAU,EACVf,aAAa,MAEbY,OAAOI,oBAAqB,OACtBhB,YAAcV,MAAMW,QAAQC,IAAIU,OAAOK,mBAC7CJ,GAAGb,YAAcN,KAAKO,QAAQX,MAAOU,oBAElCa,GAaXK,gBAAgB5B,MAAOqB,YACbC,OAAStB,MAAMuB,GAAGX,IAAIS,UACvBC,cACM,SAIPO,eACElB,QAAUX,MAAMW,QAAQC,IAAIU,OAAOb,WACnCqB,aAAenB,MAAAA,e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