From bb7f0cd3a5adb0729a6b979ad0a4562f1ca52761 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Thu, 7 Nov 2024 10:18:11 +0100 Subject: [PATCH 01/15] 119602: Improve profile page link accessibility --- src/app/profile-page/profile-page.component.html | 2 +- src/assets/i18n/en.json5 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/profile-page/profile-page.component.html b/src/app/profile-page/profile-page.component.html index d8394ac5d4c..d2809a04b64 100644 --- a/src/app/profile-page/profile-page.component.html +++ b/src/app/profile-page/profile-page.component.html @@ -35,7 +35,7 @@

{{'profile.head' | translate}}

{{'profile.card.accessibility.header' | translate}}
-
{{'profile.card.accessibility.content' | translate}}
+ {{'profile.card.accessibility.content' | translate}} {{'profile.card.accessibility.link' | translate}}
diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index fc749377a98..dc69f0fbe86 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -3278,7 +3278,7 @@ "profile.card.accessibility.header": "Accessibility", - "profile.card.accessibility.link": "Accessibility Settings Page", + "profile.card.accessibility.link": "Go to Accessibility Settings Page", "profile.card.identify": "Identify", From fe90d39943f62d025b0e3ab64d57bcc017ed46b2 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 18 Nov 2024 11:36:10 +0100 Subject: [PATCH 02/15] 119602: Add placeholder in form --- .../accessibility/accessibility-settings.service.ts | 11 +++++++++++ .../accessibility-settings.component.html | 1 + .../accessibility-settings.component.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/app/accessibility/accessibility-settings.service.ts b/src/app/accessibility/accessibility-settings.service.ts index 4089fd03b17..77b6c91bea8 100644 --- a/src/app/accessibility/accessibility-settings.service.ts +++ b/src/app/accessibility/accessibility-settings.service.ts @@ -224,4 +224,15 @@ export class AccessibilitySettingsService { } } + getPlaceholder(setting: AccessibilitySetting): string { + switch (setting) { + case AccessibilitySetting.NotificationTimeOut: + return environment.notifications.timeOut.toString(); + case AccessibilitySetting.LiveRegionTimeOut: + return environment.liveRegion.messageTimeOutDurationMs.toString(); + default: + return ''; + } + } + } diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.html b/src/app/info/accessibility-settings/accessibility-settings.component.html index 6550c6a2880..8a76917462c 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.html +++ b/src/app/info/accessibility-settings/accessibility-settings.component.html @@ -9,6 +9,7 @@

{{ 'info.accessibility-settings.title' | translate }}

diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.ts b/src/app/info/accessibility-settings/accessibility-settings.component.ts index 97e3ddb321f..ed1d481be61 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.ts @@ -38,6 +38,10 @@ export class AccessibilitySettingsComponent implements OnInit { return this.settingsService.getInputType(setting); } + getPlaceholder(setting: AccessibilitySetting): string { + return this.settingsService.getPlaceholder(setting); + } + saveSettings() { this.settingsService.setSettings(this.formValues).pipe(take(1)).subscribe(location => { this.notificationsService.success(null, this.translateService.instant('info.accessibility-settings.save-notification.' + location)); From ecb00a95a07424bafa1976e871086585c3374b7a Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 18 Nov 2024 13:50:46 +0100 Subject: [PATCH 03/15] 119602: Implement converting of accessibility settings values --- .../accessibility-settings.service.ts | 105 +++++++++++++++++- .../accessibility-settings.component.ts | 22 +++- 2 files changed, 122 insertions(+), 5 deletions(-) diff --git a/src/app/accessibility/accessibility-settings.service.ts b/src/app/accessibility/accessibility-settings.service.ts index 77b6c91bea8..bdf1d296797 100644 --- a/src/app/accessibility/accessibility-settings.service.ts +++ b/src/app/accessibility/accessibility-settings.service.ts @@ -30,7 +30,7 @@ export enum AccessibilitySetting { LiveRegionTimeOut = 'liveRegionTimeOut', } -export type AccessibilitySettings = { [key in AccessibilitySetting]?: any }; +export type AccessibilitySettings = { [key in AccessibilitySetting]?: string }; /** * Service handling the retrieval and configuration of accessibility settings. @@ -235,4 +235,107 @@ export class AccessibilitySettingsService { } } + /** + * Returns the converter method for the provided setting. + * The converter methods are used to convert the value entered by the user in the form to the format that is used + * to store the setting value. + */ + getFormValueToStoredValueConverterMethod(setting: AccessibilitySetting): (value: string) => string { + switch (setting) { + case AccessibilitySetting.NotificationTimeOut: + return secondsToMilliseconds; + case AccessibilitySetting.LiveRegionTimeOut: + return secondsToMilliseconds; + default: + return null; + } + } + + /** + * Convert the user-configured value to the format used to store the setting value. + * Returns the provided value without conversion if no converter is configured for the provided setting. + */ + convertFormValueToStoredValue(setting: AccessibilitySetting, value: string): string { + const converterMethod = this.getFormValueToStoredValueConverterMethod(setting); + + if (hasValue(converterMethod)) { + return converterMethod(value); + } else { + return value; + } + } + + /** + * Convert all values in the provided accessibility settings object to values ready to be stored. + */ + convertAllFormValuesToStoredValues(settings: AccessibilitySettings): AccessibilitySettings { + const convertedSettings = {}; + + this.getAllAccessibilitySettingKeys().filter(setting => setting in settings).forEach(setting => + convertedSettings[setting] = this.convertFormValueToStoredValue(setting, settings[setting]) + ); + + return convertedSettings; + } + + /** + * Returns the converter method for the provided setting. + * The converter methods are used to convert the value as it is stored to the format visible by the user in the form. + */ + getStoredValueToFormValueConverterMethod(setting: AccessibilitySetting): (value: string) => string { + switch (setting) { + case AccessibilitySetting.NotificationTimeOut: + return millisecondsToSeconds; + case AccessibilitySetting.LiveRegionTimeOut: + return millisecondsToSeconds; + default: + return null; + } + } + + /** + * Convert the stored value to the format used in the form. + * Returns the provided value without conversion if no converter is configured for the provided setting. + */ + convertStoredValueToFormValue(setting: AccessibilitySetting, value: string): string { + const converterMethod = this.getStoredValueToFormValueConverterMethod(setting); + + if (hasValue(converterMethod)) { + return converterMethod(value); + } else { + return value; + } + } + + /** + * Convert all values in the provided accessibility settings object to values ready to show in the form. + */ + convertAllStoredValuesToFormValues(settings: AccessibilitySettings): AccessibilitySettings { + const convertedSettings = {}; + + this.getAllAccessibilitySettingKeys().filter(setting => setting in settings).forEach(setting => + convertedSettings[setting] = this.convertStoredValueToFormValue(setting, settings[setting]) + ); + + return convertedSettings; + } + +} + +function secondsToMilliseconds(secondsStr: string): string { + const seconds = parseFloat(secondsStr); + if (isNaN(seconds)) { + return null; + } else { + return (seconds * 1000).toString(); + } +} + +function millisecondsToSeconds(millisecondsStr: string): string { + const milliseconds = parseFloat(millisecondsStr); + if (isNaN(milliseconds)) { + return null; + } else { + return (milliseconds / 1000).toString(); + } } diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.ts b/src/app/info/accessibility-settings/accessibility-settings.component.ts index ed1d481be61..6d325e8f0cf 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.ts @@ -29,9 +29,7 @@ export class AccessibilitySettingsComponent implements OnInit { ngOnInit() { this.accessibilitySettingsOptions = this.settingsService.getAllAccessibilitySettingKeys(); - this.settingsService.getAll().pipe(take(1)).subscribe(currentSettings => { - this.formValues = currentSettings; - }); + this.updateFormValues(); } getInputType(setting: AccessibilitySetting): string { @@ -42,10 +40,26 @@ export class AccessibilitySettingsComponent implements OnInit { return this.settingsService.getPlaceholder(setting); } + /** + * Saves the user-configured settings + */ saveSettings() { - this.settingsService.setSettings(this.formValues).pipe(take(1)).subscribe(location => { + const formValues = this.formValues; + const convertedValues = this.settingsService.convertAllFormValuesToStoredValues(formValues); + this.settingsService.setSettings(convertedValues).pipe(take(1)).subscribe(location => { this.notificationsService.success(null, this.translateService.instant('info.accessibility-settings.save-notification.' + location)); }); + + this.updateFormValues(); + } + + /** + * Updates the form values with the currently stored accessibility settings + */ + updateFormValues() { + this.settingsService.getAll().pipe(take(1)).subscribe(storedSettings => { + this.formValues = this.settingsService.convertAllStoredValuesToFormValues(storedSettings); + }); } } From fdfa6e2c06042a22b6055760818406ea6b83ff9f Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 18 Nov 2024 14:26:48 +0100 Subject: [PATCH 04/15] 119602: Update values after converters implementation --- src/app/accessibility/accessibility-settings.service.ts | 4 ++-- src/assets/i18n/en.json5 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/accessibility/accessibility-settings.service.ts b/src/app/accessibility/accessibility-settings.service.ts index bdf1d296797..8434614434f 100644 --- a/src/app/accessibility/accessibility-settings.service.ts +++ b/src/app/accessibility/accessibility-settings.service.ts @@ -227,9 +227,9 @@ export class AccessibilitySettingsService { getPlaceholder(setting: AccessibilitySetting): string { switch (setting) { case AccessibilitySetting.NotificationTimeOut: - return environment.notifications.timeOut.toString(); + return millisecondsToSeconds(environment.notifications.timeOut.toString()); case AccessibilitySetting.LiveRegionTimeOut: - return environment.liveRegion.messageTimeOutDurationMs.toString(); + return millisecondsToSeconds(environment.liveRegion.messageTimeOutDurationMs.toString()); default: return ''; } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index dc69f0fbe86..6cf15ed8448 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1846,11 +1846,11 @@ "info.accessibility-settings.liveRegionTimeOut.label": "Live region time-out", - "info.accessibility-settings.liveRegionTimeOut.hint": "The duration in milliseconds after which a message in the live region disappears.", + "info.accessibility-settings.liveRegionTimeOut.hint": "The duration in seconds after which a message in the live region disappears.", "info.accessibility-settings.notificationTimeOut.label": "Notification time-out", - "info.accessibility-settings.notificationTimeOut.hint": "The duration in milliseconds after which a notification disappears. Set to 0 for notifications to remain indefinitely.", + "info.accessibility-settings.notificationTimeOut.hint": "The duration in seconds after which a notification disappears. Set to 0 for notifications to remain indefinitely.", "info.accessibility-settings.save-notification.cookie": "Successfully saved settings locally.", From dc8a699e94be3069b1eed53a3f9927d2aa151bec Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Fri, 22 Nov 2024 11:55:05 +0100 Subject: [PATCH 05/15] 119602: Rework convertion & form format --- .../accessibility-settings.service.ts | 108 +++--------------- .../accessibility-settings.component.html | 35 ++++-- .../accessibility-settings.component.ts | 16 +-- 3 files changed, 49 insertions(+), 110 deletions(-) diff --git a/src/app/accessibility/accessibility-settings.service.ts b/src/app/accessibility/accessibility-settings.service.ts index 8434614434f..48e2c8f5de9 100644 --- a/src/app/accessibility/accessibility-settings.service.ts +++ b/src/app/accessibility/accessibility-settings.service.ts @@ -32,6 +32,11 @@ export enum AccessibilitySetting { export type AccessibilitySettings = { [key in AccessibilitySetting]?: string }; +export interface AccessibilitySettingsFormValues { + notificationTimeOut: string, + liveRegionTimeOut: string, +} + /** * Service handling the retrieval and configuration of accessibility settings. * @@ -210,20 +215,6 @@ export class AccessibilitySettingsService { } } - /** - * Returns the input type that a form should use for the provided {@link AccessibilitySetting} - */ - getInputType(setting: AccessibilitySetting): string { - switch (setting) { - case AccessibilitySetting.NotificationTimeOut: - return 'number'; - case AccessibilitySetting.LiveRegionTimeOut: - return 'number'; - default: - return 'text'; - } - } - getPlaceholder(setting: AccessibilitySetting): string { switch (setting) { case AccessibilitySetting.NotificationTimeOut: @@ -236,88 +227,23 @@ export class AccessibilitySettingsService { } /** - * Returns the converter method for the provided setting. - * The converter methods are used to convert the value entered by the user in the form to the format that is used - * to store the setting value. + * Convert values in the provided accessibility settings object to values ready to be stored. */ - getFormValueToStoredValueConverterMethod(setting: AccessibilitySetting): (value: string) => string { - switch (setting) { - case AccessibilitySetting.NotificationTimeOut: - return secondsToMilliseconds; - case AccessibilitySetting.LiveRegionTimeOut: - return secondsToMilliseconds; - default: - return null; - } - } - - /** - * Convert the user-configured value to the format used to store the setting value. - * Returns the provided value without conversion if no converter is configured for the provided setting. - */ - convertFormValueToStoredValue(setting: AccessibilitySetting, value: string): string { - const converterMethod = this.getFormValueToStoredValueConverterMethod(setting); - - if (hasValue(converterMethod)) { - return converterMethod(value); - } else { - return value; - } + convertFormValuesToStoredValues(settings: AccessibilitySettingsFormValues): AccessibilitySettings { + return { + 'notificationTimeOut': secondsToMilliseconds(settings.notificationTimeOut), + 'liveRegionTimeOut': secondsToMilliseconds(settings.liveRegionTimeOut), + }; } /** - * Convert all values in the provided accessibility settings object to values ready to be stored. + * Convert values in the provided accessibility settings object to values ready to show in the form. */ - convertAllFormValuesToStoredValues(settings: AccessibilitySettings): AccessibilitySettings { - const convertedSettings = {}; - - this.getAllAccessibilitySettingKeys().filter(setting => setting in settings).forEach(setting => - convertedSettings[setting] = this.convertFormValueToStoredValue(setting, settings[setting]) - ); - - return convertedSettings; - } - - /** - * Returns the converter method for the provided setting. - * The converter methods are used to convert the value as it is stored to the format visible by the user in the form. - */ - getStoredValueToFormValueConverterMethod(setting: AccessibilitySetting): (value: string) => string { - switch (setting) { - case AccessibilitySetting.NotificationTimeOut: - return millisecondsToSeconds; - case AccessibilitySetting.LiveRegionTimeOut: - return millisecondsToSeconds; - default: - return null; - } - } - - /** - * Convert the stored value to the format used in the form. - * Returns the provided value without conversion if no converter is configured for the provided setting. - */ - convertStoredValueToFormValue(setting: AccessibilitySetting, value: string): string { - const converterMethod = this.getStoredValueToFormValueConverterMethod(setting); - - if (hasValue(converterMethod)) { - return converterMethod(value); - } else { - return value; - } - } - - /** - * Convert all values in the provided accessibility settings object to values ready to show in the form. - */ - convertAllStoredValuesToFormValues(settings: AccessibilitySettings): AccessibilitySettings { - const convertedSettings = {}; - - this.getAllAccessibilitySettingKeys().filter(setting => setting in settings).forEach(setting => - convertedSettings[setting] = this.convertStoredValueToFormValue(setting, settings[setting]) - ); - - return convertedSettings; + convertStoredValuesToFormValues(settings: AccessibilitySettings): AccessibilitySettingsFormValues { + return { + notificationTimeOut: millisecondsToSeconds(settings.notificationTimeOut), + liveRegionTimeOut: millisecondsToSeconds(settings.liveRegionTimeOut), + }; } } diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.html b/src/app/info/accessibility-settings/accessibility-settings.component.html index 8a76917462c..947bff495a1 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.html +++ b/src/app/info/accessibility-settings/accessibility-settings.component.html @@ -2,19 +2,36 @@

{{ 'info.accessibility-settings.title' | translate }}

-
-
diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.ts b/src/app/info/accessibility-settings/accessibility-settings.component.ts index ea7c853a972..0de18152eef 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.ts @@ -57,4 +57,14 @@ export class AccessibilitySettingsComponent implements OnInit { }); } + /** + * Resets accessibility settings + */ + resetSettings() { + this.settingsService.clearSettings().pipe(take(1)).subscribe(() => { + this.notificationsService.success(null, this.translateService.instant('info.accessibility-settings.reset-notification')); + this.updateFormValues(); + }); + } + } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index d9533da9c7f..69127375cf4 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1860,6 +1860,10 @@ "info.accessibility-settings.save-notification.metadata": "Successfully saved settings on the user profile.", + "info.accessibility-settings.reset-notification": "Successfully reset settings.", + + "info.accessibility-settings.reset": "Reset accessibility settings", + "info.accessibility-settings.submit": "Save accessibility settings", "info.accessibility-settings.title": "Accessibility settings", From 287d0283313beae07b7e8d0fcd47b71c349730c1 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Fri, 22 Nov 2024 16:03:52 +0100 Subject: [PATCH 08/15] 119602: Make input boxes smaller --- .../accessibility-settings.component.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.html b/src/app/info/accessibility-settings/accessibility-settings.component.html index 43371d33366..076cfdf9648 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.html +++ b/src/app/info/accessibility-settings/accessibility-settings.component.html @@ -7,7 +7,7 @@

{{ 'info.accessibility-settings.title' | translate }}

{{ 'info.accessibility-settings.disableNotificationTimeOut.label' | translate }} -
+
{{ 'info.accessibility-settings.title' | translate }} {{ 'info.accessibility-settings.notificationTimeOut.label' | translate }} -
+
{{ 'info.accessibility-settings.title' | translate }} {{ 'info.accessibility-settings.liveRegionTimeOut.label' | translate }} -
+
Date: Fri, 22 Nov 2024 16:09:12 +0100 Subject: [PATCH 09/15] 119602: Add unit after input fields --- .../accessibility-settings.component.html | 8 ++++++++ src/assets/i18n/en.json5 | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.html b/src/app/info/accessibility-settings/accessibility-settings.component.html index 076cfdf9648..d3c03f556b6 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.html +++ b/src/app/info/accessibility-settings/accessibility-settings.component.html @@ -35,6 +35,10 @@

{{ 'info.accessibility-settings.title' | translate }}

{{ 'info.accessibility-settings.notificationTimeOut.hint' | translate }}
+ +
+ {{ 'info.accessibility-settings.notificationTimeOut.unit' | translate }} +
@@ -52,6 +56,10 @@

{{ 'info.accessibility-settings.title' | translate }}

{{ 'info.accessibility-settings.liveRegionTimeOut.hint' | translate }}
+ +
+ {{ 'info.accessibility-settings.liveRegionTimeOut.unit' | translate }} +
diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 69127375cf4..54286d60744 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1850,11 +1850,15 @@ "info.accessibility-settings.liveRegionTimeOut.label": "Live region time-out", - "info.accessibility-settings.liveRegionTimeOut.hint": "The duration in seconds after which a message in the live region disappears.", + "info.accessibility-settings.liveRegionTimeOut.hint": "The duration after which a message in the live region disappears.", + + "info.accessibility-settings.liveRegionTimeOut.unit": "Seconds", "info.accessibility-settings.notificationTimeOut.label": "Notification time-out", - "info.accessibility-settings.notificationTimeOut.hint": "The duration in seconds after which a notification disappears.", + "info.accessibility-settings.notificationTimeOut.hint": "The duration after which a notification disappears.", + + "info.accessibility-settings.notificationTimeOut.unit": "Seconds", "info.accessibility-settings.save-notification.cookie": "Successfully saved settings locally.", From 5a28e66b2f6b6c8335821eb5526f7f347810115d Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 25 Nov 2024 09:44:27 +0100 Subject: [PATCH 10/15] 119602: Move hints to contextHelp --- .../accessibility-settings.component.html | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.html b/src/app/info/accessibility-settings/accessibility-settings.component.html index d3c03f556b6..d247b12f949 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.html +++ b/src/app/info/accessibility-settings/accessibility-settings.component.html @@ -7,15 +7,19 @@

{{ 'info.accessibility-settings.title' | translate }}

{{ 'info.accessibility-settings.disableNotificationTimeOut.label' | translate }} -
+
+
- - {{ 'info.accessibility-settings.disableNotificationTimeOut.hint' | translate }} - +
@@ -30,15 +34,19 @@

{{ 'info.accessibility-settings.title' | translate }}

[readOnly]="formValues.disableNotificationTimeOut" [(ngModel)]="formValues.notificationTimeOut" [ngModelOptions]="{ standalone: true }" [attr.aria-describedby]="'notificationTimeOutHint'"> - - - {{ 'info.accessibility-settings.notificationTimeOut.hint' | translate }} -
-
+
{{ 'info.accessibility-settings.notificationTimeOut.unit' | translate }}
+ +
+
@@ -51,15 +59,19 @@

{{ 'info.accessibility-settings.title' | translate }}

[placeholder]="getPlaceholder(AccessibilitySetting.LiveRegionTimeOut)" [(ngModel)]="formValues.liveRegionTimeOut" [ngModelOptions]="{ standalone: true }" [attr.aria-describedby]="'liveRegionTimeOutHint'"> - - - {{ 'info.accessibility-settings.liveRegionTimeOut.hint' | translate }} -
-
+
{{ 'info.accessibility-settings.liveRegionTimeOut.unit' | translate }}
+ +
+
From ced163a25f40dabd446c9141f10aa6e69b1460a8 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 25 Nov 2024 09:49:09 +0100 Subject: [PATCH 11/15] 119602: Remove obsolete tests --- .../accessibility-settings.service.spec.ts | 8 -------- .../accessibility-settings.component.spec.ts | 13 +------------ 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/app/accessibility/accessibility-settings.service.spec.ts b/src/app/accessibility/accessibility-settings.service.spec.ts index d6f61840575..5344c31d452 100644 --- a/src/app/accessibility/accessibility-settings.service.spec.ts +++ b/src/app/accessibility/accessibility-settings.service.spec.ts @@ -368,12 +368,4 @@ describe('accessibilitySettingsService', () => { }); }); - describe('getInputType', () => { - it('should correctly return the input type', () => { - expect(service.getInputType(AccessibilitySetting.NotificationTimeOut)).toEqual('number'); - expect(service.getInputType(AccessibilitySetting.LiveRegionTimeOut)).toEqual('number'); - expect(service.getInputType('unknownValue' as AccessibilitySetting)).toEqual('text'); - }); - }); - }); diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts b/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts index f6d3252a384..3ba0e1ab967 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts @@ -4,7 +4,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { AuthServiceStub } from '../../shared/testing/auth-service.stub'; import { getAccessibilitySettingsServiceStub } from '../../accessibility/accessibility-settings.service.stub'; -import { AccessibilitySettingsService, AccessibilitySetting } from '../../accessibility/accessibility-settings.service'; +import { AccessibilitySettingsService } from '../../accessibility/accessibility-settings.service'; import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub'; import { AuthService } from '../../core/auth/auth.service'; import { NotificationsService } from '../../shared/notifications/notifications.service'; @@ -47,22 +47,11 @@ describe('AccessibilitySettingsComponent', () => { }); describe('On Init', () => { - it('should retrieve all accessibility settings options', () => { - expect(settingsService.getAllAccessibilitySettingKeys).toHaveBeenCalled(); - }); - it('should retrieve the current settings', () => { expect(settingsService.getAll).toHaveBeenCalled(); }); }); - describe('getInputType', () => { - it('should retrieve the input type for the setting from the service', () => { - component.getInputType(AccessibilitySetting.LiveRegionTimeOut); - expect(settingsService.getInputType).toHaveBeenCalledWith(AccessibilitySetting.LiveRegionTimeOut); - }); - }); - describe('saveSettings', () => { it('should save the settings in the service', () => { settingsService.setSettings = jasmine.createSpy('setSettings').and.returnValue(of('cookie')); From ec016e80fb931f8f9ea25a64e0cbeab8d8c4dc16 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 25 Nov 2024 10:00:04 +0100 Subject: [PATCH 12/15] 119602: Update AccessibilitySettingsService stub --- .../accessibility/accessibility-settings.service.stub.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/accessibility/accessibility-settings.service.stub.ts b/src/app/accessibility/accessibility-settings.service.stub.ts index b619a337de9..4ac965059e6 100644 --- a/src/app/accessibility/accessibility-settings.service.stub.ts +++ b/src/app/accessibility/accessibility-settings.service.stub.ts @@ -31,4 +31,10 @@ export class AccessibilitySettingsServiceStub { setSettingsInCookie = jasmine.createSpy('setSettingsInCookie'); getInputType = jasmine.createSpy('getInputType').and.returnValue('text'); + + convertFormValuesToStoredValues = jasmine.createSpy('convertFormValuesToStoredValues').and.returnValue({}); + + convertStoredValuesToFormValues = jasmine.createSpy('convertStoredValuesToFormValues').and.returnValue({}); + + getPlaceholder = jasmine.createSpy('getPlaceholder').and.returnValue('placeholder'); } From deb4a63c88dce3b9dd906911cfc2cd83a6ffc8e5 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 25 Nov 2024 10:12:39 +0100 Subject: [PATCH 13/15] 119602: Add additional accessibilitySettingsComponent tests --- .../accessibility-settings.component.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts b/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts index 3ba0e1ab967..bcd4ff94c86 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.spec.ts @@ -50,6 +50,10 @@ describe('AccessibilitySettingsComponent', () => { it('should retrieve the current settings', () => { expect(settingsService.getAll).toHaveBeenCalled(); }); + + it('should convert retrieved settings to form format', () => { + expect(settingsService.convertStoredValuesToFormValues).toHaveBeenCalled(); + }); }); describe('saveSettings', () => { @@ -59,6 +63,12 @@ describe('AccessibilitySettingsComponent', () => { expect(settingsService.setSettings).toHaveBeenCalled(); }); + it('should convert form settings to stored format', () => { + settingsService.setSettings = jasmine.createSpy('setSettings').and.returnValue(of('cookie')); + component.saveSettings(); + expect(settingsService.convertFormValuesToStoredValues).toHaveBeenCalled(); + }); + it('should give the user a notification mentioning where the settings were saved', () => { settingsService.setSettings = jasmine.createSpy('setSettings').and.returnValue(of('cookie')); component.saveSettings(); From c38352ed22072921469b7c8b7f00ef6bc18a0019 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Mon, 25 Nov 2024 10:29:16 +0100 Subject: [PATCH 14/15] 119602: Update doc comments --- .../accessibility-settings.service.ts | 14 ++++++++++++-- .../accessibility-settings.component.ts | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/accessibility/accessibility-settings.service.ts b/src/app/accessibility/accessibility-settings.service.ts index e86742d76de..f2151675391 100644 --- a/src/app/accessibility/accessibility-settings.service.ts +++ b/src/app/accessibility/accessibility-settings.service.ts @@ -23,16 +23,22 @@ export const ACCESSIBILITY_SETTINGS_METADATA_KEY = 'dspace.accessibility.setting /** * Enum containing all possible accessibility settings. - * When adding new settings, the {@link AccessibilitySettingsService#getInputType} method and the i18n keys for the - * accessibility settings page should be updated. + * When adding new settings, make sure to add the new setting to the accessibility-settings component. + * The converter methods to convert from stored format to form format (and vice-versa) need to be updated as well. */ export enum AccessibilitySetting { NotificationTimeOut = 'notificationTimeOut', LiveRegionTimeOut = 'liveRegionTimeOut', } +/** + * Type representing an object that contains accessibility settings values. + */ export type AccessibilitySettings = { [key in AccessibilitySetting]?: string }; +/** + * The accessibility settings object format used by the accessibility-settings component form. + */ export interface AccessibilitySettingsFormValues { disableNotificationTimeOut: boolean, notificationTimeOut: string, @@ -226,6 +232,10 @@ export class AccessibilitySettingsService { return this.setSettingsInAuthenticatedUserMetadata({}); } + /** + * Retrieve the placeholder to be used for the provided AccessibilitySetting. + * Returns an empty string when no placeholder is specified for the provided setting. + */ getPlaceholder(setting: AccessibilitySetting): string { switch (setting) { case AccessibilitySetting.NotificationTimeOut: diff --git a/src/app/info/accessibility-settings/accessibility-settings.component.ts b/src/app/info/accessibility-settings/accessibility-settings.component.ts index 0de18152eef..cd417393d44 100644 --- a/src/app/info/accessibility-settings/accessibility-settings.component.ts +++ b/src/app/info/accessibility-settings/accessibility-settings.component.ts @@ -9,6 +9,9 @@ import { take } from 'rxjs'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; +/** + * Component providing the form where users can update accessibility settings. + */ @Component({ selector: 'ds-accessibility-settings', templateUrl: './accessibility-settings.component.html' From 56d82764fd0d58e5b3ea2dd9bf15d2e90c754051 Mon Sep 17 00:00:00 2001 From: Andreas Awouters Date: Fri, 29 Nov 2024 09:43:08 +0100 Subject: [PATCH 15/15] 119602: Fix compares --- .../notifications-board.component.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/app/shared/notifications/notifications-board/notifications-board.component.ts b/src/app/shared/notifications/notifications-board/notifications-board.component.ts index 20bf7175f6f..c6abb39f705 100644 --- a/src/app/shared/notifications/notifications-board/notifications-board.component.ts +++ b/src/app/shared/notifications/notifications-board/notifications-board.component.ts @@ -10,8 +10,6 @@ import { import { select, Store } from '@ngrx/store'; import { BehaviorSubject, Subscription, take } from 'rxjs'; -import difference from 'lodash/difference'; - import { NotificationsService } from '../notifications.service'; import { AppState } from '../../../app.reducer'; import { notificationsStateSelector } from '../selectors'; @@ -23,6 +21,7 @@ import { AccessibilitySetting } from '../../../accessibility/accessibility-settings.service'; import cloneDeep from 'lodash/cloneDeep'; +import differenceWith from 'lodash/differenceWith'; @Component({ selector: 'ds-notifications-board', @@ -69,13 +68,13 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy { this.notifications = []; } else if (state.length > this.notifications.length) { // Add - const newElem = difference(state, this.notifications); + const newElem = differenceWith(state, this.notifications, this.toCheck); newElem.forEach((notification) => { this.add(notification); }); } else { // Remove - const delElem = difference(this.notifications, state); + const delElem = differenceWith(this.notifications, state, this.toCheck); delElem.forEach((notification) => { this.notifications = this.notifications.filter((item: INotification) => item.id !== notification.id); @@ -117,16 +116,15 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy { } private block(item: INotification): boolean { - const toCheck = item.html ? this.checkHtml : this.checkStandard; this.notifications.forEach((notification) => { - if (toCheck(notification, item)) { + if (this.toCheck(notification, item)) { return true; } }); if (this.notifications.length > 0) { this.notifications.forEach((notification) => { - if (toCheck(notification, item)) { + if (this.toCheck(notification, item)) { return true; } }); @@ -138,9 +136,17 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy { } else { return false; } - return toCheck(comp, item); + return this.toCheck(comp, item); } + private toCheck = (checker: INotification, item: INotification) => { + if (item.html) { + return this.checkHtml(checker, item); + } else { + return this.checkStandard(checker, item); + } + }; + private checkStandard(checker: INotification, item: INotification): boolean { return checker.type === item.type && checker.title === item.title && checker.content === item.content; }