Front/Back: add entry settings modal

This commit is contained in:
X4Lo committed 2024-10-21 15:43:09 +01:00
1 parent 8724a96b81
commit 625ec3367e
15 files changed
+334 -57

No files matched your search

@@ -0,0 +1,59 @@
import { Component, Inject, OnInit } from '@angular/core';
import {
MatDialogRef,
MAT_DIALOG_DATA,
MatDialog,
} from '@angular/material/dialog';
import { EntryService } from '../../../core/services/entry.service';
import { FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'app-entry-settings-modal',
templateUrl: './entry-settings-modal.component.html',
styleUrls: ['./entry-settings-modal.component.css'],
})
export class EntrySettingsModalComponent implements OnInit {
entryId!: number;
entryForm: FormGroup;
constructor(
public dialogRef: MatDialogRef<EntrySettingsModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private formBuilder: FormBuilder,
private entryService: EntryService
) {
this.entryForm = this.formBuilder.group({
watchlist: [null],
favorit: [null],
hidden: [null],
showInCalendar: [null],
autoSync: [null],
});
if (this.data && this.data.entry) {
this.entryForm.patchValue(this.data.entry);
this.entryId = this.data.entry.id;
} else {
this.dialogRef.close();
}
}
ngOnInit() {}
onSubmit() {
const entryData = this.entryForm.value;
this.entryService.updateEntry(this.entryId, entryData).subscribe({
next: (result) => {
this.dialogRef.close({ entry: result });
},
error: (error) => {
console.log(error);
},
});
}
onClose() {
this.dialogRef.close();
}
}