MOBILE-4543 course: Improvements on course options delegate
parent
0d56f802f2
commit
4f56e08f9b
|
@ -64,7 +64,7 @@ export class AddonBadgesUserHandlerService implements CoreUserProfileHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (navOptions && navOptions.badges !== undefined) {
|
||||
if (navOptions?.badges !== undefined) {
|
||||
return navOptions.badges;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ export class AddonBlogCourseOptionHandlerService implements CoreCourseOptionsHan
|
|||
): Promise<boolean> {
|
||||
const enabled = await CoreCourseHelper.hasABlockNamed(courseId, 'blog_menu');
|
||||
|
||||
if (enabled && navOptions && navOptions.blogs !== undefined) {
|
||||
if (enabled && navOptions?.blogs !== undefined) {
|
||||
return navOptions.blogs;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCourseProvider } from '@features/course/services/course';
|
||||
import { CoreCourseAccessDataType } from '@features/course/services/course';
|
||||
import {
|
||||
CoreCourseAccess,
|
||||
CoreCourseOptionsHandler,
|
||||
|
@ -50,11 +50,11 @@ export class AddonCompetencyCourseOptionHandlerService implements CoreCourseOpti
|
|||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
if (accessData && accessData.type === CoreCourseProvider.ACCESS_GUEST) {
|
||||
if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) {
|
||||
return false; // Not enabled for guest access.
|
||||
}
|
||||
|
||||
if (navOptions && navOptions.competencies !== undefined) {
|
||||
if (navOptions?.competencies !== undefined) {
|
||||
return navOptions.competencies;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ export class AddonCompetencyCourseOptionHandlerService implements CoreCourseOpti
|
|||
* @inheritdoc
|
||||
*/
|
||||
async invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise<void> {
|
||||
if (navOptions && navOptions.competencies !== undefined) {
|
||||
if (navOptions?.competencies !== undefined) {
|
||||
// No need to invalidate anything.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCourseProvider } from '@features/course/services/course';
|
||||
import { CoreCourseAccessDataType } from '@features/course/services/course';
|
||||
import {
|
||||
CoreCourseAccess,
|
||||
CoreCourseOptionsHandler,
|
||||
|
@ -43,7 +43,7 @@ export class AddonCourseCompletionCourseOptionHandlerService implements CoreCour
|
|||
* @inheritdoc
|
||||
*/
|
||||
async isEnabledForCourse(courseId: number, accessData: CoreCourseAccess): Promise<boolean> {
|
||||
if (accessData && accessData.type === CoreCourseProvider.ACCESS_GUEST) {
|
||||
if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) {
|
||||
return false; // Not enabled for guest access.
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCourseProvider } from '@features/course/services/course';
|
||||
import { CoreCourseAccessDataType } from '@features/course/services/course';
|
||||
import {
|
||||
CoreCourseAccess,
|
||||
CoreCourseOptionsHandler,
|
||||
|
@ -47,11 +47,11 @@ export class AddonNotesCourseOptionHandlerService implements CoreCourseOptionsHa
|
|||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
if (accessData && accessData.type === CoreCourseProvider.ACCESS_GUEST) {
|
||||
if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) {
|
||||
return false; // Not enabled for guest access.
|
||||
}
|
||||
|
||||
if (navOptions && navOptions.notes !== undefined) {
|
||||
if (navOptions?.notes !== undefined) {
|
||||
return navOptions.notes;
|
||||
}
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
|||
* @returns Promise resolved when done.
|
||||
*/
|
||||
protected async loadMenuHandlers(refresh?: boolean): Promise<void> {
|
||||
if (!this.course) {
|
||||
if (!this.course || !this.canAccessCourse) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,9 @@ import {
|
|||
CoreCoursesProvider,
|
||||
CoreCourseUserAdminOrNavOptionIndexed,
|
||||
} from '@features/courses/services/courses';
|
||||
import { CoreCourseProvider } from './course';
|
||||
import { CoreCourseAccessDataType } from './course';
|
||||
import { Params } from '@angular/router';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEnrolledCourseDataWithExtraInfoAndOptions } from '@features/courses/services/courses-helper';
|
||||
import { CorePromisedValue } from '@classes/promised-value';
|
||||
|
||||
/**
|
||||
|
@ -313,20 +312,20 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with array of handlers.
|
||||
*/
|
||||
protected async getHandlersForAccess(
|
||||
protected async updateHandlersForAccess(
|
||||
courseId: number,
|
||||
refresh: boolean,
|
||||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<CoreCourseOptionsHandler[]> {
|
||||
): Promise<void> {
|
||||
|
||||
// If the handlers aren't loaded, do not refresh.
|
||||
if (!this.loaded[courseId]) {
|
||||
refresh = false;
|
||||
}
|
||||
|
||||
if (refresh || !this.coursesHandlers[courseId] || this.coursesHandlers[courseId].access.type != accessData.type) {
|
||||
if (refresh || !this.coursesHandlers[courseId] || this.coursesHandlers[courseId].access.type !== accessData.type) {
|
||||
if (!this.coursesHandlers[courseId]) {
|
||||
this.coursesHandlers[courseId] = {
|
||||
access: accessData,
|
||||
|
@ -347,8 +346,6 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
}
|
||||
|
||||
await this.coursesHandlers[courseId].deferred;
|
||||
|
||||
return this.coursesHandlers[courseId].enabledHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -358,18 +355,14 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param course The course object.
|
||||
* @param refresh True if it should refresh the list.
|
||||
* @param isGuest Whether user is using an ACCESS_GUEST enrolment method.
|
||||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with array of handlers.
|
||||
*/
|
||||
getHandlersToDisplay(
|
||||
course: CoreCourseAnyCourseData,
|
||||
refresh = false,
|
||||
isGuest = false,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<CoreCourseOptionsHandlerToDisplay[]> {
|
||||
return this.getHandlersToDisplayInternal(false, course, refresh, isGuest, navOptions, admOptions) as
|
||||
return this.getHandlersToDisplayInternal(false, course, refresh, isGuest) as
|
||||
Promise<CoreCourseOptionsHandlerToDisplay[]>;
|
||||
}
|
||||
|
||||
|
@ -380,18 +373,14 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param course The course object.
|
||||
* @param refresh True if it should refresh the list.
|
||||
* @param isGuest Whether user is using an ACCESS_GUEST enrolment method.
|
||||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with array of handlers.
|
||||
*/
|
||||
getMenuHandlersToDisplay(
|
||||
course: CoreCourseAnyCourseData,
|
||||
refresh = false,
|
||||
isGuest = false,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<CoreCourseOptionsMenuHandlerToDisplay[]> {
|
||||
return this.getHandlersToDisplayInternal(true, course, refresh, isGuest, navOptions, admOptions) as
|
||||
return this.getHandlersToDisplayInternal(true, course, refresh, isGuest) as
|
||||
Promise<CoreCourseOptionsMenuHandlerToDisplay[]>;
|
||||
}
|
||||
|
||||
|
@ -403,8 +392,6 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param course The course object.
|
||||
* @param refresh True if it should refresh the list.
|
||||
* @param isGuest Whether user is using an ACCESS_GUEST enrolment method.
|
||||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with array of handlers.
|
||||
*/
|
||||
protected async getHandlersToDisplayInternal(
|
||||
|
@ -412,36 +399,30 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
course: CoreCourseAnyCourseData,
|
||||
refresh = false,
|
||||
isGuest = false,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<CoreCourseOptionsHandlerToDisplay[] | CoreCourseOptionsMenuHandlerToDisplay[]> {
|
||||
|
||||
const courseWithOptions: CoreCourseAnyCourseDataWithOptions = course;
|
||||
const accessData = {
|
||||
type: isGuest ? CoreCourseProvider.ACCESS_GUEST : CoreCourseProvider.ACCESS_DEFAULT,
|
||||
type: isGuest ? CoreCourseAccessDataType.ACCESS_GUEST : CoreCourseAccessDataType.ACCESS_DEFAULT,
|
||||
};
|
||||
const handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] | CoreCourseOptionsMenuHandlerToDisplay[] = [];
|
||||
|
||||
if (navOptions) {
|
||||
courseWithOptions.navOptions = navOptions;
|
||||
}
|
||||
if (admOptions) {
|
||||
courseWithOptions.admOptions = admOptions;
|
||||
}
|
||||
|
||||
await this.loadCourseOptions(courseWithOptions, refresh);
|
||||
|
||||
// Call getHandlersForAccess to make sure the handlers have been loaded.
|
||||
await this.getHandlersForAccess(course.id, refresh, accessData, courseWithOptions.navOptions, courseWithOptions.admOptions);
|
||||
// Call updateHandlersForAccess to make sure the handlers have been loaded.
|
||||
await this.updateHandlersForAccess(
|
||||
course.id,
|
||||
refresh,
|
||||
accessData,
|
||||
courseWithOptions.navOptions,
|
||||
courseWithOptions.admOptions,
|
||||
);
|
||||
|
||||
const promises: Promise<void>[] = [];
|
||||
|
||||
let handlerList: CoreCourseOptionsMenuHandler[] | CoreCourseOptionsHandler[];
|
||||
if (menu) {
|
||||
handlerList = this.coursesHandlers[course.id].enabledMenuHandlers;
|
||||
} else {
|
||||
handlerList = this.coursesHandlers[course.id].enabledHandlers;
|
||||
}
|
||||
const handlerList = menu
|
||||
? this.coursesHandlers[course.id].enabledMenuHandlers
|
||||
: this.coursesHandlers[course.id].enabledHandlers;
|
||||
|
||||
handlerList.forEach((handler: CoreCourseOptionsMenuHandler | CoreCourseOptionsHandler) => {
|
||||
const getFunction = menu
|
||||
|
@ -461,8 +442,8 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
});
|
||||
|
||||
return;
|
||||
}).catch((err) => {
|
||||
this.logger.error('Error getting data for handler', handler.name, err);
|
||||
}).catch((error) => {
|
||||
this.logger.error(`Error getting data for handler ${handler.name}`, error);
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -477,17 +458,44 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
return handlersToDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the handlers for a course using a certain access type.
|
||||
*
|
||||
* @param courseId The course ID.
|
||||
* @param refresh True if it should refresh the list.
|
||||
* @param accessData Access type and data. Default, guest, ...
|
||||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with array of handlers.
|
||||
* @deprecated since 4.4.
|
||||
*/
|
||||
protected async hasHandlersForAccess(
|
||||
courseId: number,
|
||||
refresh: boolean,
|
||||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
await this.updateHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions);
|
||||
|
||||
const handlers = this.coursesHandlers[courseId].enabledHandlers;
|
||||
|
||||
return !!(handlers && handlers.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a course has any handler enabled for default access, using course object.
|
||||
*
|
||||
* @param course The course object.
|
||||
* @param refresh True if it should refresh the list.
|
||||
* @returns Promise resolved with boolean: true if it has handlers, false otherwise.
|
||||
* @deprecated since 4.4.
|
||||
*/
|
||||
async hasHandlersForCourse(course: CoreEnrolledCourseDataWithExtraInfoAndOptions, refresh = false): Promise<boolean> {
|
||||
async hasHandlersForCourse(course: CoreCourseAnyCourseDataWithOptions, refresh = false): Promise<boolean> {
|
||||
// Load course options if missing.
|
||||
await this.loadCourseOptions(course, refresh);
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
return this.hasHandlersForDefault(course.id, refresh, course.navOptions, course.admOptions);
|
||||
}
|
||||
|
||||
|
@ -499,6 +507,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with boolean: true if it has handlers, false otherwise.
|
||||
* @deprecated since 4.4.
|
||||
*/
|
||||
async hasHandlersForDefault(
|
||||
courseId: number,
|
||||
|
@ -506,14 +515,14 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
// Default access.
|
||||
const accessData = {
|
||||
type: CoreCourseProvider.ACCESS_DEFAULT,
|
||||
};
|
||||
|
||||
const handlers = await this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions);
|
||||
|
||||
return !!(handlers && handlers.length);
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
return await this.hasHandlersForAccess(
|
||||
courseId,
|
||||
refresh,
|
||||
{ type: CoreCourseAccessDataType.ACCESS_DEFAULT },
|
||||
navOptions,
|
||||
admOptions,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -524,6 +533,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param navOptions Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Promise resolved with boolean: true if it has handlers, false otherwise.
|
||||
* @deprecated since 4.4.
|
||||
*/
|
||||
async hasHandlersForGuest(
|
||||
courseId: number,
|
||||
|
@ -531,14 +541,14 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
admOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
// Guest access.
|
||||
const accessData = {
|
||||
type: CoreCourseProvider.ACCESS_GUEST,
|
||||
};
|
||||
|
||||
const handlers = await this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions);
|
||||
|
||||
return !!(handlers && handlers.length);
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
return await this.hasHandlersForAccess(
|
||||
courseId,
|
||||
refresh,
|
||||
{ type: CoreCourseAccessDataType.ACCESS_GUEST },
|
||||
navOptions,
|
||||
admOptions,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -547,7 +557,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param courseId Course ID.
|
||||
* @returns Promise resolved when done.
|
||||
*/
|
||||
async invalidateCourseHandlers(courseId: number): Promise<void> {
|
||||
protected async invalidateCourseHandlers(courseId: number): Promise<void> {
|
||||
const promises: Promise<void>[] = [];
|
||||
const courseData = this.coursesHandlers[courseId];
|
||||
|
||||
|
@ -556,7 +566,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
}
|
||||
|
||||
courseData.enabledHandlers.forEach((handler) => {
|
||||
if (handler?.invalidateEnabledForCourse) {
|
||||
if (handler.invalidateEnabledForCourse) {
|
||||
promises.push(
|
||||
handler.invalidateEnabledForCourse(courseId, courseData.navOptions, courseData.admOptions),
|
||||
);
|
||||
|
@ -579,7 +589,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
return true;
|
||||
}
|
||||
|
||||
return time == this.lastUpdateHandlersForCoursesStart[courseId];
|
||||
return time === this.lastUpdateHandlersForCoursesStart[courseId];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -590,12 +600,13 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @returns Promise resolved when done.
|
||||
*/
|
||||
protected async loadCourseOptions(course: CoreCourseAnyCourseDataWithOptions, refresh = false): Promise<void> {
|
||||
if (course.navOptions === undefined || course.admOptions === undefined || refresh) {
|
||||
|
||||
const options = await CoreCourses.getCoursesAdminAndNavOptions([course.id]);
|
||||
course.navOptions = options.navOptions[course.id];
|
||||
course.admOptions = options.admOptions[course.id];
|
||||
if (!refresh && course.navOptions !== undefined && course.admOptions !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = await CoreCourses.getCoursesAdminAndNavOptions([course.id]);
|
||||
course.navOptions = options.navOptions[course.id];
|
||||
course.admOptions = options.admOptions[course.id];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -618,7 +629,7 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
* @param admOptions Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||
* @returns Resolved when updated.
|
||||
*/
|
||||
async updateHandlersForCourse(
|
||||
protected async updateHandlersForCourse(
|
||||
courseId: number,
|
||||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
|
@ -676,5 +687,5 @@ export class CoreCourseOptionsDelegateService extends CoreDelegate<CoreCourseOpt
|
|||
export const CoreCourseOptionsDelegate = makeSingleton(CoreCourseOptionsDelegateService);
|
||||
|
||||
export type CoreCourseAccess = {
|
||||
type: string; // Either CoreCourseProvider.ACCESS_GUEST or CoreCourseProvider.ACCESS_DEFAULT.
|
||||
type: CoreCourseAccessDataType;
|
||||
};
|
||||
|
|
|
@ -80,7 +80,7 @@ declare module '@singletons/events' {
|
|||
/**
|
||||
* Course Module completion status enumeration.
|
||||
*/
|
||||
export enum CoreCourseModuleCompletionStatus {
|
||||
export const enum CoreCourseModuleCompletionStatus {
|
||||
COMPLETION_INCOMPLETE = 0,
|
||||
COMPLETION_COMPLETE = 1,
|
||||
COMPLETION_COMPLETE_PASS = 2,
|
||||
|
@ -90,7 +90,7 @@ export enum CoreCourseModuleCompletionStatus {
|
|||
/**
|
||||
* @deprecated since 4.3 Not used anymore.
|
||||
*/
|
||||
export enum CoreCourseCompletionMode {
|
||||
export const enum CoreCourseCompletionMode {
|
||||
FULL = 'full',
|
||||
BASIC = 'basic',
|
||||
}
|
||||
|
@ -98,12 +98,20 @@ export enum CoreCourseCompletionMode {
|
|||
/**
|
||||
* Completion tracking valid values.
|
||||
*/
|
||||
export enum CoreCourseModuleCompletionTracking {
|
||||
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.
|
||||
*/
|
||||
|
@ -112,10 +120,17 @@ export class CoreCourseProvider {
|
|||
|
||||
static readonly ALL_SECTIONS_ID = -2;
|
||||
static readonly STEALTH_MODULES_SECTION_ID = -1;
|
||||
static readonly ACCESS_GUEST = 'courses_access_guest';
|
||||
static readonly ACCESS_DEFAULT = 'courses_access_default';
|
||||
static readonly ALL_COURSES_CLEARED = -1;
|
||||
|
||||
/**
|
||||
* @deprecated since 4.4 Not used anymore. Use CoreCourseAccessDataType instead.
|
||||
*/
|
||||
static readonly ACCESS_GUEST = CoreCourseAccessDataType.ACCESS_GUEST;
|
||||
/**
|
||||
* @deprecated since 4.4 Not used anymore. Use CoreCourseAccessDataType instead.
|
||||
*/
|
||||
static readonly ACCESS_DEFAULT = CoreCourseAccessDataType.ACCESS_DEFAULT;
|
||||
|
||||
static readonly COMPONENT = 'CoreCourse';
|
||||
|
||||
readonly CORE_MODULES = [
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
CoreCourseSearchedData,
|
||||
CoreCourseUserAdminOrNavOptionIndexed,
|
||||
} from '@features/courses/services/courses';
|
||||
import { CoreCourse, CoreCourseProvider } from '@features/course/services/course';
|
||||
import { CoreCourse, CoreCourseAccessDataType } from '@features/course/services/course';
|
||||
import {
|
||||
CoreGrades,
|
||||
CoreGradesGradeItem,
|
||||
|
@ -680,11 +680,11 @@ export class CoreGradesHelperProvider {
|
|||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): Promise<boolean> {
|
||||
if (accessData && accessData.type == CoreCourseProvider.ACCESS_GUEST) {
|
||||
if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) {
|
||||
return false; // Not enabled for guests.
|
||||
}
|
||||
|
||||
if (navOptions && navOptions.grades !== undefined) {
|
||||
if (navOptions?.grades !== undefined) {
|
||||
return navOptions.grades;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ export class CoreGradesCourseOptionHandlerService implements CoreCourseOptionsHa
|
|||
async invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise<void> {
|
||||
await CoreGrades.invalidateCourseGradesPermissionsData(courseId);
|
||||
|
||||
if (navOptions && navOptions.grades !== undefined) {
|
||||
if (navOptions?.grades !== undefined) {
|
||||
// No need to invalidate user courses.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export class CoreGradesCourseParticipantsOptionHandlerService implements CoreCou
|
|||
async invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise<void> {
|
||||
await CoreGrades.invalidateCourseGradesPermissionsData(courseId);
|
||||
|
||||
if (navOptions && navOptions.grades !== undefined) {
|
||||
if (navOptions?.grades !== undefined) {
|
||||
// No need to invalidate user courses.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCourseProvider } from '@features/course/services/course';
|
||||
import { CoreCourseAccessDataType } from '@features/course/services/course';
|
||||
import {
|
||||
CoreCourseAccess,
|
||||
CoreCourseOptionsHandler,
|
||||
|
@ -37,7 +37,7 @@ export class CoreUserCourseOptionHandlerService implements CoreCourseOptionsHand
|
|||
* @inheritdoc
|
||||
*/
|
||||
invalidateEnabledForCourse(courseId: number, navOptions?: CoreCourseUserAdminOrNavOptionIndexed): Promise<void> {
|
||||
if (navOptions && navOptions.participants !== undefined) {
|
||||
if (navOptions?.participants !== undefined) {
|
||||
// No need to invalidate anything.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ export class CoreUserCourseOptionHandlerService implements CoreCourseOptionsHand
|
|||
accessData: CoreCourseAccess,
|
||||
navOptions?: CoreCourseUserAdminOrNavOptionIndexed,
|
||||
): boolean | Promise<boolean> {
|
||||
if (accessData && accessData.type == CoreCourseProvider.ACCESS_GUEST) {
|
||||
if (accessData && accessData.type === CoreCourseAccessDataType.ACCESS_GUEST) {
|
||||
return false; // Not enabled for guests.
|
||||
}
|
||||
|
||||
if (navOptions && navOptions.participants !== undefined) {
|
||||
if (navOptions?.participants !== undefined) {
|
||||
return navOptions.participants;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue