MDL-77329 course: Prevent collapse state loss

This commit is contained in:
James C
2023-03-09 12:01:27 +01:00
committed by Ferran Recio
parent abff12eda1
commit fc4a4e6450
3 changed files with 11 additions and 5 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -295,6 +295,9 @@ export default class {
*/
async sectionIndexCollapsed(stateManager, sectionIds, collapsed) {
const collapsedIds = this._updateStateSectionPreference(stateManager, 'indexcollapsed', sectionIds, collapsed);
if (!collapsedIds) {
return;
}
const course = stateManager.get('course');
await this._callEditWebservice('section_index_collapsed', course.id, collapsedIds);
}
@@ -308,6 +311,9 @@ export default class {
*/
async sectionContentCollapsed(stateManager, sectionIds, collapsed) {
const collapsedIds = this._updateStateSectionPreference(stateManager, 'contentcollapsed', sectionIds, collapsed);
if (!collapsedIds) {
return;
}
const course = stateManager.get('course');
await this._callEditWebservice('section_content_collapsed', course.id, collapsedIds);
}
@@ -319,7 +325,7 @@ export default class {
* @param {string} preferenceName the preference name
* @param {array} sectionIds the affected section ids
* @param {boolean} preferenceValue the new preferenceValue value
* @return {array} the list of all sections with that preference set to true
* @return {Number[]|null} sections ids with the preference value true or null if no update is required
*/
_updateStateSectionPreference(stateManager, preferenceName, sectionIds, preferenceValue) {
stateManager.setReadOnly(false);
@@ -328,7 +334,7 @@ export default class {
sectionIds.forEach(sectionId => {
const section = stateManager.get('section', sectionId);
if (section === undefined) {
return;
return null;
}
const newValue = preferenceValue ?? section[preferenceName];
if (section[preferenceName] != newValue) {
@@ -338,7 +344,7 @@ export default class {
});
stateManager.setReadOnly(true);
if (affectedSections.size == 0) {
return [];
return null;
}
// Get all collapsed section ids.
const collapsedSectionIds = [];