MOBILE-3779 wiki: Handle params in wiki index link
parent
9a63793cf2
commit
cb5bde99da
|
@ -350,13 +350,21 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
cmId: this.module.id,
|
cmId: this.module.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// If no page specified, search first page.
|
if (!this.currentPage) {
|
||||||
if (!this.currentPage && !this.pageTitle) {
|
if (!this.pageTitle) {
|
||||||
|
// No page specified, search first page.
|
||||||
const firstPage = subwikiPages.find((page) => page.firstpage );
|
const firstPage = subwikiPages.find((page) => page.firstpage );
|
||||||
if (firstPage) {
|
if (firstPage) {
|
||||||
this.currentPage = firstPage.id;
|
this.currentPage = firstPage.id;
|
||||||
this.pageTitle = firstPage.title;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now get the offline pages.
|
// Now get the offline pages.
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Params } from '@angular/router';
|
||||||
import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler';
|
import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
|
@ -28,6 +29,17 @@ export class AddonModWikiIndexLinkHandlerService extends CoreContentLinksModuleI
|
||||||
super('AddonModWiki', 'wiki', 'wid');
|
super('AddonModWiki', 'wiki', 'wid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
getPageParams(url: string, params: Record<string, string>): 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);
|
export const AddonModWikiIndexLinkHandler = makeSingleton(AddonModWikiIndexLinkHandlerService);
|
||||||
|
|
|
@ -335,7 +335,10 @@ export class AddonModWikiProvider {
|
||||||
|
|
||||||
const response = await site.read<AddonModWikiGetSubwikisWSResponse>('mod_wiki_get_subwikis', params, preSets);
|
const response = await site.read<AddonModWikiGetSubwikisWSResponse>('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.
|
* Data returned by mod_wiki_get_subwikis WS.
|
||||||
*/
|
*/
|
||||||
export type AddonModWikiGetSubwikisWSResponse = {
|
export type AddonModWikiGetSubwikisWSResponse = {
|
||||||
subwikis: AddonModWikiSubwiki[];
|
subwikis: AddonModWikiSubwikiWSData[];
|
||||||
warnings?: CoreWSExternalWarning[];
|
warnings?: CoreWSExternalWarning[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subwiki data returned by mod_wiki_get_subwikis WS.
|
* Subwiki data returned by mod_wiki_get_subwikis WS.
|
||||||
*/
|
*/
|
||||||
export type AddonModWikiSubwiki = {
|
export type AddonModWikiSubwikiWSData = {
|
||||||
id: number; // Subwiki ID.
|
id: number; // Subwiki ID.
|
||||||
wikiid: number; // Wiki ID.
|
wikiid: number; // Wiki ID.
|
||||||
groupid: number; // Group ID.
|
groupid: string; // Group ID.
|
||||||
userid: number; // User ID.
|
userid: number; // User ID.
|
||||||
canedit: boolean; // True if user can edit the subwiki.
|
canedit: boolean; // True if user can edit the subwiki.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subwiki data with some calculated data.
|
||||||
|
*/
|
||||||
|
export type AddonModWikiSubwiki = Omit<AddonModWikiSubwikiWSData, 'groupid'> & {
|
||||||
|
groupid: number; // Group ID.
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Params of mod_wiki_get_wikis_by_courses WS.
|
* Params of mod_wiki_get_wikis_by_courses WS.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue