blrec/webapp/src/app/settings/notification-settings/serverchan-notification-settings/serverchan-notification-settings.component.ts
2022-06-18 16:25:23 +08:00

54 lines
1.6 KiB
TypeScript

import {
Component,
OnInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import pick from 'lodash-es/pick';
import {
KEYS_OF_MESSAGE_TEMPLATE_SETTINGS,
KEYS_OF_NOTIFICATION_SETTINGS,
KEYS_OF_NOTIFIER_SETTINGS,
KEYS_OF_SERVERCHAN_SETTINGS,
MessageTemplateSettings,
NotificationSettings,
NotifierSettings,
ServerchanNotificationSettings,
ServerchanSettings,
} from '../../shared/setting.model';
@Component({
selector: 'app-serverchan-notification-settings',
templateUrl: './serverchan-notification-settings.component.html',
styleUrls: ['./serverchan-notification-settings.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ServerchanNotificationSettingsComponent implements OnInit {
serverchanSettings!: ServerchanSettings;
notifierSettings!: NotifierSettings;
notificationSettings!: NotificationSettings;
messageTemplateSettings!: MessageTemplateSettings;
constructor(
private changeDetector: ChangeDetectorRef,
private route: ActivatedRoute
) {}
ngOnInit(): void {
this.route.data.subscribe((data) => {
const settings = data.settings as ServerchanNotificationSettings;
this.serverchanSettings = pick(settings, KEYS_OF_SERVERCHAN_SETTINGS);
this.notifierSettings = pick(settings, KEYS_OF_NOTIFIER_SETTINGS);
this.notificationSettings = pick(settings, KEYS_OF_NOTIFICATION_SETTINGS);
this.messageTemplateSettings = pick(
settings,
KEYS_OF_MESSAGE_TEMPLATE_SETTINGS
);
this.changeDetector.markForCheck();
});
}
}