forked from CIT/Vmeda.Online
		
	MOBILE-3970 course: Move courseMenuHandlers to course summary
This commit is contained in:
		
							parent
							
								
									449727d2c2
								
							
						
					
					
						commit
						53f986a26b
					
				@ -1,9 +1,4 @@
 | 
			
		||||
<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>
 | 
			
		||||
<ion-content>
 | 
			
		||||
    <ion-refresher slot="fixed" [disabled]="!dataLoaded || !displayRefresher" (ionRefresh)="doRefresh($event.target)">
 | 
			
		||||
 | 
			
		||||
@ -29,10 +29,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 {
 | 
			
		||||
    CoreCourseOptionsDelegate,
 | 
			
		||||
    CoreCourseOptionsMenuHandlerToDisplay,
 | 
			
		||||
} from '@features/course/services/course-options-delegate';
 | 
			
		||||
import { CoreCourseOptionsMenuHandlerToDisplay } from '@features/course/services/course-options-delegate';
 | 
			
		||||
import { CoreCourseSync, CoreCourseSyncProvider } from '@features/course/services/sync';
 | 
			
		||||
import { CoreCourseFormatComponent } from '../../components/format/format';
 | 
			
		||||
import {
 | 
			
		||||
@ -69,7 +66,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
 | 
			
		||||
    protected syncObserver?: CoreEventObserver;
 | 
			
		||||
    protected isDestroyed = false;
 | 
			
		||||
    protected modulesHaveCompletion = false;
 | 
			
		||||
    protected isGuest = false;
 | 
			
		||||
    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.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber');
 | 
			
		||||
        this.moduleId = CoreNavigator.getRouteNumberParam('moduleId');
 | 
			
		||||
        this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest');
 | 
			
		||||
 | 
			
		||||
        this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => {
 | 
			
		||||
            if (this.modulesHaveCompletion) {
 | 
			
		||||
@ -184,7 +179,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
 | 
			
		||||
        try {
 | 
			
		||||
            await Promise.all([
 | 
			
		||||
                this.loadSections(refresh),
 | 
			
		||||
                this.loadMenuHandlers(refresh),
 | 
			
		||||
                this.loadCourseFormatOptions(),
 | 
			
		||||
            ]);
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
@ -248,16 +242,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
 | 
			
		||||
        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.
 | 
			
		||||
     *
 | 
			
		||||
@ -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.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@
 | 
			
		||||
        <div *ngIf="courseImageUrl" class="core-course-thumb">
 | 
			
		||||
            <img [src]="courseImageUrl" core-external-content alt="" />
 | 
			
		||||
        </div>
 | 
			
		||||
        <div *ngIf="course">
 | 
			
		||||
        <ng-container *ngIf="course">
 | 
			
		||||
            <ion-item class="ion-text-wrap">
 | 
			
		||||
                <ion-label>
 | 
			
		||||
                    <p *ngIf="course.categoryname">
 | 
			
		||||
@ -94,13 +94,13 @@
 | 
			
		||||
                    </ng-container>
 | 
			
		||||
                </ion-label>
 | 
			
		||||
            </ion-item>
 | 
			
		||||
        </div>
 | 
			
		||||
        </ng-container>
 | 
			
		||||
    </core-loading>
 | 
			
		||||
</ion-content>
 | 
			
		||||
 | 
			
		||||
<ion-footer>
 | 
			
		||||
<ion-footer *ngIf="course && dataLoaded">
 | 
			
		||||
    <!-- Enrol -->
 | 
			
		||||
    <ng-container *ngIf="!isEnrolled">
 | 
			
		||||
    <ion-card *ngIf="!isEnrolled">
 | 
			
		||||
        <ion-item class="ion-text-wrap" *ngFor="let instance of selfEnrolInstances">
 | 
			
		||||
            <ion-label>
 | 
			
		||||
                <p class="item-heading">{{ instance.name }}</p>
 | 
			
		||||
@ -122,6 +122,14 @@
 | 
			
		||||
                <p class="item-heading">{{ 'core.courses.notenrollable' | translate }}</p>
 | 
			
		||||
            </ion-label>
 | 
			
		||||
        </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>
 | 
			
		||||
 | 
			
		||||
    <ion-button class="ion-margin" (click)="openCourse()" *ngIf="!avoidOpenCourse && canAccessCourse" expand="block">
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,10 @@ import {
 | 
			
		||||
    CoreCoursesProvider,
 | 
			
		||||
    CoreEnrolledCourseData,
 | 
			
		||||
} 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 { ModalController, NgZone, Platform, Translate } from '@singletons';
 | 
			
		||||
import { CoreCoursesSelfEnrolPasswordComponent } from '../../../courses/components/self-enrol-password/self-enrol-password';
 | 
			
		||||
@ -59,6 +62,8 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
 | 
			
		||||
    courseImageUrl?: string;
 | 
			
		||||
    progress?: number;
 | 
			
		||||
 | 
			
		||||
    courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = [];
 | 
			
		||||
 | 
			
		||||
    protected isGuestEnabled = false;
 | 
			
		||||
    protected useGuestAccess = false;
 | 
			
		||||
    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.
 | 
			
		||||
     *
 | 
			
		||||
     * @param refresh If it's refreshing content.
 | 
			
		||||
     */
 | 
			
		||||
    protected async getCourse(): Promise<void> {
 | 
			
		||||
    protected async getCourse(refresh = false): Promise<void> {
 | 
			
		||||
        // Get course enrolment methods.
 | 
			
		||||
        this.selfEnrolInstances = [];
 | 
			
		||||
 | 
			
		||||
@ -223,9 +230,26 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
 | 
			
		||||
            this.progress = this.course.progress;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        await this.loadMenuHandlers(refresh);
 | 
			
		||||
 | 
			
		||||
        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.
 | 
			
		||||
     *
 | 
			
		||||
@ -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.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user