From cb5bde99daa3db6f6151b7c13b71868adb8f5c73 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 26 Jul 2021 15:06:23 +0200 Subject: [PATCH] MOBILE-3779 wiki: Handle params in wiki index link --- src/addons/mod/wiki/components/index/index.ts | 20 +++++++++++++------ .../mod/wiki/services/handlers/index-link.ts | 12 +++++++++++ src/addons/mod/wiki/services/wiki.ts | 18 +++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 6fd242ed7..e0a5f3da2 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -350,12 +350,20 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp cmId: this.module.id, }); - // If no page specified, search first page. - if (!this.currentPage && !this.pageTitle) { - const firstPage = subwikiPages.find((page) => page.firstpage ); - if (firstPage) { - this.currentPage = firstPage.id; - this.pageTitle = firstPage.title; + if (!this.currentPage) { + if (!this.pageTitle) { + // No page specified, search first page. + const firstPage = subwikiPages.find((page) => page.firstpage ); + if (firstPage) { + this.currentPage = firstPage.id; + this.pageTitle = firstPage.title; + } + } else { + // Got the page title but not its ID. Search the page. + const page = subwikiPages.find((page) => page.title === this.pageTitle ); + if (page) { + this.currentPage = page.id; + } } } diff --git a/src/addons/mod/wiki/services/handlers/index-link.ts b/src/addons/mod/wiki/services/handlers/index-link.ts index 50c5c4531..c31e68885 100644 --- a/src/addons/mod/wiki/services/handlers/index-link.ts +++ b/src/addons/mod/wiki/services/handlers/index-link.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; +import { Params } from '@angular/router'; import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler'; import { makeSingleton } from '@singletons'; @@ -28,6 +29,17 @@ export class AddonModWikiIndexLinkHandlerService extends CoreContentLinksModuleI super('AddonModWiki', 'wiki', 'wid'); } + /** + * @inheritdoc + */ + getPageParams(url: string, params: Record): Params { + return { + groupId: params.group || params.group === '0' ? Number(params.group) : undefined, + userId: params.uid || params.uid === '0' ? Number(params.uid) : undefined, + pageTitle: params.title, + }; + } + } export const AddonModWikiIndexLinkHandler = makeSingleton(AddonModWikiIndexLinkHandlerService); diff --git a/src/addons/mod/wiki/services/wiki.ts b/src/addons/mod/wiki/services/wiki.ts index 3bdfcf796..5a10fc8b9 100644 --- a/src/addons/mod/wiki/services/wiki.ts +++ b/src/addons/mod/wiki/services/wiki.ts @@ -335,7 +335,10 @@ export class AddonModWikiProvider { const response = await site.read('mod_wiki_get_subwikis', params, preSets); - return response.subwikis; + return response.subwikis.map(subwiki => ({ + ...subwiki, + groupid: Number(subwiki.groupid), // Convert groupid to number. + })); } /** @@ -1112,21 +1115,28 @@ export type AddonModWikiGetSubwikisWSParams = { * Data returned by mod_wiki_get_subwikis WS. */ export type AddonModWikiGetSubwikisWSResponse = { - subwikis: AddonModWikiSubwiki[]; + subwikis: AddonModWikiSubwikiWSData[]; warnings?: CoreWSExternalWarning[]; }; /** * Subwiki data returned by mod_wiki_get_subwikis WS. */ -export type AddonModWikiSubwiki = { +export type AddonModWikiSubwikiWSData = { id: number; // Subwiki ID. wikiid: number; // Wiki ID. - groupid: number; // Group ID. + groupid: string; // Group ID. userid: number; // User ID. canedit: boolean; // True if user can edit the subwiki. }; +/** + * Subwiki data with some calculated data. + */ +export type AddonModWikiSubwiki = Omit & { + groupid: number; // Group ID. +}; + /** * Params of mod_wiki_get_wikis_by_courses WS. */