MOBILE-3936 reminders: Add click listeners

main
Pau Ferrer Ocaña 2022-11-15 13:20:56 +01:00
parent 36dfd856bb
commit d40a488758
15 changed files with 79 additions and 2 deletions

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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<unknown>[] = [
@ -82,6 +83,8 @@ const routes: Routes = [
CoreContentLinksDelegate.registerHandler(AddonModDataShowLinkHandler.instance);
CoreContentLinksDelegate.registerHandler(AddonModDataEditLinkHandler.instance);
CoreTagAreaDelegate.registerHandler(AddonModDataTagAreaHandler.instance);
CoreCourseHelper.registerModuleReminderClick(AddonModDataProvider.COMPONENT);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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<unknown>[] = [
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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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);
},
},
],

View File

@ -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<boolean> {
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<CoreRemindersPushNotificationData>(
component,
async (notification) => {
await ApplicationInit.donePromise;
CoreCourseHelper.navigateToModule(
notification.instanceId,
{
siteId: notification.siteId,
},
);
},
);
}
}
export const CoreCourseHelper = makeSingleton(CoreCourseHelperProvider);

View File

@ -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<CoreRemindersPushNotificationData>(
'course',
async (notification) => {
await ApplicationInit.donePromise;
CoreCourseHelper.getAndOpenCourse(notification.instanceId, {}, notification.siteId);
},
);
},
},
],

View File

@ -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) {