50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { Component } from '@angular/core';
|
|
import {NtfyService} from "../../../../api";
|
|
import {Form, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
|
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
|
|
|
@Component({
|
|
selector: 'app-ntfy-settings',
|
|
templateUrl: './ntfy-settings.component.html',
|
|
styleUrls: ['./ntfy-settings.component.css']
|
|
})
|
|
export class NtfySettingsComponent {
|
|
|
|
host_formCtrl = new FormControl('', [Validators.required])
|
|
topic_formCtrl = new FormControl('', [Validators.required])
|
|
user_formCtrl = new FormControl('', [Validators.required])
|
|
token_formCtrl = new FormControl('', [Validators.required])
|
|
|
|
constructor(private ntfyService: NtfyService,
|
|
private snackbar: MatSnackBar) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.ntfyService.ntfyGet().subscribe({
|
|
next: resp => {
|
|
this.host_formCtrl.setValue(resp.ntfy_host);
|
|
this.topic_formCtrl.setValue(resp.ntfy_topic);
|
|
this.user_formCtrl.setValue(resp.ntfy_user);
|
|
this.token_formCtrl.setValue(resp.ntfy_token!);
|
|
}
|
|
})
|
|
}
|
|
|
|
save() {
|
|
const token = this.token_formCtrl.value === "****" ? "" : this.token_formCtrl.value!
|
|
const user = this.user_formCtrl.value === "****" ? "" : this.user_formCtrl.value!
|
|
this.ntfyService.ntfyPost({
|
|
ntfy_host: this.host_formCtrl.value!,
|
|
ntfy_topic: this.topic_formCtrl.value!,
|
|
ntfy_token: token,
|
|
ntfy_user: user
|
|
}).subscribe({
|
|
next: resp => {
|
|
this.snackbar.open("Ntfy-Configuration updated", "", {duration: 2000})
|
|
this.user_formCtrl.setValue("****");
|
|
this.token_formCtrl.setValue("****");
|
|
}
|
|
})
|
|
}
|
|
}
|