Files
kmtnflower/src/app/admin/admin-history-tab.component.ts
T

46 lines
1.2 KiB
TypeScript

import { Component, inject, output } from '@angular/core';
import { CommonModule } from '@angular/common';
import { firstValueFrom } from 'rxjs';
import { HistoryEntry } from '../interfaces/history-entry';
import { HistoryEntryService } from '../services/history-entry.service';
@Component({
selector: 'app-admin-history-tab',
standalone: true,
imports: [CommonModule],
templateUrl: './admin-history-tab.component.html',
styleUrl: './admin-history-tab.component.scss',
})
export class AdminHistoryTabComponent {
private historyEntryService = inject(HistoryEntryService);
readonly openForm = output<void>();
readonly editItem = output<HistoryEntry>();
readonly deleteItem = output<number>();
readonly entries$ = this.historyEntryService.getHistoryEntries();
ngOnInit(): void {
this.load();
}
async load(): Promise<void> {
await firstValueFrom(this.historyEntryService.getHistoryEntries());
}
onAdd(): void {
this.openForm.emit();
}
onEdit(entry: HistoryEntry): void {
this.editItem.emit(entry);
}
async onDelete(id: number): Promise<void> {
if (!confirm('Delete this history entry?')) return;
await firstValueFrom(this.historyEntryService.deleteHistoryEntry(id));
await this.load();
}
}