From 2f395125525f665a0849fe630c0f371e13e706b8 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 5 Apr 2022 12:19:37 +0200 Subject: [PATCH] MOBILE-3833 course: Make last access coherent with recent block --- src/addons/mod/data/pages/entry/entry.ts | 2 +- src/addons/mod/feedback/pages/attempt/attempt.ts | 8 -------- src/addons/mod/feedback/pages/attempts/attempts.ts | 10 ---------- .../feedback/pages/nonrespondents/nonrespondents.ts | 8 -------- .../mod/forum/pages/discussion/discussion.page.ts | 8 -------- src/addons/mod/glossary/pages/entry/entry.ts | 8 -------- .../pages/attempt-results/attempt-results.ts | 4 ---- .../h5pactivity/pages/user-attempts/user-attempts.ts | 4 ---- .../pages/users-attempts/users-attempts.ts | 4 ---- .../mod/lesson/pages/user-retake/user-retake.page.ts | 8 -------- src/addons/mod/quiz/pages/review/review.page.ts | 4 ---- src/addons/mod/wiki/components/index/index.ts | 10 ++++++++++ .../course/classes/main-resource-component.ts | 11 ++++++++++- 13 files changed, 21 insertions(+), 68 deletions(-) diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index 6bc442857..761962bb1 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -212,7 +212,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { this.logAfterFetch = false; await CoreUtils.ignoreErrors(AddonModData.logView(this.database.id, this.database.name)); - // Store module viewed. It's done in this page because it can be reached using a link. + // Store module viewed because this page also updates recent accessed items block. CoreCourse.storeModuleViewed(this.courseId, this.moduleId); } } catch (error) { diff --git a/src/addons/mod/feedback/pages/attempt/attempt.ts b/src/addons/mod/feedback/pages/attempt/attempt.ts index 7ee5e6028..e8981da89 100644 --- a/src/addons/mod/feedback/pages/attempt/attempt.ts +++ b/src/addons/mod/feedback/pages/attempt/attempt.ts @@ -16,7 +16,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager'; -import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; @@ -50,7 +49,6 @@ export class AddonModFeedbackAttemptPage implements OnInit, OnDestroy { loaded = false; protected attemptId: number; - protected fetchSuccess = false; constructor() { this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); @@ -132,12 +130,6 @@ export class AddonModFeedbackAttemptPage implements OnInit, OnDestroy { return attemptItem; }).filter((itemData) => itemData); // Filter items with errors. - - if (!this.fetchSuccess) { - this.fetchSuccess = true; - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); - } } catch (message) { // Some call failed on fetch, go back. CoreDomUtils.showErrorModalDefault(message, 'core.course.errorgetmodule', true); diff --git a/src/addons/mod/feedback/pages/attempts/attempts.ts b/src/addons/mod/feedback/pages/attempts/attempts.ts index 1da06886d..ecea1615d 100644 --- a/src/addons/mod/feedback/pages/attempts/attempts.ts +++ b/src/addons/mod/feedback/pages/attempts/attempts.ts @@ -25,7 +25,6 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { AddonModFeedbackAttemptItem, AddonModFeedbackAttemptsSource } from '../../classes/feedback-attempts-source'; import { AddonModFeedbackWSAnonAttempt, AddonModFeedbackWSAttempt } from '../../services/feedback'; -import { CoreCourse } from '@features/course/services/course'; /** * Page that displays feedback attempts. @@ -187,13 +186,4 @@ export class AddonModFeedbackAttemptsPage implements AfterViewInit, OnDestroy { * Attempts manager. */ class AddonModFeedbackAttemptsManager extends CoreListItemsManager { - - /** - * @inheritdoc - */ - protected async logActivity(): Promise { - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.getSource().COURSE_ID, this.getSource().CM_ID); - } - } diff --git a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts index 59b4f7ca5..db568a32a 100644 --- a/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts +++ b/src/addons/mod/feedback/pages/nonrespondents/nonrespondents.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, OnInit } from '@angular/core'; -import { CoreCourse } from '@features/course/services/course'; import { IonRefresher } from '@ionic/angular'; import { CoreGroupInfo, CoreGroups } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; @@ -35,7 +34,6 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit { protected courseId!: number; protected feedback?: AddonModFeedbackWSFeedback; protected page = 0; - protected fetchSuccess = false; selectedGroup!: number; groupInfo?: CoreGroupInfo; @@ -83,12 +81,6 @@ export class AddonModFeedbackNonRespondentsPage implements OnInit { this.selectedGroup = CoreGroups.validateGroupId(this.selectedGroup, this.groupInfo); await this.loadGroupUsers(this.selectedGroup); - - if (!this.fetchSuccess) { - this.fetchSuccess = true; - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); - } } catch (message) { CoreDomUtils.showErrorModalDefault(message, 'core.course.errorgetmodule', true); diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index a59703a50..4fec08325 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -17,7 +17,6 @@ import { Component, OnDestroy, ViewChild, OnInit, AfterViewInit, ElementRef, Opt import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; -import { CoreCourse } from '@features/course/services/course'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreRatingInfo, CoreRatingProvider } from '@features/rating/services/rating'; import { CoreRatingOffline } from '@features/rating/services/rating-offline'; @@ -120,7 +119,6 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes protected ratingOfflineObserver?: CoreEventObserver; protected ratingSyncObserver?: CoreEventObserver; protected changeDiscObserver?: CoreEventObserver; - protected fetchSuccess = false; constructor( @Optional() protected splitView: CoreSplitViewComponent, @@ -547,12 +545,6 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes this.hasOfflineRatings = await CoreRatingOffline.hasRatings('mod_forum', 'post', ContextLevel.MODULE, this.cmId, this.discussionId); - - if (!this.fetchSuccess) { - this.fetchSuccess = true; - // Store module viewed. It's done in this page because it can be reached using a link. - this.courseId && this.cmId && CoreCourse.storeModuleViewed(this.courseId, this.cmId); - } } catch (error) { CoreDomUtils.showErrorModal(error); } finally { diff --git a/src/addons/mod/glossary/pages/entry/entry.ts b/src/addons/mod/glossary/pages/entry/entry.ts index f07b4004b..ca53e83e0 100644 --- a/src/addons/mod/glossary/pages/entry/entry.ts +++ b/src/addons/mod/glossary/pages/entry/entry.ts @@ -17,7 +17,6 @@ import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; import { CoreCommentsCommentsComponent } from '@features/comments/components/comments/comments'; import { CoreComments } from '@features/comments/services/comments'; -import { CoreCourse } from '@features/course/services/course'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTag } from '@features/tag/services/tag'; import { IonRefresher } from '@ionic/angular'; @@ -59,7 +58,6 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { cmId?: number; protected entryId!: number; - protected fetchSuccess = false; constructor(protected route: ActivatedRoute) {} @@ -148,12 +146,6 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { this.entry = result.entry; this.ratingInfo = result.ratinginfo; - if (!this.fetchSuccess) { - this.fetchSuccess = true; - // Store module viewed. It's done in this page because it can be reached using a link. - this.cmId && CoreCourse.storeModuleViewed(this.courseId, this.cmId); - } - if (this.glossary) { // Glossary already loaded, nothing else to load. return; diff --git a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts index 458449191..3b3727a2b 100644 --- a/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts +++ b/src/addons/mod/h5pactivity/pages/attempt-results/attempt-results.ts @@ -25,7 +25,6 @@ import { AddonModH5PActivityData, AddonModH5PActivityAttemptResults, } from '../../services/h5pactivity'; -import { CoreCourse } from '@features/course/services/course'; /** * Page that displays results of an attempt. @@ -100,9 +99,6 @@ export class AddonModH5PActivityAttemptResultsPage implements OnInit { this.h5pActivity.name, { attemptId: this.attemptId }, )); - - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error loading attempt.'); diff --git a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts index a45b31b05..bb95f9fcb 100644 --- a/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/user-attempts/user-attempts.ts @@ -26,7 +26,6 @@ import { AddonModH5PActivityData, AddonModH5PActivityUserAttempts, } from '../../services/h5pactivity'; -import { CoreCourse } from '@features/course/services/course'; /** * Page that displays user attempts of a certain user. @@ -102,9 +101,6 @@ export class AddonModH5PActivityUserAttemptsPage implements OnInit { this.h5pActivity.name, { userId: this.userId }, )); - - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error loading attempts.'); diff --git a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts index 2acb07e59..f50cd056c 100644 --- a/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts +++ b/src/addons/mod/h5pactivity/pages/users-attempts/users-attempts.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, OnInit } from '@angular/core'; -import { CoreCourse } from '@features/course/services/course'; import { CoreUser, CoreUserProfile } from '@features/user/services/user'; import { IonRefresher } from '@ionic/angular'; @@ -93,9 +92,6 @@ export class AddonModH5PActivityUsersAttemptsPage implements OnInit { if (!this.fetchSuccess) { this.fetchSuccess = true; CoreUtils.ignoreErrors(AddonModH5PActivity.logViewReport(this.h5pActivity.id, this.h5pActivity.name)); - - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error loading attempts.'); diff --git a/src/addons/mod/lesson/pages/user-retake/user-retake.page.ts b/src/addons/mod/lesson/pages/user-retake/user-retake.page.ts index 4ac48bf57..21fbb7fac 100644 --- a/src/addons/mod/lesson/pages/user-retake/user-retake.page.ts +++ b/src/addons/mod/lesson/pages/user-retake/user-retake.page.ts @@ -34,7 +34,6 @@ import { AddonModLessonUserAttemptAnswerPageWSData, } from '../../services/lesson'; import { AddonModLessonAnswerData, AddonModLessonHelper } from '../../services/lesson-helper'; -import { CoreCourse } from '@features/course/services/course'; import { CoreTime } from '@singletons/time'; /** @@ -60,7 +59,6 @@ export class AddonModLessonUserRetakePage implements OnInit { protected userId?: number; // User ID to see the retakes. protected retakeNumber?: number; // Number of the initial retake to see. protected previousSelectedRetake?: number; // To be able to detect the previous selected retake when it has changed. - protected fetchSuccess = false; /** * Component being initialized. @@ -162,12 +160,6 @@ export class AddonModLessonUserRetakePage implements OnInit { this.student.profileimageurl = user?.profileimageurl; await this.setRetake(this.selectedRetake); - - if (!this.fetchSuccess) { - this.fetchSuccess = true; - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); - } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'Error getting data.', true); } diff --git a/src/addons/mod/quiz/pages/review/review.page.ts b/src/addons/mod/quiz/pages/review/review.page.ts index 1a3a4c3f6..957d86304 100644 --- a/src/addons/mod/quiz/pages/review/review.page.ts +++ b/src/addons/mod/quiz/pages/review/review.page.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; -import { CoreCourse } from '@features/course/services/course'; import { CoreQuestionQuestionParsed } from '@features/question/services/question'; import { CoreQuestionHelper } from '@features/question/services/question-helper'; import { IonContent, IonRefresher } from '@ionic/angular'; @@ -162,9 +161,6 @@ export class AddonModQuizReviewPage implements OnInit { CoreUtils.ignoreErrors( AddonModQuiz.logViewAttemptReview(this.attemptId, this.quiz.id, this.quiz.name), ); - - // Store module viewed. It's done in this page because it can be reached using a link. - CoreCourse.storeModuleViewed(this.courseId, this.cmId); } } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'addon.mod_quiz.errorgetquiz', true); diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index 558db1026..fac51cd87 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -447,6 +447,16 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp } } + /** + * @inheritdoc + */ + protected async storeModuleViewed(): Promise { + // Only store module viewed when viewing the main page. + if (!this.pageId) { + await super.storeModuleViewed(); + } + } + /** * Get path to the wiki home view. If cannot determine or it's current view, return undefined. * diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index a9600520c..9e995d682 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -442,7 +442,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, } this.fetchSuccess = true; - CoreCourse.storeModuleViewed(this.courseId, this.module.id, { sectionId: this.module.section }); + this.storeModuleViewed(); // Log activity now. try { @@ -456,6 +456,15 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, } } + /** + * Store module as viewed. + * + * @return Promise resolved when done. + */ + protected async storeModuleViewed(): Promise { + await CoreCourse.storeModuleViewed(this.courseId, this.module.id, { sectionId: this.module.section }); + } + /** * Log activity. *