From 9076a614930f041c9d6d0a08449dc643de45d837 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 24 Nov 2022 11:13:18 +0100 Subject: [PATCH 1/4] MOBILE-4081 core: Fix site name not translated in My Courses --- src/core/classes/site.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index b90932cd3..ebe35ee73 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -958,18 +958,12 @@ export class CoreSite { // Call the WS. const initialToken = this.token ?? ''; - // Call the WS. - if (method !== 'core_webservice_get_site_info') { - // Send the language to use. Do it after checking cache to prevent losing offline data when changing language. - // Don't send it to core_webservice_get_site_info, that WS is used to check if Moodle version is supported. - data = { - ...data, - moodlewssettinglang: preSets.lang ?? await CoreLang.getCurrentLanguage(), - }; - // Moodle uses underscore instead of dash. - data.moodlewssettinglang = data.moodlewssettinglang.replace('-', '_'); - - } + // Send the language to use. Do it after checking cache to prevent losing offline data when changing language. + // Moodle uses underscore instead of dash. + data = { + ...data, + moodlewssettinglang: (preSets.lang ?? await CoreLang.getCurrentLanguage()).replace('-', '_'), + }; try { return await this.callOrEnqueueRequest(method, data, preSets, wsPreSets); @@ -988,6 +982,14 @@ export class CoreSite { } } + if (error?.errorcode === 'invalidparameter' && method === 'core_webservice_get_site_info') { + // Retry without passing the lang, this parameter isn't supported in 3.4 or older sites + // and we need this WS call to be able to determine if the site is supported or not. + delete data.moodlewssettinglang; + + return await this.callOrEnqueueRequest(method, data, preSets, wsPreSets); + } + throw error; } } From 2ad9d2645c6fae55b02840667db27ac9f6fbecaa Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 24 Nov 2022 12:38:10 +0100 Subject: [PATCH 2/4] MOBILE-4081 wiki: Fix create page with HTML in title --- src/addons/mod/wiki/pages/edit/edit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/mod/wiki/pages/edit/edit.ts b/src/addons/mod/wiki/pages/edit/edit.ts index 48f2c2adf..e6b09f027 100644 --- a/src/addons/mod/wiki/pages/edit/edit.ts +++ b/src/addons/mod/wiki/pages/edit/edit.ts @@ -87,7 +87,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { this.userId = CoreNavigator.getRouteNumberParam('userId'); let pageTitle = CoreNavigator.getRouteParam('pageTitle'); - pageTitle = pageTitle ? pageTitle.replace(/\+/g, ' ') : ''; + pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), true) : ''; this.canEditTitle = !pageTitle; this.title = pageTitle ? From 32d1e0761b15e081be6990a834408d81a8bb9bb6 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 24 Nov 2022 13:09:06 +0100 Subject: [PATCH 3/4] MOBILE-4081 wiki: Allow viewing empty subwikis --- src/addons/mod/wiki/components/index/index.ts | 14 ++++---------- .../addon-mod-wiki-subwiki-picker.html | 3 +-- .../components/subwiki-picker/subwiki-picker.ts | 9 +++------ 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 830572a90..1c922bf49 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -638,14 +638,8 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param subwikiId Subwiki ID. * @param userId User ID of the subwiki. * @param groupId Group ID of the subwiki. - * @param canEdit Whether the subwiki can be edited. */ - goToSubwiki(subwikiId: number, userId: number, groupId: number, canEdit: boolean): void { - // Check if the subwiki is disabled. - if (subwikiId <= 0 && !canEdit) { - return; - } - + goToSubwiki(subwikiId: number, userId: number, groupId: number): void { if (subwikiId != this.currentSubwiki!.id || userId != this.currentSubwiki!.userid || groupId != this.currentSubwiki!.groupid) { @@ -828,7 +822,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param event Event. */ async showSubwikiPicker(event: MouseEvent): Promise { - const popoverData = await CoreDomUtils.openPopover({ + const subwiki = await CoreDomUtils.openPopover({ component: AddonModWikiSubwikiPickerComponent, componentProps: { subwikis: this.subwikiData.subwikis, @@ -837,8 +831,8 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp event, }); - if (popoverData) { - this.goToSubwiki(popoverData.id, popoverData.userid, popoverData.groupid, popoverData.canedit); + if (subwiki) { + this.goToSubwiki(subwiki.id, subwiki.userid, subwiki.groupid); } } diff --git a/src/addons/mod/wiki/components/subwiki-picker/addon-mod-wiki-subwiki-picker.html b/src/addons/mod/wiki/components/subwiki-picker/addon-mod-wiki-subwiki-picker.html index 44224516e..aa7de86e6 100644 --- a/src/addons/mod/wiki/components/subwiki-picker/addon-mod-wiki-subwiki-picker.html +++ b/src/addons/mod/wiki/components/subwiki-picker/addon-mod-wiki-subwiki-picker.html @@ -5,8 +5,7 @@

{{ group.label }}

- {{ subwiki.name }} 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 beb98788c..de8d7a318 100644 --- a/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts +++ b/src/addons/mod/wiki/components/subwiki-picker/subwiki-picker.ts @@ -49,12 +49,9 @@ export class AddonModWikiSubwikiPickerComponent { * @param subwiki The subwiki to open. */ openSubwiki(subwiki: AddonModWikiSubwiki): void { - // Check if the subwiki is disabled. - if (subwiki.id > 0 || subwiki.canedit) { - // Check if it isn't current subwiki. - if (subwiki != this.currentSubwiki) { - PopoverController.dismiss(subwiki); - } + // Check if it isn't current subwiki. + if (subwiki !== this.currentSubwiki) { + PopoverController.dismiss(subwiki); } } From 2c20a24f84c5cd9c4682c13c17d6675c27342094 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 24 Nov 2022 14:01:51 +0100 Subject: [PATCH 4/4] MOBILE-4081 wiki: Remove non-null assertions in index page --- src/addons/mod/wiki/components/index/index.ts | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 1c922bf49..852380f03 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -327,8 +327,8 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp await this.showLoadingAndFetch(true, false); - if (this.currentPage) { - CoreUtils.ignoreErrors(AddonModWiki.logPageView(this.currentPage, this.wiki!.id, this.wiki!.name)); + if (this.currentPage && this.wiki) { + CoreUtils.ignoreErrors(AddonModWiki.logPageView(this.currentPage, this.wiki.id, this.wiki.name)); } }, CoreSites.getCurrentSiteId()); } @@ -373,7 +373,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp // If no page specified, search page title in the offline pages. if (!this.currentPage) { - const searchTitle = this.pageTitle ? this.pageTitle : this.wiki!.firstpagetitle; + const searchTitle = this.pageTitle ? this.pageTitle : this.wiki?.firstpagetitle ?? ''; const pageExists = dbPages.some((page) => page.title == searchTitle); if (pageExists) { @@ -482,7 +482,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp `${AddonModWikiModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/edit`, { params: { - pageTitle: this.wiki!.firstpagetitle, + pageTitle: this.wiki?.firstpagetitle ?? '', wikiId: this.currentSubwiki?.wikiid, userId: this.currentSubwiki?.userid, groupId: this.currentSubwiki?.groupid, @@ -640,9 +640,11 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param groupId Group ID of the subwiki. */ goToSubwiki(subwikiId: number, userId: number, groupId: number): void { - if (subwikiId != this.currentSubwiki!.id || userId != this.currentSubwiki!.userid || - groupId != this.currentSubwiki!.groupid) { - + if ( + subwikiId !== this.currentSubwiki?.id || + userId !== this.currentSubwiki?.userid || + groupId !== this.currentSubwiki?.groupid + ) { this.openPageOrSubwiki({ subwikiId: subwikiId, userId: userId, @@ -710,13 +712,17 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * @param result Data returned on the sync function. * @return If suceed or not. */ - protected hasSyncSucceed(result: AddonModWikiSyncWikiResult): boolean { - if (result.updated) { + protected hasSyncSucceed(result: AddonModWikiSyncWikiResult | undefined): boolean { + if (!result) { + return false; + } + + if (result.updated && this.wiki) { // Trigger event. this.ignoreManualSyncEvent = true; CoreEvents.trigger(AddonModWikiSyncProvider.MANUAL_SYNCED, { ...result, - wikiId: this.wiki!.id, + wikiId: this.wiki.id, }); } @@ -841,8 +847,12 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp * * @return Promise resolved when done. */ - protected sync(): Promise { - return AddonModWikiSync.syncWiki(this.wiki!.id, this.courseId, this.wiki!.coursemodule); + protected async sync(): Promise { + if (!this.wiki) { + return; + } + + return AddonModWikiSync.syncWiki(this.wiki.id, this.courseId, this.wiki.coursemodule); } /** @@ -1063,14 +1073,16 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp this.subwikiData.subwikis.push({ label: '', subwikis: subwikiList }); } - AddonModWiki.setSubwikiList( - this.wiki!.id, - this.subwikiData.subwikis, - this.subwikiData.count, - this.subwikiData.subwikiSelected, - this.subwikiData.userSelected, - this.subwikiData.groupSelected, - ); + if (this.wiki) { + AddonModWiki.setSubwikiList( + this.wiki.id, + this.subwikiData.subwikis, + this.subwikiData.count, + this.subwikiData.subwikiSelected, + this.subwikiData.userSelected, + this.subwikiData.groupSelected, + ); + } } }