MDL-71113 js: Bare minimum fixes to build jsdoc
[moodle.git] / course / amd / build / local / courseeditor / mutations.min.js.map
CommitLineData
e6779782 1{"version":3,"sources":["../../../src/local/courseeditor/mutations.js"],"names":["action","courseId","ids","ajax","call","methodname","args","courseid","ajaxresult","JSON","parse","statemanager","cmids","state","_callEditWebservice","course","id","updates","setReadOnly","_processUpdates","sectionIds","forEach","update","name","Error","current","Map","get","fields","processUpdate"],"mappings":"wKAeA,uD,owBAsB8BA,C,CAAQC,C,CAAUC,C,wGACjBC,WAAKC,IAAL,CAAU,CAAC,CAC9BC,UAAU,CAAE,2BADkB,CAE9BC,IAAI,CAAE,CACFN,MAAM,CAANA,CADE,CAEFO,QAAQ,CAAEN,CAFR,CAGFC,GAAG,CAAHA,CAHE,CAFwB,CAAD,CAAV,EAOnB,CAPmB,C,QAAnBM,C,iCAQGC,IAAI,CAACC,KAAL,CAAWF,CAAX,C,kMAUGG,C,CAAcC,C,2FAClBC,C,CAAQF,CAAY,CAACE,K,gBACL,MAAKC,mBAAL,CAAyB,UAAzB,CAAqCD,CAAK,CAACE,MAAN,CAAaC,EAAlD,CAAsDJ,CAAtD,C,QAAhBK,C,QACNN,CAAY,CAACO,WAAb,KACA,KAAKC,eAAL,CAAqBR,CAArB,CAAmCM,CAAnC,E,8LAUeN,C,CAAcS,C,2FACvBP,C,CAAQF,CAAY,CAACE,K,gBACL,MAAKC,mBAAL,CAAyB,eAAzB,CAA0CD,CAAK,CAACE,MAAN,CAAaC,EAAvD,CAA2DI,CAA3D,C,QAAhBH,C,QACN,KAAKE,eAAL,CAAqBR,CAArB,CAAmCM,CAAnC,E,yKASYN,C,CAAcM,C,CAAS,CAEnC,GAAMJ,CAAAA,CAAK,CAAGF,CAAY,CAACE,KAA3B,CAEAF,CAAY,CAACO,WAAb,KAMAD,CAAO,CAACI,OAAR,CAAgB,SAACC,CAAD,CAAY,CACxB,GAAIA,CAAM,CAACC,IAAP,SAAJ,CAA+B,CAC3B,KAAMC,CAAAA,KAAK,CAAC,2BAAD,CACd,CAED,GAAIC,CAAAA,CAAO,CAAGZ,CAAK,CAACS,CAAM,CAACC,IAAR,CAAnB,CACA,GAAIE,CAAO,WAAYC,CAAAA,GAAvB,CAA4B,CACxBD,CAAO,CAAGZ,CAAK,CAACS,CAAM,CAACC,IAAR,CAAL,CAAmBI,GAAnB,CAAuBL,CAAM,CAACM,MAAP,CAAcZ,EAArC,CACb,CACD,GAAI,CAACS,CAAL,CAAc,CACVH,CAAM,CAACtB,MAAP,CAAgB,QACnB,CAEDW,CAAY,CAACkB,aAAb,CAA2BP,CAAM,CAACC,IAAlC,CAAwCD,CAAM,CAACtB,MAA/C,CAAuDsB,CAAM,CAACM,MAA9D,CACH,CAdD,EAgBAjB,CAAY,CAACO,WAAb,IACH,C","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\nimport ajax from 'core/ajax';\n\n/**\n * Default mutation manager\n *\n * @module core_course/local/courseeditor/mutations\n * @class core_course/local/courseeditor/mutations\n * @copyright 2021 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n\n // All course editor mutations for Moodle 4.0 will be located in this file.\n\n /**\n * Private method to call core_course_update_course webservice.\n *\n * @method _callEditWebservice\n * @param {string} action\n * @param {int} courseId\n * @param {array} ids\n */\n async _callEditWebservice(action, courseId, ids) {\n let ajaxresult = await ajax.call([{\n methodname: 'core_course_update_course',\n args: {\n action,\n courseid: courseId,\n ids,\n }\n }])[0];\n return JSON.parse(ajaxresult);\n }\n\n /**\n * Get updated state data related to some cm ids.\n *\n * @method cmState\n * @param {StateManager} statemanager the current state\n * @param {array} cmids the list of cm ids to update\n */\n async cmState(statemanager, cmids) {\n const state = statemanager.state;\n const updates = await this._callEditWebservice('cm_state', state.course.id, cmids);\n statemanager.setReadOnly(false);\n this._processUpdates(statemanager, updates);\n }\n\n /**\n * Get updated state data related to some section ids.\n *\n * @method sectionState\n * @param {StateManager} statemanager the current state\n * @param {array} sectionIds the list of section ids to update\n */\n async sectionState(statemanager, sectionIds) {\n const state = statemanager.state;\n const updates = await this._callEditWebservice('section_state', state.course.id, sectionIds);\n this._processUpdates(statemanager, updates);\n }\n\n /**\n * Helper to propcess both section_state and cm_state action results.\n *\n * @param {StateManager} statemanager the current state\n * @param {Array} updates of updates.\n */\n _processUpdates(statemanager, updates) {\n\n const state = statemanager.state;\n\n statemanager.setReadOnly(false);\n\n // The cm_state and section_state state action returns only updated states. However, most of the time we need this\n // mutation to fix discrepancies between the course content and the course state because core_course_edit_module\n // does not provide enough information to rebuild some state objects. This is the reason why we cannot use\n // the batch method processUpdates as the rest of mutations do.\n updates.forEach((update) => {\n if (update.name === undefined) {\n throw Error('Missing state update name');\n }\n // Compare the action with the current state.\n let current = state[update.name];\n if (current instanceof Map) {\n current = state[update.name].get(update.fields.id);\n }\n if (!current) {\n update.action = 'create';\n }\n\n statemanager.processUpdate(update.name, update.action, update.fields);\n });\n\n statemanager.setReadOnly(true);\n }\n}\n"],"file":"mutations.min.js"}