commit
ebcbcb6e4c
|
@ -38,6 +38,7 @@ import { CoreCoursesHelper, CoreCourseWithImageAndColor } from '@features/course
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { CoreColors } from '@singletons/colors';
|
import { CoreColors } from '@singletons/colors';
|
||||||
import { CoreText } from '@singletons/text';
|
import { CoreText } from '@singletons/text';
|
||||||
|
import { CorePromisedValue } from '@classes/promised-value';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that shows the summary of a course including buttons to enrol and other available options.
|
* Page that shows the summary of a course including buttons to enrol and other available options.
|
||||||
|
@ -70,7 +71,8 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
|
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
|
||||||
|
|
||||||
protected useGuestAccess = false;
|
protected useGuestAccess = false;
|
||||||
protected guestInstanceId?: number;
|
protected guestInstanceId = new CorePromisedValue<number | undefined>();
|
||||||
|
protected courseData = new CorePromisedValue<CoreCourseSummaryData | undefined>();
|
||||||
protected waitStart = 0;
|
protected waitStart = 0;
|
||||||
protected enrolUrl = '';
|
protected enrolUrl = '';
|
||||||
protected pageDestroyed = false;
|
protected pageDestroyed = false;
|
||||||
|
@ -130,11 +132,12 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
* password is required for guest access.
|
* password is required for guest access.
|
||||||
*/
|
*/
|
||||||
protected async canAccessAsGuest(): Promise<boolean> {
|
protected async canAccessAsGuest(): Promise<boolean> {
|
||||||
if (this.guestInstanceId === undefined) {
|
const guestInstanceId = await this.guestInstanceId;
|
||||||
|
if (guestInstanceId === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = await CoreCourses.getCourseGuestEnrolmentInfo(this.guestInstanceId);
|
const info = await CoreCourses.getCourseGuestEnrolmentInfo(guestInstanceId);
|
||||||
|
|
||||||
// Guest access with password is not supported by the app.
|
// Guest access with password is not supported by the app.
|
||||||
return !!info.status && !info.passwordrequired;
|
return !!info.status && !info.passwordrequired;
|
||||||
|
@ -146,32 +149,70 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
* @param refresh If it's refreshing content.
|
* @param refresh If it's refreshing content.
|
||||||
*/
|
*/
|
||||||
protected async getCourse(refresh = false): Promise<void> {
|
protected async getCourse(refresh = false): Promise<void> {
|
||||||
// Get course enrolment methods.
|
|
||||||
this.selfEnrolInstances = [];
|
|
||||||
this.otherEnrolments = false;
|
this.otherEnrolments = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const enrolmentMethods = await CoreCourses.getCourseEnrolmentMethods(this.courseId);
|
await Promise.all([
|
||||||
this.guestInstanceId = undefined;
|
this.getEnrolmentMethods(),
|
||||||
|
this.getCourseData(),
|
||||||
enrolmentMethods.forEach((method) => {
|
this.loadCourseExtraData(),
|
||||||
if (!method.status) {
|
]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method.type === 'self') {
|
|
||||||
this.selfEnrolInstances.push(method);
|
|
||||||
} else if (method.type === 'guest') {
|
|
||||||
this.guestInstanceId = method.id;
|
|
||||||
} else {
|
|
||||||
// Other enrolments that comes from that WS should need user action.
|
|
||||||
this.otherEnrolments = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModalDefault(error, 'Error getting enrolment data');
|
CoreDomUtils.showErrorModalDefault(error, 'Error getting enrolment data');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.setCourseColor();
|
||||||
|
|
||||||
|
if (!this.course ||
|
||||||
|
!('progress' in this.course) ||
|
||||||
|
typeof this.course.progress !== 'number' ||
|
||||||
|
this.course.progress < 0 ||
|
||||||
|
this.course.completionusertracked === false
|
||||||
|
) {
|
||||||
|
this.progress = undefined;
|
||||||
|
} else {
|
||||||
|
this.progress = this.course.progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.loadMenuHandlers(refresh);
|
||||||
|
|
||||||
|
this.dataLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get course enrolment methods.
|
||||||
|
*/
|
||||||
|
protected async getEnrolmentMethods(): Promise<void> {
|
||||||
|
this.selfEnrolInstances = [];
|
||||||
|
this.guestInstanceId.reset();
|
||||||
|
|
||||||
|
const enrolmentMethods = await CoreCourses.getCourseEnrolmentMethods(this.courseId);
|
||||||
|
|
||||||
|
enrolmentMethods.forEach((method) => {
|
||||||
|
if (!method.status) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method.type === 'self') {
|
||||||
|
this.selfEnrolInstances.push(method);
|
||||||
|
} else if (method.type === 'guest') {
|
||||||
|
this.guestInstanceId.resolve(method.id);
|
||||||
|
} else {
|
||||||
|
// Other enrolments that comes from that WS should need user action.
|
||||||
|
this.otherEnrolments = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.guestInstanceId.isSettled()) {
|
||||||
|
// No guest instance found.
|
||||||
|
this.guestInstanceId.resolve(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get course data.
|
||||||
|
*/
|
||||||
|
protected async getCourseData(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// Check if user is enrolled in the course.
|
// Check if user is enrolled in the course.
|
||||||
try {
|
try {
|
||||||
|
@ -192,16 +233,26 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
this.useGuestAccess = this.canAccessCourse;
|
this.useGuestAccess = this.canAccessCourse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.courseData.resolve(this.course);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load some extra data for the course.
|
||||||
|
*/
|
||||||
|
protected async loadCourseExtraData(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const courseByField = await CoreCourses.getCourseByField('id', this.courseId);
|
const courseByField = await CoreCourses.getCourseByField('id', this.courseId);
|
||||||
if (this.course) {
|
const courseData = await this.courseData;
|
||||||
this.course.customfields = courseByField.customfields;
|
|
||||||
this.course.contacts = courseByField.contacts;
|
if (courseData) {
|
||||||
this.course.displayname = courseByField.displayname;
|
courseData.customfields = courseByField.customfields;
|
||||||
this.course.categoryname = courseByField.categoryname;
|
courseData.contacts = courseByField.contacts;
|
||||||
this.course.overviewfiles = courseByField.overviewfiles;
|
courseData.displayname = courseByField.displayname;
|
||||||
|
courseData.categoryname = courseByField.categoryname;
|
||||||
|
courseData.overviewfiles = courseByField.overviewfiles;
|
||||||
} else {
|
} else {
|
||||||
this.course = courseByField;
|
this.course = courseByField;
|
||||||
|
this.courseData.resolve(courseByField);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enrollmentmethods contains ALL enrolment methods including manual.
|
// enrollmentmethods contains ALL enrolment methods including manual.
|
||||||
|
@ -212,23 +263,6 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.setCourseColor();
|
|
||||||
|
|
||||||
if (!this.course ||
|
|
||||||
!('progress' in this.course) ||
|
|
||||||
typeof this.course.progress !== 'number' ||
|
|
||||||
this.course.progress < 0 ||
|
|
||||||
this.course.completionusertracked === false
|
|
||||||
) {
|
|
||||||
this.progress = undefined;
|
|
||||||
} else {
|
|
||||||
this.progress = this.course.progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.loadMenuHandlers(refresh);
|
|
||||||
|
|
||||||
this.dataLoaded = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,8 +409,8 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
|
||||||
promises.push(CoreCourses.invalidateCourseEnrolmentMethods(this.courseId));
|
promises.push(CoreCourses.invalidateCourseEnrolmentMethods(this.courseId));
|
||||||
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions(this.courseId));
|
promises.push(CoreCourseOptionsDelegate.clearAndInvalidateCoursesOptions(this.courseId));
|
||||||
promises.push(CoreCourses.invalidateCoursesByField('id', this.courseId));
|
promises.push(CoreCourses.invalidateCoursesByField('id', this.courseId));
|
||||||
if (this.guestInstanceId) {
|
if (this.guestInstanceId.value) {
|
||||||
promises.push(CoreCourses.invalidateCourseGuestEnrolmentInfo(this.guestInstanceId));
|
promises.push(CoreCourses.invalidateCourseGuestEnrolmentInfo(this.guestInstanceId.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises).finally(() => this.getCourse()).finally(() => {
|
await Promise.all(promises).finally(() => this.getCourse()).finally(() => {
|
||||||
|
|
|
@ -482,23 +482,17 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
||||||
* @return Promise resolved with the total size (0 if unknown)
|
* @return Promise resolved with the total size (0 if unknown)
|
||||||
*/
|
*/
|
||||||
async getModuleStoredSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> {
|
async getModuleStoredSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> {
|
||||||
let downloadedSize = await this.getModuleDownloadedSize(module, courseId);
|
|
||||||
|
|
||||||
if (isNaN(downloadedSize)) {
|
|
||||||
downloadedSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const site = CoreSites.getCurrentSite();
|
const site = CoreSites.getCurrentSite();
|
||||||
const handler = this.getPrefetchHandlerFor(module.modname);
|
const handler = this.getPrefetchHandlerFor(module.modname);
|
||||||
if (!handler || !site) {
|
|
||||||
// If there is no handler then we can't find out the component name.
|
|
||||||
// We can't work out the cached size, so just return downloaded size.
|
|
||||||
return downloadedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachedSize = await site.getComponentCacheSize(handler.component, module.id);
|
const [downloadedSize, cachedSize] = await Promise.all([
|
||||||
|
this.getModuleDownloadedSize(module, courseId),
|
||||||
|
handler && site ? site.getComponentCacheSize(handler.component, module.id) : 0,
|
||||||
|
]);
|
||||||
|
|
||||||
return cachedSize + downloadedSize;
|
const totalSize = cachedSize + downloadedSize;
|
||||||
|
|
||||||
|
return isNaN(totalSize) ? 0 : totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue