From d3b02b07e45401161918749fbee7bb9a835abde6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 12 Jul 2024 11:39:29 +0200 Subject: [PATCH] MOBILE-4616 quiz: Move quiz constants to a file --- src/addons/mod/quiz/components/index/index.ts | 16 ++++++++++------ src/addons/mod/quiz/constants.ts | 4 ++++ src/addons/mod/quiz/quiz-lazy.module.ts | 2 +- src/addons/mod/quiz/quiz.module.ts | 8 ++++---- src/addons/mod/quiz/services/handlers/module.ts | 5 ++--- src/addons/mod/quiz/services/quiz-helper.ts | 4 ++-- src/addons/mod/quiz/services/quiz-sync.ts | 6 ++---- src/addons/mod/quiz/services/quiz.ts | 5 +++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/addons/mod/quiz/components/index/index.ts b/src/addons/mod/quiz/components/index/index.ts index 5c571eb9a..0e2d76bd3 100644 --- a/src/addons/mod/quiz/components/index/index.ts +++ b/src/addons/mod/quiz/components/index/index.ts @@ -26,7 +26,6 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; import { Translate } from '@singletons'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { AddonModQuizModuleHandlerService } from '../../services/handlers/module'; import { AddonModQuizPrefetchHandler } from '../../services/handlers/prefetch'; import { AddonModQuiz, @@ -42,10 +41,15 @@ import { AddonModQuizAttempt, AddonModQuizHelper, AddonModQuizQuizData } from '. import { AddonModQuizAutoSyncData, AddonModQuizSync, - AddonModQuizSyncProvider, AddonModQuizSyncResult, } from '../../services/quiz-sync'; -import { ADDON_MOD_QUIZ_ATTEMPT_FINISHED_EVENT, ADDON_MOD_QUIZ_COMPONENT, AddonModQuizAttemptStates } from '../../constants'; +import { + ADDON_MOD_QUIZ_ATTEMPT_FINISHED_EVENT, + ADDON_MOD_QUIZ_AUTO_SYNCED, + ADDON_MOD_QUIZ_COMPONENT, + ADDON_MOD_QUIZ_PAGE_NAME, + AddonModQuizAttemptStates, +} from '../../constants'; import { QuestionDisplayOptionsMarks } from '@features/question/constants'; /** @@ -83,7 +87,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp bestGrade?: AddonModQuizGetUserBestGradeWSResponse; // Best grade data. protected fetchContentDefaultError = 'addon.mod_quiz.errorgetquiz'; // Default error to show when loading contents. - protected syncEventName = AddonModQuizSyncProvider.AUTO_SYNCED; + protected syncEventName = ADDON_MOD_QUIZ_AUTO_SYNCED; protected autoReview?: AddonModQuizAttemptFinishedData; // Data to auto-review an attempt after finishing. protected quizAccessInfo?: AddonModQuizGetQuizAccessInformationWSResponse; // Quiz access info. @@ -505,7 +509,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp this.hasPlayed = true; CoreNavigator.navigateToSitePath( - `${AddonModQuizModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/player`, + `${ADDON_MOD_QUIZ_PAGE_NAME}/${this.courseId}/${this.module.id}/player`, { params: { moduleUrl: this.module.url, @@ -657,7 +661,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp */ async reviewAttempt(attemptId: number): Promise { await CoreNavigator.navigateToSitePath( - `${AddonModQuizModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/review/${attemptId}`, + `${ADDON_MOD_QUIZ_PAGE_NAME}/${this.courseId}/${this.module.id}/review/${attemptId}`, ); } diff --git a/src/addons/mod/quiz/constants.ts b/src/addons/mod/quiz/constants.ts index cc5e687d3..67bd89826 100644 --- a/src/addons/mod/quiz/constants.ts +++ b/src/addons/mod/quiz/constants.ts @@ -14,10 +14,14 @@ export const ADDON_MOD_QUIZ_COMPONENT = 'mmaModQuiz'; +export const ADDON_MOD_QUIZ_PAGE_NAME = 'mod_quiz'; + export const ADDON_MOD_QUIZ_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModQuiz'; export const ADDON_MOD_QUIZ_ATTEMPT_FINISHED_EVENT = 'addon_mod_quiz_attempt_finished'; +export const ADDON_MOD_QUIZ_AUTO_SYNCED = 'addon_mod_quiz_autom_synced'; + export const ADDON_MOD_QUIZ_SHOW_TIME_BEFORE_DEADLINE = 3600; export const ADDON_MOD_QUIZ_IMMEDIATELY_AFTER_PERIOD = 120; // Time considered 'immedately after the attempt', in seconds. diff --git a/src/addons/mod/quiz/quiz-lazy.module.ts b/src/addons/mod/quiz/quiz-lazy.module.ts index 99f8d8607..1d4c4e0eb 100644 --- a/src/addons/mod/quiz/quiz-lazy.module.ts +++ b/src/addons/mod/quiz/quiz-lazy.module.ts @@ -53,4 +53,4 @@ const routes: Routes = [ AddonModQuizReviewPage, ], }) -export class AddonModQuizLazyModule {} +export default class AddonModQuizLazyModule {} diff --git a/src/addons/mod/quiz/quiz.module.ts b/src/addons/mod/quiz/quiz.module.ts index e51dc8888..c8e465620 100644 --- a/src/addons/mod/quiz/quiz.module.ts +++ b/src/addons/mod/quiz/quiz.module.ts @@ -28,12 +28,12 @@ import { SITE_SCHEMA } from './services/database/quiz'; import { AddonModQuizGradeLinkHandler } from './services/handlers/grade-link'; import { AddonModQuizIndexLinkHandler } from './services/handlers/index-link'; import { AddonModQuizListLinkHandler } from './services/handlers/list-link'; -import { AddonModQuizModuleHandler, AddonModQuizModuleHandlerService } from './services/handlers/module'; +import { AddonModQuizModuleHandler } from './services/handlers/module'; import { AddonModQuizPrefetchHandler } from './services/handlers/prefetch'; import { AddonModQuizPushClickHandler } from './services/handlers/push-click'; import { AddonModQuizReviewLinkHandler } from './services/handlers/review-link'; import { AddonModQuizSyncCronHandler } from './services/handlers/sync-cron'; -import { ADDON_MOD_QUIZ_COMPONENT } from './constants'; +import { ADDON_MOD_QUIZ_COMPONENT, ADDON_MOD_QUIZ_PAGE_NAME } from './constants'; /** * Get mod Quiz services. @@ -69,8 +69,8 @@ export async function getModQuizComponentModules(): Promise { const routes: Routes = [ { - path: AddonModQuizModuleHandlerService.PAGE_NAME, - loadChildren: () => import('./quiz-lazy.module').then(m => m.AddonModQuizLazyModule), + path: ADDON_MOD_QUIZ_PAGE_NAME, + loadChildren: () => import('./quiz-lazy.module'), }, ]; diff --git a/src/addons/mod/quiz/services/handlers/module.ts b/src/addons/mod/quiz/services/handlers/module.ts index 39c563c7d..73c2ca744 100644 --- a/src/addons/mod/quiz/services/handlers/module.ts +++ b/src/addons/mod/quiz/services/handlers/module.ts @@ -18,6 +18,7 @@ import { CoreConstants, ModPurpose } from '@/core/constants'; import { CoreCourseModuleHandler } from '@features/course/services/module-delegate'; import { makeSingleton } from '@singletons'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; +import { ADDON_MOD_QUIZ_PAGE_NAME } from '../../constants'; /** * Handler to support quiz modules. @@ -25,11 +26,9 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand @Injectable({ providedIn: 'root' }) export class AddonModQuizModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler { - static readonly PAGE_NAME = 'mod_quiz'; - name = 'AddonModQuiz'; modName = 'quiz'; - protected pageName = AddonModQuizModuleHandlerService.PAGE_NAME; + protected pageName = ADDON_MOD_QUIZ_PAGE_NAME; supportedFeatures = { [CoreConstants.FEATURE_GROUPS]: true, diff --git a/src/addons/mod/quiz/services/quiz-helper.ts b/src/addons/mod/quiz/services/quiz-helper.ts index 66432a360..383cf2320 100644 --- a/src/addons/mod/quiz/services/quiz-helper.ts +++ b/src/addons/mod/quiz/services/quiz-helper.ts @@ -23,7 +23,6 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton, Translate } from '@singletons'; import { AddonModQuizAccessRuleDelegate } from './access-rules-delegate'; -import { AddonModQuizModuleHandlerService } from './handlers/module'; import { AddonModQuiz, AddonModQuizAttemptWSData, @@ -34,6 +33,7 @@ import { import { AddonModQuizOffline } from './quiz-offline'; import { ADDON_MOD_QUIZ_IMMEDIATELY_AFTER_PERIOD, + ADDON_MOD_QUIZ_PAGE_NAME, AddonModQuizAttemptStates, AddonModQuizDisplayOptionsAttemptStates, } from '../constants'; @@ -349,7 +349,7 @@ export class AddonModQuizHelperProvider { // Go to the review page. await CoreNavigator.navigateToSitePath( - `${AddonModQuizModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/review/${attemptId}`, + `${ADDON_MOD_QUIZ_PAGE_NAME}/${module.course}/${module.id}/review/${attemptId}`, { params: { page: page == undefined || isNaN(page) ? -1 : page, diff --git a/src/addons/mod/quiz/services/quiz-sync.ts b/src/addons/mod/quiz/services/quiz-sync.ts index 60ef311bd..dd36abfb2 100644 --- a/src/addons/mod/quiz/services/quiz-sync.ts +++ b/src/addons/mod/quiz/services/quiz-sync.ts @@ -31,7 +31,7 @@ import { AddonModQuizAttemptDBRecord } from './database/quiz'; import { AddonModQuizPrefetchHandler } from './handlers/prefetch'; import { AddonModQuiz, AddonModQuizAttemptWSData, AddonModQuizQuizWSData } from './quiz'; import { AddonModQuizOffline, AddonModQuizQuestionsWithAnswers } from './quiz-offline'; -import { ADDON_MOD_QUIZ_COMPONENT } from '../constants'; +import { ADDON_MOD_QUIZ_AUTO_SYNCED, ADDON_MOD_QUIZ_COMPONENT } from '../constants'; /** * Service to sync quizzes. @@ -39,8 +39,6 @@ import { ADDON_MOD_QUIZ_COMPONENT } from '../constants'; @Injectable({ providedIn: 'root' }) export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider { - static readonly AUTO_SYNCED = 'addon_mod_quiz_autom_synced'; - protected componentTranslatableString = 'quiz'; constructor() { @@ -221,7 +219,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider if (data) { // Sync successful. Send event. - CoreEvents.trigger(AddonModQuizSyncProvider.AUTO_SYNCED, { + CoreEvents.trigger(ADDON_MOD_QUIZ_AUTO_SYNCED, { quizId: quiz.id, attemptFinished: data.attemptFinished, warnings: data.warnings, diff --git a/src/addons/mod/quiz/services/quiz.ts b/src/addons/mod/quiz/services/quiz.ts index 44a948489..07604d170 100644 --- a/src/addons/mod/quiz/services/quiz.ts +++ b/src/addons/mod/quiz/services/quiz.ts @@ -37,7 +37,7 @@ import { makeSingleton, Translate } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { AddonModQuizAccessRuleDelegate } from './access-rules-delegate'; import { AddonModQuizOffline, AddonModQuizQuestionsWithAnswers } from './quiz-offline'; -import { AddonModQuizAutoSyncData, AddonModQuizSyncProvider } from './quiz-sync'; +import { AddonModQuizAutoSyncData } from './quiz-sync'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { QUESTION_INVALID_STATE_CLASSES, @@ -52,6 +52,7 @@ import { AddonModQuizGradeMethods, AddonModQuizDisplayOptionsAttemptStates, ADDON_MOD_QUIZ_IMMEDIATELY_AFTER_PERIOD, + ADDON_MOD_QUIZ_AUTO_SYNCED, } from '../constants'; import { CoreIonicColorNames } from '@singletons/colors'; @@ -64,7 +65,7 @@ declare module '@singletons/events' { */ export interface CoreEventsData { [ADDON_MOD_QUIZ_ATTEMPT_FINISHED_EVENT]: AddonModQuizAttemptFinishedData; - [AddonModQuizSyncProvider.AUTO_SYNCED]: AddonModQuizAutoSyncData; + [ADDON_MOD_QUIZ_AUTO_SYNCED]: AddonModQuizAutoSyncData; } }