|
|
@ -25,7 +25,7 @@ import { ActivatedRoute } from '@angular/router'; |
|
|
import { deepClone, isDefinedAndNotNull } from '@core/utils'; |
|
|
import { deepClone, isDefinedAndNotNull } from '@core/utils'; |
|
|
import { |
|
|
import { |
|
|
NotificationDeliveryMethod, |
|
|
NotificationDeliveryMethod, |
|
|
NotificationDeliveryMethodTranslateMap, |
|
|
NotificationDeliveryMethodTranslateMap, NotificationSettingsDeliveryMethod, |
|
|
NotificationUserSettings |
|
|
NotificationUserSettings |
|
|
} from '@shared/models/notification.models'; |
|
|
} from '@shared/models/notification.models'; |
|
|
import { NotificationService } from '@core/http/notification.service'; |
|
|
import { NotificationService } from '@core/http/notification.service'; |
|
|
@ -40,7 +40,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
|
|
|
|
|
|
notificationSettings: UntypedFormGroup; |
|
|
notificationSettings: UntypedFormGroup; |
|
|
|
|
|
|
|
|
notificationDeliveryMethods = [NotificationDeliveryMethod.WEB, NotificationDeliveryMethod.SMS, NotificationDeliveryMethod.EMAIL]; |
|
|
notificationDeliveryMethods = Object.values(NotificationSettingsDeliveryMethod); |
|
|
notificationDeliveryMethodTranslateMap = NotificationDeliveryMethodTranslateMap; |
|
|
notificationDeliveryMethodTranslateMap = NotificationDeliveryMethodTranslateMap; |
|
|
|
|
|
|
|
|
allowNotificationDeliveryMethods: Array<NotificationDeliveryMethod>; |
|
|
allowNotificationDeliveryMethods: Array<NotificationDeliveryMethod>; |
|
|
@ -76,6 +76,10 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
if (settings.prefs) { |
|
|
if (settings.prefs) { |
|
|
preparedSettings = this.prepareNotificationSettings(settings.prefs); |
|
|
preparedSettings = this.prepareNotificationSettings(settings.prefs); |
|
|
preparedSettings.forEach((setting) => { |
|
|
preparedSettings.forEach((setting) => { |
|
|
|
|
|
setting.enabledDeliveryMethods = Object.assign( |
|
|
|
|
|
setting.enabledDeliveryMethods, |
|
|
|
|
|
this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}) |
|
|
|
|
|
); |
|
|
notificationSettingsControls.push(this.fb.control(setting, [Validators.required])); |
|
|
notificationSettingsControls.push(this.fb.control(setting, [Validators.required])); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -105,7 +109,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
if (settings) { |
|
|
if (settings) { |
|
|
settings.forEach((setting) => { |
|
|
settings.forEach((setting) => { |
|
|
setting.enabled = true; |
|
|
setting.enabled = true; |
|
|
setting.enabledDeliveryMethods = this.notificationDeliveryMethods; |
|
|
setting.enabledDeliveryMethods = this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}); |
|
|
notificationSettingsControls.push(this.fb.control(setting, [Validators.required])); |
|
|
notificationSettingsControls.push(this.fb.control(setting, [Validators.required])); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -119,7 +123,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
getChecked = (method: NotificationDeliveryMethod = null): boolean => { |
|
|
getChecked = (method: NotificationDeliveryMethod = null): boolean => { |
|
|
const type = this.notificationSettings.get('prefs').value; |
|
|
const type = this.notificationSettings.get('prefs').value; |
|
|
if (isDefinedAndNotNull(method)) { |
|
|
if (isDefinedAndNotNull(method)) { |
|
|
return isDefinedAndNotNull(type) && type.every(resource => resource.enabledDeliveryMethods.includes(method)); |
|
|
return isDefinedAndNotNull(type) && type.every(resource => resource.enabledDeliveryMethods[method]); |
|
|
} |
|
|
} |
|
|
return isDefinedAndNotNull(type) && type.every(resource => resource.enabled); |
|
|
return isDefinedAndNotNull(type) && type.every(resource => resource.enabled); |
|
|
}; |
|
|
}; |
|
|
@ -133,7 +137,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
const type = this.notificationSettings.get('prefs').value; |
|
|
const type = this.notificationSettings.get('prefs').value; |
|
|
if (isDefinedAndNotNull(type)) { |
|
|
if (isDefinedAndNotNull(type)) { |
|
|
const checkedResource = isDefinedAndNotNull(deliveryMethod) ? |
|
|
const checkedResource = isDefinedAndNotNull(deliveryMethod) ? |
|
|
type.filter(resource => resource.enabledDeliveryMethods.includes(deliveryMethod)) : |
|
|
type.filter(resource => resource.enabledDeliveryMethods[deliveryMethod]) : |
|
|
type.filter(resource => resource.enabled); |
|
|
type.filter(resource => resource.enabled); |
|
|
return checkedResource.length !== 0 && checkedResource.length !== type.length; |
|
|
return checkedResource.length !== 0 && checkedResource.length !== type.length; |
|
|
} |
|
|
} |
|
|
@ -143,13 +147,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn |
|
|
changeInstanceTypeCheckBox = (value: boolean, deliveryMethod: NotificationDeliveryMethod = null): void => { |
|
|
changeInstanceTypeCheckBox = (value: boolean, deliveryMethod: NotificationDeliveryMethod = null): void => { |
|
|
const type = deepClone(this.notificationSettings.get('prefs').value); |
|
|
const type = deepClone(this.notificationSettings.get('prefs').value); |
|
|
if (isDefinedAndNotNull(deliveryMethod)) { |
|
|
if (isDefinedAndNotNull(deliveryMethod)) { |
|
|
type.forEach(notificationType => { |
|
|
type.forEach(notificationType => notificationType.enabledDeliveryMethods[deliveryMethod] = value); |
|
|
if (value && !notificationType.enabledDeliveryMethods.includes(deliveryMethod)) { |
|
|
|
|
|
notificationType.enabledDeliveryMethods.push(deliveryMethod); |
|
|
|
|
|
} else if (!value && notificationType.enabledDeliveryMethods.includes(deliveryMethod)) { |
|
|
|
|
|
notificationType.enabledDeliveryMethods.splice(notificationType.enabledDeliveryMethods.indexOf(deliveryMethod), 1); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
type.forEach(notificationType => notificationType.enabled = value); |
|
|
type.forEach(notificationType => notificationType.enabled = value); |
|
|
} |
|
|
} |
|
|
|