MOBILE-4616 choice: Move choice constants to a file

main
Pau Ferrer Ocaña 2024-07-11 16:00:37 +02:00
parent eb2555e5ad
commit f65d640999
7 changed files with 22 additions and 18 deletions

View File

@ -35,4 +35,4 @@ const routes: Routes = [
AddonModChoiceIndexPage,
],
})
export class AddonModChoiceLazyModule {}
export default class AddonModChoiceLazyModule {}

View File

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

View File

@ -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();

View File

@ -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';

View File

@ -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<AddonModChoiceSyncResult> {
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,

View File

@ -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;
}
}

View File

@ -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,