MOBILE-2324 courses: Remove course options from course preview
parent
a0312278d8
commit
a856b5c90e
|
@ -122,11 +122,15 @@ export class CoreCourseSectionPage implements OnDestroy {
|
|||
*/
|
||||
protected loadData(refresh?: boolean): Promise<any> {
|
||||
// First of all, get the course because the data might have changed.
|
||||
return this.coursesProvider.getUserCourse(this.course.id).then((course) => {
|
||||
return this.coursesProvider.getUserCourse(this.course.id).catch(() => {
|
||||
// Error getting the course, probably guest access.
|
||||
}).then((course) => {
|
||||
const promises = [];
|
||||
let promise;
|
||||
|
||||
this.course = course;
|
||||
if (course) {
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
// Get the completion status.
|
||||
if (this.course.enablecompletion === false) {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<core-loading [hideUntil]="dataLoaded">
|
||||
|
||||
<ion-list *ngIf="course">
|
||||
<a ion-item text-wrap (click)="openCourse()" [title]="course.fullname" [attr.detail-none]="!handlersShouldBeShown">
|
||||
<a ion-item text-wrap (click)="openCourse()" [title]="course.fullname" [attr.detail-none]="!canAccessCourse">
|
||||
<ion-icon name="ionic" item-start></ion-icon>
|
||||
<h2><core-format-text [text]="course.fullname"></core-format-text></h2>
|
||||
<p *ngIf="course.categoryname">{{course.categoryname}}</p>
|
||||
|
@ -41,24 +41,15 @@
|
|||
<ion-item *ngIf="!isEnrolled && !selfEnrolInstances.length && !paypalEnabled">
|
||||
<p>{{ 'core.courses.notenrollable' | translate }}</p>
|
||||
</ion-item>
|
||||
<a ion-item *ngIf="handlersShouldBeShown" (click)="prefetchCourse()" detail-none>
|
||||
<a ion-item *ngIf="canAccessCourse" (click)="prefetchCourse()" detail-none>
|
||||
<ion-icon *ngIf="prefetchCourseData.prefetchCourseIcon != 'spinner'" [name]="prefetchCourseData.prefetchCourseIcon" item-start></ion-icon>
|
||||
<ion-spinner *ngIf="prefetchCourseData.prefetchCourseIcon == 'spinner'" item-start></ion-spinner>
|
||||
<h2>{{ 'core.course.downloadcourse' | translate }}</h2>
|
||||
</a>
|
||||
<a ion-item (click)="openCourse()" [title]="course.fullname" *ngIf="handlersShouldBeShown">
|
||||
<a ion-item (click)="openCourse()" [title]="course.fullname" *ngIf="canAccessCourse">
|
||||
<ion-icon name="briefcase" item-start></ion-icon>
|
||||
<h2>{{ 'core.course.contents' | translate }}</h2>
|
||||
</a>
|
||||
<ng-container *ngIf="handlersShouldBeShown && course._handlers && course._handlers.length">
|
||||
<a ion-item text-wrap *ngFor="let handler of course._handlers" class="core-courses-handler {{handler.data.class}}" (click)="handler.data.action(course)" [title]="handler.data.title | translate">
|
||||
<ion-icon [name]="handler.data.icon" item-start></ion-icon>
|
||||
<h2>{{ handler.data.title | translate }}</h2>
|
||||
</a>
|
||||
</ng-container>
|
||||
<ion-item class="core-loading-course-handlers" text-center *ngIf="handlersShouldBeShown && !handlersLoaded">
|
||||
<ion-spinner></ion-spinner>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</core-loading>
|
||||
</ion-content>
|
||||
|
|
|
@ -36,8 +36,7 @@ import { CoreCourseHelperProvider } from '../../../course/providers/helper';
|
|||
export class CoreCoursesCoursePreviewPage implements OnDestroy {
|
||||
course: any;
|
||||
isEnrolled: boolean;
|
||||
handlersShouldBeShown = true;
|
||||
handlersLoaded: boolean;
|
||||
canAccessCourse = true;
|
||||
component = 'CoreCoursesCoursePreview';
|
||||
selfEnrolInstances: any[] = [];
|
||||
paypalEnabled: boolean;
|
||||
|
@ -206,19 +205,17 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
|
|||
// Success retrieving the course, we can assume the user has permissions to view it.
|
||||
this.course.fullname = course.fullname || this.course.fullname;
|
||||
this.course.summary = course.summary || this.course.summary;
|
||||
|
||||
return this.loadCourseHandlers(refresh, false);
|
||||
this.canAccessCourse = true;
|
||||
}).catch(() => {
|
||||
// The user is not an admin/manager. Check if we can provide guest access to the course.
|
||||
return this.canAccessAsGuest().then((passwordRequired) => {
|
||||
if (!passwordRequired) {
|
||||
return this.loadCourseHandlers(refresh, true);
|
||||
this.canAccessCourse = true;
|
||||
} else {
|
||||
return Promise.reject(null);
|
||||
this.canAccessCourse = false;
|
||||
}
|
||||
}).catch(() => {
|
||||
this.course._handlers = [];
|
||||
this.handlersShouldBeShown = false;
|
||||
this.canAccessCourse = false;
|
||||
});
|
||||
});
|
||||
}).finally(() => {
|
||||
|
@ -226,25 +223,11 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load course nav handlers.
|
||||
*
|
||||
* @param {boolean} refresh Whether the user is refreshing the data.
|
||||
* @param {boolean} guest Whether it's guest access.
|
||||
*/
|
||||
protected loadCourseHandlers(refresh: boolean, guest: boolean): Promise<any> {
|
||||
return this.courseOptionsDelegate.getHandlersToDisplay(this.course, refresh, guest, true).then((handlers) => {
|
||||
this.course._handlers = handlers;
|
||||
this.handlersShouldBeShown = true;
|
||||
this.handlersLoaded = true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the course.
|
||||
*/
|
||||
openCourse(): void {
|
||||
if (!this.handlersShouldBeShown) {
|
||||
if (!this.canAccessCourse) {
|
||||
// Course cannot be opened.
|
||||
return;
|
||||
}
|
||||
|
@ -435,8 +418,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
|
|||
* Prefetch the course.
|
||||
*/
|
||||
prefetchCourse(): void {
|
||||
this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course, undefined, this.course._handlers)
|
||||
.catch((error) => {
|
||||
this.courseHelper.confirmAndPrefetchCourse(this.prefetchCourseData, this.course).catch((error) => {
|
||||
if (!this.pageDestroyed) {
|
||||
this.domUtils.showErrorModalDefault(error, 'core.course.errordownloadingcourse', true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue