MOBILE-4616 h5p: Move h5p constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:41:46 +02:00
parent 67cae258f6
commit 8236f1c38b
11 changed files with 109 additions and 75 deletions

View File

@ -35,21 +35,24 @@ import {
AddonModH5PActivity, AddonModH5PActivity,
AddonModH5PActivityAccessInfo, AddonModH5PActivityAccessInfo,
AddonModH5PActivityData, AddonModH5PActivityData,
AddonModH5PActivityProvider,
AddonModH5PActivityXAPIPostStateData, AddonModH5PActivityXAPIPostStateData,
AddonModH5PActivityXAPIStateData, AddonModH5PActivityXAPIStateData,
AddonModH5PActivityXAPIStatementsData, AddonModH5PActivityXAPIStatementsData,
MOD_H5PACTIVITY_STATE_ID,
} from '../../services/h5pactivity'; } from '../../services/h5pactivity';
import { import {
AddonModH5PActivitySync, AddonModH5PActivitySync,
AddonModH5PActivitySyncProvider,
AddonModH5PActivitySyncResult, AddonModH5PActivitySyncResult,
} from '../../services/h5pactivity-sync'; } from '../../services/h5pactivity-sync';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { AddonModH5PActivityModuleHandlerService } from '../../services/handlers/module';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; 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. * Component that displays an H5P activity entry page.
@ -62,7 +65,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
@Output() onActivityFinish = new EventEmitter<boolean>(); @Output() onActivityFinish = new EventEmitter<boolean>();
component = AddonModH5PActivityProvider.COMPONENT; component = ADDON_MOD_H5PACTIVITY_COMPONENT;
pluginName = 'h5pactivity'; pluginName = 'h5pactivity';
h5pActivity?: AddonModH5PActivityData; // The H5P activity object. h5pActivity?: AddonModH5PActivityData; // The H5P activity object.
@ -90,7 +93,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
contentState?: string; contentState?: string;
protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity'; protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity';
protected syncEventName = AddonModH5PActivitySyncProvider.AUTO_SYNCED; protected syncEventName = ADDON_MOD_H5PACTIVITY_AUTO_SYNCED;
protected site: CoreSite; protected site: CoreSite;
protected observer?: CoreEventObserver; protected observer?: CoreEventObserver;
protected messageListenerFunction: (event: MessageEvent) => Promise<void>; protected messageListenerFunction: (event: MessageEvent) => Promise<void>;
@ -147,7 +150,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
await this.loadContentState(); // Loading the state requires the access info. 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 && this.canViewAllAttempts = !!this.h5pActivity.enabletracking && !!this.accessInfo?.canreviewattempts &&
AddonModH5PActivity.canGetUsersAttemptsInSite(); AddonModH5PActivity.canGetUsersAttemptsInSite();
@ -250,11 +253,11 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
this.saveFreq = this.h5pActivity.savestatefreq; this.saveFreq = this.h5pActivity.savestatefreq;
const contentState = await CoreXAPI.getState( const contentState = await CoreXAPI.getState(
AddonModH5PActivityProvider.TRACK_COMPONENT, ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT,
this.h5pActivity.context, this.h5pActivity.context,
MOD_H5PACTIVITY_STATE_ID, ADDON_MOD_H5PACTIVITY_STATE_ID,
{ {
appComponent: AddonModH5PActivityProvider.COMPONENT, appComponent: ADDON_MOD_H5PACTIVITY_COMPONENT,
appComponentId: this.h5pActivity.coursemodule, appComponentId: this.h5pActivity.coursemodule,
readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK, readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK,
}, },
@ -464,7 +467,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
try { try {
await CoreNavigator.navigateToSitePath( 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 { } finally {
this.isOpeningPage = false; this.isOpeningPage = false;
@ -479,7 +482,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
try { try {
await CoreNavigator.navigateToSitePath( await CoreNavigator.navigateToSitePath(
`${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/users`, `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${this.courseId}/${this.module.id}/users`,
); );
} finally { } finally {
this.isOpeningPage = false; this.isOpeningPage = false;
@ -696,7 +699,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
return; return;
} }
await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(AddonModH5PActivityProvider.TRACK_COMPONENT, { await CoreUtils.ignoreErrors(CoreXAPIOffline.deleteStates(ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT, {
itemId: this.h5pActivity.context, itemId: this.h5pActivity.context,
})); }));
} }

View File

@ -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';

View File

@ -56,4 +56,4 @@ const routes: Routes = [
AddonModH5PActivityUsersAttemptsPage, AddonModH5PActivityUsersAttemptsPage,
], ],
}) })
export class AddonModH5PActivityLazyModule {} export default class AddonModH5PActivityLazyModule {}

View File

@ -20,15 +20,16 @@ import { CoreCourseModulePrefetchDelegate } from '@features/course/services/modu
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
import { CoreCronDelegate } from '@services/cron'; import { CoreCronDelegate } from '@services/cron';
import { AddonModH5PActivityIndexLinkHandler } from './services/handlers/index-link'; 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 { AddonModH5PActivityPrefetchHandler } from './services/handlers/prefetch';
import { AddonModH5PActivityReportLinkHandler } from './services/handlers/report-link'; import { AddonModH5PActivityReportLinkHandler } from './services/handlers/report-link';
import { AddonModH5PActivitySyncCronHandler } from './services/handlers/sync-cron'; import { AddonModH5PActivitySyncCronHandler } from './services/handlers/sync-cron';
import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from './constants';
const routes: Routes = [ const routes: Routes = [
{ {
path: AddonModH5PActivityModuleHandlerService.PAGE_NAME, path: ADDON_MOD_H5PACTIVITY_PAGE_NAME,
loadChildren: () => import('./h5pactivity-lazy.module').then(m => m.AddonModH5PActivityLazyModule), loadChildren: () => import('./h5pactivity-lazy.module'),
}, },
]; ];

View File

@ -20,12 +20,12 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { import {
AddonModH5PActivity, AddonModH5PActivity,
AddonModH5PActivityProvider,
AddonModH5PActivityData, AddonModH5PActivityData,
AddonModH5PActivityAttemptResults, AddonModH5PActivityAttemptResults,
} from '../../services/h5pactivity'; } from '../../services/h5pactivity';
import { CoreTime } from '@singletons/time'; import { CoreTime } from '@singletons/time';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { ADDON_MOD_H5PACTIVITY_COMPONENT } from '../../constants';
/** /**
* Page that displays results of an attempt. * Page that displays results of an attempt.
@ -41,7 +41,7 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit {
h5pActivity?: AddonModH5PActivityData; h5pActivity?: AddonModH5PActivityData;
attempt?: AddonModH5PActivityAttemptResults; attempt?: AddonModH5PActivityAttemptResults;
user?: CoreUserProfile; user?: CoreUserProfile;
component = AddonModH5PActivityProvider.COMPONENT; component = ADDON_MOD_H5PACTIVITY_COMPONENT;
courseId!: number; courseId!: number;
cmId!: number; cmId!: number;

View File

@ -21,11 +21,11 @@ import { CoreUtils } from '@services/utils/utils';
import { import {
AddonModH5PActivity, AddonModH5PActivity,
AddonModH5PActivityData, AddonModH5PActivityData,
AddonModH5PActivityProvider,
AddonModH5PActivityUserAttempts, AddonModH5PActivityUserAttempts,
} from '../../services/h5pactivity'; } from '../../services/h5pactivity';
import { CoreTime } from '@singletons/time'; import { CoreTime } from '@singletons/time';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { AddonModH5PActivityGradeMethod } from '../../constants';
/** /**
* Page that displays all users that can attempt an H5P activity. * 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); user.user = await CoreUser.getProfile(user.userid, this.courseId, true);
// Calculate the score of the user. // Calculate the score of the user.
if (h5pActivity.grademethod === AddonModH5PActivityProvider.GRADEMANUAL) { if (h5pActivity.grademethod === AddonModH5PActivityGradeMethod.GRADEMANUAL) {
// No score. // No score.
} else if (h5pActivity.grademethod === AddonModH5PActivityProvider.GRADEAVERAGEATTEMPT) { } else if (h5pActivity.grademethod === AddonModH5PActivityGradeMethod.GRADEAVERAGEATTEMPT) {
if (user.attempts.length) { if (user.attempts.length) {
// Calculate the average. // Calculate the average.
const sumScores = user.attempts.reduce((sumScores, attempt) => const sumScores = user.attempts.reduce((sumScores, attempt) =>

View File

@ -29,7 +29,6 @@ import {
AddonModH5PActivity, AddonModH5PActivity,
AddonModH5PActivityAttempt, AddonModH5PActivityAttempt,
AddonModH5PActivityData, AddonModH5PActivityData,
AddonModH5PActivityProvider,
} from './h5pactivity'; } from './h5pactivity';
import { CoreXAPIStateDBRecord, CoreXAPIStatementDBRecord } from '@features/xapi/services/database/xapi'; import { CoreXAPIStateDBRecord, CoreXAPIStatementDBRecord } from '@features/xapi/services/database/xapi';
import { CoreTextUtils } from '@services/utils/text'; 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 { CoreXAPIItemAgent } from '@features/xapi/classes/item-agent';
import { CoreWSError } from '@classes/errors/wserror'; import { CoreWSError } from '@classes/errors/wserror';
import { CoreArray } from '@singletons/array'; 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. * Service to sync H5P activities.
@ -44,8 +48,6 @@ import { CoreArray } from '@singletons/array';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModH5PActivitySyncResult> { export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModH5PActivitySyncResult> {
static readonly AUTO_SYNCED = 'addon_mod_h5pactivity_autom_synced';
protected componentTranslatableString = 'h5pactivity'; protected componentTranslatableString = 'h5pactivity';
constructor() { constructor() {
@ -86,7 +88,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
if (result?.updated) { if (result?.updated) {
// Sync successful, send event. // Sync successful, send event.
CoreEvents.trigger(AddonModH5PActivitySyncProvider.AUTO_SYNCED, { CoreEvents.trigger(ADDON_MOD_H5PACTIVITY_AUTO_SYNCED, {
contextId, contextId,
warnings: result.warnings, warnings: result.warnings,
}, siteId); }, siteId);
@ -161,7 +163,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
const deleteOfflineData = async (): Promise<void> => { const deleteOfflineData = async (): Promise<void> => {
await Promise.all([ await Promise.all([
statements.length ? CoreXAPIOffline.deleteStatementsForContext(contextId, siteId) : undefined, 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, itemId: contextId,
siteId, siteId,
}) : undefined, }) : undefined,
@ -207,7 +209,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
// Sync offline logs. // Sync offline logs.
await CoreUtils.ignoreErrors( await CoreUtils.ignoreErrors(
CoreCourseLogHelper.syncActivity(AddonModH5PActivityProvider.COMPONENT, h5pActivity.id, siteId), CoreCourseLogHelper.syncActivity(ADDON_MOD_H5PACTIVITY_COMPONENT, h5pActivity.id, siteId),
); );
const results = await Promise.all([ const results = await Promise.all([

View File

@ -25,13 +25,15 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { makeSingleton, Translate } from '@singletons/index'; import { makeSingleton, Translate } from '@singletons/index';
import { CoreWSError } from '@classes/errors/wserror'; import { CoreWSError } from '@classes/errors/wserror';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { AddonModH5PActivityAutoSyncData, AddonModH5PActivitySyncProvider } from './h5pactivity-sync'; import { AddonModH5PActivityAutoSyncData } from './h5pactivity-sync';
import { CoreTime } from '@singletons/time'; import { CoreTime } from '@singletons/time';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
import {
export const MOD_H5PACTIVITY_STATE_ID = 'state'; ADDON_MOD_H5PACTIVITY_AUTO_SYNCED,
ADDON_MOD_H5PACTIVITY_COMPONENT,
const ROOT_CACHE_KEY = 'mmaModH5PActivity:'; ADDON_MOD_H5PACTIVITY_USERS_PER_PAGE,
AddonModH5PActivityGradeMethod,
} from '../constants';
/** /**
* Service that provides some features for H5P activity. * Service that provides some features for H5P activity.
@ -39,16 +41,7 @@ const ROOT_CACHE_KEY = 'mmaModH5PActivity:';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AddonModH5PActivityProvider { export class AddonModH5PActivityProvider {
static readonly COMPONENT = 'mmaModH5PActivity'; protected static readonly ROOT_CACHE_KEY = '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.
/** /**
* Check if a certain site allows viewing list of users and their attempts. * Check if a certain site allows viewing list of users and their attempts.
@ -151,7 +144,7 @@ export class AddonModH5PActivityProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getAccessInformationCacheKey(id: number): string { 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 = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getAccessInformationCacheKey(id), cacheKey: this.getAccessInformationCacheKey(id),
updateFrequency: CoreSite.FREQUENCY_OFTEN, updateFrequency: CoreSite.FREQUENCY_OFTEN,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -259,7 +252,7 @@ export class AddonModH5PActivityProvider {
): Promise<{users: AddonModH5PActivityUserAttempts[]; canLoadMore: boolean}> { ): Promise<{users: AddonModH5PActivityUserAttempts[]; canLoadMore: boolean}> {
options = options || {}; options = options || {};
options.page = options.page || 0; 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); const site = await CoreSites.getSite(options.siteId);
@ -274,7 +267,7 @@ export class AddonModH5PActivityProvider {
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getUsersAttemptsCacheKey(id, options), cacheKey: this.getUsersAttemptsCacheKey(id, options),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -320,7 +313,7 @@ export class AddonModH5PActivityProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getUsersAttemptsCommonCacheKey(id: number): string { 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. * @returns Cache key.
*/ */
protected getAttemptResultsCommonCacheKey(id: number): string { 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 = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getAttemptResultsCacheKey(id, params.attemptids), cacheKey: this.getAttemptResultsCacheKey(id, params.attemptids),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -435,7 +428,7 @@ export class AddonModH5PActivityProvider {
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getAttemptResultsCommonCacheKey(id), cacheKey: this.getAttemptResultsCommonCacheKey(id),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -491,7 +484,7 @@ export class AddonModH5PActivityProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getH5PActivityDataCacheKey(courseId: number): string { 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 = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getH5PActivityDataCacheKey(courseId), cacheKey: this.getH5PActivityDataCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY, updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -598,7 +591,7 @@ export class AddonModH5PActivityProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getUserAttemptsCommonCacheKey(id: number): string { 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 = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getUserAttemptsCacheKey(id, params.userids), cacheKey: this.getUserAttemptsCacheKey(id, params.userids),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModH5PActivityProvider.COMPONENT, component: ADDON_MOD_H5PACTIVITY_COMPONENT,
componentId: options.cmId, componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
}; };
@ -788,7 +781,7 @@ export class AddonModH5PActivityProvider {
return CoreCourseLogHelper.log( return CoreCourseLogHelper.log(
'mod_h5pactivity_view_h5pactivity', 'mod_h5pactivity_view_h5pactivity',
params, params,
AddonModH5PActivityProvider.COMPONENT, ADDON_MOD_H5PACTIVITY_COMPONENT,
id, id,
siteId, siteId,
); );
@ -818,7 +811,7 @@ export class AddonModH5PActivityProvider {
return CoreCourseLogHelper.log( return CoreCourseLogHelper.log(
'mod_h5pactivity_log_report_viewed', 'mod_h5pactivity_log_report_viewed',
params, params,
AddonModH5PActivityProvider.COMPONENT, ADDON_MOD_H5PACTIVITY_COMPONENT,
id, id,
site.getId(), site.getId(),
); );
@ -842,7 +835,7 @@ export type AddonModH5PActivityWSData = {
grade?: number; // The maximum grade for submission. grade?: number; // The maximum grade for submission.
displayoptions: number; // H5P Button display options. displayoptions: number; // H5P Button display options.
enabletracking: number; // Enable xAPI tracking. 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. contenthash?: string; // Sha1 hash of file content.
coursemodule: number; // Coursemodule. coursemodule: number; // Coursemodule.
context: number; // Context ID. context: number; // Context ID.
@ -1151,7 +1144,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 {
[AddonModH5PActivitySyncProvider.AUTO_SYNCED]: AddonModH5PActivityAutoSyncData; [ADDON_MOD_H5PACTIVITY_AUTO_SYNCED]: AddonModH5PActivityAutoSyncData;
} }
} }

View File

@ -18,6 +18,7 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate'; import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModH5PActivity } from '../h5pactivity'; import { AddonModH5PActivity } from '../h5pactivity';
import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from '../../constants';
/** /**
* Handler to support H5P activities. * Handler to support H5P activities.
@ -25,11 +26,9 @@ import { AddonModH5PActivity } from '../h5pactivity';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AddonModH5PActivityModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler { export class AddonModH5PActivityModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
static readonly PAGE_NAME = 'mod_h5pactivity';
name = 'AddonModH5PActivity'; name = 'AddonModH5PActivity';
modName = 'h5pactivity'; modName = 'h5pactivity';
protected pageName = AddonModH5PActivityModuleHandlerService.PAGE_NAME; protected pageName = ADDON_MOD_H5PACTIVITY_PAGE_NAME;
supportedFeatures = { supportedFeatures = {
[CoreConstants.FEATURE_GROUPS]: true, [CoreConstants.FEATURE_GROUPS]: true,

View File

@ -32,9 +32,12 @@ import {
AddonModH5PActivity, AddonModH5PActivity,
AddonModH5PActivityAccessInfo, AddonModH5PActivityAccessInfo,
AddonModH5PActivityData, AddonModH5PActivityData,
AddonModH5PActivityProvider,
MOD_H5PACTIVITY_STATE_ID,
} from '../h5pactivity'; } from '../h5pactivity';
import {
ADDON_MOD_H5PACTIVITY_COMPONENT,
ADDON_MOD_H5PACTIVITY_STATE_ID,
ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT,
} from '../../constants';
/** /**
* Handler to prefetch h5p activity. * Handler to prefetch h5p activity.
@ -44,7 +47,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
name = 'AddonModH5PActivity'; name = 'AddonModH5PActivity';
modName = 'h5pactivity'; modName = 'h5pactivity';
component = AddonModH5PActivityProvider.COMPONENT; component = ADDON_MOD_H5PACTIVITY_COMPONENT;
updatesNames = /^configuration$|^.*files$|^tracks$|^usertracks$/; updatesNames = /^configuration$|^.*files$|^tracks$|^usertracks$/;
/** /**
@ -113,7 +116,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
await Promise.all([ await Promise.all([
this.prefetchWSData(h5pActivity, siteId), 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), this.prefetchMainFile(module, h5pActivity, siteId),
CoreH5P.getCustomCssSrc(siteId), CoreH5P.getCustomCssSrc(siteId),
]); ]);
@ -146,14 +149,14 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile)); const fileState = await CoreFilepool.getFileStateByUrl(siteId, CoreFileHelper.getFileUrl(deployedFile));
if (fileState !== DownloadStatus.DOWNLOADED) { 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, itemId: h5pActivity.context,
siteId, 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( await CoreXAPI.getStateFromServer(
AddonModH5PActivityProvider.TRACK_COMPONENT, ADDON_MOD_H5PACTIVITY_TRACK_COMPONENT,
h5pActivity.context, h5pActivity.context,
MOD_H5PACTIVITY_STATE_ID, ADDON_MOD_H5PACTIVITY_STATE_ID,
{ {
appComponent: AddonModH5PActivityProvider.COMPONENT, appComponent: ADDON_MOD_H5PACTIVITY_COMPONENT,
appComponentId: h5pActivity.coursemodule, appComponentId: h5pActivity.coursemodule,
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -23,7 +23,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModH5PActivity } from '../h5pactivity'; import { AddonModH5PActivity } from '../h5pactivity';
import { AddonModH5PActivityModuleHandlerService } from './module'; import { ADDON_MOD_H5PACTIVITY_PAGE_NAME } from '../../constants';
/** /**
* Handler to treat links to H5P activity report. * Handler to treat links to H5P activity report.
@ -88,7 +88,7 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink
* @param siteId Site ID. * @param siteId Site ID.
*/ */
protected async openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): Promise<void> { protected async openAttemptResults(cmId: number, attemptId: number, courseId: number, siteId: string): Promise<void> {
const path = AddonModH5PActivityModuleHandlerService.PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`; const path = ADDON_MOD_H5PACTIVITY_PAGE_NAME + `/${courseId}/${cmId}/attemptresults/${attemptId}`;
await CoreNavigator.navigateToSitePath(path, { await CoreNavigator.navigateToSitePath(path, {
siteId, siteId,
@ -125,9 +125,9 @@ export class AddonModH5PActivityReportLinkHandlerService extends CoreContentLink
let path: string; let path: string;
if (canViewAllAttempts) { if (canViewAllAttempts) {
path = `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/users`; path = `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${courseId}/${cmId}/users`;
} else { } else {
path = `${AddonModH5PActivityModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/userattempts/${userId}`; path = `${ADDON_MOD_H5PACTIVITY_PAGE_NAME}/${courseId}/${cmId}/userattempts/${userId}`;
} }
CoreNavigator.navigateToSitePath(path, { CoreNavigator.navigateToSitePath(path, {