2
0
Fork 0

MOBILE-4081 user: Admit profile urls without id

main
Pau Ferrer Ocaña 2022-11-25 12:01:47 +01:00
parent 63621a0789
commit fed0239c72
2 changed files with 13 additions and 5 deletions

View File

@ -31,9 +31,9 @@ import { CoreDomUtils } from '@services/utils/dom';
}) })
export class AddonCourseCompletionReportPage implements OnInit { export class AddonCourseCompletionReportPage implements OnInit {
protected courseId!: number;
protected userId!: number; protected userId!: number;
courseId!: number;
completionLoaded = false; completionLoaded = false;
completion?: AddonCourseCompletionCourseCompletionStatus; completion?: AddonCourseCompletionCourseCompletionStatus;
showSelfComplete = false; showSelfComplete = false;

View File

@ -17,6 +17,7 @@ import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
/** /**
@ -27,7 +28,7 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa
name = 'CoreUserProfileLinkHandler'; name = 'CoreUserProfileLinkHandler';
// Match user/view.php and user/profile.php but NOT grade/report/user/. // Match user/view.php and user/profile.php but NOT grade/report/user/.
pattern = /((\/user\/view\.php)|(\/user\/profile\.php)).*([?&]id=\d+)/; pattern = /(\/user\/view\.php)|(\/user\/profile\.php)/;
/** /**
* @inheritdoc * @inheritdoc
@ -37,11 +38,18 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa
url: string, url: string,
params: Record<string, string>, params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { ): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{ return [{
action: (siteId): void => { action: async (siteId): Promise<void> => {
let userId = params.id ? parseInt(params.id, 10) : 0;
if (!userId) {
const site = await CoreSites.getSite(siteId);
userId = site.getUserId();
}
const pageParams = { const pageParams = {
courseId: params.course, courseId: params.course,
userId: parseInt(params.id, 10), userId,
}; };
CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId }); CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId });
@ -53,7 +61,7 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa
* @inheritdoc * @inheritdoc
*/ */
async isEnabled(siteId: string, url: string): Promise<boolean> { async isEnabled(siteId: string, url: string): Promise<boolean> {
return url.indexOf('/grade/report/') == -1; return url.indexOf('/grade/report/') === -1;
} }
} }