diff --git a/src/addons/mod/survey/components/index/index.ts b/src/addons/mod/survey/components/index/index.ts index e7570b19f..0d8a4b583 100644 --- a/src/addons/mod/survey/components/index/index.ts +++ b/src/addons/mod/survey/components/index/index.ts @@ -25,7 +25,6 @@ import { Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { getPrefetchHandlerInstance } from '../../services/handlers/prefetch'; import { - AddonModSurveyProvider, AddonModSurveySurvey, AddonModSurvey, AddonModSurveySubmitAnswerData, @@ -35,10 +34,10 @@ import { AddonModSurveyOffline } from '../../services/survey-offline'; import { AddonModSurveyAutoSyncData, AddonModSurveySync, - AddonModSurveySyncProvider, AddonModSurveySyncResult, } from '../../services/survey-sync'; import { CoreUtils } from '@services/utils/utils'; +import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../../constants'; /** * Component that displays a survey. @@ -50,7 +49,7 @@ import { CoreUtils } from '@services/utils/utils'; }) export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit { - component = AddonModSurveyProvider.COMPONENT; + component = ADDON_MOD_SURVEY_COMPONENT; pluginName = 'survey'; survey?: AddonModSurveySurvey; @@ -58,7 +57,7 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo answers: Record = {}; protected currentUserId?: number; - protected syncEventName = AddonModSurveySyncProvider.AUTO_SYNCED; + protected syncEventName = ADDON_MOD_SURVEY_AUTO_SYNCED; constructor( protected content?: IonContent, diff --git a/src/addons/mod/survey/constants.ts b/src/addons/mod/survey/constants.ts index bcbc93f72..3480546df 100644 --- a/src/addons/mod/survey/constants.ts +++ b/src/addons/mod/survey/constants.ts @@ -24,3 +24,5 @@ export const ADDON_MOD_SURVEY_PREFETCH_COMPONENT = ADDON_MOD_SURVEY_COMPONENT; export const ADDON_MOD_SURVEY_PREFETCH_UPDATE_NAMES = /^configuration$|^.*files$|^answers$/; export const ADDON_MOD_SURVEY_SYNC_CRON_NAME = 'AddonModSurveySyncCronHandler'; + +export const ADDON_MOD_SURVEY_AUTO_SYNCED = 'addon_mod_survey_autom_synced'; diff --git a/src/addons/mod/survey/services/handlers/prefetch-lazy.ts b/src/addons/mod/survey/services/handlers/prefetch-lazy.ts index f8b361afa..32b8120c9 100644 --- a/src/addons/mod/survey/services/handlers/prefetch-lazy.ts +++ b/src/addons/mod/survey/services/handlers/prefetch-lazy.ts @@ -19,9 +19,10 @@ import { CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; -import { AddonModSurvey, AddonModSurveyProvider } from '../survey'; +import { AddonModSurvey } from '../survey'; import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync'; import { AddonModSurveyPrefetchHandlerService } from '@addons/mod/survey/services/handlers/prefetch'; +import { ADDON_MOD_SURVEY_COMPONENT } from '../../constants'; /** * Handler to prefetch surveys. @@ -84,7 +85,7 @@ export class AddonModSurveyPrefetchHandlerLazyService extends AddonModSurveyPref const files = this.getIntroFilesFromInstance(module, survey); // Prefetch files. - promises.push(CoreFilepool.addFilesToQueue(siteId, files, AddonModSurveyProvider.COMPONENT, module.id)); + promises.push(CoreFilepool.addFilesToQueue(siteId, files, ADDON_MOD_SURVEY_COMPONENT, module.id)); // If survey isn't answered, prefetch the questions. if (!survey.surveydone) { diff --git a/src/addons/mod/survey/services/survey-sync.ts b/src/addons/mod/survey/services/survey-sync.ts index 71c32018f..54a793fe6 100644 --- a/src/addons/mod/survey/services/survey-sync.ts +++ b/src/addons/mod/survey/services/survey-sync.ts @@ -24,8 +24,9 @@ import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { getPrefetchHandlerInstance } from './handlers/prefetch'; -import { AddonModSurvey, AddonModSurveyProvider } from './survey'; +import { AddonModSurvey } from './survey'; import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from './survey-offline'; +import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../constants'; /** * Service to sync surveys. @@ -33,8 +34,6 @@ import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from '. @Injectable( { providedIn: 'root' }) export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvider { - static readonly AUTO_SYNCED = 'addon_mod_survey_autom_synced'; - protected componentTranslatableString = 'survey'; constructor() { @@ -83,7 +82,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid if (result && result.updated) { // Sync successful, send event. - CoreEvents.trigger(AddonModSurveySyncProvider.AUTO_SYNCED, { + CoreEvents.trigger(ADDON_MOD_SURVEY_AUTO_SYNCED, { surveyId: entry.surveyid, userId: entry.userid, warnings: result.warnings, @@ -155,7 +154,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid }; // Sync offline logs. - CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(AddonModSurveyProvider.COMPONENT, surveyId, siteId)); + CoreUtils.ignoreErrors(CoreCourseLogHelper.syncActivity(ADDON_MOD_SURVEY_COMPONENT, surveyId, siteId)); let answersNumber = 0; let data: AddonModSurveyAnswersDBRecordFormatted | undefined; @@ -229,7 +228,7 @@ declare module '@singletons/events' { * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation */ export interface CoreEventsData { - [AddonModSurveySyncProvider.AUTO_SYNCED]: AddonModSurveyAutoSyncData; + [ADDON_MOD_SURVEY_AUTO_SYNCED]: AddonModSurveyAutoSyncData; } } diff --git a/src/addons/mod/survey/services/survey.ts b/src/addons/mod/survey/services/survey.ts index 81824a3e4..ca76d8e34 100644 --- a/src/addons/mod/survey/services/survey.ts +++ b/src/addons/mod/survey/services/survey.ts @@ -25,9 +25,7 @@ import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWar import { makeSingleton, Translate } from '@singletons'; import { AddonModSurveyOffline } from './survey-offline'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; -import { ADDON_MOD_SURVEY_COMPONENT } from '@addons/mod/survey/constants'; - -const ROOT_CACHE_KEY = 'mmaModSurvey:'; +import { ADDON_MOD_SURVEY_COMPONENT } from '../constants'; /** * Service that provides some features for surveys. @@ -35,7 +33,7 @@ const ROOT_CACHE_KEY = 'mmaModSurvey:'; @Injectable( { providedIn: 'root' }) export class AddonModSurveyProvider { - static readonly COMPONENT = ADDON_MOD_SURVEY_COMPONENT; + protected static readonly ROOT_CACHE_KEY = 'mmaModSurvey:'; /** * Get a survey's questions. @@ -54,7 +52,7 @@ export class AddonModSurveyProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getQuestionsCacheKey(surveyId), updateFrequency: CoreSite.FREQUENCY_RARELY, - component: AddonModSurveyProvider.COMPONENT, + component: ADDON_MOD_SURVEY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -74,7 +72,7 @@ export class AddonModSurveyProvider { * @returns Cache key. */ protected getQuestionsCacheKey(surveyId: number): string { - return ROOT_CACHE_KEY + 'questions:' + surveyId; + return AddonModSurveyProvider.ROOT_CACHE_KEY + 'questions:' + surveyId; } /** @@ -84,7 +82,7 @@ export class AddonModSurveyProvider { * @returns Cache key. */ protected getSurveyCacheKey(courseId: number): string { - return ROOT_CACHE_KEY + 'survey:' + courseId; + return AddonModSurveyProvider.ROOT_CACHE_KEY + 'survey:' + courseId; } /** @@ -111,7 +109,7 @@ export class AddonModSurveyProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getSurveyCacheKey(courseId), updateFrequency: CoreSite.FREQUENCY_RARELY, - component: AddonModSurveyProvider.COMPONENT, + component: ADDON_MOD_SURVEY_COMPONENT, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -175,7 +173,7 @@ export class AddonModSurveyProvider { return; })); - promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModSurveyProvider.COMPONENT, moduleId)); + promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_SURVEY_COMPONENT, moduleId)); await CoreUtils.allPromises(promises); } @@ -221,7 +219,7 @@ export class AddonModSurveyProvider { await CoreCourseLogHelper.log( 'mod_survey_view_survey', params, - AddonModSurveyProvider.COMPONENT, + ADDON_MOD_SURVEY_COMPONENT, id, siteId, ); diff --git a/src/addons/mod/survey/survey-lazy.module.ts b/src/addons/mod/survey/survey-lazy.module.ts index bd372d315..ff8a578d0 100644 --- a/src/addons/mod/survey/survey-lazy.module.ts +++ b/src/addons/mod/survey/survey-lazy.module.ts @@ -36,4 +36,4 @@ const routes: Routes = [ AddonModSurveyIndexPage, ], }) -export class AddonModSurveyLazyModule {} +export default class AddonModSurveyLazyModule {} diff --git a/src/addons/mod/survey/survey.module.ts b/src/addons/mod/survey/survey.module.ts index 707f22845..3f1c3e8e7 100644 --- a/src/addons/mod/survey/survey.module.ts +++ b/src/addons/mod/survey/survey.module.ts @@ -31,7 +31,7 @@ import { ADDON_MOD_SURVEY_PAGE_NAME } from '@addons/mod/survey/constants'; const routes: Routes = [ { path: ADDON_MOD_SURVEY_PAGE_NAME, - loadChildren: () => import('./survey-lazy.module').then(m => m.AddonModSurveyLazyModule), + loadChildren: () => import('./survey-lazy.module'), }, ];