diff --git a/src/addons/competency/competency.module.ts b/src/addons/competency/competency.module.ts index 8daa6170b..f6f970a3a 100644 --- a/src/addons/competency/competency.module.ts +++ b/src/addons/competency/competency.module.ts @@ -28,7 +28,7 @@ import { Routes } from '@angular/router'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreCourseIndexRoutingModule } from '@features/course/course-routing.module'; import { PARTICIPANTS_PAGE_NAME } from '@features/user/constants'; -import { COURSE_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME } from '@features/course/constants'; import { ADDON_COMPETENCY_LEARNING_PLANS_PAGE, ADDON_COMPETENCY_COMPETENCIES_PAGE } from './constants'; /** @@ -52,11 +52,11 @@ const mainMenuChildrenRoutes: Routes = [ loadChildren: () => import('./competency-learning-plans-lazy.module'), }, { - path: `${COURSE_PAGE_NAME}/:courseId/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, + path: `${CORE_COURSE_PAGE_NAME}/:courseId/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, loadChildren: () => import('./competency-course-details-lazy.module'), }, { - path: `${COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, + path: `${CORE_COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, loadChildren: () => import('./competency-course-details-lazy.module'), }, ]; diff --git a/src/addons/competency/services/handlers/competency-link.ts b/src/addons/competency/services/handlers/competency-link.ts index 69a42f6ee..f87ff9fd0 100644 --- a/src/addons/competency/services/handlers/competency-link.ts +++ b/src/addons/competency/services/handlers/competency-link.ts @@ -16,7 +16,7 @@ import { ADDON_COMPETENCY_COMPETENCIES_PAGE, ADDON_COMPETENCY_LEARNING_PLANS_PAG import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; -import { COURSE_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME } from '@features/course/constants'; import { CoreNavigator } from '@services/navigator'; import { makeSingleton } from '@singletons'; import { AddonCompetency } from '../competency'; @@ -41,7 +41,7 @@ export class AddonCompetencyCompetencyLinkHandlerService extends CoreContentLink action: async (siteId: string): Promise => { if (courseId) { await CoreNavigator.navigateToSitePath( - `${COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, + `${CORE_COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}`, { params: { userId: params.userid }, siteId, diff --git a/src/addons/competency/services/handlers/course-option.ts b/src/addons/competency/services/handlers/course-option.ts index 1288774df..62a400083 100644 --- a/src/addons/competency/services/handlers/course-option.ts +++ b/src/addons/competency/services/handlers/course-option.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreCourseAccessDataType } from '@features/course/services/course'; +import { CoreCourseAccessDataType } from '@features/course/constants'; import { CoreCourseAccess, CoreCourseOptionsHandler, diff --git a/src/addons/competency/services/handlers/push-click.ts b/src/addons/competency/services/handlers/push-click.ts index 63e4b1a50..438791a20 100644 --- a/src/addons/competency/services/handlers/push-click.ts +++ b/src/addons/competency/services/handlers/push-click.ts @@ -14,7 +14,7 @@ import { ADDON_COMPETENCY_COMPETENCIES_PAGE, ADDON_COMPETENCY_LEARNING_PLANS_PAGE } from '@addons/competency/constants'; import { Injectable } from '@angular/core'; -import { COURSE_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME } from '@features/course/constants'; import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate'; import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications'; import { CoreNavigator } from '@services/navigator'; @@ -75,7 +75,7 @@ export class AddonCompetencyPushClickHandlerService implements CorePushNotificat if (courseId) { await CoreNavigator.navigateToSitePath( - `${COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}/${competencyId}`, + `${CORE_COURSE_PAGE_NAME}/${courseId}/${ADDON_COMPETENCY_COMPETENCIES_PAGE}/${competencyId}`, { params: { userId }, siteId: notification.site, diff --git a/src/addons/competency/services/handlers/user.ts b/src/addons/competency/services/handlers/user.ts index 28c06c66e..a2caca4f2 100644 --- a/src/addons/competency/services/handlers/user.ts +++ b/src/addons/competency/services/handlers/user.ts @@ -14,7 +14,7 @@ import { ADDON_COMPETENCY_COMPETENCIES_PAGE, ADDON_COMPETENCY_LEARNING_PLANS_PAGE } from '@addons/competency/constants'; import { Injectable } from '@angular/core'; -import { COURSE_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME } from '@features/course/constants'; import { CoreUserProfile } from '@features/user/services/user'; import { CoreUserProfileHandler, @@ -112,9 +112,13 @@ export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler action: (event, user, context, contextId): void => { event.preventDefault(); event.stopPropagation(); - CoreNavigator.navigateToSitePath( - [COURSE_PAGE_NAME, contextId, PARTICIPANTS_PAGE_NAME, user.id, ADDON_COMPETENCY_COMPETENCIES_PAGE].join('/'), - ); + CoreNavigator.navigateToSitePath([ + CORE_COURSE_PAGE_NAME, + contextId, + PARTICIPANTS_PAGE_NAME, + user.id, + ADDON_COMPETENCY_COMPETENCIES_PAGE, + ].join('/')); }, }; } diff --git a/src/addons/coursecompletion/services/handlers/course-option.ts b/src/addons/coursecompletion/services/handlers/course-option.ts index 928cb6691..64779e6e9 100644 --- a/src/addons/coursecompletion/services/handlers/course-option.ts +++ b/src/addons/coursecompletion/services/handlers/course-option.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreCourseAccessDataType } from '@features/course/services/course'; +import { CoreCourseAccessDataType } from '@features/course/constants'; import { CoreCourseAccess, CoreCourseOptionsHandler, diff --git a/src/addons/mod/forum/forum.module.ts b/src/addons/mod/forum/forum.module.ts index 8dfe77225..648108b5a 100644 --- a/src/addons/mod/forum/forum.module.ts +++ b/src/addons/mod/forum/forum.module.ts @@ -37,7 +37,7 @@ import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate'; import { AddonModForumTagAreaHandler } from './services/handlers/tag-area'; import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; import { AddonModForumPushClickHandler } from './services/handlers/push-click'; -import { COURSE_CONTENTS_PATH } from '@features/course/constants'; +import { CORE_COURSE_CONTENTS_PATH } from '@features/course/constants'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { ADDON_MOD_FORUM_COMPONENT, ADDON_MOD_FORUM_PAGE_NAME, ADDON_MOD_FORUM_SEARCH_PAGE_NAME } from './constants'; @@ -58,12 +58,12 @@ const mainMenuRoutes: Routes = [ ...conditionalRoutes( [ { - path: `${COURSE_CONTENTS_PATH}/${ADDON_MOD_FORUM_PAGE_NAME}/new/:timeCreated`, + path: `${CORE_COURSE_CONTENTS_PATH}/${ADDON_MOD_FORUM_PAGE_NAME}/new/:timeCreated`, loadChildren: () => import('./forum-new-discussion-lazy.module'), data: { discussionsPathPrefix: `${ADDON_MOD_FORUM_PAGE_NAME}/` }, }, { - path: `${COURSE_CONTENTS_PATH}/${ADDON_MOD_FORUM_PAGE_NAME}/:discussionId`, + path: `${CORE_COURSE_CONTENTS_PATH}/${ADDON_MOD_FORUM_PAGE_NAME}/:discussionId`, loadChildren: () => import('./forum-discussion-lazy.module'), data: { discussionsPathPrefix: `${ADDON_MOD_FORUM_PAGE_NAME}/` }, }, diff --git a/src/addons/mod/glossary/glossary.module.ts b/src/addons/mod/glossary/glossary.module.ts index e2af50f59..f38f6d745 100644 --- a/src/addons/mod/glossary/glossary.module.ts +++ b/src/addons/mod/glossary/glossary.module.ts @@ -16,7 +16,7 @@ import { conditionalRoutes } from '@/app/app-routing.module'; import { APP_INITIALIZER, NgModule } from '@angular/core'; import { Routes } from '@angular/router'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; -import { COURSE_CONTENTS_PATH } from '@features/course/constants'; +import { CORE_COURSE_CONTENTS_PATH } from '@features/course/constants'; import { CoreCourseContentsRoutingModule } from '@features/course/course-contents-routing.module'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; @@ -52,18 +52,18 @@ const mainMenuRoutes: Routes = [ // Single Activity format navigation. { - path: `${COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/new`, + path: `${CORE_COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/new`, loadChildren: () => import('./glossary-edit-lazy.module'), data: { glossaryPathPrefix: `${ADDON_MOD_GLOSSARY_PAGE_NAME}/` }, }, { - path: `${COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/:entrySlug/edit`, + path: `${CORE_COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/:entrySlug/edit`, loadChildren: () => import('./glossary-edit-lazy.module'), data: { glossaryPathPrefix: `${ADDON_MOD_GLOSSARY_PAGE_NAME}/` }, }, ...conditionalRoutes( [{ - path: `${COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/:entrySlug`, + path: `${CORE_COURSE_CONTENTS_PATH}/${ADDON_MOD_GLOSSARY_PAGE_NAME}/entry/:entrySlug`, loadChildren: () => import('./glossary-entry-lazy.module'), data: { glossaryPathPrefix: `${ADDON_MOD_GLOSSARY_PAGE_NAME}/` }, }], diff --git a/src/addons/notes/services/handlers/course-option.ts b/src/addons/notes/services/handlers/course-option.ts index acb9153e6..b987dbd56 100644 --- a/src/addons/notes/services/handlers/course-option.ts +++ b/src/addons/notes/services/handlers/course-option.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreCourseAccessDataType } from '@features/course/services/course'; +import { CoreCourseAccessDataType } from '@features/course/constants'; import { CoreCourseAccess, CoreCourseOptionsHandler, @@ -47,7 +47,7 @@ export class AddonNotesCourseOptionHandlerService implements CoreCourseOptionsHa accessData: CoreCourseAccess, navOptions?: CoreCourseUserAdminOrNavOptionIndexed, ): Promise { - if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) { + if (accessData?.type === CoreCourseAccessDataType.ACCESS_GUEST) { return false; // Not enabled for guest access. } diff --git a/src/addons/storagemanager/pages/course-storage/course-storage.ts b/src/addons/storagemanager/pages/course-storage/course-storage.ts index c64314930..4d1a60ae9 100644 --- a/src/addons/storagemanager/pages/course-storage/course-storage.ts +++ b/src/addons/storagemanager/pages/course-storage/course-storage.ts @@ -14,7 +14,8 @@ import { CoreConstants, DownloadStatus } from '@/core/constants'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core'; -import { CoreCourse, CoreCourseProvider, sectionContentIsModule } from '@features/course/services/course'; +import { CORE_COURSE_ALL_COURSES_CLEARED, CORE_COURSE_ALL_SECTIONS_ID } from '@features/course/constants'; +import { CoreCourse, sectionContentIsModule } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData, @@ -181,7 +182,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { // Listen for changes in course status. this.courseStatusObserver = CoreEvents.on(CoreEvents.COURSE_STATUS_CHANGED, (data) => { - if (data.courseId === this.courseId || data.courseId === CoreCourseProvider.ALL_COURSES_CLEARED) { + if (data.courseId === this.courseId || data.courseId === CORE_COURSE_ALL_COURSES_CLEARED) { this.updateCourseStatus(data.status); } }, CoreSites.getCurrentSiteId()); @@ -723,7 +724,7 @@ export class AddonStorageManagerCourseStoragePage implements OnInit, OnDestroy { } await Promise.all(sections.map(async (section) => { - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID) { return; } diff --git a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts index ab658f4a4..857ac0d2f 100644 --- a/src/addons/storagemanager/pages/courses-storage/courses-storage.ts +++ b/src/addons/storagemanager/pages/courses-storage/courses-storage.ts @@ -15,7 +15,8 @@ import { DownloadStatus } from '@/core/constants'; import { Component, OnDestroy, OnInit } from '@angular/core'; import { CoreQueueRunner } from '@classes/queue-runner'; -import { CoreCourse, CoreCourseProvider } from '@features/course/services/course'; +import { CORE_COURSE_ALL_COURSES_CLEARED } from '@features/course/constants'; +import { CoreCourse } from '@features/course/services/course'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreSettingsHelper, CoreSiteSpaceUsage } from '@features/settings/services/settings-helper'; @@ -181,7 +182,7 @@ export class AddonStorageManagerCoursesStoragePage implements OnInit, OnDestroy * @param courseId Updated course id. */ private async onCourseUpdated(courseId: number, status: DownloadStatus): Promise { - if (courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { + if (courseId == CORE_COURSE_ALL_COURSES_CLEARED) { await this.downloadedCoursesQueue.run(() => this.setDownloadedCourses([])); return; diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index 65ddf72f1..9f088a956 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -30,7 +30,6 @@ import { CoreDynamicComponent } from '@components/dynamic-component/dynamic-comp import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourse, - CoreCourseProvider, sectionContentIsModule, } from '@features/course/services/course'; import { @@ -57,7 +56,12 @@ import { CoreModals } from '@services/modals'; import { CoreSharedModule } from '@/core/shared.module'; import { CoreBlockComponentsModule } from '@features/block/components/components.module'; import { CoreSites } from '@services/sites'; -import { COURSE_ALL_SECTIONS_PREFERRED_PREFIX, COURSE_EXPANDED_SECTIONS_PREFIX } from '@features/course/constants'; +import { + CORE_COURSE_ALL_SECTIONS_ID, + CORE_COURSE_ALL_SECTIONS_PREFERRED_PREFIX, + CORE_COURSE_EXPANDED_SECTIONS_PREFIX, + CORE_COURSE_STEALTH_MODULES_SECTION_ID, +} from '@features/course/constants'; import { toBoolean } from '@/core/transforms/boolean'; import { CoreInfiniteLoadingComponent } from '@components/infinite-loading/infinite-loading'; import { CoreSite } from '@classes/sites/site'; @@ -129,8 +133,8 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { selectedSection?: CoreCourseSectionToDisplay; previousSection?: CoreCourseSectionToDisplay; nextSection?: CoreCourseSectionToDisplay; - allSectionsId = CoreCourseProvider.ALL_SECTIONS_ID; - stealthModulesSectionId = CoreCourseProvider.STEALTH_MODULES_SECTION_ID; + allSectionsId = CORE_COURSE_ALL_SECTIONS_ID; + stealthModulesSectionId = CORE_COURSE_STEALTH_MODULES_SECTION_ID; loaded = false; lastModuleViewed?: CoreCourseViewedModulesDBRecord; viewedModules: Record = {}; @@ -299,7 +303,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param sections Sections to treat. */ protected async treatSections(sections: CoreCourseSectionToDisplay[]): Promise { - const hasAllSections = sections[0].id === CoreCourseProvider.ALL_SECTIONS_ID; + const hasAllSections = sections[0].id === CORE_COURSE_ALL_SECTIONS_ID; const hasSeveralSections = sections.length > 2 || (sections.length === 2 && !hasAllSections); await this.initializeViewedModules(); @@ -765,7 +769,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { * @param show Whether if all sections is preferred. */ protected async setAllSectionsPreferred(show: boolean): Promise { - await this.currentSite?.setLocalSiteConfig(`${COURSE_ALL_SECTIONS_PREFERRED_PREFIX}${this.course.id}`, show ? 1 : 0); + await this.currentSite?.setLocalSiteConfig(`${CORE_COURSE_ALL_SECTIONS_PREFERRED_PREFIX}${this.course.id}`, show ? 1 : 0); } /** @@ -775,7 +779,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { */ protected async isAllSectionsPreferred(): Promise { const showAllSections = - await this.currentSite?.getLocalSiteConfig(`${COURSE_ALL_SECTIONS_PREFERRED_PREFIX}${this.course.id}`, 0); + await this.currentSite?.getLocalSiteConfig(`${CORE_COURSE_ALL_SECTIONS_PREFERRED_PREFIX}${this.course.id}`, 0); return !!showAllSections; } @@ -788,7 +792,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { .filter((section) => section.expanded && section.id > 0).map((section) => section.id); await this.currentSite?.setLocalSiteConfig( - `${COURSE_EXPANDED_SECTIONS_PREFIX}${this.course.id}`, + `${CORE_COURSE_EXPANDED_SECTIONS_PREFIX}${this.course.id}`, expandedSections.join(','), ); } @@ -798,7 +802,7 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { */ protected async initializeExpandedSections(): Promise { const expandedSections = await CoreUtils.ignoreErrors( - this.currentSite?.getLocalSiteConfig(`${COURSE_EXPANDED_SECTIONS_PREFIX}${this.course.id}`), + this.currentSite?.getLocalSiteConfig(`${CORE_COURSE_EXPANDED_SECTIONS_PREFIX}${this.course.id}`), ); if (expandedSections === undefined) { diff --git a/src/core/features/course/components/course-index/course-index.ts b/src/core/features/course/components/course-index/course-index.ts index b1c3c6150..0f5214155 100644 --- a/src/core/features/course/components/course-index/course-index.ts +++ b/src/core/features/course/components/course-index/course-index.ts @@ -16,8 +16,6 @@ import { CoreSharedModule } from '@/core/shared.module'; import { Component, ElementRef, Input, OnInit } from '@angular/core'; import { CoreCourse, - CoreCourseModuleCompletionStatus, - CoreCourseProvider, sectionContentIsModule, } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData, CoreCourseSection } from '@features/course/services/course-helper'; @@ -28,6 +26,7 @@ import { CoreSites } from '@services/sites'; import { CoreWait } from '@singletons/wait'; import { ModalController } from '@singletons'; import { CoreDom } from '@singletons/dom'; +import { CoreCourseModuleCompletionStatus, CORE_COURSE_ALL_SECTIONS_ID } from '@features/course/constants'; /** * Component to display course index modal. @@ -47,7 +46,7 @@ export class CoreCourseCourseIndexComponent implements OnInit { @Input() selectedId?: number; @Input() course?: CoreCourseAnyCourseData; - allSectionId = CoreCourseProvider.ALL_SECTIONS_ID; + allSectionId = CORE_COURSE_ALL_SECTIONS_ID; highlighted?: string; sectionsToRender: CourseIndexSection[] = []; loaded = false; diff --git a/src/core/features/course/components/course-section/course-section.ts b/src/core/features/course/components/course-section/course-section.ts index ff7968d84..a7155f0cf 100644 --- a/src/core/features/course/components/course-section/course-section.ts +++ b/src/core/features/course/components/course-section/course-section.ts @@ -25,8 +25,9 @@ import { CoreCourseComponentsModule } from '../components.module'; import { toBoolean } from '@/core/transforms/boolean'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourseViewedModulesDBRecord } from '@features/course/services/database/course'; -import { CoreCourseModuleCompletionStatus, sectionContentIsModule } from '@features/course/services/course'; +import { sectionContentIsModule } from '@features/course/services/course'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; +import { CoreCourseModuleCompletionStatus } from '@features/course/constants'; /** * Component to display course section. diff --git a/src/core/features/course/components/module-completion-details/module-completion-details.ts b/src/core/features/course/components/module-completion-details/module-completion-details.ts index ee72d2d78..c48cf7e5e 100644 --- a/src/core/features/course/components/module-completion-details/module-completion-details.ts +++ b/src/core/features/course/components/module-completion-details/module-completion-details.ts @@ -14,9 +14,9 @@ import { CoreSharedModule } from '@/core/shared.module'; import { Component, Input, OnInit } from '@angular/core'; +import { CoreCourseModuleCompletionStatus } from '@features/course/constants'; import { - CoreCourseModuleCompletionStatus, CoreCourseModuleWSRuleDetails, } from '@features/course/services/course'; import { CoreCourseModuleCompletionData } from '@features/course/services/course-helper'; diff --git a/src/core/features/course/components/module-completion-legacy/module-completion-legacy.ts b/src/core/features/course/components/module-completion-legacy/module-completion-legacy.ts index 66e1cb6a7..af3f15aef 100644 --- a/src/core/features/course/components/module-completion-legacy/module-completion-legacy.ts +++ b/src/core/features/course/components/module-completion-legacy/module-completion-legacy.ts @@ -18,7 +18,7 @@ import { CoreUser } from '@features/user/services/user'; import { CoreCourseModuleCompletionStatus, CoreCourseModuleCompletionTracking, -} from '@features/course/services/course'; +} from '@features/course/constants'; import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { Translate } from '@singletons'; import { CoreCourseModuleCompletionBaseComponent } from '@features/course/classes/module-completion'; @@ -76,7 +76,7 @@ export class CoreCourseModuleCompletionLegacyComponent extends CoreCourseModuleC let langKey: string | undefined; let image: string | undefined; - if (this.completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_MANUAL) { + if (this.completion.tracking === CoreCourseModuleCompletionTracking.MANUAL) { if (this.completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE) { image = 'completion-manual-n'; langKey = 'core.completion-alt-manual-n'; @@ -84,7 +84,7 @@ export class CoreCourseModuleCompletionLegacyComponent extends CoreCourseModuleC image = 'completion-manual-y'; langKey = 'core.completion-alt-manual-y'; } - } else if (this.completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC) { + } else if (this.completion.tracking === CoreCourseModuleCompletionTracking.AUTOMATIC) { if (this.completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE) { image = 'completion-auto-n'; langKey = 'core.completion-alt-auto-n'; diff --git a/src/core/features/course/components/module-completion/module-completion.ts b/src/core/features/course/components/module-completion/module-completion.ts index aa4ddf20c..55689504f 100644 --- a/src/core/features/course/components/module-completion/module-completion.ts +++ b/src/core/features/course/components/module-completion/module-completion.ts @@ -15,9 +15,7 @@ import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChange } from '@angular/core'; import { CoreCourseModuleCompletionBaseComponent } from '@features/course/classes/module-completion'; -import { - CoreCourseModuleCompletionStatus, -} from '@features/course/services/course'; +import { CoreCourseModuleCompletionStatus } from '@features/course/constants'; import { CorePopovers } from '@services/popovers'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreUser } from '@features/user/services/user'; diff --git a/src/core/features/course/constants.ts b/src/core/features/course/constants.ts index aecd60ad6..9e62a8128 100644 --- a/src/core/features/course/constants.ts +++ b/src/core/features/course/constants.ts @@ -12,10 +12,52 @@ // See the License for the specific language governing permissions and // limitations under the License. -export const COURSE_INDEX_PATH = ':courseId'; -export const COURSE_PAGE_NAME = 'course'; -export const CONTENTS_PAGE_NAME = 'contents'; -export const COURSE_CONTENTS_PATH = `${COURSE_PAGE_NAME}/${COURSE_INDEX_PATH}/${CONTENTS_PAGE_NAME}`; +export const CORE_COURSE_INDEX_PATH = ':courseId'; +export const CORE_COURSE_PAGE_NAME = 'course'; +export const CORE_COURSE_CONTENTS_PAGE_NAME = 'contents'; +export const CORE_COURSE_CONTENTS_PATH = `${CORE_COURSE_PAGE_NAME}/${CORE_COURSE_INDEX_PATH}/${CORE_COURSE_CONTENTS_PAGE_NAME}`; -export const COURSE_ALL_SECTIONS_PREFERRED_PREFIX = 'CoreCourseFormatAllSectionsPreferred-'; -export const COURSE_EXPANDED_SECTIONS_PREFIX = 'CoreCourseFormatExpandedSections-'; +export const CORE_COURSE_ALL_SECTIONS_PREFERRED_PREFIX = 'CoreCourseFormatAllSectionsPreferred-'; +export const CORE_COURSE_EXPANDED_SECTIONS_PREFIX = 'CoreCourseFormatExpandedSections-'; + +export const CORE_COURSE_ALL_SECTIONS_ID = -2; +export const CORE_COURSE_STEALTH_MODULES_SECTION_ID = -1; +export const CORE_COURSE_ALL_COURSES_CLEARED = -1; + +export const CORE_COURSE_PROGRESS_UPDATED_EVENT = 'progress_updated'; + +export const CORE_COURSE_AUTO_SYNCED = 'core_course_autom_synced'; + +export const CORE_COURSE_COMPONENT = 'CoreCourse'; + +export const CORE_COURSE_CORE_MODULES = [ + 'assign', 'bigbluebuttonbn', 'book', 'chat', 'choice', 'data', 'feedback', 'folder', 'forum', 'glossary', 'h5pactivity', + 'imscp', 'label', 'lesson', 'lti', 'page', 'quiz', 'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop', +]; + +/** + * Course Module completion status enumeration. + */ +export const enum CoreCourseModuleCompletionStatus { + COMPLETION_INCOMPLETE = 0, + COMPLETION_COMPLETE = 1, + COMPLETION_COMPLETE_PASS = 2, + COMPLETION_COMPLETE_FAIL = 3, +} + +/** + * Completion tracking valid values. + */ +export const enum CoreCourseModuleCompletionTracking { + NONE = 0, + MANUAL = 1, + AUTOMATIC = 2, +} + +export const CoreCourseAccessDataType = { + ACCESS_GUEST: 'courses_access_guest', // eslint-disable-line @typescript-eslint/naming-convention + ACCESS_DEFAULT: 'courses_access_default', // eslint-disable-line @typescript-eslint/naming-convention +} as const; + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type CoreCourseAccessDataType = typeof CoreCourseAccessDataType[keyof typeof CoreCourseAccessDataType]; diff --git a/src/core/features/course/course-lazy.module.ts b/src/core/features/course/course-lazy.module.ts index 63b2ff507..18426ba7e 100644 --- a/src/core/features/course/course-lazy.module.ts +++ b/src/core/features/course/course-lazy.module.ts @@ -22,7 +22,7 @@ import { CoreCourseIndexPage } from '@features/course/pages/index'; import { CoreCourseListModTypePage } from '@features/course/pages/list-mod-type/list-mod-type'; import { CoreCourseModulePreviewPage } from '@features/course/pages/module-preview/module-preview'; import { CoreCourseHelper } from './services/course-helper'; -import { COURSE_INDEX_PATH } from './constants'; +import { CORE_COURSE_INDEX_PATH } from './constants'; /** * Build module routes. @@ -35,7 +35,7 @@ function buildRoutes(injector: Injector): Routes { return [ { - path: COURSE_INDEX_PATH, + path: CORE_COURSE_INDEX_PATH, children: [ { path: '', diff --git a/src/core/features/course/course.module.ts b/src/core/features/course/course.module.ts index 975db35a6..5e89c4b8a 100644 --- a/src/core/features/course/course.module.ts +++ b/src/core/features/course/course.module.ts @@ -31,7 +31,7 @@ import { CoreCourseModulesTagAreaHandler } from './services/handlers/modules-tag import { CoreCourse } from './services/course'; import { buildRegExpUrlMatcher } from '@/app/app-routing.module'; import { CoreCourseIndexRoutingModule } from '@features/course/course-routing.module'; -import { COURSE_PAGE_NAME, CONTENTS_PAGE_NAME } from './constants'; +import { CORE_COURSE_PAGE_NAME, CORE_COURSE_CONTENTS_PAGE_NAME } from './constants'; /** * Get course services. @@ -70,7 +70,15 @@ export async function getCourseServices(): Promise[]> { export async function getCourseExportedObjects(): Promise> { const { CoreCourseActivityPrefetchHandlerBase } = await import('@features/course/classes/activity-prefetch-handler'); const { CoreCourseResourcePrefetchHandlerBase } = await import('@features/course/classes/resource-prefetch-handler'); - const { CoreCourseAccessDataType } = await import('@features/course/services/course'); + const { + CoreCourseAccessDataType, + CORE_COURSE_ALL_SECTIONS_ID, + CORE_COURSE_STEALTH_MODULES_SECTION_ID, + CORE_COURSE_ALL_COURSES_CLEARED, + CORE_COURSE_PROGRESS_UPDATED_EVENT, + CORE_COURSE_COMPONENT, + CORE_COURSE_CORE_MODULES, + } = await import('@features/course/constants'); const { CoreCourseUnsupportedModuleComponent } = await import ('@features/course/components/unsupported-module/unsupported-module'); const { CoreCourseFormatSingleActivityComponent } = @@ -83,6 +91,12 @@ export async function getCourseExportedObjects(): Promise[]> const routes: Routes = [ { - matcher: buildRegExpUrlMatcher(new RegExp(`^${COURSE_PAGE_NAME}(/deep)*`)), + matcher: buildRegExpUrlMatcher(new RegExp(`^${CORE_COURSE_PAGE_NAME}(/deep)*`)), loadChildren: () => import('@features/course/course-lazy.module'), }, ]; const courseIndexRoutes: Routes = [ { - path: CONTENTS_PAGE_NAME, + path: CORE_COURSE_CONTENTS_PAGE_NAME, loadChildren: () => import('@features/course/course-contents-lazy.module'), }, ]; diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index 99148c0e9..b303289a6 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -21,8 +21,6 @@ import { CoreCourses, CoreCourseAnyCourseData } from '@features/courses/services import { CoreCourse, CoreCourseCompletionActivityStatus, - CoreCourseModuleCompletionStatus, - CoreCourseProvider, } from '@features/course/services/course'; import { CoreCourseHelper, @@ -32,7 +30,7 @@ import { } from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; -import { CoreCourseSync, CoreCourseSyncProvider } from '@features/course/services/sync'; +import { CoreCourseSync } from '@features/course/services/sync'; import { CoreCourseFormatComponent } from '../../components/course-format/course-format'; import { CoreEvents, @@ -43,6 +41,11 @@ import { CoreRefreshContext, CORE_REFRESH_CONTEXT } from '@/core/utils/refresh-c import { CoreCoursesHelper } from '@features/courses/services/courses-helper'; import { CoreSites } from '@services/sites'; import { CoreWait } from '@singletons/wait'; +import { + CoreCourseModuleCompletionStatus, + CORE_COURSE_AUTO_SYNCED, + CORE_COURSE_PROGRESS_UPDATED_EVENT, +} from '@features/course/constants'; /** * Page that displays the contents of a course. @@ -154,7 +157,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon this.onCompletionChange(data.completion); }); - this.syncObserver = CoreEvents.on(CoreCourseSyncProvider.AUTO_SYNCED, (data) => { + this.syncObserver = CoreEvents.on(CORE_COURSE_AUTO_SYNCED, (data) => { if (!data || data.courseId != this.course.id) { return; } @@ -362,7 +365,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon return; } - CoreEvents.trigger(CoreCourseProvider.PROGRESS_UPDATED, { + CoreEvents.trigger(CORE_COURSE_PROGRESS_UPDATED_EVENT, { courseId: this.course.id, progress: this.course.progress, }, siteId); } diff --git a/src/core/features/course/pages/index/index.ts b/src/core/features/course/pages/index/index.ts index 59f4c77aa..463689768 100644 --- a/src/core/features/course/pages/index/index.ts +++ b/src/core/features/course/pages/index/index.ts @@ -20,11 +20,11 @@ import { CoreCourseFormatDelegate } from '../../services/format-delegate'; import { CoreCourseOptionsDelegate } from '../../services/course-options-delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreCourse, CoreCourseProvider, CoreCourseWSSection } from '@features/course/services/course'; +import { CoreCourse, CoreCourseWSSection } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreUtils } from '@services/utils/utils'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; -import { CONTENTS_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_CONTENTS_PAGE_NAME, CORE_COURSE_PROGRESS_UPDATED_EVENT } from '@features/course/constants'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '@features/courses/services/courses-helper'; import { CoreColors } from '@singletons/colors'; @@ -64,7 +64,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { protected isGuest = false; protected openModule = true; protected contentsTab: CoreTabsOutletTab & { pageParams: Params } = { - page: CONTENTS_PAGE_NAME, + page: CORE_COURSE_CONTENTS_PAGE_NAME, title: 'core.course', pageParams: {}, }; @@ -93,7 +93,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy { const siteId = CoreSites.getCurrentSiteId(); - this.progressObserver = CoreEvents.on(CoreCourseProvider.PROGRESS_UPDATED, (data) => { + this.progressObserver = CoreEvents.on(CORE_COURSE_PROGRESS_UPDATED_EVENT, (data) => { if (!this.course || this.course.id !== data.courseId || !('progress' in this.course)) { return; } diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 6aae35fb0..8cba6bc00 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -22,10 +22,7 @@ import { CoreCourseCompletionActivityStatus, CoreCourseModuleWSCompletionData, CoreCourseModuleContentFile, - CoreCourseProvider, CoreCourseWSSection, - CoreCourseModuleCompletionTracking, - CoreCourseModuleCompletionStatus, CoreCourseGetContentsWSModule, sectionContentIsModule, CoreCourseAnyModuleData, @@ -78,6 +75,13 @@ import { CoreEnrolAction, CoreEnrolDelegate } from '@features/enrol/services/enr import { LazyRoutesModule } from '@/app/app-routing.module'; import { CoreModals } from '@services/modals'; import { CoreLoadings } from '@services/loadings'; +import { + CoreCourseModuleCompletionTracking, + CoreCourseModuleCompletionStatus, + CORE_COURSE_ALL_SECTIONS_ID, + CORE_COURSE_STEALTH_MODULES_SECTION_ID, + CORE_COURSE_COMPONENT, +} from '../constants'; /** * Prefetch info of a module. @@ -255,7 +259,7 @@ export class CoreCourseHelperProvider { * @returns Wether section is stealth (accessible but not visible to students). */ isSectionStealth(section: CoreCourseWSSection): boolean { - return section.hiddenbynumsections === 1 || section.id === CoreCourseProvider.STEALTH_MODULES_SECTION_ID; + return section.hiddenbynumsections === 1 || section.id === CORE_COURSE_STEALTH_MODULES_SECTION_ID; } /** @@ -283,7 +287,7 @@ export class CoreCourseHelperProvider { refresh?: boolean, checkUpdates: boolean = true, ): Promise<{statusData: CoreCourseModulesStatus; section: CoreCourseSectionWithStatus}> { - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID) { throw new CoreError('Invalid section'); } @@ -462,7 +466,7 @@ export class CoreCourseHelperProvider { }; const getSectionSize = async (section: CoreCourseWSSection): Promise => { - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID) { return { size: 0, total: true }; } @@ -579,7 +583,7 @@ export class CoreCourseHelperProvider { */ createAllSectionsSection(): CoreCourseSection { return { - id: CoreCourseProvider.ALL_SECTIONS_ID, + id: CORE_COURSE_ALL_SECTIONS_ID, name: Translate.instant('core.course.allsections'), hasContent: true, summary: '', @@ -1659,7 +1663,7 @@ export class CoreCourseHelperProvider { if (updateAllSections) { // Prefetch all the sections. If the first section is "All sections", use it. Otherwise, use a fake "All sections". allSectionsSection = sections[0]; - if (sections[0].id !== CoreCourseProvider.ALL_SECTIONS_ID) { + if (sections[0].id !== CORE_COURSE_ALL_SECTIONS_ID) { allSectionsSection = this.createAllSectionsSection(); } allSectionsSection.isDownloading = true; @@ -1667,7 +1671,7 @@ export class CoreCourseHelperProvider { const promises = sections.map(async (section) => { // Download all the sections except "All sections". - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID) { return; } @@ -1706,7 +1710,7 @@ export class CoreCourseHelperProvider { * @returns Promise resolved when the section is prefetched. */ protected async prefetchSingleSectionIfNeeded(section: CoreCourseSectionWithStatus, courseId: number): Promise { - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID || section.hiddenbynumsections) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID || section.hiddenbynumsections) { return; } @@ -1721,7 +1725,7 @@ export class CoreCourseHelperProvider { // Download the files in the section description. const introFiles = CoreFilepool.extractDownloadableFilesFromHtmlAsFakeFileObjects(section.summary); promises.push(CoreUtils.ignoreErrors( - CoreFilepool.addFilesToQueue(siteId, introFiles, CoreCourseProvider.COMPONENT, courseId), + CoreFilepool.addFilesToQueue(siteId, introFiles, CORE_COURSE_COMPONENT, courseId), )); try { @@ -1782,7 +1786,7 @@ export class CoreCourseHelperProvider { result: CoreCourseModulesStatus, courseId: number, ): Promise { - if (section.id === CoreCourseProvider.ALL_SECTIONS_ID) { + if (section.id === CORE_COURSE_ALL_SECTIONS_ID) { return; } @@ -1881,7 +1885,7 @@ export class CoreCourseHelperProvider { await Promise.all([ ...modules.map((module) => this.removeModuleStoredData(module, courseId)), - siteId && CoreFilepool.removeFilesByComponent(siteId, CoreCourseProvider.COMPONENT, courseId), + siteId && CoreFilepool.removeFilesByComponent(siteId, CORE_COURSE_COMPONENT, courseId), ]); await CoreCourse.setCourseStatus(courseId, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED); @@ -1922,7 +1926,7 @@ export class CoreCourseHelperProvider { } if (completion.cmid === undefined || - completion.tracking !== CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_MANUAL) { + completion.tracking !== CoreCourseModuleCompletionTracking.MANUAL) { return; } @@ -2087,7 +2091,7 @@ export class CoreCourseHelperProvider { return undefined; } - if (completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE) { + if (completion.tracking === CoreCourseModuleCompletionTracking.NONE) { return undefined; } diff --git a/src/core/features/course/services/course-options-delegate.ts b/src/core/features/course/services/course-options-delegate.ts index 536e5d275..77c3325e2 100644 --- a/src/core/features/course/services/course-options-delegate.ts +++ b/src/core/features/course/services/course-options-delegate.ts @@ -23,7 +23,7 @@ import { CoreCourses, CoreCourseUserAdminOrNavOptionIndexed, } from '@features/courses/services/courses'; -import { CoreCourseAccessDataType } from './course'; +import { CoreCourseAccessDataType } from '../constants'; import { Params } from '@angular/router'; import { makeSingleton } from '@singletons'; import { CorePromisedValue } from '@classes/promised-value'; diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 6701ddb73..5c9d34af6 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -46,7 +46,7 @@ import { CoreCourseHelper, CoreCourseModuleData, CoreCourseModuleCompletionData import { CoreCourseFormatDelegate } from './format-delegate'; import { CoreCronDelegate } from '@services/cron'; import { CoreCourseLogCronHandler } from './handlers/log-cron'; -import { CoreCourseAutoSyncData, CoreCourseSyncProvider } from './sync'; +import { CoreCourseAutoSyncData } from './sync'; import { CoreTagItem } from '@features/tag/services/tag'; import { CoreNavigationOptions, CoreNavigator } from '@services/navigator'; import { CoreCourseModuleDelegate } from './module-delegate'; @@ -64,8 +64,18 @@ import { CoreArray } from '@singletons/array'; import { CoreText } from '@singletons/text'; import { ArrayElement } from '@/core/utils/types'; import { CORE_COURSES_MY_COURSES_UPDATED_EVENT, CoreCoursesMyCoursesUpdatedEventAction } from '@features/courses/constants'; - -const ROOT_CACHE_KEY = 'mmCourse:'; +import { + CoreCourseAccessDataType, + CoreCourseModuleCompletionStatus, + CoreCourseModuleCompletionTracking, + CORE_COURSE_ALL_COURSES_CLEARED, + CORE_COURSE_ALL_SECTIONS_ID, + CORE_COURSE_COMPONENT, + CORE_COURSE_CORE_MODULES, + CORE_COURSE_PROGRESS_UPDATED_EVENT, + CORE_COURSE_STEALTH_MODULES_SECTION_ID, + CORE_COURSE_AUTO_SYNCED, +} from '../constants'; export type CoreCourseProgressUpdated = { progress: number; courseId: number }; @@ -77,58 +87,18 @@ declare module '@singletons/events' { * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation */ export interface CoreEventsData { - [CoreCourseSyncProvider.AUTO_SYNCED]: CoreCourseAutoSyncData; - [CoreCourseProvider.PROGRESS_UPDATED]: CoreCourseProgressUpdated; + [CORE_COURSE_AUTO_SYNCED]: CoreCourseAutoSyncData; + [CORE_COURSE_PROGRESS_UPDATED_EVENT]: CoreCourseProgressUpdated; } } -/** - * Course Module completion status enumeration. - */ -export const enum CoreCourseModuleCompletionStatus { - COMPLETION_INCOMPLETE = 0, - COMPLETION_COMPLETE = 1, - COMPLETION_COMPLETE_PASS = 2, - COMPLETION_COMPLETE_FAIL = 3, -} - -/** - * @deprecated since 4.3 Not used anymore. - */ -export const enum CoreCourseCompletionMode { - FULL = 'full', - BASIC = 'basic', -} - -/** - * Completion tracking valid values. - */ -export const enum CoreCourseModuleCompletionTracking { - COMPLETION_TRACKING_NONE = 0, - COMPLETION_TRACKING_MANUAL = 1, - COMPLETION_TRACKING_AUTOMATIC = 2, -} - -export const CoreCourseAccessDataType = { - ACCESS_GUEST: 'courses_access_guest', // eslint-disable-line @typescript-eslint/naming-convention - ACCESS_DEFAULT: 'courses_access_default', // eslint-disable-line @typescript-eslint/naming-convention -} as const; - -// eslint-disable-next-line @typescript-eslint/no-redeclare -export type CoreCourseAccessDataType = typeof CoreCourseAccessDataType[keyof typeof CoreCourseAccessDataType]; - /** * Service that provides some features regarding a course. */ @Injectable({ providedIn: 'root' }) export class CoreCourseProvider { - static readonly ALL_SECTIONS_ID = -2; - static readonly STEALTH_MODULES_SECTION_ID = -1; - static readonly ALL_COURSES_CLEARED = -1; - static readonly PROGRESS_UPDATED = 'progress_updated'; - /** * @deprecated since 4.4 Not used anymore. Use CoreCourseAccessDataType instead. */ @@ -138,12 +108,32 @@ export class CoreCourseProvider { */ static readonly ACCESS_DEFAULT = CoreCourseAccessDataType.ACCESS_DEFAULT; - static readonly COMPONENT = 'CoreCourse'; + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_ALL_SECTIONS_ID instead. + */ + static readonly ALL_SECTIONS_ID = CORE_COURSE_ALL_SECTIONS_ID; + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_STEALTH_MODULES_SECTION_ID instead. + */ + static readonly STEALTH_MODULES_SECTION_ID = CORE_COURSE_STEALTH_MODULES_SECTION_ID; + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_ALL_COURSES_CLEARED instead. + */ + static readonly ALL_COURSES_CLEARED = CORE_COURSE_ALL_COURSES_CLEARED; + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_PROGRESS_UPDATED instead. + */ + static readonly PROGRESS_UPDATED = CORE_COURSE_PROGRESS_UPDATED_EVENT; - static readonly CORE_MODULES = [ - 'assign', 'bigbluebuttonbn', 'book', 'chat', 'choice', 'data', 'feedback', 'folder', 'forum', 'glossary', 'h5pactivity', - 'imscp', 'label', 'lesson', 'lti', 'page', 'quiz', 'resource', 'scorm', 'survey', 'url', 'wiki', 'workshop', - ]; + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_COMPONENT instead. + */ + static readonly COMPONENT = CORE_COURSE_COMPONENT; + + /** + * @deprecated since 5.0 Not used anymore. Use COURSE_CORE_MODULES instead. + */ + static readonly CORE_MODULES = CORE_COURSE_CORE_MODULES; protected logger: CoreLogger; protected statusTables: LazyMap>>; @@ -151,6 +141,8 @@ export class CoreCourseProvider { AsyncInstance> >; + protected static readonly ROOT_CACHE_KEY = 'mmCourse:'; + constructor() { this.logger = CoreLogger.getInstance('CoreCourseProvider'); this.statusTables = lazyMap( @@ -253,7 +245,7 @@ export class CoreCourseProvider { * @returns Whether it's an automatic completion that hasn't been completed yet. */ isIncompleteAutomaticCompletion(completion: CoreCourseModuleCompletionData): boolean { - return completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_AUTOMATIC && + return completion.tracking === CoreCourseModuleCompletionTracking.AUTOMATIC && completion.state === CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE; } @@ -291,7 +283,7 @@ export class CoreCourseProvider { await this.statusTables[site.getId()].delete(); this.triggerCourseStatusChanged( - CoreCourseProvider.ALL_COURSES_CLEARED, + CORE_COURSE_ALL_COURSES_CLEARED, DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED, site.id, ); @@ -378,7 +370,7 @@ export class CoreCourseProvider { const onlineCompletion = completionStatus[offlineCompletion.cmid]; // If the activity uses manual completion, override the value with the offline one. - if (onlineCompletion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_MANUAL) { + if (onlineCompletion.tracking === CoreCourseModuleCompletionTracking.MANUAL) { onlineCompletion.state = offlineCompletion.completed; onlineCompletion.offline = true; } @@ -400,7 +392,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getActivitiesCompletionCacheKey(courseId: number, userId: number): string { - return ROOT_CACHE_KEY + 'activitiescompletion:' + courseId + ':' + userId; + return CoreCourseProvider.ROOT_CACHE_KEY + 'activitiescompletion:' + courseId + ':' + userId; } /** @@ -472,7 +464,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getCourseBlocksCacheKey(courseId: number): string { - return ROOT_CACHE_KEY + 'courseblocks:' + courseId; + return CoreCourseProvider.ROOT_CACHE_KEY + 'courseblocks:' + courseId; } /** @@ -669,7 +661,7 @@ export class CoreCourseProvider { let foundModule: CoreCourseGetContentsWSModule | undefined; const foundSection = sections.find((section) => { - if (section.id != CoreCourseProvider.STEALTH_MODULES_SECTION_ID && + if (section.id != CORE_COURSE_STEALTH_MODULES_SECTION_ID && sectionId !== undefined && sectionId != section.id ) { @@ -820,7 +812,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getModuleBasicInfoByInstanceCacheKey(instanceId: number, moduleName: string): string { - return ROOT_CACHE_KEY + 'moduleByInstance:' + moduleName + ':' + instanceId; + return CoreCourseProvider.ROOT_CACHE_KEY + 'moduleByInstance:' + moduleName + ':' + instanceId; } /** @@ -830,7 +822,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getModuleCacheKey(moduleId: number): string { - return ROOT_CACHE_KEY + 'module:' + moduleId; + return CoreCourseProvider.ROOT_CACHE_KEY + 'module:' + moduleId; } /** @@ -840,7 +832,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getModuleByModNameCacheKey(modName: string): string { - return ROOT_CACHE_KEY + 'module:modName:' + modName; + return CoreCourseProvider.ROOT_CACHE_KEY + 'module:modName:' + modName; } /** @@ -1069,7 +1061,7 @@ export class CoreCourseProvider { * @returns Cache key. */ protected getSectionsCacheKey(courseId: number): string { - return ROOT_CACHE_KEY + 'sections:' + courseId; + return CoreCourseProvider.ROOT_CACHE_KEY + 'sections:' + courseId; } /** @@ -1408,7 +1400,7 @@ export class CoreCourseProvider { */ isCoreModule(moduleName: string): boolean { // If core modules are removed for a certain version we should check the version of the site. - return CoreCourseProvider.CORE_MODULES.includes(moduleName); + return CORE_COURSE_CORE_MODULES.includes(moduleName); } /** diff --git a/src/core/features/course/services/sync.ts b/src/core/features/course/services/sync.ts index e38e3ad56..94921ea2b 100644 --- a/src/core/features/course/services/sync.ts +++ b/src/core/features/course/services/sync.ts @@ -29,6 +29,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { makeSingleton, Translate } from '@singletons'; import { CoreEvents } from '@singletons/events'; import { CoreCourses } from '@features/courses/services/courses'; +import { CORE_COURSE_AUTO_SYNCED } from '../constants'; /** * Service to sync course offline data. This only syncs the offline data of the course itself, not the offline data of @@ -37,8 +38,6 @@ import { CoreCourses } from '@features/courses/services/courses'; @Injectable({ providedIn: 'root' }) export class CoreCourseSyncProvider extends CoreSyncBaseProvider { - static readonly AUTO_SYNCED = 'core_course_autom_synced'; - constructor() { super('CoreCourseSyncProvider'); } @@ -96,7 +95,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { + this.progressObserver = CoreEvents.on(CORE_COURSE_PROGRESS_UPDATED_EVENT, (data) => { if (!this.course || this.course.id !== data.courseId || !('progress' in this.course)) { return; } @@ -203,7 +204,7 @@ export class CoreCoursesCourseListItemComponent implements OnInit, OnDestroy, On // Listen for status change in course. this.courseStatusObserver = CoreEvents.on(CoreEvents.COURSE_STATUS_CHANGED, (data: CoreEventCourseStatusChanged) => { - if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { + if (data.courseId == this.course.id || data.courseId == CORE_COURSE_ALL_COURSES_CLEARED) { this.updateCourseStatus(data.status); } }, CoreSites.getCurrentSiteId()); diff --git a/src/core/features/grades/grades.module.ts b/src/core/features/grades/grades.module.ts index 533bd16c3..40527316f 100644 --- a/src/core/features/grades/grades.module.ts +++ b/src/core/features/grades/grades.module.ts @@ -29,7 +29,7 @@ import { CoreGradesUserLinkHandler } from './services/handlers/user-link'; import { CoreGradesCourseParticipantsOptionHandler } from '@features/grades/services/handlers/course-participants-option'; import { conditionalRoutes } from '@/app/app-routing.module'; import { CoreScreen } from '@services/screen'; -import { COURSE_PAGE_NAME, COURSE_INDEX_PATH } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME, CORE_COURSE_INDEX_PATH } from '@features/course/constants'; /** * Get grades services. @@ -53,12 +53,12 @@ const mainMenuChildrenRoutes: Routes = [ data: { swipeManagerSource: 'courses' }, }, { - path: `${COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${GRADES_PAGE_NAME}`, + path: `${CORE_COURSE_PAGE_NAME}/:courseId/${PARTICIPANTS_PAGE_NAME}/:userId/${GRADES_PAGE_NAME}`, loadChildren: () => import('./grades-course-lazy.module'), }, ...conditionalRoutes([ { - path: `${COURSE_PAGE_NAME}/${COURSE_INDEX_PATH}/${GRADES_PARTICIPANTS_PAGE_NAME}/:userId`, + path: `${CORE_COURSE_PAGE_NAME}/${CORE_COURSE_INDEX_PATH}/${GRADES_PARTICIPANTS_PAGE_NAME}/:userId`, loadChildren: () => import('./grades-course-lazy.module'), data: { swipeManagerSource: 'participants' }, }, diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index d09fa96c8..70da26191 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -22,7 +22,7 @@ import { CoreCourseSearchedData, CoreCourseUserAdminOrNavOptionIndexed, } from '@features/courses/services/courses'; -import { CoreCourse, CoreCourseAccessDataType } from '@features/course/services/course'; +import { CoreCourse } from '@features/course/services/course'; import { CoreGrades, CoreGradesGradeItem, @@ -45,6 +45,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg import { CoreCourseAccess } from '@features/course/services/course-options-delegate'; import { CoreLoadings } from '@services/loadings'; import { convertTextToHTMLElement } from '@/core/utils/create-html-element'; +import { CoreCourseAccessDataType } from '@features/course/constants'; export const GRADES_PAGE_NAME = 'grades'; export const GRADES_PARTICIPANTS_PAGE_NAME = 'participant-grades'; diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index 3f1186416..e0d92f668 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { COURSE_PAGE_NAME } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME } from '@features/course/constants'; import { CoreGrades } from '@features/grades/services/grades'; import { CoreUserProfile } from '@features/user/services/user'; @@ -99,7 +99,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { event.preventDefault(); event.stopPropagation(); CoreNavigator.navigateToSitePath( - [COURSE_PAGE_NAME, contextId, PARTICIPANTS_PAGE_NAME, user.id, GRADES_PAGE_NAME].join('/'), + [CORE_COURSE_PAGE_NAME, contextId, PARTICIPANTS_PAGE_NAME, user.id, GRADES_PAGE_NAME].join('/'), ); }, }; diff --git a/src/core/features/user/services/handlers/course-option.ts b/src/core/features/user/services/handlers/course-option.ts index 431668217..af685989c 100644 --- a/src/core/features/user/services/handlers/course-option.ts +++ b/src/core/features/user/services/handlers/course-option.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreCourseAccessDataType } from '@features/course/services/course'; +import { CoreCourseAccessDataType } from '@features/course/constants'; import { CoreCourseAccess, CoreCourseOptionsHandler, diff --git a/src/core/features/user/user.module.ts b/src/core/features/user/user.module.ts index 373a922f3..1916281ae 100644 --- a/src/core/features/user/user.module.ts +++ b/src/core/features/user/user.module.ts @@ -34,7 +34,7 @@ import { CoreUserHelper } from './services/user-helper'; import { AppRoutingModule, conditionalRoutes } from '@/app/app-routing.module'; import { CoreScreen } from '@services/screen'; import { CoreEvents } from '@singletons/events'; -import { COURSE_PAGE_NAME, COURSE_INDEX_PATH } from '@features/course/constants'; +import { CORE_COURSE_PAGE_NAME, CORE_COURSE_INDEX_PATH } from '@features/course/constants'; import { PARTICIPANTS_PAGE_NAME } from './constants'; /** @@ -74,7 +74,7 @@ const routes: Routes = [ }, ...conditionalRoutes([ { - path: `${COURSE_PAGE_NAME}/${COURSE_INDEX_PATH}/${PARTICIPANTS_PAGE_NAME}/:userId`, + path: `${CORE_COURSE_PAGE_NAME}/${CORE_COURSE_INDEX_PATH}/${PARTICIPANTS_PAGE_NAME}/:userId`, loadChildren: () => import('@features/user/user-profile-lazy.module'), data: { swipeManagerSource: 'participants',