From 573af7c513d963032bdc854b390c056c694c5aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 30 Jun 2023 12:49:15 +0200 Subject: [PATCH] MOBILE-4283 quiz: Allow students to hide timer --- .../components/submission/submission.scss | 10 ++-- src/addons/mod/assign/pages/edit/edit.html | 2 +- src/addons/mod/assign/pages/edit/edit.scss | 20 ++++---- src/addons/mod/quiz/pages/player/player.html | 10 ++-- src/addons/mod/quiz/pages/player/player.scss | 24 ++++------ src/core/components/timer/core-timer.html | 47 ++++++++++++------- src/core/components/timer/timer.scss | 36 ++++++++++++-- src/core/components/timer/timer.ts | 26 +++++++--- 8 files changed, 104 insertions(+), 71 deletions(-) diff --git a/src/addons/mod/assign/components/submission/submission.scss b/src/addons/mod/assign/components/submission/submission.scss index 2ae6d827b..ba7e1b126 100644 --- a/src/addons/mod/assign/components/submission/submission.scss +++ b/src/addons/mod/assign/components/submission/submission.scss @@ -27,15 +27,15 @@ margin-right: 2px; } - core-timer .core-timer { + core-timer { &.core-timer-under-300 { - background-color: var(--danger-tint); - color: var(--danger-shade); + --timer-background: var(--danger-tint); + --timer-text-color: var(--danger-shade); } &.core-timer-under-900 { - background-color: var(--warning-tint); - color: var(--warning-shade); + --timer-background: var(--warning-tint); + --timer-text-color: var(--warning-shade); } } } diff --git a/src/addons/mod/assign/pages/edit/edit.html b/src/addons/mod/assign/pages/edit/edit.html index b138f8712..c4566ad3c 100644 --- a/src/addons/mod/assign/pages/edit/edit.html +++ b/src/addons/mod/assign/pages/edit/edit.html @@ -22,7 +22,7 @@ + [underTimeClassThresholds]="[300, 900]"> diff --git a/src/addons/mod/assign/pages/edit/edit.scss b/src/addons/mod/assign/pages/edit/edit.scss index de79e53ed..225a5028d 100644 --- a/src/addons/mod/assign/pages/edit/edit.scss +++ b/src/addons/mod/assign/pages/edit/edit.scss @@ -1,17 +1,13 @@ -:host ::ng-deep { +:host { core-timer { - display: block; + &.core-timer-under-300 { + --timer-background: var(--danger-tint); + --timer-text-color: var(--danger-shade); + } - .core-timer { - &.core-timer-under-300 { - background-color: var(--danger-tint); - color: var(--danger-shade); - } - - &.core-timer-under-900 { - background-color: var(--warning-tint); - color: var(--warning-shade); - } + &.core-timer-under-900 { + --timer-background: var(--warning-tint); + --timer-text-color: var(--warning-shade); } } } diff --git a/src/addons/mod/quiz/pages/player/player.html b/src/addons/mod/quiz/pages/player/player.html index 645f3eff1..0b10e3ef6 100644 --- a/src/addons/mod/quiz/pages/player/player.html +++ b/src/addons/mod/quiz/pages/player/player.html @@ -22,13 +22,9 @@ - - - - - - - + + diff --git a/src/addons/mod/quiz/pages/player/player.scss b/src/addons/mod/quiz/pages/player/player.scss index 4569e5005..1242fc6f4 100644 --- a/src/addons/mod/quiz/pages/player/player.scss +++ b/src/addons/mod/quiz/pages/player/player.scss @@ -9,22 +9,14 @@ $quiz-timer-iterations: 15 !default; margin-bottom: 2px; } - ion-content ion-toolbar { - border-bottom: 1px solid var(--stroke); - } - - core-timer ::ng-deep { - .core-timer { - // Make the timer go red when it's reaching 0. - @for $i from 0 through $quiz-timer-iterations { - &.core-timer-timeleft-#{$i} { - background-color: rgba($quiz-timer-warn-color, 1 - ($i / $quiz-timer-iterations)) !important; - - @if $i <= $quiz-timer-iterations / 2 { - label, span, ion-icon { - color: var(--white); - } - } + core-timer { + // Make the timer go red when it's reaching 0. + @for $i from 0 through $quiz-timer-iterations { + &.core-timer-timeleft-#{$i} { + $timer-background: rgba($quiz-timer-warn-color, 1 - ($i / $quiz-timer-iterations)); + --timer-background: #{$timer-background}; + @if $i <= $quiz-timer-iterations / 2 { + --timer-text-color: var(--white); } } } diff --git a/src/core/components/timer/core-timer.html b/src/core/components/timer/core-timer.html index 8cf5a57e8..811f753b5 100644 --- a/src/core/components/timer/core-timer.html +++ b/src/core/components/timer/core-timer.html @@ -1,21 +1,32 @@ - - - + + + + + + + +
- - +
-
- -
+ + +
+ {{ timerText }} + + {{ timeLeft | coreSecondsToHMS }} + +
- - {{ timerText }} - {{ timeLeft | coreSecondsToHMS }} - - {{ timeUpText }} - {{ 'core.timesup' | translate }} - - +
+ ( + ) +
+
+ +
+ {{ timeUpText }} + {{ 'core.timesup' | translate }} +
+
+
diff --git a/src/core/components/timer/timer.scss b/src/core/components/timer/timer.scss index 12955ee2d..aa91db278 100644 --- a/src/core/components/timer/timer.scss +++ b/src/core/components/timer/timer.scss @@ -1,14 +1,40 @@ :host { - .core-timer { - --background: transparent !important; - border-radius: var(--big-radius); + --timer-background: transparent; + .core-timer { .core-timer-time-left, .core-timesup { font-weight: bold; } - span { - margin-right: 5px; + .core-timesup { + flex-grow: 1; + text-align: center; + } + } + + ion-item.core-timer { + --background: var(--timer-background); + --color: var(--timer-text-color, var(--text-color)); + } + + div.core-timer { + background: var(--timer-background); + color: var(--timer-text-color, var(--text-color)); + border-radius: var(--big-radius); + } + + button { + color: var(--timer-text-color, var(--core-link-color)); + } + + ion-item.core-timer ion-label, + div.core-timer { + display: flex; + align-items: center; + + .core-timer-visibility { + flex-grow: 1; + text-align: end; } } } diff --git a/src/core/components/timer/timer.ts b/src/core/components/timer/timer.ts index 5b19b5557..f68ee10bd 100644 --- a/src/core/components/timer/timer.ts +++ b/src/core/components/timer/timer.ts @@ -29,11 +29,12 @@ import { CoreTimeUtils } from '@services/utils/time'; }) export class CoreTimerComponent implements OnInit, OnDestroy { - @Input() endTime?: string | number; // Timestamp (in seconds) when the timer should end. + @Input() endTime = 0; // Timestamp (in seconds) when the timer should end. @Input() timerText?: string; // Text to show next to the timer. If not defined, no text shown. @Input() timeLeftClass?: string; // Name of the class to apply with each second. By default, 'core-timer-timeleft-'. @Input() timeLeftClassThreshold = 100; // Number of seconds to start adding the timeLeftClass. Set it to -1 to not add it. - @Input() align?: string; // Where to align the time and text. Defaults to 'left'. Other values: 'center', 'right'. + @Input() align = 'start'; // Where to align the time and text. Defaults to 'start'. Other values: 'center', 'end'. + @Input() hiddable = false; // Whether the user can hide the time left. @Input() timeUpText?: string; // Text to show when the timer reaches 0. If not defined, 'core.timesup'. @Input() mode: CoreTimerMode = CoreTimerMode.ITEM; // How to display data. @Input() underTimeClassThresholds = []; // Number of seconds to add the class 'core-timer-under-'. @@ -41,6 +42,7 @@ export class CoreTimerComponent implements OnInit, OnDestroy { timeLeft?: number; // Seconds left to end. modeBasic = CoreTimerMode.BASIC; + showTimeLeft = true; protected timeInterval?: number; protected element?: HTMLElement; @@ -54,18 +56,21 @@ export class CoreTimerComponent implements OnInit, OnDestroy { */ ngOnInit(): void { const timeLeftClass = this.timeLeftClass || 'core-timer-timeleft-'; - const endTime = Math.round(Number(this.endTime)); + const endTime = Math.round(this.endTime); this.underTimeClassThresholds.sort((a, b) => a - b); // Sort by increase order. - if (!endTime) { - return; + // @deprecated since 4.3. Use start/end instead. + if (this.align === 'left') { + this.align = 'start'; + } else if (this.align === 'right') { + this.align = 'end'; } let container: HTMLElement | undefined; // Check time left every 200ms. this.timeInterval = window.setInterval(() => { - container = container || this.elementRef.nativeElement.querySelector('.core-timer'); + container = container || this.elementRef.nativeElement; this.timeLeft = Math.max(endTime - CoreTimeUtils.timestamp(), 0); if (container) { @@ -104,7 +109,14 @@ export class CoreTimerComponent implements OnInit, OnDestroy { } /** - * Component destroyed. + * Toggles the time left visibility. + */ + toggleTimeLeftVisibility(): void { + this.showTimeLeft = !this.showTimeLeft; + } + + /** + * @inheritdoc */ ngOnDestroy(): void { clearInterval(this.timeInterval);