MOBILE-4616 survey: Move survey constants to a file

main
Pau Ferrer Ocaña 2024-07-11 16:41:34 +02:00
parent 62f097dc92
commit 346e3d8d57
7 changed files with 23 additions and 24 deletions

View File

@ -25,7 +25,6 @@ import { Translate } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { getPrefetchHandlerInstance } from '../../services/handlers/prefetch'; import { getPrefetchHandlerInstance } from '../../services/handlers/prefetch';
import { import {
AddonModSurveyProvider,
AddonModSurveySurvey, AddonModSurveySurvey,
AddonModSurvey, AddonModSurvey,
AddonModSurveySubmitAnswerData, AddonModSurveySubmitAnswerData,
@ -35,10 +34,10 @@ import { AddonModSurveyOffline } from '../../services/survey-offline';
import { import {
AddonModSurveyAutoSyncData, AddonModSurveyAutoSyncData,
AddonModSurveySync, AddonModSurveySync,
AddonModSurveySyncProvider,
AddonModSurveySyncResult, AddonModSurveySyncResult,
} from '../../services/survey-sync'; } from '../../services/survey-sync';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../../constants';
/** /**
* Component that displays a survey. * Component that displays a survey.
@ -50,7 +49,7 @@ import { CoreUtils } from '@services/utils/utils';
}) })
export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit { export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit {
component = AddonModSurveyProvider.COMPONENT; component = ADDON_MOD_SURVEY_COMPONENT;
pluginName = 'survey'; pluginName = 'survey';
survey?: AddonModSurveySurvey; survey?: AddonModSurveySurvey;
@ -58,7 +57,7 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo
answers: Record<string, string> = {}; answers: Record<string, string> = {};
protected currentUserId?: number; protected currentUserId?: number;
protected syncEventName = AddonModSurveySyncProvider.AUTO_SYNCED; protected syncEventName = ADDON_MOD_SURVEY_AUTO_SYNCED;
constructor( constructor(
protected content?: IonContent, protected content?: IonContent,

View File

@ -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_PREFETCH_UPDATE_NAMES = /^configuration$|^.*files$|^answers$/;
export const ADDON_MOD_SURVEY_SYNC_CRON_NAME = 'AddonModSurveySyncCronHandler'; export const ADDON_MOD_SURVEY_SYNC_CRON_NAME = 'AddonModSurveySyncCronHandler';
export const ADDON_MOD_SURVEY_AUTO_SYNCED = 'addon_mod_survey_autom_synced';

View File

@ -19,9 +19,10 @@ import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModSurvey, AddonModSurveyProvider } from '../survey'; import { AddonModSurvey } from '../survey';
import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync'; import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync';
import { AddonModSurveyPrefetchHandlerService } from '@addons/mod/survey/services/handlers/prefetch'; import { AddonModSurveyPrefetchHandlerService } from '@addons/mod/survey/services/handlers/prefetch';
import { ADDON_MOD_SURVEY_COMPONENT } from '../../constants';
/** /**
* Handler to prefetch surveys. * Handler to prefetch surveys.
@ -84,7 +85,7 @@ export class AddonModSurveyPrefetchHandlerLazyService extends AddonModSurveyPref
const files = this.getIntroFilesFromInstance(module, survey); const files = this.getIntroFilesFromInstance(module, survey);
// Prefetch files. // 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 isn't answered, prefetch the questions.
if (!survey.surveydone) { if (!survey.surveydone) {

View File

@ -24,8 +24,9 @@ import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { getPrefetchHandlerInstance } from './handlers/prefetch'; import { getPrefetchHandlerInstance } from './handlers/prefetch';
import { AddonModSurvey, AddonModSurveyProvider } from './survey'; import { AddonModSurvey } from './survey';
import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from './survey-offline'; import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from './survey-offline';
import { ADDON_MOD_SURVEY_AUTO_SYNCED, ADDON_MOD_SURVEY_COMPONENT } from '../constants';
/** /**
* Service to sync surveys. * Service to sync surveys.
@ -33,8 +34,6 @@ import { AddonModSurveyAnswersDBRecordFormatted, AddonModSurveyOffline } from '.
@Injectable( { providedIn: 'root' }) @Injectable( { providedIn: 'root' })
export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModSurveySyncResult> { export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModSurveySyncResult> {
static readonly AUTO_SYNCED = 'addon_mod_survey_autom_synced';
protected componentTranslatableString = 'survey'; protected componentTranslatableString = 'survey';
constructor() { constructor() {
@ -83,7 +82,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
if (result && result.updated) { if (result && result.updated) {
// Sync successful, send event. // Sync successful, send event.
CoreEvents.trigger(AddonModSurveySyncProvider.AUTO_SYNCED, { CoreEvents.trigger(ADDON_MOD_SURVEY_AUTO_SYNCED, {
surveyId: entry.surveyid, surveyId: entry.surveyid,
userId: entry.userid, userId: entry.userid,
warnings: result.warnings, warnings: result.warnings,
@ -155,7 +154,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
}; };
// Sync offline logs. // 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 answersNumber = 0;
let data: AddonModSurveyAnswersDBRecordFormatted | undefined; let data: AddonModSurveyAnswersDBRecordFormatted | undefined;
@ -229,7 +228,7 @@ declare module '@singletons/events' {
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
*/ */
export interface CoreEventsData { export interface CoreEventsData {
[AddonModSurveySyncProvider.AUTO_SYNCED]: AddonModSurveyAutoSyncData; [ADDON_MOD_SURVEY_AUTO_SYNCED]: AddonModSurveyAutoSyncData;
} }
} }

View File

@ -25,9 +25,7 @@ import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWar
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { AddonModSurveyOffline } from './survey-offline'; import { AddonModSurveyOffline } from './survey-offline';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
import { ADDON_MOD_SURVEY_COMPONENT } from '@addons/mod/survey/constants'; import { ADDON_MOD_SURVEY_COMPONENT } from '../constants';
const ROOT_CACHE_KEY = 'mmaModSurvey:';
/** /**
* Service that provides some features for surveys. * Service that provides some features for surveys.
@ -35,7 +33,7 @@ const ROOT_CACHE_KEY = 'mmaModSurvey:';
@Injectable( { providedIn: 'root' }) @Injectable( { providedIn: 'root' })
export class AddonModSurveyProvider { export class AddonModSurveyProvider {
static readonly COMPONENT = ADDON_MOD_SURVEY_COMPONENT; protected static readonly ROOT_CACHE_KEY = 'mmaModSurvey:';
/** /**
* Get a survey's questions. * Get a survey's questions.
@ -54,7 +52,7 @@ export class AddonModSurveyProvider {
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getQuestionsCacheKey(surveyId), cacheKey: this.getQuestionsCacheKey(surveyId),
updateFrequency: CoreSite.FREQUENCY_RARELY, updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModSurveyProvider.COMPONENT, component: ADDON_MOD_SURVEY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -74,7 +72,7 @@ export class AddonModSurveyProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getQuestionsCacheKey(surveyId: number): string { 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. * @returns Cache key.
*/ */
protected getSurveyCacheKey(courseId: number): string { 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 = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getSurveyCacheKey(courseId), cacheKey: this.getSurveyCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY, updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModSurveyProvider.COMPONENT, component: ADDON_MOD_SURVEY_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -175,7 +173,7 @@ export class AddonModSurveyProvider {
return; return;
})); }));
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModSurveyProvider.COMPONENT, moduleId)); promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_SURVEY_COMPONENT, moduleId));
await CoreUtils.allPromises(promises); await CoreUtils.allPromises(promises);
} }
@ -221,7 +219,7 @@ export class AddonModSurveyProvider {
await CoreCourseLogHelper.log( await CoreCourseLogHelper.log(
'mod_survey_view_survey', 'mod_survey_view_survey',
params, params,
AddonModSurveyProvider.COMPONENT, ADDON_MOD_SURVEY_COMPONENT,
id, id,
siteId, siteId,
); );

View File

@ -36,4 +36,4 @@ const routes: Routes = [
AddonModSurveyIndexPage, AddonModSurveyIndexPage,
], ],
}) })
export class AddonModSurveyLazyModule {} export default class AddonModSurveyLazyModule {}

View File

@ -31,7 +31,7 @@ import { ADDON_MOD_SURVEY_PAGE_NAME } from '@addons/mod/survey/constants';
const routes: Routes = [ const routes: Routes = [
{ {
path: ADDON_MOD_SURVEY_PAGE_NAME, path: ADDON_MOD_SURVEY_PAGE_NAME,
loadChildren: () => import('./survey-lazy.module').then(m => m.AddonModSurveyLazyModule), loadChildren: () => import('./survey-lazy.module'),
}, },
]; ];