From e145748d939ad784f00dba12345418f541d73fdd Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 10 Jun 2024 16:24:58 +0200 Subject: [PATCH 1/3] MOBILE-4470 ddmarker: Fix markers in wrong position sometimes --- src/addons/qtype/ddmarker/classes/ddmarker.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/addons/qtype/ddmarker/classes/ddmarker.ts b/src/addons/qtype/ddmarker/classes/ddmarker.ts index e29bd2042..fead3a931 100644 --- a/src/addons/qtype/ddmarker/classes/ddmarker.ts +++ b/src/addons/qtype/ddmarker/classes/ddmarker.ts @@ -19,6 +19,7 @@ import { CoreEventObserver } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; import { AddonQtypeDdMarkerQuestionData } from '../component/ddmarker'; import { AddonQtypeDdMarkerGraphicsApi } from './graphics_api'; +import { CoreUtils } from '@services/utils/utils'; /** * Class to make a question of ddmarker type work. @@ -692,17 +693,21 @@ export class AddonQtypeDdMarkerQuestion { bgImg.src = this.imgSrc; } - const imgLoaded = (): void => { + const imgLoaded = async (): Promise => { bgImg.removeEventListener('load', imgLoaded); this.makeImageDropable(); - setTimeout(() => { - this.redrawDragsAndDrops(); - }); - this.afterImageLoadDone = true; this.question.loaded = true; + + // Wait for image to be visible, otherwise the calculated positions are wrong. + const visiblePromise = CoreDom.waitToBeVisible(bgImg); + + await CoreUtils.ignoreErrors(CoreUtils.timeoutPromise(visiblePromise, 500)); + visiblePromise.cancel(); // In case of timeout, cancel the promise. + + this.redrawDragsAndDrops(); }; if (!bgImg.src || (bgImg.complete && bgImg.naturalWidth)) { From fcea6c311cd7a357d30e2d5e5ca5ffc89b553113 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 10 Jun 2024 16:53:25 +0200 Subject: [PATCH 2/3] MOBILE-4470 user-menu: Fix interval running forever in tablet In tablet the user-menu-button at the top right was hidden using CSS, but this button has a user tour associated. This meant that the user tour kept looking for the button to be visible forever, checking it every 50ms. --- .../components/user-menu-button/user-menu-button.html | 4 ++-- .../components/user-menu-button/user-menu-button.scss | 4 ---- .../components/user-menu-button/user-menu-button.ts | 9 ++++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.html b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.html index 766db041e..03cb08f3b 100644 --- a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.html +++ b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.html @@ -1,3 +1,3 @@ - diff --git a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.scss b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.scss index 4e2aba989..9e1de95e2 100644 --- a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.scss +++ b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.scss @@ -1,7 +1,3 @@ -:host-context(ion-tabs.placement-side ion-toolbar) { - display: none; -} - :host core-user-avatar { --userpicture-padding: 6px !important; } diff --git a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.ts b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.ts index 9d83a9e83..e747efdeb 100644 --- a/src/core/features/mainmenu/components/user-menu-button/user-menu-button.ts +++ b/src/core/features/mainmenu/components/user-menu-button/user-menu-button.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input, OnInit, Optional } from '@angular/core'; import { CoreSiteInfo } from '@classes/sites/unauthenticated-site'; import { CoreUserTourDirectiveOptions } from '@directives/user-tour'; import { CoreUserToursAlignment, CoreUserToursSide } from '@features/usertours/services/user-tours'; @@ -22,6 +22,7 @@ import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMainMenuUserMenuTourComponent } from '../user-menu-tour/user-menu-tour'; import { CoreMainMenuUserMenuComponent } from '../user-menu/user-menu'; +import { CoreMainMenuPage } from '@features/mainmenu/pages/menu/menu'; /** * Component to display an avatar on the header to open user menu. @@ -45,10 +46,8 @@ export class CoreMainMenuUserButtonComponent implements OnInit { side: CoreScreen.isMobile ? CoreUserToursSide.Start : CoreUserToursSide.End, }; - constructor(protected routerOutlet: IonRouterOutlet) { - const currentSite = CoreSites.getRequiredCurrentSite(); - - this.siteInfo = currentSite.getInfo(); + constructor(protected routerOutlet: IonRouterOutlet, @Optional() protected menuPage: CoreMainMenuPage | null) { + this.siteInfo = CoreSites.getCurrentSite()?.getInfo(); } /** From ad08fcf4b90ea251a71034679b42ede9855b8bbb Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 11 Jun 2024 08:22:43 +0200 Subject: [PATCH 3/3] MOBILE-4470 quiz: Fix pipe translate not found in prefetch --- .../mod/quiz/components/components.module.ts | 3 -- ...-modal.ts => preflight-modal.component.ts} | 0 .../preflight-modal/preflight-modal.module.ts | 36 +++++++++++++++++++ src/addons/mod/quiz/services/quiz-helper.ts | 4 ++- 4 files changed, 39 insertions(+), 4 deletions(-) rename src/addons/mod/quiz/components/preflight-modal/{preflight-modal.ts => preflight-modal.component.ts} (100%) create mode 100644 src/addons/mod/quiz/components/preflight-modal/preflight-modal.module.ts diff --git a/src/addons/mod/quiz/components/components.module.ts b/src/addons/mod/quiz/components/components.module.ts index 364eabad8..32f249166 100644 --- a/src/addons/mod/quiz/components/components.module.ts +++ b/src/addons/mod/quiz/components/components.module.ts @@ -19,7 +19,6 @@ import { CoreCourseComponentsModule } from '@features/course/components/componen import { AddonModQuizConnectionErrorComponent } from './connection-error/connection-error'; import { AddonModQuizIndexComponent } from './index/index'; import { AddonModQuizNavigationModalComponent } from './navigation-modal/navigation-modal'; -import { AddonModQuizPreflightModalComponent } from './preflight-modal/preflight-modal'; import { AddonModQuizAttemptInfoComponent } from './attempt-info/attempt-info'; import { AddonModQuizAttemptStateComponent } from './attempt-state/attempt-state'; import { AddonModQuizQuestionCardComponent } from './question-card/question-card'; @@ -31,7 +30,6 @@ import { AddonModQuizQuestionCardComponent } from './question-card/question-card AddonModQuizIndexComponent, AddonModQuizConnectionErrorComponent, AddonModQuizNavigationModalComponent, - AddonModQuizPreflightModalComponent, AddonModQuizQuestionCardComponent, ], imports: [ @@ -44,7 +42,6 @@ import { AddonModQuizQuestionCardComponent } from './question-card/question-card AddonModQuizIndexComponent, AddonModQuizConnectionErrorComponent, AddonModQuizNavigationModalComponent, - AddonModQuizPreflightModalComponent, AddonModQuizQuestionCardComponent, ], diff --git a/src/addons/mod/quiz/components/preflight-modal/preflight-modal.ts b/src/addons/mod/quiz/components/preflight-modal/preflight-modal.component.ts similarity index 100% rename from src/addons/mod/quiz/components/preflight-modal/preflight-modal.ts rename to src/addons/mod/quiz/components/preflight-modal/preflight-modal.component.ts diff --git a/src/addons/mod/quiz/components/preflight-modal/preflight-modal.module.ts b/src/addons/mod/quiz/components/preflight-modal/preflight-modal.module.ts new file mode 100644 index 000000000..77952a6f8 --- /dev/null +++ b/src/addons/mod/quiz/components/preflight-modal/preflight-modal.module.ts @@ -0,0 +1,36 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { NgModule } from '@angular/core'; + +import { CoreSharedModule } from '@/core/shared.module'; +import { CoreCourseComponentsModule } from '@features/course/components/components.module'; +import { AddonModQuizPreflightModalComponent } from './preflight-modal.component'; + +export { AddonModQuizPreflightModalComponent }; + +@NgModule({ + declarations: [ + AddonModQuizPreflightModalComponent, + ], + imports: [ + CoreSharedModule, + CoreCourseComponentsModule, + ], + exports: [ + AddonModQuizPreflightModalComponent, + + ], +}) +export class AddonModQuizPreflightModalComponentModule {} diff --git a/src/addons/mod/quiz/services/quiz-helper.ts b/src/addons/mod/quiz/services/quiz-helper.ts index b5bf2f317..66432a360 100644 --- a/src/addons/mod/quiz/services/quiz-helper.ts +++ b/src/addons/mod/quiz/services/quiz-helper.ts @@ -22,7 +22,6 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton, Translate } from '@singletons'; -import { AddonModQuizPreflightModalComponent } from '../components/preflight-modal/preflight-modal'; import { AddonModQuizAccessRuleDelegate } from './access-rules-delegate'; import { AddonModQuizModuleHandlerService } from './handlers/module'; import { @@ -269,6 +268,9 @@ export class AddonModQuizHelperProvider { ); } + const { AddonModQuizPreflightModalComponent } = + await import('@addons/mod/quiz/components/preflight-modal/preflight-modal.module'); + // Create and show the modal. const modalData = await CoreDomUtils.openModal>({ component: AddonModQuizPreflightModalComponent,