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 { entryId!: number; entryForm: FormGroup; constructor( public dialogRef: MatDialogRef, @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(); } } 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 while updating entry settings`, error); this.dialogRef.close(); }, }); } onClose() { this.dialogRef.close(); } }