From 9d0a9ef7466778f95655710732f8010131d9ef98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 30 Oct 2018 16:50:21 +0100 Subject: [PATCH 1/2] MOBILE-2669 completion: Don't get completion if previously received --- .../mod/assign/components/index/index.ts | 4 +- src/addon/mod/book/components/index/index.ts | 2 +- src/addon/mod/chat/components/index/index.ts | 2 +- .../mod/choice/components/index/index.ts | 4 +- src/addon/mod/data/components/index/index.ts | 2 +- src/addon/mod/feedback/pages/form/form.ts | 2 +- .../mod/folder/components/index/index.ts | 2 +- src/addon/mod/forum/components/index/index.ts | 4 +- .../mod/glossary/components/index/index.ts | 4 +- src/addon/mod/imscp/components/index/index.ts | 2 +- .../mod/lesson/components/index/index.ts | 2 +- src/addon/mod/lti/components/index/index.ts | 2 +- src/addon/mod/lti/providers/module-handler.ts | 2 +- src/addon/mod/page/components/index/index.ts | 2 +- src/addon/mod/quiz/components/index/index.ts | 8 +-- .../mod/resource/components/index/index.ts | 2 +- src/addon/mod/resource/providers/helper.ts | 2 +- src/addon/mod/scorm/components/index/index.ts | 2 +- .../mod/survey/components/index/index.ts | 2 +- src/addon/mod/url/components/index/index.ts | 2 +- src/addon/mod/url/providers/module-handler.ts | 2 +- src/addon/mod/wiki/components/index/index.ts | 2 +- .../mod/workshop/components/index/index.ts | 4 +- .../workshop/pages/submission/submission.ts | 2 +- .../module-completion/module-completion.ts | 2 +- .../components/module/core-course-module.html | 6 +- src/core/course/pages/section/section.ts | 55 +++++++++++-------- src/core/course/providers/helper.ts | 23 ++++++-- src/core/course/providers/sync.ts | 7 ++- upgrade.txt | 1 + 30 files changed, 91 insertions(+), 67 deletions(-) diff --git a/src/addon/mod/assign/components/index/index.ts b/src/addon/mod/assign/components/index/index.ts index d5945f7cc..f46e35bc7 100644 --- a/src/addon/mod/assign/components/index/index.ts +++ b/src/addon/mod/assign/components/index/index.ts @@ -75,7 +75,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo this.loadContent(false, true).then(() => { this.assignProvider.logView(this.assign.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); @@ -104,7 +104,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo this.submittedObserver = this.eventsProvider.on(AddonModAssignProvider.SUBMITTED_FOR_GRADING_EVENT, (data) => { if (this.assign && data.assignmentId == this.assign.id && data.userId == this.userId) { // Assignment submitted, check completion. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); // Reload data since it can have offline data now. this.showLoadingAndRefresh(true, false); diff --git a/src/addon/mod/book/components/index/index.ts b/src/addon/mod/book/components/index/index.ts index 9e8a29ebc..573a53778 100644 --- a/src/addon/mod/book/components/index/index.ts +++ b/src/addon/mod/book/components/index/index.ts @@ -166,7 +166,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp this.bookProvider.logView(this.module.instance, chapterId).then(() => { // Module is completed when last chapter is viewed, so we only check completion if the last is reached. if (!this.nextChapter) { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } }).catch(() => { // Ignore errors. diff --git a/src/addon/mod/chat/components/index/index.ts b/src/addon/mod/chat/components/index/index.ts index 12f773827..e21d5623a 100644 --- a/src/addon/mod/chat/components/index/index.ts +++ b/src/addon/mod/chat/components/index/index.ts @@ -48,7 +48,7 @@ export class AddonModChatIndexComponent extends CoreCourseModuleMainActivityComp this.loadContent().then(() => { this.chatProvider.logView(this.chat.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/choice/components/index/index.ts b/src/addon/mod/choice/components/index/index.ts index e8880dcbc..358a0ac6e 100644 --- a/src/addon/mod/choice/components/index/index.ts +++ b/src/addon/mod/choice/components/index/index.ts @@ -67,7 +67,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo return; } this.choiceProvider.logView(this.choice.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); @@ -354,7 +354,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo this.choiceProvider.submitResponse(this.choice.id, this.choice.name, this.courseId, responses).then(() => { // Success! // Check completion since it could be configured to complete once the user answers the choice. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); this.domUtils.scrollToTop(this.content); // Let's refresh the data. diff --git a/src/addon/mod/data/components/index/index.ts b/src/addon/mod/data/components/index/index.ts index 5f7a9a957..71f922666 100644 --- a/src/addon/mod/data/components/index/index.ts +++ b/src/addon/mod/data/components/index/index.ts @@ -104,7 +104,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp } this.dataProvider.logView(this.data.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/feedback/pages/form/form.ts b/src/addon/mod/feedback/pages/form/form.ts index c468f03bc..214f12bd7 100644 --- a/src/addon/mod/feedback/pages/form/form.ts +++ b/src/addon/mod/feedback/pages/form/form.ts @@ -95,7 +95,7 @@ export class AddonModFeedbackFormPage implements OnDestroy { ionViewDidLoad(): void { this.fetchData().then(() => { this.feedbackProvider.logView(this.feedback.id, true).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/folder/components/index/index.ts b/src/addon/mod/folder/components/index/index.ts index f977be7e3..6b735e53d 100644 --- a/src/addon/mod/folder/components/index/index.ts +++ b/src/addon/mod/folder/components/index/index.ts @@ -56,7 +56,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo } else { this.loadContent().then(() => { this.folderProvider.logView(this.module.instance).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/forum/components/index/index.ts b/src/addon/mod/forum/components/index/index.ts index 817e18a76..46ccc4c13 100644 --- a/src/addon/mod/forum/components/index/index.ts +++ b/src/addon/mod/forum/components/index/index.ts @@ -114,7 +114,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom } this.forumProvider.logView(this.forum.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); @@ -423,7 +423,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom }); // Check completion since it could be configured to complete once the user adds a new discussion or replies. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } } diff --git a/src/addon/mod/glossary/components/index/index.ts b/src/addon/mod/glossary/components/index/index.ts index 9cb87dd68..0d619978d 100644 --- a/src/addon/mod/glossary/components/index/index.ts +++ b/src/addon/mod/glossary/components/index/index.ts @@ -86,7 +86,7 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity } this.glossaryProvider.logView(this.glossary.id, this.viewMode).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); @@ -387,7 +387,7 @@ export class AddonModGlossaryIndexComponent extends CoreCourseModuleMainActivity this.showLoadingAndRefresh(false); // Check completion since it could be configured to complete once the user adds a new discussion or replies. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } } diff --git a/src/addon/mod/imscp/components/index/index.ts b/src/addon/mod/imscp/components/index/index.ts index 7e27a7910..7ca40d13c 100644 --- a/src/addon/mod/imscp/components/index/index.ts +++ b/src/addon/mod/imscp/components/index/index.ts @@ -53,7 +53,7 @@ export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceCom this.loadContent().then(() => { this.imscpProvider.logView(this.module.instance).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/lesson/components/index/index.ts b/src/addon/mod/lesson/components/index/index.ts index 7bd329b8e..de7981894 100644 --- a/src/addon/mod/lesson/components/index/index.ts +++ b/src/addon/mod/lesson/components/index/index.ts @@ -310,7 +310,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo */ protected logView(): void { this.lessonProvider.logViewLesson(this.lesson.id, this.password).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); diff --git a/src/addon/mod/lti/components/index/index.ts b/src/addon/mod/lti/components/index/index.ts index 0f4e3d4ca..40ccaa4f0 100644 --- a/src/addon/mod/lti/components/index/index.ts +++ b/src/addon/mod/lti/components/index/index.ts @@ -51,7 +51,7 @@ export class AddonModLtiIndexComponent extends CoreCourseModuleMainActivityCompo * Check the completion. */ protected checkCompletion(): void { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } /** diff --git a/src/addon/mod/lti/providers/module-handler.ts b/src/addon/mod/lti/providers/module-handler.ts index b8525572c..5d623cc1b 100644 --- a/src/addon/mod/lti/providers/module-handler.ts +++ b/src/addon/mod/lti/providers/module-handler.ts @@ -88,7 +88,7 @@ export class AddonModLtiModuleHandler implements CoreCourseModuleHandler { return this.ltiProvider.getLtiLaunchData(ltiData.id).then((launchData) => { // "View" LTI. this.ltiProvider.logView(ltiData.id).then(() => { - this.courseProvider.checkModuleCompletion(courseId, module.completionstatus); + this.courseProvider.checkModuleCompletion(courseId, module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/page/components/index/index.ts b/src/addon/mod/page/components/index/index.ts index cb008550b..4cf4ef924 100644 --- a/src/addon/mod/page/components/index/index.ts +++ b/src/addon/mod/page/components/index/index.ts @@ -54,7 +54,7 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp this.loadContent().then(() => { this.pageProvider.logView(this.module.instance).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/quiz/components/index/index.ts b/src/addon/mod/quiz/components/index/index.ts index 3ce3124c9..2ccfb71f7 100644 --- a/src/addon/mod/quiz/components/index/index.ts +++ b/src/addon/mod/quiz/components/index/index.ts @@ -86,7 +86,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp } this.quizProvider.logViewQuiz(this.quizData.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); @@ -370,7 +370,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp */ protected goToAutoReview(): Promise { // If we go to auto review it means an attempt was finished. Check completion status. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); // Verify that user can see the review. const attemptId = this.autoReview.attemptId; @@ -395,7 +395,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp protected hasSyncSucceed(result: any): boolean { if (result.attemptFinished) { // An attempt was finished, check completion status. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } // If the sync call isn't rejected it means the sync was successful. @@ -484,7 +484,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp protected isRefreshSyncNeeded(syncEventData: any): boolean { if (syncEventData.attemptFinished) { // An attempt was finished, check completion status. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } if (this.quizData && syncEventData.quizId == this.quizData.id) { diff --git a/src/addon/mod/resource/components/index/index.ts b/src/addon/mod/resource/components/index/index.ts index ee49883b0..cd5b50e72 100644 --- a/src/addon/mod/resource/components/index/index.ts +++ b/src/addon/mod/resource/components/index/index.ts @@ -51,7 +51,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource this.loadContent().then(() => { this.resourceProvider.logView(this.module.instance).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/resource/providers/helper.ts b/src/addon/mod/resource/providers/helper.ts index eec56772b..05c62f5aa 100644 --- a/src/addon/mod/resource/providers/helper.ts +++ b/src/addon/mod/resource/providers/helper.ts @@ -153,7 +153,7 @@ export class AddonModResourceHelperProvider { return this.courseHelper.downloadModuleAndOpenFile(module, courseId, AddonModResourceProvider.COMPONENT, module.id, module.contents).then(() => { this.resourceProvider.logView(module.instance).then(() => { - this.courseProvider.checkModuleCompletion(courseId, module.completionstatus); + this.courseProvider.checkModuleCompletion(courseId, module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/scorm/components/index/index.ts b/src/addon/mod/scorm/components/index/index.ts index 85d1e567c..ec881b25d 100644 --- a/src/addon/mod/scorm/components/index/index.ts +++ b/src/addon/mod/scorm/components/index/index.ts @@ -94,7 +94,7 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom * Check the completion. */ protected checkCompletion(): void { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } /** diff --git a/src/addon/mod/survey/components/index/index.ts b/src/addon/mod/survey/components/index/index.ts index 7db99f743..581064e0e 100644 --- a/src/addon/mod/survey/components/index/index.ts +++ b/src/addon/mod/survey/components/index/index.ts @@ -54,7 +54,7 @@ export class AddonModSurveyIndexComponent extends CoreCourseModuleMainActivityCo this.loadContent(false, true).then(() => { this.surveyProvider.logView(this.survey.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/url/components/index/index.ts b/src/addon/mod/url/components/index/index.ts index 3bbdfad79..18b495e57 100644 --- a/src/addon/mod/url/components/index/index.ts +++ b/src/addon/mod/url/components/index/index.ts @@ -172,7 +172,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo */ go(): void { this.urlProvider.logView(this.module.instance).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index bf7895760..445c85b18 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -166,7 +166,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { */ protected openUrl(module: any, courseId: number): void { this.urlProvider.logView(module.instance).then(() => { - this.courseProvider.checkModuleCompletion(courseId, module.completionstatus); + this.courseProvider.checkModuleCompletion(courseId, module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/addon/mod/wiki/components/index/index.ts b/src/addon/mod/wiki/components/index/index.ts index 545c1e1c7..b154c7f4e 100644 --- a/src/addon/mod/wiki/components/index/index.ts +++ b/src/addon/mod/wiki/components/index/index.ts @@ -105,7 +105,7 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp if (this.isMainPage) { this.wikiProvider.logView(this.wiki.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); diff --git a/src/addon/mod/workshop/components/index/index.ts b/src/addon/mod/workshop/components/index/index.ts index 0d586f426..419ef4d4a 100644 --- a/src/addon/mod/workshop/components/index/index.ts +++ b/src/addon/mod/workshop/components/index/index.ts @@ -106,7 +106,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity } this.workshopProvider.logView(this.workshop.id).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch((error) => { // Ignore errors. }); @@ -123,7 +123,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity this.showLoadingAndRefresh(true); // Check completion since it could be configured to complete once the user adds a new discussion or replies. - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); } } diff --git a/src/addon/mod/workshop/pages/submission/submission.ts b/src/addon/mod/workshop/pages/submission/submission.ts index b12dff3b5..218bfe2c7 100644 --- a/src/addon/mod/workshop/pages/submission/submission.ts +++ b/src/addon/mod/workshop/pages/submission/submission.ts @@ -131,7 +131,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy { ngOnInit(): void { this.fetchSubmissionData().then(() => { this.workshopProvider.logViewSubmission(this.submissionId).then(() => { - this.courseProvider.checkModuleCompletion(this.courseId, this.module.completionstatus); + this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata); }).catch(() => { // Ignore errors. }); diff --git a/src/core/course/components/module-completion/module-completion.ts b/src/core/course/components/module-completion/module-completion.ts index c383c41ca..4d3ef1b6a 100644 --- a/src/core/course/components/module-completion/module-completion.ts +++ b/src/core/course/components/module-completion/module-completion.ts @@ -25,7 +25,7 @@ import { CoreCourseProvider } from '../../providers/course'; * * Example usage: * - * */ @Component({ diff --git a/src/core/course/components/module/core-course-module.html b/src/core/course/components/module/core-course-module.html index 9ab0f394b..3e1a12234 100644 --- a/src/core/course/components/module/core-course-module.html +++ b/src/core/course/components/module/core-course-module.html @@ -5,9 +5,9 @@ -
+
- +
@@ -37,7 +37,7 @@ {{ 'core.course.hiddenfromstudents' | translate }} {{ 'core.course.hiddenoncoursepage' | translate }} - {{ 'core.course.manualcompletionnotsynced' | translate }} + {{ 'core.course.manualcompletionnotsynced' | translate }}
\ No newline at end of file diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index 19858d405..39ecb6568 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -184,34 +184,41 @@ export class CoreCourseSectionPage implements OnDestroy { } }).then(() => { const promises = []; - let promise; - // Get the completion status. - if (this.course.enablecompletion === false) { - // Completion not enabled. - promise = Promise.resolve({}); - } else { - promise = this.courseProvider.getActivitiesCompletionStatus(this.course.id).catch(() => { - // It failed, don't use completion. - return {}; - }); - } + // Get all the sections. + promises.push(this.courseProvider.getSections(this.course.id, false, true).then((sections) => { + if (refresh) { + // Invalidate the recently downloaded module list. To ensure info can be prefetched. + const modules = this.courseProvider.getSectionsModules(sections); - promises.push(promise.then((completionStatus) => { - // Get all the sections. - return this.courseProvider.getSections(this.course.id, false, true).then((sections) => { - if (refresh) { - // Invalidate the recently downloaded module list. To ensure info can be prefetched. - const modules = this.courseProvider.getSectionsModules(sections); - - return this.prefetchDelegate.invalidateModules(modules, this.course.id).then(() => { - return sections; - }); - } else { + return this.prefetchDelegate.invalidateModules(modules, this.course.id).then(() => { return sections; - } - }).then((sections) => { + }); + } else { + return sections; + } + }).then((sections) => { + let promise; + // Get the completion status. + if (this.course.enablecompletion === false) { + // Completion not enabled. + promise = Promise.resolve({}); + } else { + const sectionWithModules = sections.find((section) => { + return section.modules.length > 0; + }); + if (sectionWithModules && typeof sectionWithModules.modules[0].completion != 'undefined') { + promise = Promise.resolve({}); + } else { + promise = this.courseProvider.getActivitiesCompletionStatus(this.course.id).catch(() => { + // It failed, don't use completion. + return {}; + }); + } + } + + return promise.then((completionStatus) => { this.courseHelper.addHandlerDataForModules(sections, this.course.id, completionStatus, this.course.fullname); // Format the name of each section and check if it has content. diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index c48df70ad..aa708ae69 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -147,11 +147,16 @@ export class CoreCourseHelperProvider { section.modules.forEach((module) => { module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, section.id); - if (completionStatus && typeof completionStatus[module.id] != 'undefined') { - // Check if activity has completions and if it's marked. - module.completionstatus = completionStatus[module.id]; - module.completionstatus.courseId = courseId; - module.completionstatus.courseName = courseName; + if (module.completiondata && module.completion > 0) { + module.completiondata.courseId = courseId; + module.completiondata.courseName = courseName; + module.completiondata.tracking = module.completion; + module.completiondata.cmid = module.id; + } else if (completionStatus && typeof completionStatus[module.id] != 'undefined') { + // Not in use > 3.6. Check if activity has completions and if it's marked. + module.completiondata = completionStatus[module.id]; + module.completiondata.courseId = courseId; + module.completiondata.courseName = courseName; } // Check if the module is stealth. @@ -1070,7 +1075,13 @@ export class CoreCourseHelperProvider { if (this.coursesProvider.isGetCoursesByFieldAvailable()) { promises.push(this.coursesProvider.getCoursesByField('id', course.id)); } - promises.push(this.courseProvider.getActivitiesCompletionStatus(course.id)); + + const sectionWithModules = sections.find((section) => { + return section.modules.length > 0; + }); + if (!sectionWithModules || typeof sectionWithModules.modules[0].completion == 'undefined') { + promises.push(this.courseProvider.getActivitiesCompletionStatus(course.id)); + } return this.utils.allPromises(promises); }).then(() => { diff --git a/src/core/course/providers/sync.ts b/src/core/course/providers/sync.ts index 87ebc23d8..2556a1fdb 100644 --- a/src/core/course/providers/sync.ts +++ b/src/core/course/providers/sync.ts @@ -129,6 +129,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { } // Get the current completion status to check if any completion was modified in web. + // This can be retrieved on core_course_get_contents since 3.6 but this is an easy way to get them. return this.courseProvider.getActivitiesCompletionStatus(courseId, siteId, undefined, false, true, false) .then((onlineCompletions) => { @@ -183,7 +184,11 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider { if (result.updated) { // Update data. return this.courseProvider.invalidateSections(courseId, siteId).then(() => { - return this.courseProvider.getActivitiesCompletionStatus(courseId); + if (this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.6')) { + return this.courseProvider.getSections(courseId, false, true, undefined, siteId); + } else { + return this.courseProvider.getActivitiesCompletionStatus(courseId, siteId); + } }).catch(() => { // Ignore errors. }); diff --git a/upgrade.txt b/upgrade.txt index 205e5d4c0..a3c88bd60 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -6,6 +6,7 @@ information provided here is intended especially for developers. - gulp was updated to v4. In order for gulp to work, you need to install gulp-cli: npm install -g gulp-cli It's also recommended to update ionic cli to v4, otherwise some errors could be raised while building: npm install -g ionic - The value of the constant CoreCourseProvider.ALL_SECTIONS_ID has changed from -1 to -2. +- Use of completionstatus on the module object has been deprecated, use completiondata instead. === 3.5.2 === From 9a405065cb0d19923e4699d5a764439c37197007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 31 Oct 2018 11:40:01 +0100 Subject: [PATCH 2/2] MOBILE-2669 resource: Don't get activity data to render after link --- .../mod/forum/providers/module-handler.ts | 8 +++- .../mod/resource/providers/module-handler.ts | 38 +++++++++++++------ src/core/course/providers/helper.ts | 8 +++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/addon/mod/forum/providers/module-handler.ts b/src/addon/mod/forum/providers/module-handler.ts index a44a05c3a..6a6d997ae 100644 --- a/src/addon/mod/forum/providers/module-handler.ts +++ b/src/addon/mod/forum/providers/module-handler.ts @@ -77,7 +77,13 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { } }; - this.updateExtraBadge(data, courseId, module.id); + if (typeof module.afterlink != 'undefined') { + data.extraBadgeColor = ''; + const match = />(\d+)[^<]+/.exec(module.afterlink); + data.extraBadge = match ? this.translate.instant('addon.mod_forum.unreadpostsnumber', {$a : match[1] }) : ''; + } else { + this.updateExtraBadge(data, courseId, module.id); + } const event = this.eventsProvider.on(AddonModForumProvider.MARK_READ_EVENT, (eventData) => { if (eventData.courseId == courseId && eventData.moduleId == module.id) { diff --git a/src/addon/mod/resource/providers/module-handler.ts b/src/addon/mod/resource/providers/module-handler.ts index a03592261..e6e9e6278 100644 --- a/src/addon/mod/resource/providers/module-handler.ts +++ b/src/addon/mod/resource/providers/module-handler.ts @@ -134,27 +134,30 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { */ protected getResourceData(module: any, courseId: number, handlerData: CoreCourseModuleHandlerData): Promise { const promises = []; - let resourceInfo; + let infoFiles = [], + options: any = {}; // Check if the button needs to be shown or not. This also loads the module contents. promises.push(this.hideOpenButton(module, courseId).then((hideOpenButton) => { handlerData.buttons[0].hidden = hideOpenButton; })); - if (this.resourceProvider.isGetResourceWSAvailable()) { + if (typeof module.customdata != 'undefined') { + options = this.textUtils.unserialize(this.textUtils.parseJSON(module.customdata)); + } else if (this.resourceProvider.isGetResourceWSAvailable()) { // Get the resource data. promises.push(this.resourceProvider.getResourceData(courseId, module.id).then((info) => { - resourceInfo = info; + infoFiles = info.contentfiles; + options = this.textUtils.unserialize(info.displayoptions); })); } return Promise.all(promises).then(() => { - const files = module.contents && module.contents.length ? module.contents : resourceInfo && resourceInfo.contentfiles, + const files = module.contents && module.contents.length ? module.contents : infoFiles, resourceData = { icon: '', extra: '' }, - options = (resourceInfo && this.textUtils.unserialize(resourceInfo.displayoptions)) || {}, extra = []; if (files && files.length) { @@ -162,19 +165,32 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { resourceData.icon = this.mimetypeUtils.getFileIcon(file.filename); if (options.showsize) { - const size = files.reduce((result, file) => { - return result + file.filesize; - }, 0); + let size; + if (options.filedetails) { + size = options.filedetails.size; + } else { + size = files.reduce((result, file) => { + return result + file.filesize; + }, 0); + } extra.push(this.textUtils.bytesToSize(size, 1)); } + if (options.showtype) { + // We should take it from options.filedetails.size if avalaible ∫but it's already translated. extra.push(this.mimetypeUtils.getMimetypeDescription(file)); } if (options.showdate) { - /* Modified date may be up to several minutes later than uploaded date just because - teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */ - if (file.timemodified > file.timecreated + CoreConstants.SECONDS_MINUTE * 5) { + if (options.filedetails && options.filedetails.modifieddate) { + extra.push(this.translate.instant('addon.mod_resource.modifieddate', + {$a: moment(options.filedetails.modifieddate * 1000).format('LLL')})); + } else if (options.filedetails && options.filedetails.uploadeddate) { + extra.push(this.translate.instant('addon.mod_resource.uploadeddate', + {$a: moment(options.filedetails.uploadeddate * 1000).format('LLL')})); + } else if (file.timemodified > file.timecreated + CoreConstants.SECONDS_MINUTE * 5) { + /* Modified date may be up to several minutes later than uploaded date just because + teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. */ extra.push(this.translate.instant('addon.mod_resource.modifieddate', {$a: moment(file.timemodified * 1000).format('LLL')})); } else { diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index aa708ae69..73ac7e3a4 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -152,11 +152,17 @@ export class CoreCourseHelperProvider { module.completiondata.courseName = courseName; module.completiondata.tracking = module.completion; module.completiondata.cmid = module.id; + + // Use of completionstatus is deprecated, use completiondata instead. + module.completionstatus = module.completiondata; } else if (completionStatus && typeof completionStatus[module.id] != 'undefined') { - // Not in use > 3.6. Check if activity has completions and if it's marked. + // Should not happen on > 3.6. Check if activity has completions and if it's marked. module.completiondata = completionStatus[module.id]; module.completiondata.courseId = courseId; module.completiondata.courseName = courseName; + + // Use of completionstatus is deprecated, use completiondata instead. + module.completionstatus = module.completiondata; } // Check if the module is stealth.