forked from CIT/Vmeda.Online
		
	MOBILE-3659 navigator: Create functions to get number/boolean params
This commit is contained in:
		
							parent
							
								
									83dc2ba39e
								
							
						
					
					
						commit
						afa94e3354
					
				@ -97,9 +97,9 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.course = course;
 | 
					        this.course = course;
 | 
				
			||||||
        this.sectionId = CoreNavigator.instance.getRouteParam('sectionId');
 | 
					        this.sectionId = CoreNavigator.instance.getRouteNumberParam('sectionId');
 | 
				
			||||||
        this.sectionNumber = CoreNavigator.instance.getRouteParam('sectionNumber');
 | 
					        this.sectionNumber = CoreNavigator.instance.getRouteNumberParam('sectionNumber');
 | 
				
			||||||
        this.moduleId = CoreNavigator.instance.getRouteParam('moduleId');
 | 
					        this.moduleId = CoreNavigator.instance.getRouteNumberParam('moduleId');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.displayEnableDownload = !CoreSites.instance.getCurrentSite()?.isOfflineDisabled() &&
 | 
					        this.displayEnableDownload = !CoreSites.instance.getCurrentSite()?.isOfflineDisabled() &&
 | 
				
			||||||
            CoreCourseFormatDelegate.instance.displayEnableDownload(this.course);
 | 
					            CoreCourseFormatDelegate.instance.displayEnableDownload(this.course);
 | 
				
			||||||
 | 
				
			|||||||
@ -88,8 +88,8 @@ export class CoreCourseIndexPage implements OnInit, OnDestroy {
 | 
				
			|||||||
        this.contentsTab.page = CoreTextUtils.instance.concatenatePaths(this.currentPagePath, this.contentsTab.page);
 | 
					        this.contentsTab.page = CoreTextUtils.instance.concatenatePaths(this.currentPagePath, this.contentsTab.page);
 | 
				
			||||||
        this.contentsTab.pageParams = {
 | 
					        this.contentsTab.pageParams = {
 | 
				
			||||||
            course: this.course,
 | 
					            course: this.course,
 | 
				
			||||||
            sectionId: CoreNavigator.instance.getRouteParam<number>('sectionId'),
 | 
					            sectionId: CoreNavigator.instance.getRouteNumberParam('sectionId'),
 | 
				
			||||||
            sectionNumber: CoreNavigator.instance.getRouteParam<number>('sectionNumber'),
 | 
					            sectionNumber: CoreNavigator.instance.getRouteNumberParam('sectionNumber'),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (module) {
 | 
					        if (module) {
 | 
				
			||||||
 | 
				
			|||||||
@ -47,7 +47,7 @@ export class CoreCourseListModTypePage implements OnInit {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    async ngOnInit(): Promise<void> {
 | 
					    async ngOnInit(): Promise<void> {
 | 
				
			||||||
        this.title = CoreNavigator.instance.getRouteParam('title') || '';
 | 
					        this.title = CoreNavigator.instance.getRouteParam('title') || '';
 | 
				
			||||||
        this.courseId = CoreNavigator.instance.getRouteParam('courseId');
 | 
					        this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId');
 | 
				
			||||||
        this.modName = CoreNavigator.instance.getRouteParam('modName');
 | 
					        this.modName = CoreNavigator.instance.getRouteParam('modName');
 | 
				
			||||||
        this.downloadEnabled = !CoreSites.instance.getCurrentSite()?.isOfflineDisabled();
 | 
					        this.downloadEnabled = !CoreSites.instance.getCurrentSite()?.isOfflineDisabled();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@ export class CoreCourseUnsupportedModulePage implements OnInit {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    ngOnInit(): void {
 | 
					    ngOnInit(): void {
 | 
				
			||||||
        this.module = CoreNavigator.instance.getRouteParam('module');
 | 
					        this.module = CoreNavigator.instance.getRouteParam('module');
 | 
				
			||||||
        this.courseId = CoreNavigator.instance.getRouteParam('courseId');
 | 
					        this.courseId = CoreNavigator.instance.getRouteNumberParam('courseId');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -97,7 +97,7 @@ export class CoreCoursesCoursePreviewPage implements OnInit, OnDestroy {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    async ngOnInit(): Promise<void> {
 | 
					    async ngOnInit(): Promise<void> {
 | 
				
			||||||
        this.course = CoreNavigator.instance.getRouteParam('course');
 | 
					        this.course = CoreNavigator.instance.getRouteParam('course');
 | 
				
			||||||
        this.avoidOpenCourse = !!CoreNavigator.instance.getRouteParam('avoidOpenCourse');
 | 
					        this.avoidOpenCourse = !!CoreNavigator.instance.getRouteBooleanParam('avoidOpenCourse');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!this.course) {
 | 
					        if (!this.course) {
 | 
				
			||||||
            CoreNavigator.instance.back();
 | 
					            CoreNavigator.instance.back();
 | 
				
			||||||
 | 
				
			|||||||
@ -210,11 +210,35 @@ export class CoreNavigatorService {
 | 
				
			|||||||
        // Remove the parameter from our map if it's in there.
 | 
					        // Remove the parameter from our map if it's in there.
 | 
				
			||||||
        delete this.storedParams[value];
 | 
					        delete this.storedParams[value];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // @todo: Convert strings to number/boolean if needed? All number & boolean params are converted to string.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return <T> storedParam ?? value;
 | 
					        return <T> storedParam ?? value;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get a number route param.
 | 
				
			||||||
 | 
					     * Angular router automatically converts numbers to string, this function automatically converts it back to number.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param name Name of the parameter.
 | 
				
			||||||
 | 
					     * @return Value of the parameter, undefined if not found.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getRouteNumberParam(name: string): number | undefined {
 | 
				
			||||||
 | 
					        const value = this.getRouteParam<string>(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return value !== undefined ? Number(value) : value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get a boolean route param.
 | 
				
			||||||
 | 
					     * Angular router automatically converts booleans to string, this function automatically converts it back to boolean.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param name Name of the parameter.
 | 
				
			||||||
 | 
					     * @return Value of the parameter, undefined if not found.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    getRouteBooleanParam(name: string): boolean | undefined {
 | 
				
			||||||
 | 
					        const value = this.getRouteParam<string>(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return value !== undefined ? Boolean(value) : value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Navigate back.
 | 
					     * Navigate back.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user