MOBILE-4329 chore: Link handler action should be async to wait for nav

main
Pau Ferrer Ocaña 2024-03-04 16:00:39 +01:00
parent cca9a3b784
commit 7980f027f0
48 changed files with 131 additions and 141 deletions

View File

@ -35,8 +35,8 @@ export class AddonBadgesBadgeLinkHandlerService extends CoreContentLinksHandlerB
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(`/badges/${params.hash}`, { siteId });
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(`/badges/${params.hash}`, { siteId });
},
}];
}

View File

@ -36,8 +36,8 @@ export class AddonBadgesMyBadgesLinkHandlerService extends CoreContentLinksHandl
*/
getActions(): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath('/badges', { siteId });
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath('/badges', { siteId });
},
}];
}

View File

@ -44,8 +44,8 @@ export class AddonBlogIndexLinkHandlerService extends CoreContentLinksHandlerBas
params.tagid ? pageParams['tagId'] = parseInt(params.tagid, 10) : null;
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath('/blog', { params: pageParams, siteId });
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath('/blog', { params: pageParams, siteId });
},
}];
}

View File

@ -47,7 +47,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId?: string): void => {
action: async (siteId?: string): Promise<void> => {
if (!params.view || params.view == 'month' || params.view == 'mini' || params.view == 'minithree') {
// Monthly view, open the calendar tab.
const stateParams: Params = {
@ -59,7 +59,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler
stateParams.year = momentInstance.year();
stateParams.month = momentInstance.month() + 1;
CoreNavigator.navigateToSitePath('/calendar/index', {
await CoreNavigator.navigateToSitePath('/calendar/index', {
params: stateParams,
siteId,
preferCurrentTab: false,
@ -77,7 +77,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler
stateParams.month = momentInstance.month() + 1;
stateParams.day = momentInstance.date();
CoreNavigator.navigateToSitePath('/calendar/day', { params: stateParams, siteId });
await CoreNavigator.navigateToSitePath('/calendar/day', { params: stateParams, siteId });
} else if (params.view == 'upcoming' || params.view == 'upcoming_mini') {
// Upcoming view, open the calendar tab.
@ -86,7 +86,7 @@ export class AddonCalendarViewLinkHandlerService extends CoreContentLinksHandler
upcoming: true,
};
CoreNavigator.navigateToSitePath('/calendar/index', {
await CoreNavigator.navigateToSitePath('/calendar/index', {
params: stateParams,
siteId,
preferCurrentTab: false,

View File

@ -38,9 +38,9 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink
courseId = courseId || parseInt(params.courseid || params.cid, 10);
return [{
action: (siteId: string): void => {
action: async (siteId: string): Promise<void> => {
if (courseId) {
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`${COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`,
{
params: { userId: params.userid },
@ -52,7 +52,7 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink
}
if (params.planid) {
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`${ADDON_COMPETENCY_LEARNING_PLANS_PAGE}/competencies/${params.planid}`,
{
params: { userId: params.userid },

View File

@ -35,8 +35,8 @@ export class AddonCompetencyPlanLinkHandlerService extends CoreContentLinksHandl
*/
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(
`${ADDON_COMPETENCY_LEARNING_PLANS_PAGE}/${params.id}`,
{ siteId },
);

View File

@ -35,8 +35,8 @@ export class AddonCompetencyPlansLinkHandlerService extends CoreContentLinksHand
*/
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(
ADDON_COMPETENCY_LEARNING_PLANS_PAGE,
{ params: { userId: params.userid }, siteId },
);

View File

@ -35,8 +35,8 @@ export class AddonCompetencyUserCompetencyLinkHandlerService extends CoreContent
*/
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(
`${ADDON_COMPETENCY_COMPETENCIES_PAGE}/${params.id}/${ADDON_COMPETENCY_SUMMARY_PAGE}`,
{ siteId },
);

View File

@ -53,7 +53,7 @@ export class AddonCourseCompletionStatusLinkHandlerService extends CoreContentLi
userId,
};
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
'/coursecompletion',
{ params: pageParams, siteId },
);

View File

@ -35,8 +35,8 @@ export class AddonMessagesContactRequestLinkHandlerService extends CoreContentLi
*/
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
CoreNavigator.navigateToSitePath('/messages/contacts', { siteId });
action: async (siteId): Promise<void> => {
await CoreNavigator.navigateToSitePath('/messages/contacts', { siteId });
},
}];
}

View File

@ -45,9 +45,9 @@ export class AddonMessagesDiscussionLinkHandlerService extends CoreContentLinksH
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const userId = parseInt(params.id || params.user2, 10);
CoreNavigator.navigateToSitePath(`/messages/discussion/user/${userId}`, { siteId });
await CoreNavigator.navigateToSitePath(`/messages/discussion/user/${userId}`, { siteId });
},
}];
}

View File

@ -38,7 +38,7 @@ export class AddonMessagesIndexLinkHandlerService extends CoreContentLinksHandle
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: async (siteId): Promise<void> => {
CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, {
await CoreNavigator.navigateToSitePath(AddonMessagesMainMenuHandlerService.PAGE_NAME, {
siteId,
preferCurrentTab: false,
});

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
@ -34,14 +33,14 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params, courseId?: number): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>, courseId?: number): CoreContentLinksAction[] {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const dataId = parseInt(params.d, 10);
const entryId = parseInt(params.approve, 10) || parseInt(params.disapprove, 10);
const approve = parseInt(params.approve, 10) ? true : false;
AddonModDataHelper.approveOrDisapproveEntry(dataId, entryId, approve, courseId, siteId);
await AddonModDataHelper.approveOrDisapproveEntry(dataId, entryId, approve, courseId, siteId);
},
}];
}
@ -49,7 +48,7 @@ export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandl
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
if (params.d === undefined || (params.approve === undefined && params.disapprove === undefined)) {
// Required fields not defined. Cannot treat the URL.
return false;

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
@ -33,13 +32,13 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params, courseId?: number): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>, courseId?: number): CoreContentLinksAction[] {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const dataId = parseInt(params.d, 10);
const entryId = parseInt(params.delete, 10);
AddonModDataHelper.showDeleteEntryModal(dataId, entryId, courseId, siteId);
await AddonModDataHelper.showDeleteEntryModal(dataId, entryId, courseId, siteId);
},
}];
}
@ -47,7 +46,7 @@ export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandle
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
if (params.d === undefined || params.delete === undefined) {
// Required fields not defined. Cannot treat the URL.
return false;

View File

@ -37,7 +37,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: async (siteId): Promise<void> => {
const modal = await CoreDomUtils.showModalLoading();
@ -54,7 +54,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
title: module.name,
};
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/edit/${rId}`,
{ siteId, params: pageParams },
);
@ -69,7 +69,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
if (params.d === undefined) {
// Id not defined. Cannot treat the URL.
return false;

View File

@ -38,7 +38,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: async (siteId): Promise<void> => {
const modal = await CoreDomUtils.showModalLoading();
@ -65,7 +65,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
pageParams.offset = page || 0;
}
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/${rId}`,
{ siteId, params: pageParams },
);
@ -80,7 +80,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
if (params.d === undefined) {
// Id not defined. Cannot treat the URL.
return false;

View File

@ -53,7 +53,7 @@ export class AddonModFeedbackAnalysisLinkHandlerService extends CoreContentLinks
siteId,
);
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}`,
{
params: {

View File

@ -49,7 +49,7 @@ export class AddonModFeedbackCompleteLinkHandlerService extends CoreContentLinks
{ siteId, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE },
);
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/form`,
{
params: {

View File

@ -49,7 +49,7 @@ export class AddonModFeedbackPrintLinkHandlerService extends CoreContentLinksHan
{ siteId, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE },
);
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
AddonModFeedbackModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/form`,
{
params: {

View File

@ -34,8 +34,8 @@ export class AddonModFeedbackShowEntriesLinkHandlerService extends CoreContentLi
*/
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string) => {
AddonModFeedbackHelper.handleShowEntriesLink(params, siteId);
action: async (siteId: string) => {
await AddonModFeedbackHelper.handleShowEntriesLink(params, siteId);
},
}];
}

View File

@ -36,7 +36,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
getActions(
siteIds: string[],
url: string,
params: Params,
params: Record<string, string>,
courseId?: number,
data?: { instance?: string; cmid?: string; postid?: string },
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
@ -46,10 +46,10 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
// However canreply will be false.
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const discussionId = parseInt(params.d, 10);
const cmId = data?.cmid && Number(data.cmid);
courseId = courseId || (params.courseid && Number(params.courseid)) || (params.cid && Number(params.cid));
courseId = Number(courseId || params.courseid || params.cid);
const pageParams: Params = {
forumId: data?.instance && parseInt(data.instance, 10),
@ -65,7 +65,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
pageParams.parent = parseInt(params.parent);
}
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/${discussionId}`,
{ siteId, params: pageParams },
);
@ -73,13 +73,6 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
}];
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
}
export const AddonModForumDiscussionLinkHandler = makeSingleton(AddonModForumDiscussionLinkHandlerService);

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreCourse } from '@features/course/services/course';
@ -40,7 +39,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler
getActions(
siteIds: string[],
url: string,
params: Params,
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: async (siteId): Promise<void> => {
@ -69,7 +68,7 @@ export class AddonModForumPostLinkHandlerService extends CoreContentLinksHandler
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
return params.forum !== undefined;
}

View File

@ -87,10 +87,10 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink
* @param courseId Course ID.
* @param siteId Site ID.
*/
protected openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): void {
protected async openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): Promise<void> {
const path = AddonModH5PActivityModuleHandlerService.PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`;
CoreNavigator.navigateToSitePath(path, {
await CoreNavigator.navigateToSitePath(path, {
siteId,
});
}

View File

@ -52,16 +52,16 @@ export class AddonModLessonIndexLinkHandlerService extends CoreContentLinksModul
courseId?: number,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
courseId = Number(courseId || params.courseid || params.cid);
const cId = Number(courseId || params.courseid || params.cid);
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
/* Ignore the pageid param. If we open the lesson player with a certain page and the user hasn't started
the lesson, an error is thrown: could not find lesson_timer records. */
if (params.userpassword) {
this.navigateToModuleWithPassword(parseInt(params.id, 10), courseId!, params.userpassword, siteId);
await this.navigateToModuleWithPassword(parseInt(params.id, 10), cId, params.userpassword, siteId);
} else {
CoreCourseHelper.navigateToModule(parseInt(params.id, 10), {
await CoreCourseHelper.navigateToModule(parseInt(params.id, 10), {
courseId,
siteId,
});

View File

@ -47,12 +47,12 @@ export class AddonModLessonReportLinkHandlerService extends CoreContentLinksHand
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId) => {
action: async (siteId) => {
if (!params.action || params.action == 'reportoverview') {
// Go to overview.
this.openReportOverview(Number(params.id), Number(params.group), siteId);
await this.openReportOverview(Number(params.id), Number(params.group), siteId);
} else if (params.action == 'reportdetail') {
this.openUserRetake(Number(params.id), Number(params.userid), Number(params.try), siteId);
await this.openUserRetake(Number(params.id), Number(params.userid), Number(params.try), siteId);
}
},
}];

View File

@ -49,10 +49,10 @@ export class AddonModQuizReviewLinkHandlerService extends CoreContentLinksHandle
const quizId = data?.instance ? Number(data.instance) : undefined;
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const attemptId = parseInt(params.attempt, 10);
const page = parseInt(params.page, 10);
AddonModQuizHelper.handleReviewLink(attemptId, page, quizId, siteId);
await AddonModQuizHelper.handleReviewLink(attemptId, page, quizId, siteId);
},
}];
}

View File

@ -56,7 +56,7 @@ export class AddonModScormPlayerLinkHandlerService extends CoreContentLinksHandl
};
if (cmId) {
CoreCourseHelper.navigateToModule(
await CoreCourseHelper.navigateToModule(
cmId,
{
courseId,
@ -65,7 +65,7 @@ export class AddonModScormPlayerLinkHandlerService extends CoreContentLinksHandl
},
);
} else {
CoreCourseHelper.navigateToModuleByInstance(
await CoreCourseHelper.navigateToModuleByInstance(
instanceId,
'scorm',
{

View File

@ -62,7 +62,7 @@ export class AddonModWikiEditLinkHandlerService extends CoreContentLinksHandlerB
section = params.section.replace(/\+/g, ' ');
}
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
AddonModWikiModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/edit`,
{
params: {

View File

@ -67,7 +67,7 @@ export class AddonModWikiPageOrMapLinkHandlerService extends CoreContentLinksHan
timestamp: Date.now(),
}));
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
AddonModWikiModuleHandlerService.PAGE_NAME + `/${module.course}/${module.id}/page/${hash}`,
{
params: {

View File

@ -35,8 +35,8 @@ export class AddonNotificationsLinkHandlerService extends CoreContentLinksHandle
*/
getActions(): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(AddonNotificationsMainMenuHandlerService.PAGE_NAME, {
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(AddonNotificationsMainMenuHandlerService.PAGE_NAME, {
preferCurrentTab: false,
siteId,
});

View File

@ -37,8 +37,11 @@ export class AddonNotificationsPreferencesLinkHandlerService extends CoreContent
*/
getActions(): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(`preferences/${AddonNotificationsSettingsHandlerService.PAGE_NAME}`, { siteId });
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(
`preferences/${AddonNotificationsSettingsHandlerService.PAGE_NAME}`,
{ siteId },
);
},
}];
}

View File

@ -76,7 +76,7 @@ export class CoreContentLinksModuleGradeHandler extends CoreContentLinksHandlerB
const site = await CoreSites.getSite(siteId);
if (!params.userid || Number(params.userid) == site.getUserId()) {
// No user specified or current user. Navigate to module.
CoreCourseHelper.navigateToModule(
await CoreCourseHelper.navigateToModule(
Number(params.id),
{
courseId: courseIdentifier,
@ -86,10 +86,10 @@ export class CoreContentLinksModuleGradeHandler extends CoreContentLinksHandlerB
);
} else if (this.canReview) {
// Use the goToReview function.
this.goToReview(url, params, courseIdentifier, siteId);
await this.goToReview(url, params, courseIdentifier, siteId);
} else {
// Not current user and cannot review it in the app, open it in browser.
site.openInBrowserWithAutoLogin(url);
await site.openInBrowserWithAutoLogin(url);
}
modal.dismiss();

View File

@ -87,8 +87,8 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB
const instanceId = parseInt(params[this.instanceIdParam], 10);
return [{
action: (siteId) => {
CoreCourseHelper.navigateToModuleByInstance(
action: async (siteId) => {
await CoreCourseHelper.navigateToModuleByInstance(
instanceId,
this.modName,
{
@ -103,8 +103,8 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB
}
return [{
action: (siteId) => {
CoreCourseHelper.navigateToModule(
action: async (siteId) => {
await CoreCourseHelper.navigateToModule(
parseInt(params.id, 10),
{
courseId,

View File

@ -60,8 +60,8 @@ export class CoreContentLinksModuleListHandler extends CoreContentLinksHandlerBa
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
CoreNavigator.navigateToSitePath('course/' + params.id + '/list-mod-type', {
action: async (siteId): Promise<void> => {
await CoreNavigator.navigateToSitePath('course/' + params.id + '/list-mod-type', {
params: {
modName: this.modName,
title: this.title || Translate.instant('addon.mod_' + this.modName + '.modulenameplural'),

View File

@ -118,7 +118,7 @@ export interface CoreContentLinksAction {
*
* @param siteId The site ID.
*/
action(siteId: string): void;
action(siteId: string): Promise<void>;
}
/**

View File

@ -50,7 +50,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler
getActions(
siteIds: string[],
url: string,
params: Params,
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
const courseId = parseInt(params.id, 10);
const sectionId = params.sectionid ? parseInt(params.sectionid, 10) : undefined;
@ -78,7 +78,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler
}
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
siteId = siteId || CoreSites.getCurrentSiteId();
if (siteId === CoreSites.getCurrentSiteId()) {
// Check if we already are in the course index page.
@ -87,15 +87,15 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler
CoreCourse.selectCourseTab('', pageParams);
return;
} else {
this.actionOpen(courseId, url, pageParams).catch(() => {
// Ignore errors.
});
}
} else {
// Make the course the new history root (to avoid "loops" in history).
CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId);
await CoreUtils.ignoreErrors(this.actionOpen(courseId, url, pageParams));
return;
}
// Make the course the new history root (to avoid "loops" in history).
await CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId);
},
}];
}
@ -103,7 +103,7 @@ export class CoreCoursesCourseLinkHandlerService extends CoreContentLinksHandler
/**
* @inheritdoc
*/
async isEnabled(siteId: string, url: string, params: Params): Promise<boolean> {
async isEnabled(siteId: string, url: string, params: Record<string, string>): Promise<boolean> {
const courseId = parseInt(params.id, 10);
if (!courseId) {

View File

@ -33,9 +33,9 @@ export class CoreCoursesIndexLinkHandlerService extends CoreContentLinksHandlerB
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
let pageName = CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME;
const pageParams: Params = {};
@ -46,7 +46,7 @@ export class CoreCoursesIndexLinkHandlerService extends CoreContentLinksHandlerB
pageParams.mode = 'all';
}
CoreNavigator.navigateToSitePath(pageName, { params: pageParams, siteId });
await CoreNavigator.navigateToSitePath(pageName, { params: pageParams, siteId });
},
}];
}

View File

@ -36,9 +36,9 @@ export class CoreCoursesDashboardLinkHandlerService extends CoreContentLinksHand
*/
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
// Use redirect to select the tab.
CoreNavigator.navigateToSitePath(
await CoreNavigator.navigateToSitePath(
`/${CoreMainMenuHomeHandlerService.PAGE_NAME}/${CoreDashboardHomeHandlerService.PAGE_NAME}`,
{
siteId,

View File

@ -16,7 +16,6 @@ import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { makeSingleton } from '@singletons';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { Params } from '@angular/router';
import { CoreNavigator } from '@services/navigator';
/**
* Handler to treat links to my courses page.
@ -36,26 +35,22 @@ export class CoreCoursesMyCoursesLinkHandlerService extends CoreContentLinksHand
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (): void => {
this.actionOpen({
sort: params.sort || undefined,
filter: params.filter || undefined,
search: params.search || undefined,
layout: params.layout || undefined,
});
action: async (): Promise<void> => {
await CoreNavigator.navigate(
'/main/courses/my',
{
params: {
sort: params.sort || undefined,
filter: params.filter || undefined,
search: params.search || undefined,
layout: params.layout || undefined,
},
},
);
},
}];
}
/**
* Open my courses.
*
* @param params Params to send to the new page.
*/
protected actionOpen(params: Params): void {
CoreNavigator.navigate('/main/courses/my', { params });
}
}
export const CoreCoursesMyCoursesLinkHandler = makeSingleton(CoreCoursesMyCoursesLinkHandlerService);

View File

@ -36,8 +36,8 @@ export class CoreGradesOverviewLinkHandlerService extends CoreContentLinksHandle
*/
getActions(): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: siteId => {
CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId });
action: async siteId => {
await CoreNavigator.navigateToSitePath(GRADES_PAGE_NAME, { siteId });
},
}];
}

View File

@ -43,11 +43,11 @@ export class CoreGradesReportLinkHandlerService extends CoreContentLinksHandlerB
data = data || {};
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const userId = params.userid ? parseInt(params.userid, 10) : undefined;
const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined;
CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId);
await CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId);
},
}];
}

View File

@ -43,11 +43,11 @@ export class CoreGradesUserLinkHandlerService extends CoreContentLinksHandlerBas
data = data || {};
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const userId = params.user ? parseInt(params.user, 10) : undefined;
const moduleId = data?.cmid && parseInt(data.cmid, 10) || undefined;
CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId);
await CoreGradesHelper.goToGrades(courseIdentifier, userId, moduleId, siteId);
},
}];
}

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreNavigator } from '@services/navigator';
@ -34,10 +33,13 @@ export class CoreReportBuilderLinkHandlerService extends CoreContentLinksHandler
/**
* @inheritdoc
*/
getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] {
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: async (siteId): Promise<void> => {
CoreNavigator.navigateToSitePath(`${CoreReportBuilderHandlerService.PAGE_NAME}/${params.id || ''}`, { siteId });
await CoreNavigator.navigateToSitePath(
`${CoreReportBuilderHandlerService.PAGE_NAME}/${params.id || ''}`,
{ siteId },
);
},
}];
}

View File

@ -41,8 +41,8 @@ export class CoreSearchGlobalSearchLinkHandlerService extends CoreContentLinksHa
*/
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(CORE_SEARCH_PAGE_NAME, {
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(CORE_SEARCH_PAGE_NAME, {
siteId,
params: {
query: params.q,

View File

@ -46,8 +46,8 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler
}
return [{
action: (siteId: string): void => {
CoreNavigator.navigateToSitePath(
action: async (siteId: string): Promise<void> => {
await CoreNavigator.navigateToSitePath(
`/${CoreMainMenuHomeHandlerService.PAGE_NAME}/${CoreSiteHomeHomeHandlerService.PAGE_NAME}`,
{
preferCurrentTab: false,

View File

@ -38,7 +38,7 @@ export class CoreTagIndexLinkHandlerService extends CoreContentLinksHandlerBase
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const pageParams = {
tagId: parseInt(params.id, 10) || 0,
tagName: params.tag || '',
@ -50,11 +50,11 @@ export class CoreTagIndexLinkHandlerService extends CoreContentLinksHandlerBase
};
if (!pageParams.tagId && (!pageParams.tagName || !pageParams.collectionId)) {
CoreNavigator.navigateToSitePath('/tag/search', { siteId });
await CoreNavigator.navigateToSitePath('/tag/search', { siteId });
} else if (pageParams.areaId) {
CoreNavigator.navigateToSitePath('/tag/index-area', { params: pageParams, siteId });
await CoreNavigator.navigateToSitePath('/tag/index-area', { params: pageParams, siteId });
} else {
CoreNavigator.navigateToSitePath('/tag/index', { params: pageParams, siteId });
await CoreNavigator.navigateToSitePath('/tag/index', { params: pageParams, siteId });
}
},
}];

View File

@ -38,13 +38,13 @@ export class CoreTagSearchLinkHandlerService extends CoreContentLinksHandlerBase
params: Record<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{
action: (siteId): void => {
action: async (siteId): Promise<void> => {
const pageParams = {
collectionId: parseInt(params.tc, 10) || 0,
query: params.query || '',
};
CoreNavigator.navigateToSitePath('/tag/search', { params: pageParams, siteId });
await CoreNavigator.navigateToSitePath('/tag/search', { params: pageParams, siteId });
},
}];
}

View File

@ -52,7 +52,7 @@ export class CoreUserProfileLinkHandlerService extends CoreContentLinksHandlerBa
userId,
};
CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId });
await CoreNavigator.navigateToSitePath('/user', { params: pageParams, siteId });
},
}];
}