Browse Source

Merge pull request #9825 from ArtemDzhereleiko/AD/bug-fix/notification-settings/backward-compatibility

Fixed backward compatibility for notification settings
pull/9861/head
Igor Kulikov 3 years ago
committed by GitHub
parent
commit
6d131e42dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      ui-ngx/src/app/modules/home/pages/notification/settings/notification-settings.component.ts

23
ui-ngx/src/app/modules/home/pages/notification/settings/notification-settings.component.ts

@ -74,16 +74,10 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn
private patchNotificationSettings(settings: NotificationUserSettings) {
const notificationSettingsControls: Array<AbstractControl> = [];
let preparedSettings;
if (settings.prefs) {
preparedSettings = this.prepareNotificationSettings(settings.prefs);
preparedSettings.forEach((setting) => {
setting.enabledDeliveryMethods = Object.assign(
this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}),
setting.enabledDeliveryMethods
);
notificationSettingsControls.push(this.fb.control(setting, [Validators.required]));
});
this.prepareNotificationSettings(settings.prefs).forEach(setting =>
notificationSettingsControls.push(this.fb.control(setting, [Validators.required]))
);
}
this.notificationSettings.setControl('prefs', this.fb.array(notificationSettingsControls), {emitEvent: false});
}
@ -91,6 +85,17 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn
private prepareNotificationSettings(prefs: any) {
return Object.entries(prefs).map((value: any) => {
value[1].name = value[0];
if (!value[1].enabled && Object.values(value[1].enabledDeliveryMethods).some(deliveryMethod => deliveryMethod === true)) {
const enabledDeliveryMethod = deepClone(value[1].enabledDeliveryMethods);
Object.keys(enabledDeliveryMethod).forEach(key => {
enabledDeliveryMethod[key] = false;
});
value[1].enabledDeliveryMethods = enabledDeliveryMethod;
}
value[1].enabledDeliveryMethods = Object.assign(
this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}),
value[1].enabledDeliveryMethods
);
return value[1];
});
}

Loading…
Cancel
Save