MOBILE-4550 quiz: Remove unneded calls to get review WS
This commit is contained in:
		
							parent
							
								
									cdb56d172e
								
							
						
					
					
						commit
						bc88cac82a
					
				@ -196,15 +196,9 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
 | 
				
			|||||||
        if (AddonModQuiz.isQuizOffline(quiz)) {
 | 
					        if (AddonModQuiz.isQuizOffline(quiz)) {
 | 
				
			||||||
            if (sync) {
 | 
					            if (sync) {
 | 
				
			||||||
                // Try to sync the quiz.
 | 
					                // Try to sync the quiz.
 | 
				
			||||||
                try {
 | 
					                await CoreUtils.ignoreErrors(this.syncActivity(showErrors));
 | 
				
			||||||
                    await this.syncActivity(showErrors);
 | 
					 | 
				
			||||||
                } catch {
 | 
					 | 
				
			||||||
                    // Ignore errors, keep getting data even if sync fails.
 | 
					 | 
				
			||||||
                    this.autoReview = undefined;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.autoReview = undefined;
 | 
					 | 
				
			||||||
            this.showStatusSpinner = false;
 | 
					            this.showStatusSpinner = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -400,7 +394,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @returns Promise resolved when done.
 | 
					     * @returns Promise resolved when done.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected async goToAutoReview(): Promise<void> {
 | 
					    protected async goToAutoReview(attempts: AddonModQuizAttemptWSData[]): Promise<void> {
 | 
				
			||||||
        if (!this.autoReview) {
 | 
					        if (!this.autoReview) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -409,20 +403,19 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
 | 
				
			|||||||
        this.checkCompletion();
 | 
					        this.checkCompletion();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Verify that user can see the review.
 | 
					        // Verify that user can see the review.
 | 
				
			||||||
        const attemptId = this.autoReview.attemptId;
 | 
					        const attempt = attempts.find(attempt => attempt.id === this.autoReview?.attemptId);
 | 
				
			||||||
        this.autoReview = undefined;
 | 
					        this.autoReview = undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.quizAccessInfo?.canreviewmyattempts) {
 | 
					        if (!this.quiz || !this.quizAccessInfo || !attempt) {
 | 
				
			||||||
            try {
 | 
					            return;
 | 
				
			||||||
                await AddonModQuiz.getAttemptReview(attemptId, { page: -1, cmId: this.module.id });
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await CoreNavigator.navigateToSitePath(
 | 
					        const canReview = await AddonModQuizHelper.canReviewAttempt(this.quiz, this.quizAccessInfo, attempt);
 | 
				
			||||||
                    `${AddonModQuizModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/review/${attemptId}`,
 | 
					        if (!canReview) {
 | 
				
			||||||
                );
 | 
					            return;
 | 
				
			||||||
            } catch {
 | 
					 | 
				
			||||||
                // Ignore errors.
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await this.reviewAttempt(attempt.id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -451,22 +444,15 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.hasPlayed = false;
 | 
					        this.hasPlayed = false;
 | 
				
			||||||
        let promise = Promise.resolve();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Update data when we come back from the player since the attempt status could have changed.
 | 
					 | 
				
			||||||
        // Check if we need to go to review an attempt automatically.
 | 
					 | 
				
			||||||
        if (this.autoReview && this.autoReview.synced) {
 | 
					 | 
				
			||||||
            promise = this.goToAutoReview();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Refresh data.
 | 
					        // Refresh data.
 | 
				
			||||||
        this.showLoading = true;
 | 
					        this.showLoading = true;
 | 
				
			||||||
        this.content?.scrollToTop();
 | 
					        this.content?.scrollToTop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await promise;
 | 
					 | 
				
			||||||
        await CoreUtils.ignoreErrors(this.refreshContent(true));
 | 
					        await CoreUtils.ignoreErrors(this.refreshContent(true));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.showLoading = false;
 | 
					        this.showLoading = false;
 | 
				
			||||||
 | 
					        this.autoReview = undefined;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -605,7 +591,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
 | 
				
			|||||||
        const [options] = await Promise.all([
 | 
					        const [options] = await Promise.all([
 | 
				
			||||||
            AddonModQuiz.getCombinedReviewOptions(quiz.id, { cmId: this.module.id }),
 | 
					            AddonModQuiz.getCombinedReviewOptions(quiz.id, { cmId: this.module.id }),
 | 
				
			||||||
            this.getQuizGrade(),
 | 
					            this.getQuizGrade(),
 | 
				
			||||||
            openReview ? this.goToAutoReview() : undefined,
 | 
					            openReview ? this.goToAutoReview(attempts) : undefined,
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.options = options;
 | 
					        this.options = options;
 | 
				
			||||||
 | 
				
			|||||||
@ -380,7 +380,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // We have quiz data, now we'll get specific data for each attempt.
 | 
					        // We have quiz data, now we'll get specific data for each attempt.
 | 
				
			||||||
        await Promise.all(attempts.map(async (attempt) => {
 | 
					        await Promise.all(attempts.map(async (attempt) => {
 | 
				
			||||||
            await this.prefetchAttempt(quiz, attempt, preflightData, siteId);
 | 
					            await this.prefetchAttempt(quiz, quizAccessInfo, attempt, preflightData, siteId);
 | 
				
			||||||
        }));
 | 
					        }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!canStart) {
 | 
					        if (!canStart) {
 | 
				
			||||||
@ -400,6 +400,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
     * Prefetch all WS data for an attempt.
 | 
					     * Prefetch all WS data for an attempt.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param quiz Quiz.
 | 
					     * @param quiz Quiz.
 | 
				
			||||||
 | 
					     * @param accessInfo Quiz access info.
 | 
				
			||||||
     * @param attempt Attempt.
 | 
					     * @param attempt Attempt.
 | 
				
			||||||
     * @param preflightData Preflight required data (like password).
 | 
					     * @param preflightData Preflight required data (like password).
 | 
				
			||||||
     * @param siteId Site ID. If not defined, current site.
 | 
					     * @param siteId Site ID. If not defined, current site.
 | 
				
			||||||
@ -407,11 +408,11 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    async prefetchAttempt(
 | 
					    async prefetchAttempt(
 | 
				
			||||||
        quiz: AddonModQuizQuizWSData,
 | 
					        quiz: AddonModQuizQuizWSData,
 | 
				
			||||||
 | 
					        accessInfo: AddonModQuizGetQuizAccessInformationWSResponse,
 | 
				
			||||||
        attempt: AddonModQuizAttemptWSData,
 | 
					        attempt: AddonModQuizAttemptWSData,
 | 
				
			||||||
        preflightData: Record<string, string>,
 | 
					        preflightData: Record<string, string>,
 | 
				
			||||||
        siteId?: string,
 | 
					        siteId?: string,
 | 
				
			||||||
    ): Promise<void> {
 | 
					    ): Promise<void> {
 | 
				
			||||||
        const pages = AddonModQuiz.getPagesFromLayout(attempt.layout);
 | 
					 | 
				
			||||||
        const isSequential = AddonModQuiz.isNavigationSequential(quiz);
 | 
					        const isSequential = AddonModQuiz.isNavigationSequential(quiz);
 | 
				
			||||||
        let promises: Promise<unknown>[] = [];
 | 
					        let promises: Promise<unknown>[] = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -429,16 +430,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
                promises.push(AddonModQuiz.getFeedbackForGrade(quiz.id, attemptGradeNumber, modOptions));
 | 
					                promises.push(AddonModQuiz.getFeedbackForGrade(quiz.id, attemptGradeNumber, modOptions));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get the review for each page.
 | 
					            promises.push(this.prefetchAttemptReview(quiz, accessInfo, attempt, modOptions));
 | 
				
			||||||
            pages.forEach((page) => {
 | 
					 | 
				
			||||||
                promises.push(CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, {
 | 
					 | 
				
			||||||
                    page,
 | 
					 | 
				
			||||||
                    ...modOptions, // Include all options.
 | 
					 | 
				
			||||||
                })));
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the review for all questions in same page.
 | 
					 | 
				
			||||||
            promises.push(this.prefetchAttemptReviewFiles(quiz, attempt, modOptions, siteId));
 | 
					 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Attempt not finished, get data needed to continue the attempt.
 | 
					            // Attempt not finished, get data needed to continue the attempt.
 | 
				
			||||||
@ -447,6 +439,8 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (attempt.state === AddonModQuizAttemptStates.IN_PROGRESS) {
 | 
					            if (attempt.state === AddonModQuizAttemptStates.IN_PROGRESS) {
 | 
				
			||||||
                // Get data for each page.
 | 
					                // Get data for each page.
 | 
				
			||||||
 | 
					                const pages = AddonModQuiz.getPagesFromLayout(attempt.layout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                promises = promises.concat(pages.map(async (page) => {
 | 
					                promises = promises.concat(pages.map(async (page) => {
 | 
				
			||||||
                    if (isSequential && typeof attempt.currentpage === 'number' && page < attempt.currentpage) {
 | 
					                    if (isSequential && typeof attempt.currentpage === 'number' && page < attempt.currentpage) {
 | 
				
			||||||
                        // Sequential quiz, cannot get pages before the current one.
 | 
					                        // Sequential quiz, cannot get pages before the current one.
 | 
				
			||||||
@ -473,20 +467,57 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
        await Promise.all(promises);
 | 
					        await Promise.all(promises);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Prefetch attempt review data.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param quiz Quiz.
 | 
				
			||||||
 | 
					     * @param accessInfo Quiz access info.
 | 
				
			||||||
 | 
					     * @param attempt Attempt.
 | 
				
			||||||
 | 
					     * @param modOptions Other options.
 | 
				
			||||||
 | 
					     * @param siteId Site ID.
 | 
				
			||||||
 | 
					     * @returns Promise resolved when done.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected async prefetchAttemptReview(
 | 
				
			||||||
 | 
					        quiz: AddonModQuizQuizWSData,
 | 
				
			||||||
 | 
					        accessInfo: AddonModQuizGetQuizAccessInformationWSResponse,
 | 
				
			||||||
 | 
					        attempt: AddonModQuizAttemptWSData,
 | 
				
			||||||
 | 
					        modOptions: CoreCourseCommonModWSOptions,
 | 
				
			||||||
 | 
					    ): Promise<void> {
 | 
				
			||||||
 | 
					        // Check if attempt can be reviewed.
 | 
				
			||||||
 | 
					        const canReview = await AddonModQuizHelper.canReviewAttempt(quiz, accessInfo, attempt);
 | 
				
			||||||
 | 
					        if (!canReview) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const pages = AddonModQuiz.getPagesFromLayout(attempt.layout);
 | 
				
			||||||
 | 
					        const promises: Promise<unknown>[] = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get the review for each page.
 | 
				
			||||||
 | 
					        pages.forEach((page) => {
 | 
				
			||||||
 | 
					            promises.push(CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, {
 | 
				
			||||||
 | 
					                page,
 | 
				
			||||||
 | 
					                ...modOptions, // Include all options.
 | 
				
			||||||
 | 
					            })));
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Get the review for all questions in same page.
 | 
				
			||||||
 | 
					        promises.push(this.prefetchAttemptReviewFiles(quiz, attempt, modOptions));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await Promise.all(promises);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Prefetch attempt review and its files.
 | 
					     * Prefetch attempt review and its files.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param quiz Quiz.
 | 
					     * @param quiz Quiz.
 | 
				
			||||||
     * @param attempt Attempt.
 | 
					     * @param attempt Attempt.
 | 
				
			||||||
     * @param modOptions Other options.
 | 
					     * @param modOptions Other options.
 | 
				
			||||||
     * @param siteId Site ID.
 | 
					 | 
				
			||||||
     * @returns Promise resolved when done.
 | 
					     * @returns Promise resolved when done.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected async prefetchAttemptReviewFiles(
 | 
					    protected async prefetchAttemptReviewFiles(
 | 
				
			||||||
        quiz: AddonModQuizQuizWSData,
 | 
					        quiz: AddonModQuizQuizWSData,
 | 
				
			||||||
        attempt: AddonModQuizAttemptWSData,
 | 
					        attempt: AddonModQuizAttemptWSData,
 | 
				
			||||||
        modOptions: CoreCourseCommonModWSOptions,
 | 
					        modOptions: CoreCourseCommonModWSOptions,
 | 
				
			||||||
        siteId?: string,
 | 
					 | 
				
			||||||
    ): Promise<void> {
 | 
					    ): Promise<void> {
 | 
				
			||||||
        // Get the review for all questions in same page.
 | 
					        // Get the review for all questions in same page.
 | 
				
			||||||
        const data = await CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, {
 | 
					        const data = await CoreUtils.ignoreErrors(AddonModQuiz.getAttemptReview(attempt.id, {
 | 
				
			||||||
@ -503,7 +534,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
                question,
 | 
					                question,
 | 
				
			||||||
                this.component,
 | 
					                this.component,
 | 
				
			||||||
                quiz.coursemodule,
 | 
					                quiz.coursemodule,
 | 
				
			||||||
                siteId,
 | 
					                modOptions.siteId,
 | 
				
			||||||
                attempt.uniqueid,
 | 
					                attempt.uniqueid,
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        }));
 | 
					        }));
 | 
				
			||||||
@ -569,7 +600,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
 | 
				
			|||||||
            preflightData = await this.getPreflightData(quiz, quizAccessInfo, lastAttempt, askPreflight, 'core.download', siteId);
 | 
					            preflightData = await this.getPreflightData(quiz, quizAccessInfo, lastAttempt, askPreflight, 'core.download', siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get data for last attempt.
 | 
					            // Get data for last attempt.
 | 
				
			||||||
            await this.prefetchAttempt(quiz, lastAttempt, preflightData, siteId);
 | 
					            await this.prefetchAttempt(quiz, quizAccessInfo, lastAttempt, preflightData, siteId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Prefetch finished, set the right status.
 | 
					        // Prefetch finished, set the right status.
 | 
				
			||||||
 | 
				
			|||||||
@ -513,7 +513,6 @@ export class AddonModQuizProvider {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        const preSets = {
 | 
					        const preSets = {
 | 
				
			||||||
            cacheKey: this.getAttemptReviewCacheKey(attemptId, page),
 | 
					            cacheKey: this.getAttemptReviewCacheKey(attemptId, page),
 | 
				
			||||||
            cacheErrors: ['noreview'],
 | 
					 | 
				
			||||||
            component: ADDON_MOD_QUIZ_COMPONENT,
 | 
					            component: ADDON_MOD_QUIZ_COMPONENT,
 | 
				
			||||||
            componentId: options.cmId,
 | 
					            componentId: options.cmId,
 | 
				
			||||||
            ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
 | 
					            ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user