68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
|
|
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||
|
|
import { CommonModule } from '@angular/common';
|
||
|
|
import {
|
||
|
|
MAT_DIALOG_DATA,
|
||
|
|
MatDialogRef,
|
||
|
|
MatDialogModule,
|
||
|
|
} from '@angular/material/dialog';
|
||
|
|
import { MatButtonModule } from '@angular/material/button';
|
||
|
|
import { MatIconModule } from '@angular/material/icon';
|
||
|
|
import { MatChipsModule } from '@angular/material/chips';
|
||
|
|
|
||
|
|
import { Filament } from '../../models/filament.model';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Data passed into the delete confirmation dialog.
|
||
|
|
*/
|
||
|
|
export interface DeleteFilamentDialogData {
|
||
|
|
filament: Filament;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Delete confirmation dialog for filament spool removal.
|
||
|
|
*
|
||
|
|
* Displays spool details (material, brand, color, serial, remaining weight)
|
||
|
|
* and requires the user to confirm before deletion proceeds.
|
||
|
|
* Cancel dismisses the dialog with no action.
|
||
|
|
*/
|
||
|
|
@Component({
|
||
|
|
selector: 'app-delete-filament-dialog',
|
||
|
|
standalone: true,
|
||
|
|
imports: [
|
||
|
|
CommonModule,
|
||
|
|
MatDialogModule,
|
||
|
|
MatButtonModule,
|
||
|
|
MatIconModule,
|
||
|
|
MatChipsModule,
|
||
|
|
],
|
||
|
|
templateUrl: './delete-filament-dialog.component.html',
|
||
|
|
styleUrl: './delete-filament-dialog.component.scss',
|
||
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||
|
|
})
|
||
|
|
export class DeleteFilamentDialogComponent {
|
||
|
|
private readonly dialogRef = inject(
|
||
|
|
MatDialogRef<DeleteFilamentDialogComponent, boolean>
|
||
|
|
);
|
||
|
|
readonly data: DeleteFilamentDialogData = inject(MAT_DIALOG_DATA);
|
||
|
|
|
||
|
|
/** The filament spool being considered for deletion */
|
||
|
|
readonly filament = this.data.filament;
|
||
|
|
|
||
|
|
/** Format weight for display in dialog */
|
||
|
|
formatWeight(grams: number): string {
|
||
|
|
if (grams >= 1000) {
|
||
|
|
return `${(grams / 1000).toFixed(1)}kg`;
|
||
|
|
}
|
||
|
|
return `${Math.round(grams)}g`;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Cancel — close dialog with false (no deletion) */
|
||
|
|
onCancel(): void {
|
||
|
|
this.dialogRef.close(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Confirm — close dialog with true (proceed with deletion) */
|
||
|
|
onConfirm(): void {
|
||
|
|
this.dialogRef.close(true);
|
||
|
|
}
|
||
|
|
}
|