diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index 4c1fc4335..542a2b366 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -35,21 +35,24 @@ import { AddonModH5PActivity, AddonModH5PActivityAccessInfo, AddonModH5PActivityData, - AddonModH5PActivityProvider, AddonModH5PActivityXAPIPostStateData, AddonModH5PActivityXAPIStateData, AddonModH5PActivityXAPIStatementsData, - MOD_H5PACTIVITY_STATE_ID, } from '../../services/h5pactivity'; import { AddonModH5PActivitySync, - AddonModH5PActivitySyncProvider, AddonModH5PActivitySyncResult, } from '../../services/h5pactivity-sync'; import { CoreFileHelper } from '@services/file-helper'; -import { AddonModH5PActivityModuleHandlerService } from '../../services/handlers/module'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; +import { + ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, + ADDON_MOD_H5PACTIVITY_COMPONENT, + ADDON_MOD_H5PACTIVITY_PAGE_NAME, + ADDON_MOD_H5PACTIVITY_STATE_ID, + ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, +} from '../../constants'; /** * Component that displays an H5P activity entry page. @@ -62,7 +65,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv @Output() onActivityFinish = new EventEmitter(); - component = AddonModH5PActivityProvider.COMPONENT; + component = ADDON_MOD_H5PACTIVITY_COMPONENT; pluginName = 'h5pactivity'; h5pActivity?: AddonModH5PActivityData; // The H5P activity object. @@ -90,7 +93,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv contentState?: string; protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity'; - protected syncEventName = AddonModH5PActivitySyncProvider.AUTO_SYNCED; + protected syncEventName = ADDON_MOD_H5PACTIVITY_AUTO_SYNCED; protected site: CoreSite; protected observer?: CoreEventObserver; protected messageListenerFunction: (event: MessageEvent) => Promise; @@ -147,7 +150,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv await this.loadContentState(); // Loading the state requires the access info. - this.trackComponent = this.accessInfo?.cansubmit ? AddonModH5PActivityProvider.TRACK_COMPONENT : ''; + this.trackComponent = this.accessInfo?.cansubmit ? ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT : ''; this.canViewAllAttempts = !!this.h5pActivity.enabletracking && !!this.accessInfo?.canreviewattempts && AddonModH5PActivity.canGetUsersAttemptsInSite(); @@ -250,11 +253,11 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv this.saveFreq = this.h5pActivity.savestatefreq; const contentState = await CoreXAPI.getState( - AddonModH5PActivityProvider.TRACK_COMPONENT, + ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, this.h5pActivity.context, - MOD_H5PACTIVITY_STATE_ID, + ADDON_MOD_H5PACTIVITY_STATE_ID, { - appComponent: AddonModH5PActivityProvider.COMPONENT, + appComponent: ADDON_MOD_H5PACTIVITY_COMPONENT, appComponentId: this.h5pActivity.coursemodule, readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK, }, @@ -464,7 +467,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv try { await CoreNavigator.navigateToSitePath( - `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/userattempts/${userId}`, + `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${this.courseId}/${this.module.id}/userattempts/${userId}`, ); } finally { this.isOpeningPage = false; @@ -479,7 +482,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv try { await CoreNavigator.navigateToSitePath( - `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/users`, + `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${this.courseId}/${this.module.id}/users`, ); } finally { this.isOpeningPage = false; @@ -696,7 +699,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv return; } - await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, { + await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { itemId: this.h5pActivity.context, })); } diff --git a/src/addons/mod/h5pactivity/constants.ts b/src/addons/mod/h5pactivity/constants.ts new file mode 100644 index 000000000..fa0dc2d06 --- /dev/null +++ b/src/addons/mod/h5pactivity/constants.ts @@ -0,0 +1,33 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export const ADDON_MOD_H5PACTIVITY_COMPONENT = 'mmaModH5PActivity'; + +export const ADDON_MOD_H5PACTIVITY_PAGE_NAME = 'mod_h5pactivity'; + +export const ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT = 'mod_h5pactivity'; // Component for tracking. +export const ADDON_MOD_H5PACTIVITY_USERS_PER_PAGE = 20; + +// Grade type constants. +export const enum AddonModH5PActivityGradeMethod { + GRADEMANUAL = 0, // No automatic grading using attempt results. + GRADEHIGHESTATTEMPT = 1, // Use highest attempt results for grading. + GRADEAVERAGEATTEMPT = 2, // Use average attempt results for grading. + GRADELASTATTEMPT = 3, // Use last attempt results for grading. + GRADEFIRSTATTEMPT = 4, // Use first attempt results for grading. +} + +export const ADDON_MOD_H5PACTIVITY_STATE_ID = 'state'; + +export const ADDON_MOD_H5PACTIVITY_AUTO_SYNCED = 'addon_mod_h5pactivity_autom_synced'; diff --git a/src/addons/mod/h5pactivity/h5pactivity-lazy.module.ts b/src/addons/mod/h5pactivity/h5pactivity-lazy.module.ts index fe4312444..a4c5c2aef 100644 --- a/src/addons/mod/h5pactivity/h5pactivity-lazy.module.ts +++ b/src/addons/mod/h5pactivity/h5pactivity-lazy.module.ts @@ -56,4 +56,4 @@ const routes: Routes = [ AddonModH5PActivityUsersAttemptsPage, ], }) -export class AddonModH5PActivityLazyModule {} +export default class AddonModH5PActivityLazyModule {} diff --git a/src/addons/mod/h5pactivity/h5pactivity.module.ts b/src/addons/mod/h5pactivity/h5pactivity.module.ts index a5a411de0..efd806e28 100644 --- a/src/addons/mod/h5pactivity/h5pactivity.module.ts +++ b/src/addons/mod/h5pactivity/h5pactivity.module.ts @@ -20,15 +20,16 @@ import { CoreCourseModulePrefetchDelegate } from '@features/course/services/modu import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreCronDelegate } from '@services/cron'; import { AddonModH5PActivityIndexLinkHandler } from './services/handlers/index-link'; -import { AddonModH5PActivityModuleHandler, AddonModH5PActivityModuleHandlerService } from './services/handlers/module'; +import { AddonModH5PActivityModuleHandler } from './services/handlers/module'; import { AddonModH5PActivityPrefetchHandler } from './services/handlers/prefetch'; import { AddonModH5PActivityReportLinkHandler } from './services/handlers/report-link'; import { AddonModH5PActivitySyncCronHandler } from './services/handlers/sync-cron'; +import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from './constants'; const routes: Routes = [ { - path: AddonModH5PActivityModuleHandlerService.PAGE_NAME, - loadChildren: () => import('./h5pactivity-lazy.module').then(m => m.AddonModH5PActivityLazyModule), + path: ADDON_MOD_H5PACTIVITY_PAGE_NAME, + loadChildren: () => import('./h5pactivity-lazy.module'), }, ]; diff --git a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts index 6e43c7092..f10fce516 100644 --- a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts +++ b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts @@ -20,12 +20,12 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { AddonModH5PActivity, - AddonModH5PActivityProvider, AddonModH5PActivityData, AddonModH5PActivityAttemptResults, } from '../../services/h5pactivity'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; +import { ADDON_MOD_H5PACTIVITY_COMPONENT } from '../../constants'; /** * Page that displays results of an attempt. @@ -41,7 +41,7 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { h5pActivity?: AddonModH5PActivityData; attempt?: AddonModH5PActivityAttemptResults; user?: CoreUserProfile; - component = AddonModH5PActivityProvider.COMPONENT; + component = ADDON_MOD_H5PACTIVITY_COMPONENT; courseId!: number; cmId!: number; diff --git a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts index f9b2369cb..6e1d0bf85 100644 --- a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts @@ -21,11 +21,11 @@ import { CoreUtils } from '@services/utils/utils'; import { AddonModH5PActivity, AddonModH5PActivityData, - AddonModH5PActivityProvider, AddonModH5PActivityUserAttempts, } from '../../services/h5pactivity'; import { CoreTime } from '@singletons/time'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; +import { AddonModH5PActivityGradeMethod } from '../../constants'; /** * Page that displays all users that can attempt an H5P activity. @@ -164,9 +164,9 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit { user.user = await CoreUser.getProfile(user.userid, this.courseId, true); // Calculate the score of the user. - if (h5pActivity.grademethod === AddonModH5PActivityProvider.GRADEMANUAL) { + if (h5pActivity.grademethod === AddonModH5PActivityGradeMethod.GRADEMANUAL) { // No score. - } else if (h5pActivity.grademethod === AddonModH5PActivityProvider.GRADEAVERAGEATTEMPT) { + } else if (h5pActivity.grademethod === AddonModH5PActivityGradeMethod.GRADEAVERAGEATTEMPT) { if (user.attempts.length) { // Calculate the average. const sumScores = user.attempts.reduce((sumScores, attempt) => diff --git a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts index d9132942c..dc822ba76 100644 --- a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts +++ b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts @@ -29,7 +29,6 @@ import { AddonModH5PActivity, AddonModH5PActivityAttempt, AddonModH5PActivityData, - AddonModH5PActivityProvider, } from './h5pactivity'; import { CoreXAPIStateDBRecord, CoreXAPIStatementDBRecord } from '@features/xapi/services/database/xapi'; import { CoreTextUtils } from '@services/utils/text'; @@ -37,6 +36,11 @@ import { CoreXAPIIRI } from '@features/xapi/classes/iri'; import { CoreXAPIItemAgent } from '@features/xapi/classes/item-agent'; import { CoreWSError } from '@classes/errors/wserror'; import { CoreArray } from '@singletons/array'; +import { + ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, + ADDON_MOD_H5PACTIVITY_COMPONENT, + ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, +} from '../constants'; /** * Service to sync H5P activities. @@ -44,8 +48,6 @@ import { CoreArray } from '@singletons/array'; @Injectable({ providedIn: 'root' }) export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseProvider { - static readonly AUTO_SYNCED = 'addon_mod_h5pactivity_autom_synced'; - protected componentTranslatableString = 'h5pactivity'; constructor() { @@ -86,7 +88,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP if (result?.updated) { // Sync successful, send event. - CoreEvents.trigger(AddonModH5PActivitySyncProvider.AUTO_SYNCED, { + CoreEvents.trigger(ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, { contextId, warnings: result.warnings, }, siteId); @@ -161,7 +163,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP const deleteOfflineData = async (): Promise => { await Promise.all([ statements.length ? CoreXAPIOffline.deleteStatementsForContext(contextId, siteId) : undefined, - states.length ? CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, { + states.length ? CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { itemId: contextId, siteId, }) : undefined, @@ -207,7 +209,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP // Sync offline logs. await CoreUtils.ignoreErrors( - CoreCourseLogHelper.syncActivity(AddonModH5PActivityProvider.COMPONENT, h5pActivity.id, siteId), + CoreCourseLogHelper.syncActivity(ADDON_MOD_H5PACTIVITY_COMPONENT, h5pActivity.id, siteId), ); const results = await Promise.all([ diff --git a/src/addons/mod/h5pactivity/services/h5pactivity.ts b/src/addons/mod/h5pactivity/services/h5pactivity.ts index 561a5e37b..753ffd994 100644 --- a/src/addons/mod/h5pactivity/services/h5pactivity.ts +++ b/src/addons/mod/h5pactivity/services/h5pactivity.ts @@ -25,13 +25,15 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { makeSingleton, Translate } from '@singletons/index'; import { CoreWSError } from '@classes/errors/wserror'; import { CoreError } from '@classes/errors/error'; -import { AddonModH5PActivityAutoSyncData, AddonModH5PActivitySyncProvider } from './h5pactivity-sync'; +import { AddonModH5PActivityAutoSyncData } from './h5pactivity-sync'; import { CoreTime } from '@singletons/time'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; - -export const MOD_H5PACTIVITY_STATE_ID = 'state'; - -const ROOT_CACHE_KEY = 'mmaModH5PActivity:'; +import { + ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, + ADDON_MOD_H5PACTIVITY_COMPONENT, + ADDON_MOD_H5PACTIVITY_USERS_PER_PAGE, + AddonModH5PActivityGradeMethod, +} from '../constants'; /** * Service that provides some features for H5P activity. @@ -39,16 +41,7 @@ const ROOT_CACHE_KEY = 'mmaModH5PActivity:'; @Injectable({ providedIn: 'root' }) export class AddonModH5PActivityProvider { - static readonly COMPONENT = 'mmaModH5PActivity'; - static readonly TRACK_COMPONENT = 'mod_h5pactivity'; // Component for tracking. - static readonly USERS_PER_PAGE = 20; - - // Grade type constants. - static readonly GRADEMANUAL = 0; // No automathic grading using attempt results. - static readonly GRADEHIGHESTATTEMPT = 1; // Use highest attempt results for grading. - static readonly GRADEAVERAGEATTEMPT = 2; // Use average attempt results for grading. - static readonly GRADELASTATTEMPT = 3; // Use last attempt results for grading. - static readonly GRADEFIRSTATTEMPT = 4; // Use first attempt results for grading. + protected static readonly ROOT_CACHE_KEY = 'mmaModH5PActivity:'; /** * Check if a certain site allows viewing list of users and their attempts. @@ -151,7 +144,7 @@ export class AddonModH5PActivityProvider { * @returns Cache key. */ protected getAccessInformationCacheKey(id: number): string { - return ROOT_CACHE_KEY + 'accessInfo:' + id; + return AddonModH5PActivityProvider.ROOT_CACHE_KEY + 'accessInfo:' + id; } /** @@ -170,7 +163,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getAccessInformationCacheKey(id), updateFrequency: CoreSite.FREQUENCY_OFTEN, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -259,7 +252,7 @@ export class AddonModH5PActivityProvider { ): Promise<{users: AddonModH5PActivityUserAttempts[]; canLoadMore: boolean}> { options = options || {}; options.page = options.page || 0; - options.perPage = options.perPage ?? AddonModH5PActivityProvider.USERS_PER_PAGE; + options.perPage = options.perPage ?? ADDON_MOD_H5PACTIVITY_USERS_PER_PAGE; const site = await CoreSites.getSite(options.siteId); @@ -274,7 +267,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getUsersAttemptsCacheKey(id, options), updateFrequency: CoreSite.FREQUENCY_SOMETIMES, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -320,7 +313,7 @@ export class AddonModH5PActivityProvider { * @returns Cache key. */ protected getUsersAttemptsCommonCacheKey(id: number): string { - return ROOT_CACHE_KEY + 'userAttempts:' + id; + return AddonModH5PActivityProvider.ROOT_CACHE_KEY + 'userAttempts:' + id; } /** @@ -341,7 +334,7 @@ export class AddonModH5PActivityProvider { * @returns Cache key. */ protected getAttemptResultsCommonCacheKey(id: number): string { - return ROOT_CACHE_KEY + 'results:' + id; + return AddonModH5PActivityProvider.ROOT_CACHE_KEY + 'results:' + id; } /** @@ -370,7 +363,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getAttemptResultsCacheKey(id, params.attemptids), updateFrequency: CoreSite.FREQUENCY_SOMETIMES, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -435,7 +428,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getAttemptResultsCommonCacheKey(id), updateFrequency: CoreSite.FREQUENCY_SOMETIMES, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -491,7 +484,7 @@ export class AddonModH5PActivityProvider { * @returns Cache key. */ protected getH5PActivityDataCacheKey(courseId: number): string { - return ROOT_CACHE_KEY + 'h5pactivity:' + courseId; + return AddonModH5PActivityProvider.ROOT_CACHE_KEY + 'h5pactivity:' + courseId; } /** @@ -518,7 +511,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getH5PActivityDataCacheKey(courseId), updateFrequency: CoreSite.FREQUENCY_RARELY, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -598,7 +591,7 @@ export class AddonModH5PActivityProvider { * @returns Cache key. */ protected getUserAttemptsCommonCacheKey(id: number): string { - return ROOT_CACHE_KEY + 'attempts:' + id; + return AddonModH5PActivityProvider.ROOT_CACHE_KEY + 'attempts:' + id; } /** @@ -625,7 +618,7 @@ export class AddonModH5PActivityProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getUserAttemptsCacheKey(id, params.userids), updateFrequency: CoreSite.FREQUENCY_SOMETIMES, - component: AddonModH5PActivityProvider.COMPONENT, + component: ADDON_MOD_H5PACTIVITY_COMPONENT, componentId: options.cmId, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; @@ -788,7 +781,7 @@ export class AddonModH5PActivityProvider { return CoreCourseLogHelper.log( 'mod_h5pactivity_view_h5pactivity', params, - AddonModH5PActivityProvider.COMPONENT, + ADDON_MOD_H5PACTIVITY_COMPONENT, id, siteId, ); @@ -818,7 +811,7 @@ export class AddonModH5PActivityProvider { return CoreCourseLogHelper.log( 'mod_h5pactivity_log_report_viewed', params, - AddonModH5PActivityProvider.COMPONENT, + ADDON_MOD_H5PACTIVITY_COMPONENT, id, site.getId(), ); @@ -842,7 +835,7 @@ export type AddonModH5PActivityWSData = { grade?: number; // The maximum grade for submission. displayoptions: number; // H5P Button display options. enabletracking: number; // Enable xAPI tracking. - grademethod: number; // Which H5P attempt is used for grading. + grademethod: AddonModH5PActivityGradeMethod; // Which H5P attempt is used for grading. contenthash?: string; // Sha1 hash of file content. coursemodule: number; // Coursemodule. context: number; // Context ID. @@ -1151,7 +1144,7 @@ declare module '@singletons/events' { * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation */ export interface CoreEventsData { - [AddonModH5PActivitySyncProvider.AUTO_SYNCED]: AddonModH5PActivityAutoSyncData; + [ADDON_MOD_H5PACTIVITY_AUTO_SYNCED]: AddonModH5PActivityAutoSyncData; } } diff --git a/src/addons/mod/h5pactivity/services/handlers/module.ts b/src/addons/mod/h5pactivity/services/handlers/module.ts index 1470169cd..1c09f274c 100644 --- a/src/addons/mod/h5pactivity/services/handlers/module.ts +++ b/src/addons/mod/h5pactivity/services/handlers/module.ts @@ -18,6 +18,7 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand import { CoreCourseModuleHandler } from '@features/course/services/module-delegate'; import { makeSingleton } from '@singletons'; import { AddonModH5PActivity } from '../h5pactivity'; +import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from '../../constants'; /** * Handler to support H5P activities. @@ -25,11 +26,9 @@ import { AddonModH5PActivity } from '../h5pactivity'; @Injectable({ providedIn: 'root' }) export class AddonModH5PActivityModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler { - static readonly PAGE_NAME = 'mod_h5pactivity'; - name = 'AddonModH5PActivity'; modName = 'h5pactivity'; - protected pageName = AddonModH5PActivityModuleHandlerService.PAGE_NAME; + protected pageName = ADDON_MOD_H5PACTIVITY_PAGE_NAME; supportedFeatures = { [CoreConstants.FEATURE_GROUPS]: true, diff --git a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts index 97a25f59b..9463f41cf 100644 --- a/src/addons/mod/h5pactivity/services/handlers/prefetch.ts +++ b/src/addons/mod/h5pactivity/services/handlers/prefetch.ts @@ -32,9 +32,12 @@ import { AddonModH5PActivity, AddonModH5PActivityAccessInfo, AddonModH5PActivityData, - AddonModH5PActivityProvider, - MOD_H5PACTIVITY_STATE_ID, } from '../h5pactivity'; +import { + ADDON_MOD_H5PACTIVITY_COMPONENT, + ADDON_MOD_H5PACTIVITY_STATE_ID, + ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, +} from '../../constants'; /** * Handler to prefetch h5p activity. @@ -44,7 +47,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit name = 'AddonModH5PActivity'; modName = 'h5pactivity'; - component = AddonModH5PActivityProvider.COMPONENT; + component = ADDON_MOD_H5PACTIVITY_COMPONENT; updatesNames = /^configuration$|^.*files$|^tracks$|^usertracks$/; /** @@ -113,7 +116,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit await Promise.all([ this.prefetchWSData(h5pActivity, siteId), - CoreFilepool.addFilesToQueue(siteId, introFiles, AddonModH5PActivityProvider.COMPONENT, module.id), + CoreFilepool.addFilesToQueue(siteId, introFiles, ADDON_MOD_H5PACTIVITY_COMPONENT, module.id), this.prefetchMainFile(module, h5pActivity, siteId), CoreH5P.getCustomCssSrc(siteId), ]); @@ -146,14 +149,14 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile)); if (fileState !== DownloadStatus.DOWNLOADED) { - await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, { + await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, { itemId: h5pActivity.context, siteId, })); } } - await CoreFilepool.addFilesToQueue(siteId, [deployedFile], AddonModH5PActivityProvider.COMPONENT, module.id); + await CoreFilepool.addFilesToQueue(siteId, [deployedFile], ADDON_MOD_H5PACTIVITY_COMPONENT, module.id); } /** @@ -239,11 +242,11 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit } await CoreXAPI.getStateFromServer( - AddonModH5PActivityProvider.TRACK_COMPONENT, + ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, h5pActivity.context, - MOD_H5PACTIVITY_STATE_ID, + ADDON_MOD_H5PACTIVITY_STATE_ID, { - appComponent: AddonModH5PActivityProvider.COMPONENT, + appComponent: ADDON_MOD_H5PACTIVITY_COMPONENT, appComponentId: h5pActivity.coursemodule, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, siteId, diff --git a/src/addons/mod/h5pactivity/services/handlers/report-link.ts b/src/addons/mod/h5pactivity/services/handlers/report-link.ts index a2dc36862..c92418b90 100644 --- a/src/addons/mod/h5pactivity/services/handlers/report-link.ts +++ b/src/addons/mod/h5pactivity/services/handlers/report-link.ts @@ -23,7 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { AddonModH5PActivity } from '../h5pactivity'; -import { AddonModH5PActivityModuleHandlerService } from './module'; +import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from '../../constants'; /** * Handler to treat links to H5P activity report. @@ -88,7 +88,7 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink * @param siteId Site ID. */ protected async openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): Promise { - const path = AddonModH5PActivityModuleHandlerService.PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`; + const path = ADDON_MOD_H5PACTIVITY_PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`; await CoreNavigator.navigateToSitePath(path, { siteId, @@ -125,9 +125,9 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink let path: string; if (canViewAllAttempts) { - path = `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/users`; + path = `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${courseId}/${cmId}/users`; } else { - path = `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/userattempts/${userId}`; + path = `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${courseId}/${cmId}/userattempts/${userId}`; } CoreNavigator.navigateToSitePath(path, {