From 56e51e9e60fcb9bb92708720bba30ab602af383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 17 Nov 2021 11:46:37 +0100 Subject: [PATCH 1/9] MOBILE-3810 ionic: Prevent modal from opening twice --- src/core/services/utils/dom.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index bc52b22fe..c23675e5c 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -71,6 +71,7 @@ export class CoreDomUtilsProvider { protected instances: WeakMap = new WeakMap(); // Store component/directive instances indexed by element. protected debugDisplay = false; // Whether to display debug messages. Store it in a variable to make it synchronous. protected displayedAlerts: Record = {}; // To prevent duplicated alerts. + protected displayedModals: Record = {}; // To prevent duplicated modals. protected activeLoadingModals: CoreIonLoadingElement[] = []; protected logger: CoreLogger; @@ -1690,26 +1691,37 @@ export class CoreDomUtilsProvider { async openModal( options: OpenModalOptions, ): Promise { - const { waitForDismissCompleted, closeOnNavigate, ...modalOptions } = options; const listenCloseEvents = closeOnNavigate ?? true; // Default to true. - const modal = await ModalController.create(modalOptions); + // TODO: Improve this if we need two modals with same component open at the same time. + const modalId = Md5.hashAsciiStr(options.component?.toString() || ''); + + const modal = this.displayedModals[modalId] + ? this.displayedModals[modalId] + : await ModalController.create(modalOptions); let navSubscription: Subscription | undefined; - if (listenCloseEvents) { - // Listen navigation events to close modals. - navSubscription = Router.events - .pipe(filter(event => event instanceof NavigationStart)) - .subscribe(async () => { - modal.dismiss(); - }); - } - await modal.present(); + if (!this.displayedModals[modalId]) { + // Store the modal and remove it when dismissed. + this.displayedModals[modalId] = modal; + + if (listenCloseEvents) { + // Listen navigation events to close modals. + navSubscription = Router.events + .pipe(filter(event => event instanceof NavigationStart)) + .subscribe(async () => { + modal.dismiss(); + }); + } + + await modal.present(); + } const result = waitForDismissCompleted ? await modal.onDidDismiss() : await modal.onWillDismiss(); navSubscription?.unsubscribe(); + delete this.displayedModals[modalId]; if (result?.data) { return result?.data; From 8a3ae5e081c0651ebf48d6b0f2fb6e6646aefa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 16 Nov 2021 14:10:43 +0100 Subject: [PATCH 2/9] MOBILE-3810 module: Fix getIconSrc on course module handler --- .../mod/resource/services/handlers/module.ts | 28 ++++++++++++++++++- src/core/components/mod-icon/mod-icon.ts | 4 +-- .../course/services/module-delegate.ts | 8 ++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/addons/mod/resource/services/handlers/module.ts b/src/addons/mod/resource/services/handlers/module.ts index 69a3d2ce8..275ea61f7 100644 --- a/src/addons/mod/resource/services/handlers/module.ts +++ b/src/addons/mod/resource/services/handlers/module.ts @@ -15,7 +15,7 @@ import { CoreConstants } from '@/core/constants'; import { Injectable, Type } from '@angular/core'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; -import { CoreCourse } from '@features/course/services/course'; +import { CoreCourse, CoreCourseWSModule } from '@features/course/services/course'; import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; @@ -226,6 +226,32 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase }; } + /** + * @inheritdoc + */ + async getIconSrc(module?: CoreCourseWSModule): Promise { + if (!module) { + return; + } + let mimetypeIcon = ''; + + if ('contentsinfo' in module && module.contentsinfo) { + // No need to use the list of files. + const mimetype = module.contentsinfo.mimetypes[0]; + if (mimetype) { + mimetypeIcon = CoreMimetypeUtils.getMimetypeIcon(mimetype); + } + + } else if (module.contents && module.contents[0]) { + const files = module.contents; + const file = files[0]; + + mimetypeIcon = CoreMimetypeUtils.getFileIcon(file.filename || ''); + } + + return await CoreCourse.getModuleIconSrc(module.modname, module.modicon, mimetypeIcon); + } + /** * @inheritdoc */ diff --git a/src/core/components/mod-icon/mod-icon.ts b/src/core/components/mod-icon/mod-icon.ts index eba805215..c9c6b70ac 100644 --- a/src/core/components/mod-icon/mod-icon.ts +++ b/src/core/components/mod-icon/mod-icon.ts @@ -15,7 +15,7 @@ import { Component, Input, OnChanges, OnInit, SimpleChange } from '@angular/core'; import { CoreCourse } from '@features/course/services/course'; -const assetsPath = 'assets/img/mod/'; +const assetsPath = 'assets/img/'; const fallbackModName = 'external-tool'; /** @@ -51,7 +51,7 @@ export class CoreModIconComponent implements OnInit, OnChanges { * @inheritdoc */ ngOnChanges(changes: { [name: string]: SimpleChange }): void { - if (changes && changes.modicon && changes.modicon.previousValue) { + if (changes && changes.modicon && changes.modicon.previousValue !== undefined) { this.setIcon(); } } diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index f967c89a5..e5f918d1f 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -80,9 +80,10 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler { /** * Get the icon src for the module. * + * @param module: Module to get the icon from. * @return The icon src. */ - getIconSrc?(module: CoreCourseWSModule): Promise | string | undefined; + getIconSrc?(module?: CoreCourseWSModule): Promise | string | undefined; /** * Check if this type of module supports a certain feature. @@ -343,10 +344,11 @@ export class CoreCourseModuleDelegateService extends CoreDelegate { - const icon = await this.executeFunctionOnEnabled>(modname, 'getIconSrc'); + async getModuleIconSrc(modname: string, modicon?: string, module?: CoreCourseWSModule): Promise { + const icon = await this.executeFunctionOnEnabled>(modname, 'getIconSrc', [module]); return icon || await CoreCourse.getModuleIconSrc(modname, modicon) || ''; } From dace9898d04967d4871bde0220a44bcb3f83971f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 16 Nov 2021 12:58:46 +0100 Subject: [PATCH 3/9] MOBILE-3810 module: Add basic info to core-course-module-info --- .../index/addon-mod-assign-index.html | 67 +++++++--------- .../index/addon-mod-book-index.html | 25 +++--- .../index/addon-mod-chat-index.html | 16 ++-- .../index/addon-mod-choice-index.html | 31 ++++---- .../index/addon-mod-data-index.html | 27 +++---- .../index/addon-mod-feedback-index.html | 39 ++++------ .../index/addon-mod-folder-index.html | 17 ++-- .../mod/forum/components/index/index.html | 77 ++++++++----------- .../index/addon-mod-glossary-index.html | 30 ++++---- .../index/addon-mod-h5pactivity-index.html | 24 +++--- .../index/addon-mod-imscp-index.html | 11 ++- .../index/addon-mod-lesson-index.html | 26 +++---- .../components/index/addon-mod-lti-index.html | 17 ++-- .../index/addon-mod-page-index.html | 16 ++-- .../index/addon-mod-quiz-index.html | 62 +++++++-------- .../index/addon-mod-resource-index.html | 18 ++--- .../index/addon-mod-scorm-index.html | 26 +++---- .../index/addon-mod-survey-index.html | 45 +++++------ .../components/index/addon-mod-url-index.html | 16 ++-- .../index/addon-mod-wiki-index.html | 33 ++++---- src/addons/mod/wiki/pages/index/index.ts | 4 +- .../index/addon-mod-workshop-index.html | 40 ++++++---- .../course/classes/main-resource-component.ts | 4 +- .../module-description/module-description.ts | 4 +- .../module-info/core-course-module-info.html | 53 +++++++++---- .../module-info/course-module-info.scss | 6 +- .../components/module-info/module-info.ts | 35 ++++++++- .../core-course-unsupported-module.html | 5 +- 28 files changed, 365 insertions(+), 409 deletions(-) diff --git a/src/addons/mod/assign/components/index/addon-mod-assign-index.html b/src/addons/mod/assign/components/index/addon-mod-assign-index.html index ef0cd7d5d..1efbaa292 100644 --- a/src/addons/mod/assign/components/index/addon-mod-assign-index.html +++ b/src/addons/mod/assign/components/index/addon-mod-assign-index.html @@ -1,15 +1,14 @@ - + + [priority]="800" [content]="'core.moduleintro' | translate" (action)="expandDescription()" iconAction="fas-arrow-right"> - + @@ -31,26 +30,15 @@ - + + + + + - - - - - - - - - - - - - @@ -90,8 +78,7 @@ - +

{{ 'addon.mod_assign.numberofteams' | translate }}

{{ 'addon.mod_assign.numberofparticipants' | translate }}

@@ -109,48 +96,48 @@ -

{{ 'addon.mod_assign.numberofdraftsubmissions' | translate }}

+ +

{{ 'addon.mod_assign.numberofdraftsubmissions' | translate }}

+
{{ 'addon.mod_assign.numberofdraftsubmissionscountdescription' | translate: - {count: summary.submissiondraftscount} }} + {count: summary.submissiondraftscount} }}
-

{{ 'addon.mod_assign.numberofsubmittedassignments' | translate }}

+ +

{{ 'addon.mod_assign.numberofsubmittedassignments' | translate }}

+
{{ 'addon.mod_assign.numberofsubmittedassignmentscountdescription' | translate: - {count: summary.submissionssubmittedcount} }} + {count: summary.submissionssubmittedcount} }}
-

{{ 'addon.mod_assign.numberofsubmissionsneedgrading' | translate }}

+ +

{{ 'addon.mod_assign.numberofsubmissionsneedgrading' | translate }}

+
{{ 'addon.mod_assign.numberofsubmissionsneedgradingcountdescription' | translate: - {count: summary.submissionsneedgradingcount} }} + {count: summary.submissionsneedgradingcount} }}
diff --git a/src/addons/mod/book/components/index/addon-mod-book-index.html b/src/addons/mod/book/components/index/addon-mod-book-index.html index 7be6e735b..f6f090647 100644 --- a/src/addons/mod/book/components/index/addon-mod-book-index.html +++ b/src/addons/mod/book/components/index/addon-mod-book-index.html @@ -4,12 +4,12 @@ - + - + - + - - @@ -39,9 +36,8 @@
- +
- +
diff --git a/src/addons/mod/chat/components/index/addon-mod-chat-index.html b/src/addons/mod/chat/components/index/addon-mod-chat-index.html index 8f1069746..93265acea 100644 --- a/src/addons/mod/chat/components/index/addon-mod-chat-index.html +++ b/src/addons/mod/chat/components/index/addon-mod-chat-index.html @@ -1,14 +1,14 @@ - + - + @@ -27,14 +27,10 @@ - + - - - diff --git a/src/addons/mod/choice/components/index/addon-mod-choice-index.html b/src/addons/mod/choice/components/index/addon-mod-choice-index.html index 60a41827e..f0e2aa0f5 100644 --- a/src/addons/mod/choice/components/index/addon-mod-choice-index.html +++ b/src/addons/mod/choice/components/index/addon-mod-choice-index.html @@ -1,14 +1,14 @@ - + - + @@ -29,14 +29,10 @@ - + - - - @@ -54,8 +50,7 @@

{{ 'addon.mod_choice.yourselection' | translate }} - +

{{ 'addon.mod_choice.expired' | translate:{$a: closeTimeReadable} }}

@@ -145,10 +140,12 @@

- + -

{{user.fullname}}

+ +

{{user.fullname}}

+
@@ -159,7 +156,9 @@ -

{{ 'addon.mod_choice.noresultsviewable' | translate }}

+ +

{{ 'addon.mod_choice.noresultsviewable' | translate }}

+
diff --git a/src/addons/mod/data/components/index/addon-mod-data-index.html b/src/addons/mod/data/components/index/addon-mod-data-index.html index 7f8633b5d..f8a993361 100644 --- a/src/addons/mod/data/components/index/addon-mod-data-index.html +++ b/src/addons/mod/data/components/index/addon-mod-data-index.html @@ -4,28 +4,27 @@ - + - + + [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"> - + - + @@ -40,14 +39,10 @@ - + - - - diff --git a/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html b/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html index 124241f10..b6852c689 100644 --- a/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html +++ b/src/addons/mod/feedback/components/index/addon-mod-feedback-index.html @@ -1,14 +1,14 @@ - + - + @@ -29,22 +29,18 @@ - + - - - - + @@ -73,10 +69,8 @@ - +

{{ 'addon.mod_feedback.completed_feedbacks' | translate }}

@@ -87,8 +81,8 @@
- +

{{ 'addon.mod_feedback.show_nonrespondents' | translate }}

@@ -208,12 +202,12 @@

{{item.num}}. + contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId">

- +

@@ -232,8 +226,7 @@ + contextLevel="module" [contextInstanceId]="module.id" [wsNotFiltered]="true" [courseId]="courseId">

{{ 'addon.mod_feedback.average' | translate }}: {{item.average | number : '1.2-2'}} diff --git a/src/addons/mod/folder/components/index/addon-mod-folder-index.html b/src/addons/mod/folder/components/index/addon-mod-folder-index.html index 4763418b3..e44e8a1b7 100644 --- a/src/addons/mod/folder/components/index/addon-mod-folder-index.html +++ b/src/addons/mod/folder/components/index/addon-mod-folder-index.html @@ -1,14 +1,14 @@ - + - + @@ -26,14 +26,11 @@ - + +

{{subfolder.filename}}

- - - diff --git a/src/addons/mod/forum/components/index/index.html b/src/addons/mod/forum/components/index/index.html index 3703497a6..642a96d2f 100644 --- a/src/addons/mod/forum/components/index/index.html +++ b/src/addons/mod/forum/components/index/index.html @@ -1,38 +1,30 @@ - + - + - - - + - + - @@ -46,15 +38,16 @@ - + + + + {{descriptionNote}} + + - - - @@ -72,23 +65,17 @@ - +
-
- @@ -98,15 +85,12 @@ [attr.aria-label]="'addon.mod_forum.discussionpinned' | translate"> - +

- + @@ -158,8 +142,7 @@
-
diff --git a/src/addons/mod/glossary/components/index/addon-mod-glossary-index.html b/src/addons/mod/glossary/components/index/addon-mod-glossary-index.html index 02b9e0405..61cee7db8 100644 --- a/src/addons/mod/glossary/components/index/addon-mod-glossary-index.html +++ b/src/addons/mod/glossary/components/index/addon-mod-glossary-index.html @@ -10,18 +10,17 @@ - + - + + [content]="'core.refresh' | translate" (action)="doRefresh(null, $event)" [iconAction]="refreshIcon" [closeOnClick]="false"> - + - - - @@ -69,7 +64,9 @@ -

{{ 'addon.mod_glossary.entriestobesynced' | translate }}

+ +

{{ 'addon.mod_glossary.entriestobesynced' | translate }}

+
@@ -84,11 +81,12 @@ -

{{ getDivider!(entry) }}

+ +

{{ getDivider!(entry) }}

+
- + diff --git a/src/addons/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html b/src/addons/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html index ca3d3524f..1811b5b44 100644 --- a/src/addons/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html +++ b/src/addons/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html @@ -5,18 +5,17 @@ [priority]="1000" [content]="'addon.mod_h5pactivity.review_my_attempts' | translate" (action)="viewMyAttempts()" iconAction="stats-chart">
- + - + - + @@ -37,14 +36,10 @@ - + - - - @@ -79,8 +74,7 @@ - + {{ 'addon.mod_h5pactivity.downloadh5pfile' | translate }} diff --git a/src/addons/mod/imscp/components/index/addon-mod-imscp-index.html b/src/addons/mod/imscp/components/index/addon-mod-imscp-index.html index 98901925b..4f15b3bc9 100644 --- a/src/addons/mod/imscp/components/index/addon-mod-imscp-index.html +++ b/src/addons/mod/imscp/components/index/addon-mod-imscp-index.html @@ -4,14 +4,14 @@ - + - + @@ -29,8 +29,7 @@ - + diff --git a/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html b/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html index d8948ccbb..aa28071e4 100644 --- a/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html +++ b/src/addons/mod/lesson/components/index/addon-mod-lesson-index.html @@ -1,14 +1,14 @@ - + - + @@ -33,14 +33,10 @@ - + - - - @@ -132,13 +128,11 @@ - + {{ 'core.start' | translate }} - + {{ 'addon.mod_lesson.preview' | translate }} @@ -295,8 +289,8 @@ {{ 'addon.mod_lesson.overview' | translate }} - + diff --git a/src/addons/mod/lti/components/index/addon-mod-lti-index.html b/src/addons/mod/lti/components/index/addon-mod-lti-index.html index 184f09284..ef10e579e 100644 --- a/src/addons/mod/lti/components/index/addon-mod-lti-index.html +++ b/src/addons/mod/lti/components/index/addon-mod-lti-index.html @@ -1,14 +1,14 @@ - + - + @@ -20,14 +20,11 @@ - + - - -
diff --git a/src/addons/mod/page/components/index/addon-mod-page-index.html b/src/addons/mod/page/components/index/addon-mod-page-index.html index fcc229d26..2dcb76d66 100644 --- a/src/addons/mod/page/components/index/addon-mod-page-index.html +++ b/src/addons/mod/page/components/index/addon-mod-page-index.html @@ -1,14 +1,14 @@ - + - + @@ -26,14 +26,10 @@ - + - - - diff --git a/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html b/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html index 94e4bcc51..519746fe0 100644 --- a/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html +++ b/src/addons/mod/quiz/components/index/addon-mod-quiz-index.html @@ -1,14 +1,14 @@ - + - + @@ -29,19 +29,17 @@ - + - - - -

{{ rule }}

+ +

{{ rule }}

+
@@ -55,7 +53,7 @@

{{ 'addon.mod_quiz.outof' | translate: { $a: { grade: bestGrade.gradetopass, maxgrade: quiz.gradeFormatted - } } }}

+ } } }}

@@ -96,15 +94,9 @@
- + @@ -142,17 +134,21 @@

{{ 'addon.mod_quiz.comment' | translate }}

-

-

+

+ + +

{{ 'addon.mod_quiz.overallfeedback' | translate }}

-

-

+

+ + +

@@ -163,10 +159,14 @@ -

{{ message }}

+ +

{{ message }}

+
-

{{ 'addon.mod_quiz.noquestions' | translate }}

+ +

{{ 'addon.mod_quiz.noquestions' | translate }}

+
@@ -226,7 +226,9 @@ - + + +
diff --git a/src/addons/mod/resource/components/index/addon-mod-resource-index.html b/src/addons/mod/resource/components/index/addon-mod-resource-index.html index 704d31dd1..4c8e7daf6 100644 --- a/src/addons/mod/resource/components/index/addon-mod-resource-index.html +++ b/src/addons/mod/resource/components/index/addon-mod-resource-index.html @@ -1,12 +1,12 @@ - + - + - + - - - diff --git a/src/addons/mod/scorm/components/index/addon-mod-scorm-index.html b/src/addons/mod/scorm/components/index/addon-mod-scorm-index.html index 23c75ba08..58f417175 100644 --- a/src/addons/mod/scorm/components/index/addon-mod-scorm-index.html +++ b/src/addons/mod/scorm/components/index/addon-mod-scorm-index.html @@ -1,14 +1,14 @@ - + - + @@ -29,14 +29,10 @@ - + - - - @@ -134,8 +130,8 @@ {{ 'addon.mod_scorm.organizations' | translate }} - + {{ org.title }} @@ -155,8 +151,7 @@

{{ currentOrganization.title }}

- +