forked from CIT/Vmeda.Online
		
	MOBILE-3320 core: Fix grades link handler
This commit is contained in:
		
							parent
							
								
									f7e531c3d0
								
							
						
					
					
						commit
						d10e9f574a
					
				@ -27,6 +27,9 @@ function buildRoutes(injector: Injector): Routes {
 | 
			
		||||
        {
 | 
			
		||||
            path: '',
 | 
			
		||||
            component: CoreCourseIndexPage,
 | 
			
		||||
            data: {
 | 
			
		||||
                isCourseIndex: true,
 | 
			
		||||
            },
 | 
			
		||||
            children: routes.children,
 | 
			
		||||
        },
 | 
			
		||||
        ...routes.siblings,
 | 
			
		||||
 | 
			
		||||
@ -71,7 +71,7 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy {
 | 
			
		||||
                const index = this.tabs.findIndex((tab) => tab.name == data.name);
 | 
			
		||||
 | 
			
		||||
                if (index >= 0) {
 | 
			
		||||
                    this.tabsComponent?.selectByIndex(index + 1);
 | 
			
		||||
                    this.tabsComponent?.selectByIndex(index);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
@ -129,11 +129,9 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy {
 | 
			
		||||
        // Load the course handlers.
 | 
			
		||||
        const handlers = await CoreCourseOptionsDelegate.getHandlersToDisplay(this.course!, false, false);
 | 
			
		||||
 | 
			
		||||
        this.tabs = [...this.tabs, ...handlers.map(handler => handler.data)];
 | 
			
		||||
 | 
			
		||||
        let tabToLoad: number | undefined;
 | 
			
		||||
 | 
			
		||||
        // Add the courseId to the handler component data.
 | 
			
		||||
        // Create the full path.
 | 
			
		||||
        handlers.forEach((handler, index) => {
 | 
			
		||||
            handler.data.page = CoreTextUtils.concatenatePaths(this.currentPagePath, handler.data.page);
 | 
			
		||||
            handler.data.pageParams = handler.data.pageParams || {};
 | 
			
		||||
@ -144,6 +142,11 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy {
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        this.tabs = [...this.tabs, ...handlers.map(handler => ({
 | 
			
		||||
            ...handler.data,
 | 
			
		||||
            name: handler.name,
 | 
			
		||||
        }))];
 | 
			
		||||
 | 
			
		||||
        // Select the tab if needed.
 | 
			
		||||
        this.firstTabName = undefined;
 | 
			
		||||
        if (tabToLoad) {
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ import { CoreCourseLogCronHandler } from './handlers/log-cron';
 | 
			
		||||
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
 | 
			
		||||
import { CoreCourseAutoSyncData, CoreCourseSyncProvider } from './sync';
 | 
			
		||||
import { CoreTagItem } from '@features/tag/services/tag';
 | 
			
		||||
import { CoreNavigator } from '@services/navigator';
 | 
			
		||||
 | 
			
		||||
const ROOT_CACHE_KEY = 'mmCourse:';
 | 
			
		||||
 | 
			
		||||
@ -176,10 +177,14 @@ export class CoreCourseProvider {
 | 
			
		||||
     * @param courseId Course ID.
 | 
			
		||||
     * @return Whether the current view is a certain course.
 | 
			
		||||
     */
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
			
		||||
    currentViewIsCourse(courseId: number): boolean {
 | 
			
		||||
        // @todo implement
 | 
			
		||||
        return false;
 | 
			
		||||
        const route = CoreNavigator.getCurrentRoute({ routeData: { isCourseIndex: true } });
 | 
			
		||||
 | 
			
		||||
        if (!route) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Number(route.snapshot.params.courseId) == courseId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -34,6 +34,7 @@ import { CoreDomUtils } from '@services/utils/dom';
 | 
			
		||||
import { CoreNavigator } from '@services/navigator';
 | 
			
		||||
import { makeSingleton, Translate } from '@singletons';
 | 
			
		||||
import { CoreError } from '@classes/errors/error';
 | 
			
		||||
import { CoreCourseHelper } from '@features/course/services/course-helper';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Service that provides some features regarding grades information.
 | 
			
		||||
@ -458,14 +459,13 @@ export class CoreGradesHelperProvider {
 | 
			
		||||
        siteId?: string,
 | 
			
		||||
    ): Promise<void> {
 | 
			
		||||
        const modal = await CoreDomUtils.showModalLoading();
 | 
			
		||||
        let currentUserId: number;
 | 
			
		||||
 | 
			
		||||
        const site = await CoreSites.getSite(siteId);
 | 
			
		||||
 | 
			
		||||
        siteId = site.id;
 | 
			
		||||
        const currentUserId = site.getUserId();
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            const site = await CoreSites.getSite(siteId);
 | 
			
		||||
 | 
			
		||||
            siteId = site.id;
 | 
			
		||||
            currentUserId = site.getUserId();
 | 
			
		||||
 | 
			
		||||
            if (!moduleId) {
 | 
			
		||||
                throw new CoreError('Invalid moduleId');
 | 
			
		||||
            }
 | 
			
		||||
@ -477,27 +477,27 @@ export class CoreGradesHelperProvider {
 | 
			
		||||
                throw new CoreError('No grades found.');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Can get grades. Do it.
 | 
			
		||||
            const items = await CoreGrades.getGradeItems(courseId, userId, undefined, siteId);
 | 
			
		||||
 | 
			
		||||
            // Find the item of the module.
 | 
			
		||||
            const item = Array.isArray(items) && items.find((item) => moduleId == item.cmid);
 | 
			
		||||
 | 
			
		||||
            if (!item) {
 | 
			
		||||
                throw new CoreError('Grade item not found.');
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Open the item directly.
 | 
			
		||||
            const gradeId = item.id;
 | 
			
		||||
 | 
			
		||||
            await CoreUtils.ignoreErrors(
 | 
			
		||||
                CoreNavigator.navigateToSitePath(`/grades/${courseId}/${gradeId}`, {
 | 
			
		||||
                    siteId,
 | 
			
		||||
                    params: { userId },
 | 
			
		||||
                }),
 | 
			
		||||
            );
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            try {
 | 
			
		||||
                // Can get grades. Do it.
 | 
			
		||||
                const items = await CoreGrades.getGradeItems(courseId, userId, undefined, siteId);
 | 
			
		||||
 | 
			
		||||
                // Find the item of the module.
 | 
			
		||||
                const item = Array.isArray(items) && items.find((item) => moduleId == item.cmid);
 | 
			
		||||
 | 
			
		||||
                if (!item) {
 | 
			
		||||
                    throw new CoreError('Grade item not found.');
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Open the item directly.
 | 
			
		||||
                const gradeId = item.id;
 | 
			
		||||
 | 
			
		||||
                await CoreUtils.ignoreErrors(
 | 
			
		||||
                    CoreNavigator.navigateToSitePath(`/grades/${courseId}/${gradeId}`, {
 | 
			
		||||
                        siteId,
 | 
			
		||||
                        params: { userId },
 | 
			
		||||
                    }),
 | 
			
		||||
                );
 | 
			
		||||
            } catch (error) {
 | 
			
		||||
                // Cannot get grade items or there's no need to.
 | 
			
		||||
                if (userId && userId != currentUserId) {
 | 
			
		||||
                    // View another user grades. Open the grades page directly.
 | 
			
		||||
@ -517,24 +517,12 @@ export class CoreGradesHelperProvider {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // @todo
 | 
			
		||||
                // Open the course with the grades tab selected.
 | 
			
		||||
                // await CoreCourseHelper.getCourse(courseId, siteId).then(async (result) => {
 | 
			
		||||
                //     const pageParams = {
 | 
			
		||||
                //         course: result.course,
 | 
			
		||||
                //         selectedTab: 'CoreGrades',
 | 
			
		||||
                //     };
 | 
			
		||||
 | 
			
		||||
                //     // CoreContentLinksHelper.goInSite(navCtrl, 'CoreCourseSectionPage', pageParams, siteId)
 | 
			
		||||
                //     return await CoreUtils.ignoreErrors(CoreNavigator.navigateToSitePath('/course', {
 | 
			
		||||
                //         siteId,
 | 
			
		||||
                //         params: pageParams,
 | 
			
		||||
                //     }));
 | 
			
		||||
                // });
 | 
			
		||||
                await CoreCourseHelper.getAndOpenCourse(courseId, { selectedTab: 'CoreGrades' }, siteId);
 | 
			
		||||
            } catch (error) {
 | 
			
		||||
                // Cannot get course for some reason, just open the grades page.
 | 
			
		||||
                await CoreNavigator.navigateToSitePath(`/grades/${courseId}`, { siteId });
 | 
			
		||||
            }
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            // Cannot get course for some reason, just open the grades page.
 | 
			
		||||
            await CoreNavigator.navigateToSitePath(`/grades/${courseId}`, { siteId });
 | 
			
		||||
        } finally {
 | 
			
		||||
            modal.dismiss();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -64,6 +64,7 @@ export type CoreNavigatorCurrentRouteOptions = Partial<{
 | 
			
		||||
    params: Params; // Params to get the value from.
 | 
			
		||||
    route: ActivatedRoute; // Current Route.
 | 
			
		||||
    pageComponent: unknown;
 | 
			
		||||
    routeData: Record<string, unknown>;
 | 
			
		||||
}>;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -401,18 +402,22 @@ export class CoreNavigatorService {
 | 
			
		||||
     */
 | 
			
		||||
    getCurrentRoute(): ActivatedRoute;
 | 
			
		||||
    getCurrentRoute(options: CoreNavigatorCurrentRouteOptions): ActivatedRoute | null;
 | 
			
		||||
    getCurrentRoute({ route, pageComponent }: CoreNavigatorCurrentRouteOptions = {}): ActivatedRoute | null {
 | 
			
		||||
    getCurrentRoute({ route, pageComponent, routeData }: CoreNavigatorCurrentRouteOptions = {}): ActivatedRoute | null {
 | 
			
		||||
        route = route ?? Router.routerState.root;
 | 
			
		||||
 | 
			
		||||
        if (pageComponent && route.component === pageComponent) {
 | 
			
		||||
            return route;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (route.firstChild) {
 | 
			
		||||
            return this.getCurrentRoute({ route: route.firstChild, pageComponent });
 | 
			
		||||
        if (routeData && CoreUtils.basicLeftCompare(routeData, route.snapshot.data, 3)) {
 | 
			
		||||
            return route;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return pageComponent ? null : route;
 | 
			
		||||
        if (route.firstChild) {
 | 
			
		||||
            return this.getCurrentRoute({ route: route.firstChild, pageComponent, routeData });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return pageComponent || routeData ? null : route;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -176,7 +176,7 @@ export class CoreUtilsProvider {
 | 
			
		||||
        maxLevels: number = 0,
 | 
			
		||||
        level: number = 0,
 | 
			
		||||
        undefinedIsNull: boolean = true,
 | 
			
		||||
    ): boolean | undefined {
 | 
			
		||||
    ): boolean {
 | 
			
		||||
        if (typeof itemA == 'function' || typeof itemB == 'function') {
 | 
			
		||||
            return true; // Don't compare functions.
 | 
			
		||||
        } else if (typeof itemA == 'object' && typeof itemB == 'object') {
 | 
			
		||||
@ -189,7 +189,7 @@ export class CoreUtilsProvider {
 | 
			
		||||
                const value = itemA[name];
 | 
			
		||||
                if (name == '$$hashKey') {
 | 
			
		||||
                    // Ignore $$hashKey property since it's a "calculated" property.
 | 
			
		||||
                    return;
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!this.basicLeftCompare(value, itemB[name], maxLevels, level + 1)) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user