MDL-80295 core_courseformat: actvity chooser JS with section ID
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
issueNumber: MDL-80295
|
||||
notes:
|
||||
core_course:
|
||||
- message: >-
|
||||
The getModulesData and activityModules methods from
|
||||
core_course/local/activitychooser/repository are deprecated. Use
|
||||
getSectionModulesData and sectionActivityModules instead
|
||||
type: deprecated
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
define("core_course/activitychooser",["exports","core_course/local/activitychooser/dialogue","core_course/local/activitychooser/repository","core_course/local/activitychooser/selectors","core/custom_interaction_events","core/pending"],(function(_exports,ChooserDialogue,Repository,_selectors,_custom_interaction_events,_pending){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}
|
||||
define("core_course/activitychooser",["exports","core_course/local/activitychooser/dialogue","core/custom_interaction_events","core/log","core/pending","core_course/local/activitychooser/repository","core_course/local/activitychooser/selectors"],(function(_exports,ChooserDialogue,_custom_interaction_events,_log,_pending,Repository,_selectors){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}
|
||||
/**
|
||||
* A type of dialogue used as for choosing modules in a course.
|
||||
*
|
||||
* @module core_course/activitychooser
|
||||
* @copyright 2020 Mathew May <mathew.solutions>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,ChooserDialogue=_interopRequireWildcard(ChooserDialogue),Repository=_interopRequireWildcard(Repository),_selectors=_interopRequireDefault(_selectors),_custom_interaction_events=_interopRequireDefault(_custom_interaction_events),_pending=_interopRequireDefault(_pending);let initialized=!1;_exports.init=(courseId,chooserConfig)=>{const pendingPromise=new _pending.default;void 0!==chooserConfig.tabmode&&window.console.warn("The tabmode config option has been deprecated and will be ignored."),registerListenerEvents(courseId),pendingPromise.resolve()};const registerListenerEvents=courseId=>{if(initialized)return;initialized=!0;const eventsToHandle=["click",_custom_interaction_events.default.events.activate,_custom_interaction_events.default.events.keyboardActivate];_custom_interaction_events.default.define(document,eventsToHandle),eventsToHandle.forEach((eventToHandle=>{document.addEventListener(eventToHandle,(async event=>{if(!event.target.closest(_selectors.default.elements.sectionmodchooser))return;const position=function(target){var _caller$dataset$secti,_caller$dataset,_caller$dataset$befor,_caller$dataset2;let caller,sectionNum;const sectionDiv=target.closest(_selectors.default.elements.section),button=target.closest(_selectors.default.elements.sectionmodchooser);null!==sectionDiv&§ionDiv.hasAttribute("data-number")?(caller=sectionDiv,sectionNum=sectionDiv.getAttribute("data-number")):(caller=button,caller.hasAttribute("data-sectionid")&&(window.console.warn("The data-sectionid attribute has been deprecated. Please update your code to use data-sectionnum instead."),caller.setAttribute("data-sectionnum",caller.dataset.sectionid)),sectionNum=caller.dataset.sectionnum);return{sectionNum:sectionNum,sectionReturnNum:null!==(_caller$dataset$secti=null===(_caller$dataset=caller.dataset)||void 0===_caller$dataset?void 0:_caller$dataset.sectionreturnnum)&&void 0!==_caller$dataset$secti?_caller$dataset$secti:null,beforeMod:null!==(_caller$dataset$befor=null===(_caller$dataset2=caller.dataset)||void 0===_caller$dataset2?void 0:_caller$dataset2.beforemod)&&void 0!==_caller$dataset$befor?_caller$dataset$befor:null}}(event.target),footerDataPromise=Repository.getModalFooterData(courseId,position.sectionNum),modulesDataPromise=Repository.getModulesData(courseId,position.sectionNum,position.sectionReturnNum,position.beforeMod);ChooserDialogue.displayActivityChooserModal(footerDataPromise,modulesDataPromise)}))}))}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,ChooserDialogue=_interopRequireWildcard(ChooserDialogue),_custom_interaction_events=_interopRequireDefault(_custom_interaction_events),_log=_interopRequireDefault(_log),_pending=_interopRequireDefault(_pending),Repository=_interopRequireWildcard(Repository),_selectors=_interopRequireDefault(_selectors);let initialized=!1;_exports.init=(courseId,chooserConfig)=>{const pendingPromise=new _pending.default;void 0!==chooserConfig.tabmode&&window.console.warn("The tabmode config option has been deprecated and will be ignored."),registerListenerEvents(courseId),pendingPromise.resolve()};const registerListenerEvents=courseId=>{if(initialized)return;initialized=!0;const eventsToHandle=["click",_custom_interaction_events.default.events.activate,_custom_interaction_events.default.events.keyboardActivate];_custom_interaction_events.default.define(document,eventsToHandle),eventsToHandle.forEach((eventToHandle=>{document.addEventListener(eventToHandle,(async event=>{if(!event.target.closest(_selectors.default.elements.sectionmodchooser))return;const position=function(target){var _ref,_caller$dataset$secti,_caller$dataset,_caller$dataset2,_caller$dataset$secti2,_caller$dataset3,_caller$dataset$befor,_caller$dataset4;let caller,sectionNum=null,sectionId=null;const sectionDiv=target.closest(_selectors.default.elements.section),button=target.closest(_selectors.default.elements.sectionmodchooser);null!==sectionDiv&&(sectionDiv.hasAttribute("data-number")||sectionDiv.hasAttribute("data-id"))?(caller=sectionDiv,sectionNum=sectionDiv.getAttribute("data-number"),sectionId=sectionDiv.getAttribute("data-id")):(caller=button,caller.hasAttribute("data-sectionid")&&(window.console.warn("The data-sectionid attribute has been deprecated. Please update your code to use data-section-id passing the real section ID instead."),caller.setAttribute("data-sectionnum",caller.dataset.sectionid)),sectionNum=caller.dataset.sectionnum,sectionId=caller.getAttribute("data-section-id"));return{sectionNum:sectionNum,sectionId:sectionId,sectionReturnNum:null!==(_ref=null!==(_caller$dataset$secti=null===(_caller$dataset=caller.dataset)||void 0===_caller$dataset?void 0:_caller$dataset.sectionreturnnum)&&void 0!==_caller$dataset$secti?_caller$dataset$secti:null===(_caller$dataset2=caller.dataset)||void 0===_caller$dataset2?void 0:_caller$dataset2.sectionreturn)&&void 0!==_ref?_ref:null,sectionReturnId:null!==(_caller$dataset$secti2=null===(_caller$dataset3=caller.dataset)||void 0===_caller$dataset3?void 0:_caller$dataset3.sectionreturnid)&&void 0!==_caller$dataset$secti2?_caller$dataset$secti2:null,beforeMod:null!==(_caller$dataset$befor=null===(_caller$dataset4=caller.dataset)||void 0===_caller$dataset4?void 0:_caller$dataset4.beforemod)&&void 0!==_caller$dataset$befor?_caller$dataset$befor:null}}(event.target),footerDataPromise=Repository.getModalFooterData(courseId,position.sectionNum);let modulesDataPromise;position.sectionId&&""!==position.sectionId?modulesDataPromise=Repository.getSectionModulesData(courseId,position.sectionId,position.sectionReturnNum,position.beforeMod):(_log.default.debug("Having only the section number attribute in the activity chooser is deprecated. Please add the data-section-id attribute."),modulesDataPromise=Repository.getModulesData(courseId,position.sectionNum,position.sectionReturnNum,position.beforeMod)),ChooserDialogue.displayActivityChooserModal(footerDataPromise,modulesDataPromise)}))}))}}));
|
||||
|
||||
//# sourceMappingURL=activitychooser.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -1,10 +1,10 @@
|
||||
define("core_course/local/activitychooser/repository",["exports","core/ajax"],(function(_exports,_ajax){var obj;
|
||||
define("core_course/local/activitychooser/repository",["exports","core/ajax","core/log"],(function(_exports,_ajax,_log){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
/**
|
||||
* A javascript module to handle user AJAX actions.
|
||||
*
|
||||
* @module core_course/local/activitychooser/repository
|
||||
* @copyright 2019 Mathew May <mathew.solutions>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.fetchFooterData=_exports.favouriteModule=_exports.activityModules=void 0,_exports.getModalFooterData=async function(courseId,sectionNum){const cacheKey="".concat(courseId,"-").concat(sectionNum);if(sectionsFooterPromises.has(cacheKey))return sectionsFooterPromises.get(cacheKey);return sectionsFooterPromises.set(cacheKey,new Promise((resolve=>{resolve(fetchFooterData(courseId,sectionNum))}))),sectionsFooterPromises.get(cacheKey)},_exports.getModulesData=async function(courseId,sectionNum,sectionReturnNum,beforeMod){const cacheKey="".concat(courseId,"-").concat(sectionNum);sectionsModulesPromises.has(cacheKey)||sectionsModulesPromises.set(cacheKey,new Promise((resolve=>{resolve(activityModules(courseId,sectionNum))})));const moduleData=await sectionsModulesPromises.get(cacheKey);if(!moduleData)throw new Error("Cannot fetch module data");return function(webServiceData,sectionNum,sectionReturnNum,beforeMod){const newData=JSON.parse(JSON.stringify(webServiceData));return newData.content_items.forEach((module=>{module.link+="§ion="+sectionNum+"&beforemod="+(null!=beforeMod?beforeMod:0),sectionReturnNum&&(module.link+="&sr="+sectionReturnNum)})),newData.content_items}(moduleData,sectionNum,sectionReturnNum,beforeMod)},_exports.unfavouriteModule=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};const sectionsModulesPromises=new Map,sectionsFooterPromises=new Map,activityModules=(courseid,sectionnum)=>{const request={methodname:"core_course_get_course_content_items",args:{courseid:courseid,sectionnum:sectionnum}};return _ajax.default.call([request])[0]};_exports.activityModules=activityModules;_exports.favouriteModule=(modName,modID)=>{const request={methodname:"core_course_add_content_item_to_user_favourites",args:{componentname:modName,contentitemid:modID}};return _ajax.default.call([request])[0].then((()=>(sectionsModulesPromises.clear(),!0)))};_exports.unfavouriteModule=(modName,modID)=>{const request={methodname:"core_course_remove_content_item_from_user_favourites",args:{componentname:modName,contentitemid:modID}};return _ajax.default.call([request])[0].then((()=>(sectionsModulesPromises.clear(),!0)))};const fetchFooterData=(courseid,sectionid)=>{const request={methodname:"core_course_get_activity_chooser_footer",args:{courseid:courseid,sectionid:sectionid}};return _ajax.default.call([request])[0]};_exports.fetchFooterData=fetchFooterData}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.fetchFooterData=_exports.favouriteModule=_exports.activityModules=void 0,_exports.getModalFooterData=async function(courseId,sectionNum){const cacheKey="".concat(courseId,"-").concat(sectionNum);if(sectionsFooterPromises.has(cacheKey))return sectionsFooterPromises.get(cacheKey);return sectionsFooterPromises.set(cacheKey,new Promise((resolve=>{resolve(fetchFooterData(courseId,sectionNum))}))),sectionsFooterPromises.get(cacheKey)},_exports.getModulesData=async function(courseId,sectionNum,sectionReturnNum,beforeMod){_log.default.debug("The getModulesData function is deprecated. Use getSectionModulesData instead.");const cacheKey="".concat(courseId,"-").concat(sectionNum);sectionsModulesPromises.has(cacheKey)||sectionsModulesPromises.set(cacheKey,new Promise((resolve=>{resolve(activityModules(courseId,sectionNum))})));const moduleData=await sectionsModulesPromises.get(cacheKey);if(!moduleData)throw new Error("Cannot fetch module data");return sectionMapper(moduleData,null,sectionReturnNum,beforeMod,sectionNum)},_exports.getSectionModulesData=async function(courseId,sectionId,sectionReturnNum,beforeMod){const cacheKey="".concat(courseId,"-").concat(sectionId);sectionsModulesPromises.has(cacheKey)||sectionsModulesPromises.set(cacheKey,new Promise((resolve=>{resolve(sectionActivityModules(courseId,sectionId))})));const moduleData=await sectionsModulesPromises.get(cacheKey);if(!moduleData)throw new Error("Cannot fetch module data");return sectionMapper(moduleData,sectionId,sectionReturnNum,beforeMod)},_exports.unfavouriteModule=_exports.sectionActivityModules=void 0,_ajax=_interopRequireDefault(_ajax),_log=_interopRequireDefault(_log);const sectionsModulesPromises=new Map,sectionsFooterPromises=new Map,activityModules=(courseid,sectionnum)=>{_log.default.debug("The activityModules function is deprecated. Use sectionActivityModules instead.");const request={methodname:"core_course_get_course_content_items",args:{courseid:courseid,sectionnum:sectionnum}};return _ajax.default.call([request])[0]};_exports.activityModules=activityModules;const sectionActivityModules=(courseId,sectionId)=>{const request={methodname:"core_courseformat_get_section_content_items",args:{courseid:courseId,sectionid:sectionId}};return _ajax.default.call([request])[0]};_exports.sectionActivityModules=sectionActivityModules;_exports.favouriteModule=(modName,modID)=>{const request={methodname:"core_course_add_content_item_to_user_favourites",args:{componentname:modName,contentitemid:modID}};return _ajax.default.call([request])[0].then((()=>(sectionsModulesPromises.clear(),!0)))};_exports.unfavouriteModule=(modName,modID)=>{const request={methodname:"core_course_remove_content_item_from_user_favourites",args:{componentname:modName,contentitemid:modID}};return _ajax.default.call([request])[0].then((()=>(sectionsModulesPromises.clear(),!0)))};const fetchFooterData=(courseid,sectionid)=>{const request={methodname:"core_course_get_activity_chooser_footer",args:{courseid:courseid,sectionid:sectionid}};return _ajax.default.call([request])[0]};function sectionMapper(webServiceData,sectionId,sectionReturnNum,beforeMod){let legacySectionNum=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;const newData=JSON.parse(JSON.stringify(webServiceData));let urlParams="&beforemod="+(null!=beforeMod?beforeMod:0);return sectionId&&(urlParams+="§ionid=".concat(sectionId)),legacySectionNum&&(urlParams+="§ion=".concat(legacySectionNum)),sectionReturnNum&&(urlParams+="&sr=".concat(sectionReturnNum)),newData.content_items.forEach((module=>{module.link+=urlParams})),newData.content_items}_exports.fetchFooterData=fetchFooterData}));
|
||||
|
||||
//# sourceMappingURL=repository.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -22,10 +22,11 @@
|
||||
*/
|
||||
|
||||
import * as ChooserDialogue from 'core_course/local/activitychooser/dialogue';
|
||||
import CustomEvents from 'core/custom_interaction_events';
|
||||
import Log from 'core/log';
|
||||
import Pending from 'core/pending';
|
||||
import * as Repository from 'core_course/local/activitychooser/repository';
|
||||
import selectors from 'core_course/local/activitychooser/selectors';
|
||||
import CustomEvents from 'core/custom_interaction_events';
|
||||
import Pending from 'core/pending';
|
||||
|
||||
let initialized = false;
|
||||
|
||||
@@ -79,12 +80,27 @@ const registerListenerEvents = (courseId) => {
|
||||
|
||||
const footerDataPromise = Repository.getModalFooterData(courseId, position.sectionNum);
|
||||
|
||||
const modulesDataPromise = Repository.getModulesData(
|
||||
courseId,
|
||||
position.sectionNum,
|
||||
position.sectionReturnNum,
|
||||
position.beforeMod,
|
||||
);
|
||||
let modulesDataPromise;
|
||||
if (position.sectionId && position.sectionId !== '') {
|
||||
modulesDataPromise = Repository.getSectionModulesData(
|
||||
courseId,
|
||||
position.sectionId,
|
||||
position.sectionReturnNum,
|
||||
position.beforeMod,
|
||||
);
|
||||
} else {
|
||||
// Todo remove this else in Moodle 6.0 (MDL-86310)
|
||||
Log.debug(
|
||||
'Having only the section number attribute in the activity chooser is deprecated. ' +
|
||||
'Please add the data-section-id attribute.'
|
||||
);
|
||||
modulesDataPromise = Repository.getModulesData(
|
||||
courseId,
|
||||
position.sectionNum,
|
||||
position.sectionReturnNum,
|
||||
position.beforeMod,
|
||||
);
|
||||
}
|
||||
|
||||
ChooserDialogue.displayActivityChooserModal(footerDataPromise, modulesDataPromise);
|
||||
});
|
||||
@@ -97,12 +113,15 @@ const registerListenerEvents = (courseId) => {
|
||||
* @param {HTMLElement} target The target element.
|
||||
* @return {Object} The course position of the target.
|
||||
* @property {Number} sectionNum The section number.
|
||||
* @property {Number|null} sectionId The section id.
|
||||
* @property {Number|null} sectionReturnNum The section return number.
|
||||
* @property {Number|null} sectionReturnId The section return id.
|
||||
* @property {Number|null} beforeMod The ID of the cm to add the modules before.
|
||||
*/
|
||||
function getCoursePositionFromTarget(target) {
|
||||
let caller;
|
||||
let sectionNum;
|
||||
let sectionNum = null;
|
||||
let sectionId = null;
|
||||
// We need to know who called this.
|
||||
// Standard courses use the ID in the main section info.
|
||||
const sectionDiv = target.closest(selectors.elements.section);
|
||||
@@ -113,25 +132,32 @@ function getCoursePositionFromTarget(target) {
|
||||
// We always want the sectionDiv caller first as it keeps track of section number's after DnD changes.
|
||||
// The button attribute is always just a fallback for us as the section div is not always available.
|
||||
// A YUI change could be done maybe to only update the button attribute but we are going for minimal change here.
|
||||
if (sectionDiv !== null && sectionDiv.hasAttribute('data-number')) {
|
||||
if (
|
||||
sectionDiv !== null
|
||||
&& (sectionDiv.hasAttribute('data-number') || sectionDiv.hasAttribute('data-id'))
|
||||
) {
|
||||
// We check for attributes just in case of outdated contrib course formats.
|
||||
caller = sectionDiv;
|
||||
sectionNum = sectionDiv.getAttribute('data-number');
|
||||
sectionId = sectionDiv.getAttribute('data-id');
|
||||
} else {
|
||||
caller = button;
|
||||
|
||||
if (caller.hasAttribute('data-sectionid')) {
|
||||
window.console.warn(
|
||||
'The data-sectionid attribute has been deprecated. ' +
|
||||
'Please update your code to use data-sectionnum instead.'
|
||||
'Please update your code to use data-section-id passing the real section ID instead.'
|
||||
);
|
||||
caller.setAttribute('data-sectionnum', caller.dataset.sectionid);
|
||||
}
|
||||
sectionNum = caller.dataset.sectionnum;
|
||||
sectionId = caller.getAttribute('data-section-id');
|
||||
}
|
||||
return {
|
||||
sectionNum,
|
||||
sectionReturnNum: caller.dataset?.sectionreturnnum ?? null,
|
||||
sectionId,
|
||||
// The old data attribute for the section return number was data-sectionreturn.
|
||||
sectionReturnNum: caller.dataset?.sectionreturnnum ?? caller.dataset?.sectionreturn ?? null,
|
||||
sectionReturnId: caller.dataset?.sectionreturnid ?? null,
|
||||
beforeMod: caller.dataset?.beforemod ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
import ajax from 'core/ajax';
|
||||
import Log from 'core/log';
|
||||
|
||||
// A promises map for caching specific section modules data.
|
||||
const sectionsModulesPromises = new Map();
|
||||
@@ -32,11 +33,14 @@ const sectionsFooterPromises = new Map();
|
||||
* Fetch all the information on modules we'll need in the activity chooser.
|
||||
*
|
||||
* @method activityModules
|
||||
* @deprecated since Moodle 5.1
|
||||
* @todo Remove in Moodle 6.0 (MDL-86310)
|
||||
* @param {Number} courseid What course to fetch the modules for
|
||||
* @param {Number} sectionnum What course section to fetch the modules for
|
||||
* @return {object} jQuery promise
|
||||
*/
|
||||
export const activityModules = (courseid, sectionnum) => {
|
||||
Log.debug('The activityModules function is deprecated. Use sectionActivityModules instead.');
|
||||
const request = {
|
||||
methodname: 'core_course_get_course_content_items',
|
||||
args: {
|
||||
@@ -47,6 +51,25 @@ export const activityModules = (courseid, sectionnum) => {
|
||||
return ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch all the information on modules that can be added to a section.
|
||||
*
|
||||
* @method sectionActivityModules
|
||||
* @param {Number} courseId What course to fetch the modules for
|
||||
* @param {Number} sectionId What course section to fetch the modules for
|
||||
* @return {object} jQuery promise
|
||||
*/
|
||||
export const sectionActivityModules = (courseId, sectionId) => {
|
||||
const request = {
|
||||
methodname: 'core_courseformat_get_section_content_items',
|
||||
args: {
|
||||
courseid: courseId,
|
||||
sectionid: sectionId,
|
||||
},
|
||||
};
|
||||
return ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a module name, module ID & the current course we want to specify that the module
|
||||
* is a users' favourite.
|
||||
@@ -118,11 +141,12 @@ export const fetchFooterData = (courseid, sectionid) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetch all the information on modules we'll need in the activity chooser.
|
||||
* Legacy method to fetch all the information on modules using section number.
|
||||
*
|
||||
* @method fetchSectionModules
|
||||
*
|
||||
* @private
|
||||
* @deprecated since Moodle 5.1
|
||||
* @todo Remove in Moodle 6.0 (MDL-86310)
|
||||
* @param {Number} courseId Course ID.
|
||||
* @param {Number} sectionNum Section number.
|
||||
* @param {Number} sectionReturnNum Section return.
|
||||
@@ -130,6 +154,7 @@ export const fetchFooterData = (courseid, sectionid) => {
|
||||
* @return {Object} Tab data.
|
||||
*/
|
||||
export async function getModulesData(courseId, sectionNum, sectionReturnNum, beforeMod) {
|
||||
Log.debug('The getModulesData function is deprecated. Use getSectionModulesData instead.');
|
||||
const cacheKey = `${courseId}-${sectionNum}`;
|
||||
if (!sectionsModulesPromises.has(cacheKey)) {
|
||||
sectionsModulesPromises.set(
|
||||
@@ -150,9 +175,48 @@ export async function getModulesData(courseId, sectionNum, sectionReturnNum, bef
|
||||
// Apply the section num to all the module instance links.
|
||||
return sectionMapper(
|
||||
moduleData,
|
||||
sectionNum,
|
||||
null, // We do not have a section ID here.
|
||||
sectionReturnNum,
|
||||
beforeMod
|
||||
beforeMod,
|
||||
sectionNum, // Legacy section number.
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all the information on modules we'll need in the activity chooser.
|
||||
*
|
||||
* @method fetchSectionModules
|
||||
*
|
||||
* @param {Number} courseId Course ID.
|
||||
* @param {Number} sectionId Section ID.
|
||||
* @param {Number} sectionReturnNum Section return.
|
||||
* @param {Number} beforeMod Before module number to be used in the module.
|
||||
* @return {Object} Tab data.
|
||||
*/
|
||||
export async function getSectionModulesData(courseId, sectionId, sectionReturnNum, beforeMod) {
|
||||
const cacheKey = `${courseId}-${sectionId}`;
|
||||
if (!sectionsModulesPromises.has(cacheKey)) {
|
||||
sectionsModulesPromises.set(
|
||||
cacheKey,
|
||||
new Promise((resolve) => {
|
||||
resolve(sectionActivityModules(courseId, sectionId));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const moduleData = await sectionsModulesPromises.get(cacheKey);
|
||||
|
||||
// Early return if there is no module data.
|
||||
if (!moduleData) {
|
||||
throw new Error('Cannot fetch module data');
|
||||
}
|
||||
|
||||
// Apply the section num to all the module instance links.
|
||||
return sectionMapper(
|
||||
moduleData,
|
||||
sectionId,
|
||||
sectionReturnNum,
|
||||
beforeMod,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,20 +225,30 @@ export async function getModulesData(courseId, sectionNum, sectionReturnNum, bef
|
||||
* of the WS data then add on the section num to the addoption URL
|
||||
*
|
||||
* @method sectionMapper
|
||||
* @TODO remove legacySectionNum param in Moodle 6.0 (MDL-86310)
|
||||
* @param {Object} webServiceData Our original data from the Web service call
|
||||
* @param {Number} sectionNum The number of the section we need to append to the links
|
||||
* @param {Number} sectionId The number of the section we need to append to the links
|
||||
* @param {Number|null} sectionReturnNum The number of the section return we need to append to the links
|
||||
* @param {Number|null} beforeMod The ID of the cm we need to append to the links
|
||||
* @param {Number|null} legacySectionNum The legacy section number to append to the links
|
||||
* @return {Array} [modules] with URL's built
|
||||
*/
|
||||
function sectionMapper(webServiceData, sectionNum, sectionReturnNum, beforeMod) {
|
||||
function sectionMapper(webServiceData, sectionId, sectionReturnNum, beforeMod, legacySectionNum = null) {
|
||||
// We need to take a fresh deep copy of the original data as an object is a reference type.
|
||||
const newData = JSON.parse(JSON.stringify(webServiceData));
|
||||
let urlParams = '&beforemod=' + (beforeMod ?? 0);
|
||||
if (sectionId) {
|
||||
urlParams += `§ionid=${sectionId}`;
|
||||
}
|
||||
// Todo: Remove legacySectionNum in Moodle 6.0 (MDL-86310).
|
||||
if (legacySectionNum) {
|
||||
urlParams += `§ion=${legacySectionNum}`;
|
||||
}
|
||||
if (sectionReturnNum) {
|
||||
urlParams += `&sr=${sectionReturnNum}`;
|
||||
}
|
||||
newData.content_items.forEach((module) => {
|
||||
module.link += '§ion=' + sectionNum + '&beforemod=' + (beforeMod ?? 0);
|
||||
if (sectionReturnNum) {
|
||||
module.link += '&sr=' + sectionReturnNum;
|
||||
}
|
||||
module.link += urlParams;
|
||||
});
|
||||
return newData.content_items;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user