mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-71863 courseformat: new course editor methods in courseeditor AMD
The module now exports a getCourseEditor and a getCurrentCourseEditor methods. The module is more consistent as it can be used to get other course than the current one.
This commit is contained in:
parent
934fd12ca8
commit
176bf81cb1
2
course/format/amd/build/courseeditor.min.js
vendored
2
course/format/amd/build/courseeditor.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("core_courseformat/courseeditor",["exports","core_courseformat/local/courseeditor/mutations","core_courseformat/local/courseeditor/courseeditor","core_course/events"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.courseEditor=void 0;b=e(b);c=e(c);d=e(d);function e(a){return a&&a.__esModule?a:{default:a}}function f(a,b){if(b===void 0){b=document}b.dispatchEvent(new CustomEvent(d.default.stateChanged,{bubbles:!0,detail:a}))}var g=new c.default({name:"CourseEditor",eventName:d.default.stateChanged,eventDispatch:f,mutations:new b.default});a.courseEditor=g;a.init=function init(a){g.loadCourse(a)}});
|
||||
define ("core_courseformat/courseeditor",["exports","core_courseformat/local/courseeditor/mutations","core_courseformat/local/courseeditor/courseeditor","core_course/events"],function(a,b,c,d){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.getCurrentCourseEditor=a.getCourseEditor=void 0;b=e(b);c=e(c);d=e(d);function e(a){return a&&a.__esModule?a:{default:a}}var g=new Map;function f(a,b){if(b===void 0){b=document}b.dispatchEvent(new CustomEvent(d.default.stateChanged,{bubbles:!0,detail:a}))}var h=function(a){a=parseInt(a);if(!g.has(a)){g.set(a,new c.default({name:"CourseEditor".concat(a),eventName:d.default.stateChanged,eventDispatch:f,mutations:new b.default}));g.get(a).loadCourse(a)}return g.get(a)};a.getCourseEditor=h;a.getCurrentCourseEditor=function getCurrentCourseEditor(){return h(M.cfg.courseId)}});
|
||||
//# sourceMappingURL=courseeditor.min.js.map
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"sources":["../src/courseeditor.js"],"names":["dispatchStateChangedEvent","detail","target","document","dispatchEvent","CustomEvent","events","stateChanged","bubbles","courseEditor","CourseEditor","name","eventName","eventDispatch","mutations","DefaultMutations","init","courseId","loadCourse"],"mappings":"4RAuBA,OACA,OACA,O,mDAYA,QAASA,CAAAA,CAAT,CAAmCC,CAAnC,CAA2CC,CAA3C,CAAmD,CAC/C,GAAIA,CAAM,SAAV,CAA0B,CACtBA,CAAM,CAAGC,QACZ,CACDD,CAAM,CAACE,aAAP,CAAqB,GAAIC,CAAAA,WAAJ,CAAgBC,UAAOC,YAAvB,CAAqC,CACtDC,OAAO,GAD+C,CAEtDP,MAAM,CAAEA,CAF8C,CAArC,CAArB,CAIH,CAKM,GAAMQ,CAAAA,CAAY,CAAG,GAAIC,UAAJ,CAAiB,CACzCC,IAAI,CAAE,cADmC,CAEzCC,SAAS,CAAEN,UAAOC,YAFuB,CAGzCM,aAAa,CAAEb,CAH0B,CAMzCc,SAAS,CAAE,GAAIC,UAN0B,CAAjB,CAArB,C,wBAca,QAAPC,CAAAA,IAAO,CAACC,CAAD,CAAc,CAC9BR,CAAY,CAACS,UAAb,CAAwBD,CAAxB,CACH,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\n/**\n * Generic reactive module used in the course editor.\n *\n * @module core_courseformat/courseeditor\n * @copyright 2021 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport DefaultMutations from 'core_courseformat/local/courseeditor/mutations';\nimport CourseEditor from 'core_courseformat/local/courseeditor/courseeditor';\nimport events from 'core_course/events';\n\n/**\n * Trigger a state changed event.\n *\n * This function will be moved to core_course/events module\n * when the file is migrated to the new JS events structure proposed in MDL-70990.\n *\n * @method dispatchStateChangedEvent\n * @param {object} detail the full state\n * @param {object} target the custom event target (document if none provided)\n */\nfunction dispatchStateChangedEvent(detail, target) {\n if (target === undefined) {\n target = document;\n }\n target.dispatchEvent(new CustomEvent(events.stateChanged, {\n bubbles: true,\n detail: detail,\n }));\n}\n\n/**\n * This is the courseditor instance all components will register in.\n */\nexport const courseEditor = new CourseEditor({\n name: 'CourseEditor',\n eventName: events.stateChanged,\n eventDispatch: dispatchStateChangedEvent,\n // Mutations can be overridden by the format plugin using setMutations\n // but we need the default one at least.\n mutations: new DefaultMutations(),\n});\n\n/**\n * This method is called only once to load the initial state when the page is ready.\n *\n * @param {int} courseId the current course id\n */\nexport const init = (courseId) => {\n courseEditor.loadCourse(courseId);\n};\n"],"file":"courseeditor.min.js"}
|
||||
{"version":3,"sources":["../src/courseeditor.js"],"names":["courseEditorMap","Map","dispatchStateChangedEvent","detail","target","document","dispatchEvent","CustomEvent","events","stateChanged","bubbles","getCourseEditor","courseId","parseInt","has","set","CourseEditor","name","eventName","eventDispatch","mutations","DefaultMutations","get","loadCourse","getCurrentCourseEditor","M","cfg"],"mappings":"iTAuBA,OACA,OACA,O,mDAGA,GAAMA,CAAAA,CAAe,CAAG,GAAIC,CAAAA,GAA5B,CAYA,QAASC,CAAAA,CAAT,CAAmCC,CAAnC,CAA2CC,CAA3C,CAAmD,CAC/C,GAAIA,CAAM,SAAV,CAA0B,CACtBA,CAAM,CAAGC,QACZ,CACDD,CAAM,CAACE,aAAP,CAAqB,GAAIC,CAAAA,WAAJ,CAAgBC,UAAOC,YAAvB,CAAqC,CACtDC,OAAO,GAD+C,CAEtDP,MAAM,CAAEA,CAF8C,CAArC,CAArB,CAIH,CAQM,GAAMQ,CAAAA,CAAe,CAAG,SAACC,CAAD,CAAc,CACzCA,CAAQ,CAAGC,QAAQ,CAACD,CAAD,CAAnB,CAEA,GAAI,CAACZ,CAAe,CAACc,GAAhB,CAAoBF,CAApB,CAAL,CAAoC,CAChCZ,CAAe,CAACe,GAAhB,CACIH,CADJ,CAEI,GAAII,UAAJ,CAAiB,CACbC,IAAI,uBAAiBL,CAAjB,CADS,CAEbM,SAAS,CAAEV,UAAOC,YAFL,CAGbU,aAAa,CAAEjB,CAHF,CAMbkB,SAAS,CAAE,GAAIC,UANF,CAAjB,CAFJ,EAWArB,CAAe,CAACsB,GAAhB,CAAoBV,CAApB,EAA8BW,UAA9B,CAAyCX,CAAzC,CACH,CACD,MAAOZ,CAAAA,CAAe,CAACsB,GAAhB,CAAoBV,CAApB,CACV,CAlBM,C,6CAyB+B,QAAzBY,CAAAA,sBAAyB,SAAMb,CAAAA,CAAe,CAACc,CAAC,CAACC,GAAF,CAAMd,QAAP,CAArB,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\n/**\n * Generic reactive module used in the course editor.\n *\n * @module core_courseformat/courseeditor\n * @copyright 2021 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport DefaultMutations from 'core_courseformat/local/courseeditor/mutations';\nimport CourseEditor from 'core_courseformat/local/courseeditor/courseeditor';\nimport events from 'core_course/events';\n\n// A map with all the course editor instances.\nconst courseEditorMap = new Map();\n\n/**\n * Trigger a state changed event.\n *\n * This function will be moved to core_course/events module\n * when the file is migrated to the new JS events structure proposed in MDL-70990.\n *\n * @method dispatchStateChangedEvent\n * @param {object} detail the full state\n * @param {object} target the custom event target (document if none provided)\n */\nfunction dispatchStateChangedEvent(detail, target) {\n if (target === undefined) {\n target = document;\n }\n target.dispatchEvent(new CustomEvent(events.stateChanged, {\n bubbles: true,\n detail: detail,\n }));\n}\n\n/**\n * Get a specific course editor reactive instance.\n *\n * @param {number} courseId the course id\n * @returns {CourseEditor}\n */\nexport const getCourseEditor = (courseId) => {\n courseId = parseInt(courseId);\n\n if (!courseEditorMap.has(courseId)) {\n courseEditorMap.set(\n courseId,\n new CourseEditor({\n name: `CourseEditor${courseId}`,\n eventName: events.stateChanged,\n eventDispatch: dispatchStateChangedEvent,\n // Mutations can be overridden by the format plugin using setMutations\n // but we need the default one at least.\n mutations: new DefaultMutations(),\n })\n );\n courseEditorMap.get(courseId).loadCourse(courseId);\n }\n return courseEditorMap.get(courseId);\n};\n\n/**\n * Get the current course reactive instance.\n *\n * @returns {CourseEditor}\n */\nexport const getCurrentCourseEditor = () => getCourseEditor(M.cfg.courseId);\n"],"file":"courseeditor.min.js"}
|
@ -25,6 +25,9 @@ import DefaultMutations from 'core_courseformat/local/courseeditor/mutations';
|
||||
import CourseEditor from 'core_courseformat/local/courseeditor/courseeditor';
|
||||
import events from 'core_course/events';
|
||||
|
||||
// A map with all the course editor instances.
|
||||
const courseEditorMap = new Map();
|
||||
|
||||
/**
|
||||
* Trigger a state changed event.
|
||||
*
|
||||
@ -46,22 +49,34 @@ function dispatchStateChangedEvent(detail, target) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the courseditor instance all components will register in.
|
||||
* Get a specific course editor reactive instance.
|
||||
*
|
||||
* @param {number} courseId the course id
|
||||
* @returns {CourseEditor}
|
||||
*/
|
||||
export const courseEditor = new CourseEditor({
|
||||
name: 'CourseEditor',
|
||||
eventName: events.stateChanged,
|
||||
eventDispatch: dispatchStateChangedEvent,
|
||||
// Mutations can be overridden by the format plugin using setMutations
|
||||
// but we need the default one at least.
|
||||
mutations: new DefaultMutations(),
|
||||
});
|
||||
export const getCourseEditor = (courseId) => {
|
||||
courseId = parseInt(courseId);
|
||||
|
||||
if (!courseEditorMap.has(courseId)) {
|
||||
courseEditorMap.set(
|
||||
courseId,
|
||||
new CourseEditor({
|
||||
name: `CourseEditor${courseId}`,
|
||||
eventName: events.stateChanged,
|
||||
eventDispatch: dispatchStateChangedEvent,
|
||||
// Mutations can be overridden by the format plugin using setMutations
|
||||
// but we need the default one at least.
|
||||
mutations: new DefaultMutations(),
|
||||
})
|
||||
);
|
||||
courseEditorMap.get(courseId).loadCourse(courseId);
|
||||
}
|
||||
return courseEditorMap.get(courseId);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method is called only once to load the initial state when the page is ready.
|
||||
* Get the current course reactive instance.
|
||||
*
|
||||
* @param {int} courseId the current course id
|
||||
* @returns {CourseEditor}
|
||||
*/
|
||||
export const init = (courseId) => {
|
||||
courseEditor.loadCourse(courseId);
|
||||
};
|
||||
export const getCurrentCourseEditor = () => getCourseEditor(M.cfg.courseId);
|
||||
|
@ -3200,7 +3200,7 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules =
|
||||
// All the new editor elements will be loaded after the course is presented and
|
||||
// the initial course state will be generated using core_courseformat_get_state webservice.
|
||||
if ($SITE->id !== $course->id) {
|
||||
$PAGE->requires->js_call_amd('core_courseformat/courseeditor', 'init', [$course->id]);
|
||||
$PAGE->requires->js_call_amd('core_courseformat/courseeditor', 'getCourseEditor', [$course->id]);
|
||||
}
|
||||
// TODO: as part of MDL-70907, add a way to indicate the plugin needs the legacy libraries (and get a deprecation message).
|
||||
|
||||
|
@ -331,6 +331,7 @@ class page_requirements_manager {
|
||||
'admin' => $CFG->admin,
|
||||
'svgicons' => $page->theme->use_svg_icons(),
|
||||
'usertimezone' => usertimezone(),
|
||||
'courseId' => (int) $page->course->id,
|
||||
'contextid' => $contextid,
|
||||
'langrev' => get_string_manager()->get_revision(),
|
||||
'templaterev' => $this->get_templaterev()
|
||||
|
Loading…
x
Reference in New Issue
Block a user