From f65d6409990a70badfae680db58eee51822543b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 11 Jul 2024 16:00:37 +0200 Subject: [PATCH] MOBILE-4616 choice: Move choice constants to a file --- src/addons/mod/choice/choice-lazy.module.ts | 2 +- src/addons/mod/choice/choice.module.ts | 8 ++++---- src/addons/mod/choice/components/index/index.ts | 10 +++++++--- src/addons/mod/choice/constants.ts | 3 +++ src/addons/mod/choice/services/choice-sync.ts | 6 ++---- src/addons/mod/choice/services/choice.ts | 6 +++--- src/addons/mod/choice/services/handlers/module.ts | 5 ++--- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/addons/mod/choice/choice-lazy.module.ts b/src/addons/mod/choice/choice-lazy.module.ts index a5a0627e5..bcbcc9c2d 100644 --- a/src/addons/mod/choice/choice-lazy.module.ts +++ b/src/addons/mod/choice/choice-lazy.module.ts @@ -35,4 +35,4 @@ const routes: Routes = [ AddonModChoiceIndexPage, ], }) -export class AddonModChoiceLazyModule {} +export default class AddonModChoiceLazyModule {} diff --git a/src/addons/mod/choice/choice.module.ts b/src/addons/mod/choice/choice.module.ts index b09b8ab97..d681d011d 100644 --- a/src/addons/mod/choice/choice.module.ts +++ b/src/addons/mod/choice/choice.module.ts @@ -25,15 +25,15 @@ import { CORE_SITE_SCHEMAS } from '@services/sites'; import { OFFLINE_SITE_SCHEMA } from './services/database/choice'; import { AddonModChoiceIndexLinkHandler } from './services/handlers/index-link'; import { AddonModChoiceListLinkHandler } from './services/handlers/list-link'; -import { AddonModChoiceModuleHandler, AddonModChoiceModuleHandlerService } from './services/handlers/module'; +import { AddonModChoiceModuleHandler } from './services/handlers/module'; import { AddonModChoicePrefetchHandler } from './services/handlers/prefetch'; import { AddonModChoiceSyncCronHandler } from './services/handlers/sync-cron'; -import { ADDON_MOD_CHOICE_COMPONENT } from './constants'; +import { ADDON_MOD_CHOICE_COMPONENT, ADDON_MOD_CHOICE_PAGE_NAME } from './constants'; const routes: Routes = [ { - path: AddonModChoiceModuleHandlerService.PAGE_NAME, - loadChildren: () => import('./choice-lazy.module').then(m => m.AddonModChoiceLazyModule), + path: ADDON_MOD_CHOICE_PAGE_NAME, + loadChildren: () => import('./choice-lazy.module'), }, ]; diff --git a/src/addons/mod/choice/components/index/index.ts b/src/addons/mod/choice/components/index/index.ts index 69ac15956..a64944d79 100644 --- a/src/addons/mod/choice/components/index/index.ts +++ b/src/addons/mod/choice/components/index/index.ts @@ -32,11 +32,15 @@ import { AddonModChoiceOffline } from '../../services/choice-offline'; import { AddonModChoiceAutoSyncData, AddonModChoiceSync, - AddonModChoiceSyncProvider, AddonModChoiceSyncResult, } from '../../services/choice-sync'; import { AddonModChoicePrefetchHandler } from '../../services/handlers/prefetch'; -import { ADDON_MOD_CHOICE_COMPONENT, ADDON_MOD_CHOICE_PUBLISH_ANONYMOUS, AddonModChoiceShowResults } from '../../constants'; +import { + ADDON_MOD_CHOICE_AUTO_SYNCED, + ADDON_MOD_CHOICE_COMPONENT, + ADDON_MOD_CHOICE_PUBLISH_ANONYMOUS, + AddonModChoiceShowResults, +} from '../../constants'; /** * Component that displays a choice. @@ -64,7 +68,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo publishInfo?: string; // Message explaining the user what will happen with his choices. protected userId?: number; - protected syncEventName = AddonModChoiceSyncProvider.AUTO_SYNCED; + protected syncEventName = ADDON_MOD_CHOICE_AUTO_SYNCED; protected hasAnsweredOnline = false; protected now = CoreTimeUtils.timestamp(); diff --git a/src/addons/mod/choice/constants.ts b/src/addons/mod/choice/constants.ts index af337952b..9e2be82e4 100644 --- a/src/addons/mod/choice/constants.ts +++ b/src/addons/mod/choice/constants.ts @@ -13,6 +13,7 @@ // limitations under the License. export const ADDON_MOD_CHOICE_COMPONENT = 'mmaModChoice'; +export const ADDON_MOD_CHOICE_PAGE_NAME = 'mod_choice'; /** * Possible show results values. @@ -27,3 +28,5 @@ export const enum AddonModChoiceShowResults { // Possible choice publish values. export const ADDON_MOD_CHOICE_PUBLISH_ANONYMOUS = false; export const ADDON_MOD_CHOICE_PUBLISH_NAMES = true; + +export const ADDON_MOD_CHOICE_AUTO_SYNCED = 'addon_mod_choice_autom_synced'; diff --git a/src/addons/mod/choice/services/choice-sync.ts b/src/addons/mod/choice/services/choice-sync.ts index 7a9cf0040..16adaa888 100644 --- a/src/addons/mod/choice/services/choice-sync.ts +++ b/src/addons/mod/choice/services/choice-sync.ts @@ -26,7 +26,7 @@ import { CoreEvents } from '@singletons/events'; import { AddonModChoice } from './choice'; import { AddonModChoiceOffline } from './choice-offline'; import { AddonModChoicePrefetchHandler } from './handlers/prefetch'; -import { ADDON_MOD_CHOICE_COMPONENT } from '../constants'; +import { ADDON_MOD_CHOICE_AUTO_SYNCED, ADDON_MOD_CHOICE_COMPONENT } from '../constants'; /** * Service to sync choices. @@ -34,8 +34,6 @@ import { ADDON_MOD_CHOICE_COMPONENT } from '../constants'; @Injectable({ providedIn: 'root' }) export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvider { - static readonly AUTO_SYNCED = 'addon_mod_choice_autom_synced'; - protected componentTranslatableString = 'choice'; constructor() { @@ -82,7 +80,7 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid if (result?.updated) { // Sync successful, send event. - CoreEvents.trigger(AddonModChoiceSyncProvider.AUTO_SYNCED, { + CoreEvents.trigger(ADDON_MOD_CHOICE_AUTO_SYNCED, { choiceId: response.choiceid, userId: response.userid, warnings: result.warnings, diff --git a/src/addons/mod/choice/services/choice.ts b/src/addons/mod/choice/services/choice.ts index 8cbe5e197..60f50c26b 100644 --- a/src/addons/mod/choice/services/choice.ts +++ b/src/addons/mod/choice/services/choice.ts @@ -25,9 +25,9 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { AddonModChoiceOffline } from './choice-offline'; -import { AddonModChoiceAutoSyncData, AddonModChoiceSyncProvider } from './choice-sync'; +import { AddonModChoiceAutoSyncData } from './choice-sync'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; -import { ADDON_MOD_CHOICE_COMPONENT, AddonModChoiceShowResults } from '../constants'; +import { ADDON_MOD_CHOICE_AUTO_SYNCED, ADDON_MOD_CHOICE_COMPONENT, AddonModChoiceShowResults } from '../constants'; /** * Service that provides some features for choices. @@ -611,7 +611,7 @@ declare module '@singletons/events' { * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation */ export interface CoreEventsData { - [AddonModChoiceSyncProvider.AUTO_SYNCED]: AddonModChoiceAutoSyncData; + [ADDON_MOD_CHOICE_AUTO_SYNCED]: AddonModChoiceAutoSyncData; } } diff --git a/src/addons/mod/choice/services/handlers/module.ts b/src/addons/mod/choice/services/handlers/module.ts index 035b7832a..1f4523c32 100644 --- a/src/addons/mod/choice/services/handlers/module.ts +++ b/src/addons/mod/choice/services/handlers/module.ts @@ -17,6 +17,7 @@ import { Injectable, Type } from '@angular/core'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; import { CoreCourseModuleHandler } from '@features/course/services/module-delegate'; import { makeSingleton } from '@singletons'; +import { ADDON_MOD_CHOICE_PAGE_NAME } from '../../constants'; /** * Handler to support choice modules. @@ -24,11 +25,9 @@ import { makeSingleton } from '@singletons'; @Injectable({ providedIn: 'root' }) export class AddonModChoiceModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler { - static readonly PAGE_NAME = 'mod_choice'; - name = 'AddonModChoice'; modName = 'choice'; - protected pageName = AddonModChoiceModuleHandlerService.PAGE_NAME; + protected pageName = ADDON_MOD_CHOICE_PAGE_NAME; supportedFeatures = { [CoreConstants.FEATURE_GROUPS]: true,