forked from CIT/Vmeda.Online
		
	Merge pull request #2846 from NoelDeMartin/MOBILE-3320
MOBILE-3320: Fix course and feedback, add object helper
This commit is contained in:
		
						commit
						51c1a7ebbf
					
				@ -44,7 +44,7 @@ const mobileRoutes: Routes = [
 | 
			
		||||
        component: AddonModFeedbackRespondentsPage,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        path: ':courseId/:cmId/attempt/:attemptId',
 | 
			
		||||
        path: ':courseId/:cmId/respondents/attempt/:attemptId',
 | 
			
		||||
        loadChildren: () => import('./pages/attempt/attempt.module').then(m => m.AddonModFeedbackAttemptPageModule),
 | 
			
		||||
    },
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
@ -477,7 +477,12 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
 | 
			
		||||
     * @param status Status to show.
 | 
			
		||||
     */
 | 
			
		||||
    protected updateCourseStatus(status: string): void {
 | 
			
		||||
        this.prefetchCourseData = CoreCourseHelper.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
 | 
			
		||||
        this.prefetchCourseData.status = statusData.status;
 | 
			
		||||
        this.prefetchCourseData.icon = statusData.icon;
 | 
			
		||||
        this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
 | 
			
		||||
        this.prefetchCourseData.loading = statusData.loading;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -402,7 +402,12 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy {
 | 
			
		||||
     * @param status Status to show.
 | 
			
		||||
     */
 | 
			
		||||
    protected updateCourseStatus(status: string): void {
 | 
			
		||||
        this.prefetchCourseData = CoreCourseHelper.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
 | 
			
		||||
        this.prefetchCourseData.status = statusData.status;
 | 
			
		||||
        this.prefetchCourseData.icon = statusData.icon;
 | 
			
		||||
        this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
 | 
			
		||||
        this.prefetchCourseData.loading = statusData.loading;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -1163,7 +1163,7 @@ export class CoreCourseHelperProvider {
 | 
			
		||||
 | 
			
		||||
        const status = await this.determineCoursesStatus(courses);
 | 
			
		||||
 | 
			
		||||
        prefetch = this.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        prefetch = this.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
 | 
			
		||||
        if (prefetch.loading) {
 | 
			
		||||
            // It seems all courses are being downloaded, show a download button instead.
 | 
			
		||||
@ -1298,16 +1298,16 @@ export class CoreCourseHelperProvider {
 | 
			
		||||
    async getCourseStatusIconAndTitle(courseId: number, siteId?: string): Promise<CorePrefetchStatusInfo> {
 | 
			
		||||
        const status = await CoreCourse.getCourseStatus(courseId, siteId);
 | 
			
		||||
 | 
			
		||||
        return this.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        return this.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a course status icon and the langkey to use as a title from status.
 | 
			
		||||
     *
 | 
			
		||||
     * @param status Course status.
 | 
			
		||||
     * @return Title and icon name.
 | 
			
		||||
     * @return Prefetch status info.
 | 
			
		||||
     */
 | 
			
		||||
    getCourseStatusIconAndTitleFromStatus(status: string): CorePrefetchStatusInfo {
 | 
			
		||||
    getCoursePrefetchStatusInfo(status: string): CorePrefetchStatusInfo {
 | 
			
		||||
        const prefetchStatus: CorePrefetchStatusInfo = {
 | 
			
		||||
            status: status,
 | 
			
		||||
            icon: this.getPrefetchStatusIcon(status, false),
 | 
			
		||||
 | 
			
		||||
@ -49,6 +49,11 @@
 | 
			
		||||
            <ion-spinner *ngIf="(downloadCourseEnabled && prefetchCourseData.icon == 'spinner') || showSpinner"
 | 
			
		||||
                [attr.aria-label]="'core.loading' | translate"></ion-spinner>
 | 
			
		||||
 | 
			
		||||
            <!-- Downloaded icon. -->
 | 
			
		||||
            <ion-icon *ngIf="downloadCourseEnabled && prefetchCourseData.downloadSucceeded && !showSpinner"
 | 
			
		||||
                class="core-icon-downloaded" name="cloud-done" color="success" role="status"
 | 
			
		||||
                [attr.aria-label]="'core.downloaded' | translate"></ion-icon>
 | 
			
		||||
 | 
			
		||||
            <!-- Options menu. -->
 | 
			
		||||
            <ion-button fill="clear" color="dark" (click)="showCourseOptionsMenu($event)" *ngIf="!showSpinner"
 | 
			
		||||
                [attr.aria-label]="('core.displayoptions' | translate)">
 | 
			
		||||
 | 
			
		||||
@ -107,7 +107,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
 | 
			
		||||
        // Determine course prefetch icon.
 | 
			
		||||
        const status = await CoreCourse.getCourseStatus(this.course.id);
 | 
			
		||||
 | 
			
		||||
        this.prefetchCourseData = CoreCourseHelper.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        this.prefetchCourseData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
        this.courseStatus = status;
 | 
			
		||||
 | 
			
		||||
        if (this.prefetchCourseData.loading) {
 | 
			
		||||
@ -184,9 +184,13 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
 | 
			
		||||
     * @param status Status to show.
 | 
			
		||||
     */
 | 
			
		||||
    protected updateCourseStatus(status: string): void {
 | 
			
		||||
        this.prefetchCourseData = CoreCourseHelper.getCourseStatusIconAndTitleFromStatus(status);
 | 
			
		||||
        const statusData = CoreCourseHelper.getCoursePrefetchStatusInfo(status);
 | 
			
		||||
 | 
			
		||||
        this.courseStatus = status;
 | 
			
		||||
        this.prefetchCourseData.status = statusData.status;
 | 
			
		||||
        this.prefetchCourseData.icon = statusData.icon;
 | 
			
		||||
        this.prefetchCourseData.statusTranslatable = statusData.statusTranslatable;
 | 
			
		||||
        this.prefetchCourseData.loading = statusData.loading;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,10 @@ export type CoreObjectWithoutEmpty<T> = {
 | 
			
		||||
    [k in keyof T]: T[k] extends undefined | null ? never : T[k];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export type CoreObjectWithoutUndefined<T> = {
 | 
			
		||||
    [k in keyof T]: T[k] extends undefined ? never : T[k];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Singleton with helper functions for objects.
 | 
			
		||||
 */
 | 
			
		||||
@ -79,4 +83,24 @@ export class CoreObject {
 | 
			
		||||
        return cleanObj as CoreObjectWithoutEmpty<T>;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new object without undefined values.
 | 
			
		||||
     *
 | 
			
		||||
     * @param obj Objet.
 | 
			
		||||
     * @return New object without undefined values.
 | 
			
		||||
     */
 | 
			
		||||
    static withoutUndefined<T>(obj: T): CoreObjectWithoutUndefined<T> {
 | 
			
		||||
        const cleanObj = {};
 | 
			
		||||
 | 
			
		||||
        for (const [key, value] of Object.entries(obj)) {
 | 
			
		||||
            if (value === undefined) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            cleanObj[key] = value;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return cleanObj as CoreObjectWithoutUndefined<T>;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user