Browse Source

UI: Refactoring

pull/8903/head
Artem Dzhereleiko 3 years ago
parent
commit
642066d9b0
  1. 2
      ui-ngx/src/app/modules/home/pages/notification/settings/notification-setting-form.component.html
  2. 11
      ui-ngx/src/app/modules/home/pages/notification/settings/notification-setting-form.component.ts
  3. 5
      ui-ngx/src/app/modules/home/pages/notification/settings/notification-settings.component.html
  4. 18
      ui-ngx/src/app/modules/home/pages/notification/settings/notification-settings.component.ts
  5. 6
      ui-ngx/src/app/shared/models/notification.models.ts

2
ui-ngx/src/app/modules/home/pages/notification/settings/notification-setting-form.component.html

@ -27,7 +27,7 @@
</span> </span>
</mat-checkbox> </mat-checkbox>
</div> </div>
<div fxFlex fxLayout="row" *ngFor="let deliveryMethods of notificationDeliveryMethodMap"> <div fxFlex fxLayout="row" *ngFor="let deliveryMethods of deliveryMethods">
<div fxFlex fxLayoutAlign="start center"> <div fxFlex fxLayoutAlign="start center">
<mat-checkbox color="primary" <mat-checkbox color="primary"
[disabled]="!allowDeliveryMethods?.includes(deliveryMethods) || !notificationSettingsFormGroup.get('enabled').value" [disabled]="!allowDeliveryMethods?.includes(deliveryMethods) || !notificationSettingsFormGroup.get('enabled').value"

11
ui-ngx/src/app/modules/home/pages/notification/settings/notification-setting-form.component.ts

@ -20,7 +20,7 @@ import { UtilsService } from '@core/services/utils.service';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { import {
NotificationDeliveryMethod, NotificationSettingsDeliveryMethod, NotificationDeliveryMethod,
NotificationTemplateTypeTranslateMap, NotificationTemplateTypeTranslateMap,
NotificationUserSetting NotificationUserSetting
} from '@shared/models/notification.models'; } from '@shared/models/notification.models';
@ -43,12 +43,13 @@ export class NotificationSettingFormComponent implements ControlValueAccessor, O
disabled: boolean; disabled: boolean;
@Input() @Input()
allowDeliveryMethods = []; deliveryMethods: NotificationDeliveryMethod[] = [];
@Input()
allowDeliveryMethods: NotificationDeliveryMethod[] = [];
notificationSettingsFormGroup: UntypedFormGroup; notificationSettingsFormGroup: UntypedFormGroup;
notificationDeliveryMethod = NotificationSettingsDeliveryMethod;
notificationDeliveryMethodMap = Object.values(NotificationSettingsDeliveryMethod);
notificationTemplateTypeTranslateMap = NotificationTemplateTypeTranslateMap; notificationTemplateTypeTranslateMap = NotificationTemplateTypeTranslateMap;
private propagateChange = null; private propagateChange = null;
@ -68,7 +69,7 @@ export class NotificationSettingFormComponent implements ControlValueAccessor, O
ngOnInit() { ngOnInit() {
const deliveryMethod = {}; const deliveryMethod = {};
this.notificationDeliveryMethodMap.forEach(value => { this.deliveryMethods.forEach(value => {
deliveryMethod[value] = true; deliveryMethod[value] = true;
}); });
this.notificationSettingsFormGroup = this.fb.group( this.notificationSettingsFormGroup = this.fb.group(

5
ui-ngx/src/app/modules/home/pages/notification/settings/notification-settings.component.html

@ -62,7 +62,10 @@
</div> </div>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<div *ngFor="let settingsControl of notificationSettingsFormArray.controls; let i = index; let $last = last;"> <div *ngFor="let settingsControl of notificationSettingsFormArray.controls; let i = index; let $last = last;">
<tb-notification-setting-form [formControl]="settingsControl" [allowDeliveryMethods]="allowNotificationDeliveryMethods"></tb-notification-setting-form> <tb-notification-setting-form [formControl]="settingsControl"
[deliveryMethods]="notificationDeliveryMethods"
[allowDeliveryMethods]="allowNotificationDeliveryMethods">
</tb-notification-setting-form>
<mat-divider *ngIf="!$last"></mat-divider> <mat-divider *ngIf="!$last"></mat-divider>
</div> </div>
</div> </div>

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

@ -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, NotificationSettingsDeliveryMethod, NotificationDeliveryMethodTranslateMap,
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 = Object.values(NotificationSettingsDeliveryMethod); notificationDeliveryMethods: NotificationDeliveryMethod[];
notificationDeliveryMethodTranslateMap = NotificationDeliveryMethodTranslateMap; notificationDeliveryMethodTranslateMap = NotificationDeliveryMethodTranslateMap;
allowNotificationDeliveryMethods: Array<NotificationDeliveryMethod>; allowNotificationDeliveryMethods: Array<NotificationDeliveryMethod>;
@ -55,6 +55,7 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn
} }
ngOnInit() { ngOnInit() {
this.notificationDeliveryMethods = this.getNotificationDeliveryMethods();
this.notificationService.getAvailableDeliveryMethods({ignoreLoading: true}).subscribe(allowMethods => { this.notificationService.getAvailableDeliveryMethods({ignoreLoading: true}).subscribe(allowMethods => {
this.allowNotificationDeliveryMethods = allowMethods; this.allowNotificationDeliveryMethods = allowMethods;
@ -64,6 +65,15 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn
this.patchNotificationSettings(this.route.snapshot.data.userSettings); this.patchNotificationSettings(this.route.snapshot.data.userSettings);
} }
private getNotificationDeliveryMethods(): NotificationDeliveryMethod[] {
const deliveryMethods = new Set([
NotificationDeliveryMethod.WEB,
NotificationDeliveryMethod.SMS,
NotificationDeliveryMethod.EMAIL
]);
return Object.values(NotificationDeliveryMethod).filter(type => deliveryMethods.has(type));
}
private buildNotificationSettingsForm() { private buildNotificationSettingsForm() {
this.notificationSettings = this.fb.group({ this.notificationSettings = this.fb.group({
prefs: this.fb.array([]) prefs: this.fb.array([])
@ -77,8 +87,8 @@ export class NotificationSettingsComponent extends PageComponent implements OnIn
preparedSettings = this.prepareNotificationSettings(settings.prefs); preparedSettings = this.prepareNotificationSettings(settings.prefs);
preparedSettings.forEach((setting) => { preparedSettings.forEach((setting) => {
setting.enabledDeliveryMethods = Object.assign( setting.enabledDeliveryMethods = Object.assign(
setting.enabledDeliveryMethods, this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}),
this.notificationDeliveryMethods.reduce((a, v) => ({ ...a, [v]: true}), {}) setting.enabledDeliveryMethods
); );
notificationSettingsControls.push(this.fb.control(setting, [Validators.required])); notificationSettingsControls.push(this.fb.control(setting, [Validators.required]));
}); });

6
ui-ngx/src/app/shared/models/notification.models.ts

@ -598,9 +598,3 @@ export interface NotificationUserSetting {
enabled: boolean; enabled: boolean;
enabledDeliveryMethods: {[key: string]: boolean}; enabledDeliveryMethods: {[key: string]: boolean};
} }
export enum NotificationSettingsDeliveryMethod {
WEB = 'WEB',
SMS = 'SMS',
EMAIL = 'EMAIL'
}

Loading…
Cancel
Save