You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi/ClientApp/src/app/settings/notifications/ntfy.component.ts

71 lines
2.5 KiB

import { Component, OnInit } from "@angular/core";
import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { INtfyNotificationSettings, INotificationTemplates, NotificationType } from "../../interfaces";
import { TesterService } from "../../services";
import { NotificationService } from "../../services";
import { SettingsService } from "../../services";
@Component({
templateUrl: "./ntfy.component.html",
styleUrls: ["./notificationtemplate.component.scss"]
})
export class NtfyComponent implements OnInit {
public NotificationType = NotificationType;
public templates: INotificationTemplates[];
public form: UntypedFormGroup;
constructor(private settingsService: SettingsService,
private notificationService: NotificationService,
private fb: UntypedFormBuilder,
private testerService: TesterService) { }
public ngOnInit() {
this.settingsService.getNtfyNotificationSettings().subscribe(x => {
this.templates = x.notificationTemplates;
this.form = this.fb.group({
enabled: [x.enabled],
baseUrl: [x.baseUrl, [Validators.required]],
authorizationHeader: [x.authorizationHeader, []],
topic: [x.topic, [Validators.required]],
priority: [x.priority],
});
});
}
public onSubmit(form: UntypedFormGroup) {
if (form.invalid) {
this.notificationService.error("Please check your entered values");
return;
}
const settings = <INtfyNotificationSettings> form.value;
settings.notificationTemplates = this.templates;
this.settingsService.saveNtfyNotificationSettings(settings).subscribe(x => {
if (x) {
this.notificationService.success("Successfully saved the Ntfy settings");
} else {
this.notificationService.success("There was an error when saving the Ntfy settings");
}
});
}
public test(form: UntypedFormGroup) {
if (form.invalid) {
this.notificationService.error("Please check your entered values");
return;
}
this.testerService.ntfyTest(form.value).subscribe(x => {
if (x) {
this.notificationService.success("Successfully sent a Ntfy message");
} else {
this.notificationService.error("There was an error when sending the Ntfy message. Please check your settings");
}
});
}
}