From d40a488758141742334703d5f5116a9084f91137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 15 Nov 2022 13:20:56 +0100 Subject: [PATCH] MOBILE-3936 reminders: Add click listeners --- src/addons/mod/assign/assign.module.ts | 3 +++ src/addons/mod/chat/chat.module.ts | 3 +++ src/addons/mod/choice/choice.module.ts | 3 +++ src/addons/mod/data/data.module.ts | 3 +++ src/addons/mod/feedback/feedback.module.ts | 3 +++ src/addons/mod/forum/forum.module.ts | 3 +++ src/addons/mod/glossary/glossary.module.ts | 3 +++ src/addons/mod/lesson/lesson.module.ts | 3 +++ src/addons/mod/quiz/quiz.module.ts | 3 +++ src/addons/mod/scorm/scorm.module.ts | 3 +++ src/addons/mod/wiki/wiki.module.ts | 3 +++ src/addons/mod/workshop/workshop.module.ts | 3 +++ .../features/course/services/course-helper.ts | 27 +++++++++++++++++-- src/core/features/courses/courses.module.ts | 13 +++++++++ .../emulator/services/local-notifications.ts | 5 ++++ 15 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/addons/mod/assign/assign.module.ts b/src/addons/mod/assign/assign.module.ts index 001a5cf16..62b4a039c 100644 --- a/src/addons/mod/assign/assign.module.ts +++ b/src/addons/mod/assign/assign.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -77,6 +78,8 @@ const routes: Routes = [ CoreCourseModulePrefetchDelegate.registerHandler(AddonModAssignPrefetchHandler.instance); CoreCronDelegate.register(AddonModAssignSyncCronHandler.instance); CorePushNotificationsDelegate.registerClickHandler(AddonModAssignPushClickHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModAssignProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/chat/chat.module.ts b/src/addons/mod/chat/chat.module.ts index 62509fdd6..39466f886 100644 --- a/src/addons/mod/chat/chat.module.ts +++ b/src/addons/mod/chat/chat.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -52,6 +53,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModChatIndexLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModChatListLinkHandler.instance); CoreCourseModulePrefetchDelegate.registerHandler(AddonModChatPrefetchHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModChatProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/choice/choice.module.ts b/src/addons/mod/choice/choice.module.ts index ed00d95a5..838dbaa6d 100644 --- a/src/addons/mod/choice/choice.module.ts +++ b/src/addons/mod/choice/choice.module.ts @@ -16,6 +16,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -65,6 +66,8 @@ const routes: Routes = [ CoreCronDelegate.register(AddonModChoiceSyncCronHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModChoiceIndexLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModChoiceListLinkHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModChoiceProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/data/data.module.ts b/src/addons/mod/data/data.module.ts index aa75d547d..4db10171d 100644 --- a/src/addons/mod/data/data.module.ts +++ b/src/addons/mod/data/data.module.ts @@ -39,6 +39,7 @@ import { AddonModDataSyncCronHandler } from './services/handlers/sync-cron'; import { AddonModDataTagAreaHandler } from './services/handlers/tag-area'; import { AddonModDataFieldModule } from './fields/field.module'; import { AddonModDataComponentsModule } from './components/components.module'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; // List of providers (without handlers). export const ADDON_MOD_DATA_SERVICES: Type[] = [ @@ -82,6 +83,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModDataShowLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModDataEditLinkHandler.instance); CoreTagAreaDelegate.registerHandler(AddonModDataTagAreaHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModDataProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/feedback/feedback.module.ts b/src/addons/mod/feedback/feedback.module.ts index 1fb74f4d0..f932564cc 100644 --- a/src/addons/mod/feedback/feedback.module.ts +++ b/src/addons/mod/feedback/feedback.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -79,6 +80,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModFeedbackShowEntriesLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModFeedbackShowNonRespondentsLinkHandler.instance); CorePushNotificationsDelegate.registerClickHandler(AddonModFeedbackPushClickHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModFeedbackProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/forum/forum.module.ts b/src/addons/mod/forum/forum.module.ts index aa1fd3a18..1db80bdb1 100644 --- a/src/addons/mod/forum/forum.module.ts +++ b/src/addons/mod/forum/forum.module.ts @@ -43,6 +43,7 @@ import { AddonModForumOfflineProvider } from './services/forum-offline'; import { AddonModForumHelperProvider } from './services/forum-helper'; import { AddonModForumSyncProvider } from './services/forum-sync'; import { COURSE_CONTENTS_PATH } from '@features/course/course.module'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; export const ADDON_MOD_FORUM_SERVICES: Type[] = [ AddonModForumProvider, @@ -121,6 +122,8 @@ const courseContentsRoutes: Routes = conditionalRoutes( CoreContentLinksDelegate.registerHandler(AddonModForumPostLinkHandler.instance); CoreTagAreaDelegate.registerHandler(AddonModForumTagAreaHandler.instance); CorePushNotificationsDelegate.registerClickHandler(AddonModForumPushClickHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModForumProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/glossary/glossary.module.ts b/src/addons/mod/glossary/glossary.module.ts index 1b3e27e42..67b00d1be 100644 --- a/src/addons/mod/glossary/glossary.module.ts +++ b/src/addons/mod/glossary/glossary.module.ts @@ -18,6 +18,7 @@ import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { COURSE_CONTENTS_PATH } from '@features/course/course.module'; import { CoreCourseContentsRoutingModule } from '@features/course/pages/contents/contents-routing.module'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -119,6 +120,8 @@ const courseContentsRoutes: Routes = conditionalRoutes( CoreContentLinksDelegate.registerHandler(AddonModGlossaryEditLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModGlossaryEntryLinkHandler.instance); CoreTagAreaDelegate.registerHandler(AddonModGlossaryTagAreaHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModGlossaryProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/lesson/lesson.module.ts b/src/addons/mod/lesson/lesson.module.ts index 6957ca55f..cf68ac3c0 100644 --- a/src/addons/mod/lesson/lesson.module.ts +++ b/src/addons/mod/lesson/lesson.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; @@ -74,6 +75,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModLessonListLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModLessonReportLinkHandler.instance); CorePushNotificationsDelegate.registerClickHandler(AddonModLessonPushClickHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModLessonProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/quiz/quiz.module.ts b/src/addons/mod/quiz/quiz.module.ts index 05bad8666..10dfa6c42 100644 --- a/src/addons/mod/quiz/quiz.module.ts +++ b/src/addons/mod/quiz/quiz.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; @@ -78,6 +79,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModQuizReviewLinkHandler.instance); CorePushNotificationsDelegate.registerClickHandler(AddonModQuizPushClickHandler.instance); CoreCronDelegate.register(AddonModQuizSyncCronHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModQuizProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/scorm/scorm.module.ts b/src/addons/mod/scorm/scorm.module.ts index 006dea952..84f9221b0 100644 --- a/src/addons/mod/scorm/scorm.module.ts +++ b/src/addons/mod/scorm/scorm.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -73,6 +74,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModScormListLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModScormPlayerLinkHandler.instance); CorePluginFileDelegate.registerHandler(AddonModScormPluginFileHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModScormProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/wiki/wiki.module.ts b/src/addons/mod/wiki/wiki.module.ts index dd63d4c0a..b0cdc6521 100644 --- a/src/addons/mod/wiki/wiki.module.ts +++ b/src/addons/mod/wiki/wiki.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -73,6 +74,8 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(AddonModWikiEditLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModWikiPageOrMapLinkHandler.instance); CoreTagAreaDelegate.registerHandler(AddonModWikiTagAreaHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModWikiProvider.COMPONENT); }, }, ], diff --git a/src/addons/mod/workshop/workshop.module.ts b/src/addons/mod/workshop/workshop.module.ts index 28a93fc50..92ec3d3f9 100644 --- a/src/addons/mod/workshop/workshop.module.ts +++ b/src/addons/mod/workshop/workshop.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -71,6 +72,8 @@ const routes: Routes = [ CoreCronDelegate.register(AddonModWorkshopSyncCronHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModWorkshopIndexLinkHandler.instance); CoreContentLinksDelegate.registerHandler(AddonModWorkshopListLinkHandler.instance); + + CoreCourseHelper.registerModuleReminderClick(AddonModWorkshopProvider.COMPONENT); }, }, ], diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 65d242603..7bae3257d 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -30,7 +30,7 @@ import { } from './course'; import { CoreConstants } from '@/core/constants'; import { CoreLogger } from '@singletons/logger'; -import { makeSingleton, Translate } from '@singletons'; +import { ApplicationInit, makeSingleton, Translate } from '@singletons'; import { CoreFilepool } from '@services/filepool'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils, CoreUtilsOpenFileOptions } from '@services/utils/utils'; @@ -72,6 +72,8 @@ import { CoreSiteHomeHomeHandlerService } from '@features/sitehome/services/hand import { CoreStatusWithWarningsWSResponse } from '@services/ws'; import { CoreCourseWithImageAndColor } from '@features/courses/services/courses-helper'; import { CoreCourseSummaryPage } from '../pages/course-summary/course-summary'; +import { CoreRemindersPushNotificationData } from '@features/reminders/services/reminders'; +import { CoreLocalNotifications } from '@services/local-notifications'; /** * Prefetch info of a module. @@ -1606,7 +1608,7 @@ export class CoreCourseHelperProvider { * @param module The module to open. * @param courseId The course ID of the module. * @param options Other options. - * @param True if module can be opened, false otherwise. + * @return True if module can be opened, false otherwise. */ async openModule(module: CoreCourseModuleData, courseId: number, options: CoreCourseOpenModuleOptions = {}): Promise { if (!module.handlerData) { @@ -2059,6 +2061,27 @@ export class CoreCourseHelperProvider { }); } + /** + * Register click for reminder local notification. + * + * @param component Component to register. + */ + registerModuleReminderClick(component: string): void { + CoreLocalNotifications.registerClick( + component, + async (notification) => { + await ApplicationInit.donePromise; + + CoreCourseHelper.navigateToModule( + notification.instanceId, + { + siteId: notification.siteId, + }, + ); + }, + ); + } + } export const CoreCourseHelper = makeSingleton(CoreCourseHelperProvider); diff --git a/src/core/features/courses/courses.module.ts b/src/core/features/courses/courses.module.ts index 3423b63b2..c4bd4bf93 100644 --- a/src/core/features/courses/courses.module.ts +++ b/src/core/features/courses/courses.module.ts @@ -15,6 +15,7 @@ import { APP_INITIALIZER, NgModule, Type } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; @@ -22,6 +23,9 @@ import { CoreMainMenuHomeRoutingModule } from '@features/mainmenu/pages/home/hom import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate'; import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate'; import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; +import { CoreRemindersPushNotificationData } from '@features/reminders/services/reminders'; +import { CoreLocalNotifications } from '@services/local-notifications'; +import { ApplicationInit } from '@singletons'; import { CoreCoursesProvider } from './services/courses'; import { CoreCoursesHelperProvider } from './services/courses-helper'; import { CoreCoursesDashboardProvider } from './services/dashboard'; @@ -78,6 +82,15 @@ const routes: Routes = [ CoreContentLinksDelegate.registerHandler(CoreCoursesDashboardLinkHandler.instance); CorePushNotificationsDelegate.registerClickHandler(CoreCoursesEnrolPushClickHandler.instance); CorePushNotificationsDelegate.registerClickHandler(CoreCoursesRequestPushClickHandler.instance); + + CoreLocalNotifications.registerClick( + 'course', + async (notification) => { + await ApplicationInit.donePromise; + + CoreCourseHelper.getAndOpenCourse(notification.instanceId, {}, notification.siteId); + }, + ); }, }, ], diff --git a/src/core/features/emulator/services/local-notifications.ts b/src/core/features/emulator/services/local-notifications.ts index 8fac97b80..006b78230 100644 --- a/src/core/features/emulator/services/local-notifications.ts +++ b/src/core/features/emulator/services/local-notifications.ts @@ -119,6 +119,11 @@ export class LocalNotificationsMock extends LocalNotifications { notification.addEventListener('click', () => { this.observables.click.next(nextNotification); + + notification.close(); + if (nextNotification.id) { + delete(this.presentNotifications[nextNotification.id]); + } }); if (nextNotification.id) {