MOBILE-3970 course: Move courseMenuHandlers to course summary

main
Pau Ferrer Ocaña 2022-02-11 16:34:25 +01:00
parent 449727d2c2
commit 53f986a26b
4 changed files with 49 additions and 38 deletions

View File

@ -1,9 +1,4 @@
<core-navbar-buttons slot="end"> <core-navbar-buttons slot="end">
<core-context-menu>
<core-context-menu-item *ngFor="let item of courseMenuHandlers" [priority]="item.priority" (action)="openMenuItem(item)"
[content]="item.data.title | translate" [iconAction]="item.data.icon" [class]="item.data.class">
</core-context-menu-item>
</core-context-menu>
</core-navbar-buttons> </core-navbar-buttons>
<ion-content> <ion-content>
<ion-refresher slot="fixed" [disabled]="!dataLoaded || !displayRefresher" (ionRefresh)="doRefresh($event.target)"> <ion-refresher slot="fixed" [disabled]="!dataLoaded || !displayRefresher" (ionRefresh)="doRefresh($event.target)">

View File

@ -29,10 +29,7 @@ import {
} from '@features/course/services/course-helper'; } from '@features/course/services/course-helper';
import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { import { CoreCourseOptionsMenuHandlerToDisplay } from '@features/course/services/course-options-delegate';
CoreCourseOptionsDelegate,
CoreCourseOptionsMenuHandlerToDisplay,
} from '@features/course/services/course-options-delegate';
import { CoreCourseSync, CoreCourseSyncProvider } from '@features/course/services/sync'; import { CoreCourseSync, CoreCourseSyncProvider } from '@features/course/services/sync';
import { CoreCourseFormatComponent } from '../../components/format/format'; import { CoreCourseFormatComponent } from '../../components/format/format';
import { import {
@ -69,7 +66,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
protected syncObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver;
protected isDestroyed = false; protected isDestroyed = false;
protected modulesHaveCompletion = false; protected modulesHaveCompletion = false;
protected isGuest = false;
protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time. protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time.
/** /**
@ -89,7 +85,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
this.sectionId = CoreNavigator.getRouteNumberParam('sectionId'); this.sectionId = CoreNavigator.getRouteNumberParam('sectionId');
this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber'); this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber');
this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); this.moduleId = CoreNavigator.getRouteNumberParam('moduleId');
this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest');
this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => {
if (this.modulesHaveCompletion) { if (this.modulesHaveCompletion) {
@ -184,7 +179,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
try { try {
await Promise.all([ await Promise.all([
this.loadSections(refresh), this.loadSections(refresh),
this.loadMenuHandlers(refresh),
this.loadCourseFormatOptions(), this.loadCourseFormatOptions(),
]); ]);
} catch (error) { } catch (error) {
@ -248,16 +242,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
this.displayRefresher = CoreCourseFormatDelegate.displayRefresher(this.course, this.sections); this.displayRefresher = CoreCourseFormatDelegate.displayRefresher(this.course, this.sections);
} }
/**
* Load the course menu handlers.
*
* @param refresh If it's refreshing content.
* @return Promise resolved when done.
*/
protected async loadMenuHandlers(refresh?: boolean): Promise<void> {
this.courseMenuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(this.course, refresh, this.isGuest);
}
/** /**
* Load course format options if needed. * Load course format options if needed.
* *
@ -379,16 +363,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
} }
} }
/**
* Opens a menu item registered to the delegate.
*
* @param item Item to open
*/
openMenuItem(item: CoreCourseOptionsMenuHandlerToDisplay): void {
const params = Object.assign({ course: this.course }, item.data.pageParams);
CoreNavigator.navigateToSitePath(item.data.page, { params });
}
/** /**
* Page destroyed. * Page destroyed.
*/ */

View File

@ -23,7 +23,7 @@
<div *ngIf="courseImageUrl" class="core-course-thumb"> <div *ngIf="courseImageUrl" class="core-course-thumb">
<img [src]="courseImageUrl" core-external-content alt="" /> <img [src]="courseImageUrl" core-external-content alt="" />
</div> </div>
<div *ngIf="course"> <ng-container *ngIf="course">
<ion-item class="ion-text-wrap"> <ion-item class="ion-text-wrap">
<ion-label> <ion-label>
<p *ngIf="course.categoryname"> <p *ngIf="course.categoryname">
@ -94,13 +94,13 @@
</ng-container> </ng-container>
</ion-label> </ion-label>
</ion-item> </ion-item>
</div> </ng-container>
</core-loading> </core-loading>
</ion-content> </ion-content>
<ion-footer> <ion-footer *ngIf="course && dataLoaded">
<!-- Enrol --> <!-- Enrol -->
<ng-container *ngIf="!isEnrolled"> <ion-card *ngIf="!isEnrolled">
<ion-item class="ion-text-wrap" *ngFor="let instance of selfEnrolInstances"> <ion-item class="ion-text-wrap" *ngFor="let instance of selfEnrolInstances">
<ion-label> <ion-label>
<p class="item-heading">{{ instance.name }}</p> <p class="item-heading">{{ instance.name }}</p>
@ -122,6 +122,14 @@
<p class="item-heading">{{ 'core.courses.notenrollable' | translate }}</p> <p class="item-heading">{{ 'core.courses.notenrollable' | translate }}</p>
</ion-label> </ion-label>
</ion-item> </ion-item>
</ion-card>
<ng-container *ngIf="canAccessCourse">
<ion-button class="ion-margin" *ngFor="let item of courseMenuHandlers" (click)="openMenuItem(item)" [class]="item.data.class"
expand="block">
<ion-icon *ngIf="item.data.icon" [name]="item.data.icon" slot="start" aria-hidden="true"></ion-icon>
<ion-label>{{item.data.title | translate }}</ion-label>
</ion-button>
</ng-container> </ng-container>
<ion-button class="ion-margin" (click)="openCourse()" *ngIf="!avoidOpenCourse && canAccessCourse" expand="block"> <ion-button class="ion-margin" (click)="openCourse()" *ngIf="!avoidOpenCourse && canAccessCourse" expand="block">

View File

@ -26,7 +26,10 @@ import {
CoreCoursesProvider, CoreCoursesProvider,
CoreEnrolledCourseData, CoreEnrolledCourseData,
} from '@features/courses/services/courses'; } from '@features/courses/services/courses';
import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; import {
CoreCourseOptionsDelegate,
CoreCourseOptionsMenuHandlerToDisplay,
} from '@features/course/services/course-options-delegate';
import { CoreCourseHelper } from '@features/course/services/course-helper'; import { CoreCourseHelper } from '@features/course/services/course-helper';
import { ModalController, NgZone, Platform, Translate } from '@singletons'; import { ModalController, NgZone, Platform, Translate } from '@singletons';
import { CoreCoursesSelfEnrolPasswordComponent } from '../../../courses/components/self-enrol-password/self-enrol-password'; import { CoreCoursesSelfEnrolPasswordComponent } from '../../../courses/components/self-enrol-password/self-enrol-password';
@ -59,6 +62,8 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
courseImageUrl?: string; courseImageUrl?: string;
progress?: number; progress?: number;
courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
protected isGuestEnabled = false; protected isGuestEnabled = false;
protected useGuestAccess = false; protected useGuestAccess = false;
protected guestInstanceId?: number; protected guestInstanceId?: number;
@ -145,8 +150,10 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
/** /**
* Convenience function to get course. We use this to determine if a user can see the course or not. * Convenience function to get course. We use this to determine if a user can see the course or not.
*
* @param refresh If it's refreshing content.
*/ */
protected async getCourse(): Promise<void> { protected async getCourse(refresh = false): Promise<void> {
// Get course enrolment methods. // Get course enrolment methods.
this.selfEnrolInstances = []; this.selfEnrolInstances = [];
@ -223,9 +230,26 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
this.progress = this.course.progress; this.progress = this.course.progress;
} }
await this.loadMenuHandlers(refresh);
this.dataLoaded = true; this.dataLoaded = true;
} }
/**
* Load the course menu handlers.
*
* @param refresh If it's refreshing content.
* @return Promise resolved when done.
*/
protected async loadMenuHandlers(refresh?: boolean): Promise<void> {
if (!this.course) {
return;
}
this.courseMenuHandlers =
await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(this.course, refresh, this.useGuestAccess);
}
/** /**
* Open the course. * Open the course.
* *
@ -399,6 +423,16 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
} }
} }
/**
* Opens a menu item registered to the delegate.
*
* @param item Item to open
*/
openMenuItem(item: CoreCourseOptionsMenuHandlerToDisplay): void {
const params = Object.assign({ course: this.course }, item.data.pageParams);
CoreNavigator.navigateToSitePath(item.data.page, { params });
}
/** /**
* Close the modal. * Close the modal.
*/ */