From 2bfc9c73ccc7408c53d2b586f8343ddfcdd79c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 11 May 2023 10:30:54 +0200 Subject: [PATCH] MOBILE-4270 wiki: Fix subwiki ordering --- src/addons/mod/wiki/components/index/index.ts | 53 ++++++++++--------- .../subwiki-picker/subwiki-picker.ts | 4 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 38780e1bb..ee1f0721e 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -885,7 +885,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp await Promise.all(this.loadedSubwikis.map(async (subwiki) => { let groupLabel = ''; - if (subwiki.groupid == 0 && subwiki.userid == 0) { + if (subwiki.groupid === 0 && subwiki.userid === 0) { // Add 'All participants' subwiki if needed at the start. if (!allParticipants) { subwikiList.unshift({ @@ -899,7 +899,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp allParticipants = true; } } else { - if (subwiki.groupid != 0 && userGroups.length > 0) { + if (subwiki.groupid !== 0 && userGroups.length > 0) { // Get groupLabel if it has groupId. const group = userGroups.find(group => group.id == subwiki.groupid); groupLabel = group?.name ?? ''; @@ -907,7 +907,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp groupLabel = Translate.instant('addon.mod_wiki.notingroup'); } - if (subwiki.userid != 0) { + if (subwiki.userid !== 0) { if (!multiLevelList && subwiki.groupid != 0) { multiLevelList = true; } @@ -953,8 +953,6 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp showMyGroupsLabel: boolean, multiLevelList: boolean, ): void { - subwikiList.sort((a, b) => a.groupid - b.groupid); - this.groupWiki = showMyGroupsLabel; this.subwikiData.count = subwikiList.length; @@ -1036,34 +1034,39 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp grouping.subwikis.push(subwiki); }); } else if (showMyGroupsLabel) { - const noGrouping: AddonModWikiSubwikiListGrouping = { label: '', subwikis: [] }; - const myGroupsGrouping: AddonModWikiSubwikiListGrouping = { label: Translate.instant('core.mygroups'), subwikis: [] }; - const otherGroupsGrouping: AddonModWikiSubwikiListGrouping = { - label: Translate.instant('core.othergroups'), - subwikis: [], - }; + const noGroupSubwikis: AddonModWikiSubwikiListSubwiki[] = []; + const myGroupsSubwikis: AddonModWikiSubwikiListSubwiki[] = []; + const otherGroupsSubwikis: AddonModWikiSubwikiListSubwiki[] = []; - // As we loop over each subwiki, add it to the current group + // As we loop over each subwiki, add it to the current group. subwikiList.forEach((subwiki) => { // Add the subwiki to the currently active grouping. - if (subwiki.canedit === undefined) { - noGrouping.subwikis.push(subwiki); + if (subwiki.groupid === 0 && subwiki.userid === 0) { + // All participants + noGroupSubwikis.push(subwiki); } else if (subwiki.canedit) { - myGroupsGrouping.subwikis.push(subwiki); + myGroupsSubwikis.push(subwiki); } else { - otherGroupsGrouping.subwikis.push(subwiki); + otherGroupsSubwikis.push(subwiki); } }); - // Add each grouping to the subwikis - if (noGrouping.subwikis.length > 0) { - this.subwikiData.subwikis.push(noGrouping); - } - if (myGroupsGrouping.subwikis.length > 0) { - this.subwikiData.subwikis.push(myGroupsGrouping); - } - if (otherGroupsGrouping.subwikis.length > 0) { - this.subwikiData.subwikis.push(otherGroupsGrouping); + if (myGroupsSubwikis.length > 0 && otherGroupsSubwikis.length > 0) { + // Add each grouping to the subwikis. + if (noGroupSubwikis.length > 0) { + this.subwikiData.subwikis.push({ label: '', subwikis: noGroupSubwikis }); + } + + if (myGroupsSubwikis.length > 0) { + this.subwikiData.subwikis.push({ label: Translate.instant('core.mygroups'), subwikis: myGroupsSubwikis }); + } + + if (otherGroupsSubwikis.length > 0) { + this.subwikiData.subwikis.push({ label: Translate.instant('core.othergroups'), subwikis: otherGroupsSubwikis }); + } + } else { + // Mix it again since it does not have groups and other groups. + this.subwikiData.subwikis.push({ label: '', subwikis: subwikiList }); } } else { this.subwikiData.subwikis.push({ label: '', subwikis: subwikiList }); diff --git a/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts b/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts index fcef85719..ffbbb93e8 100644 --- a/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts +++ b/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts @@ -38,10 +38,10 @@ export class AddonModWikiSubwikiPickerComponent { isSubwikiSelected(subwiki: AddonModWikiSubwiki): boolean { if (subwiki.id > 0 && this.currentSubwiki.id > 0) { - return subwiki.id == this.currentSubwiki.id; + return subwiki.id === this.currentSubwiki.id; } - return subwiki.userid == this.currentSubwiki.userid && subwiki.groupid == this.currentSubwiki.groupid; + return subwiki.userid === this.currentSubwiki.userid && subwiki.groupid === this.currentSubwiki.groupid; } /**