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 { 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<string, string> = {};
protected currentUserId?: number;
protected syncEventName = AddonModSurveySyncProvider.AUTO_SYNCED;
protected syncEventName = ADDON_MOD_SURVEY_AUTO_SYNCED;
constructor(
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_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 { 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) {

View File

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

View File

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

View File

@ -36,4 +36,4 @@ const routes: Routes = [
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 = [
{
path: ADDON_MOD_SURVEY_PAGE_NAME,
loadChildren: () => import('./survey-lazy.module').then(m => m.AddonModSurveyLazyModule),
loadChildren: () => import('./survey-lazy.module'),
},
];