timemanager/frontend/src/app/taskgroups/taskgroup-deletion/taskgroup-deletion.component.ts

47 lines
1.4 KiB
TypeScript

import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA as MAT_DIALOG_DATA, MatDialogRef as MatDialogRef} from "@angular/material/dialog";
import {TaskgroupEntityInfo, TaskgroupService} from "../../../api";
import {MatSnackBar as MatSnackBar} from "@angular/material/snack-bar";
@Component({
selector: 'app-taskgroup-deletion',
templateUrl: './taskgroup-deletion.component.html',
styleUrls: ['./taskgroup-deletion.component.css']
})
export class TaskgroupDeletionComponent implements OnInit {
constructor(@Inject(MAT_DIALOG_DATA) public data: TaskgroupEntityInfo,
private dialogRef: MatDialogRef<TaskgroupDeletionComponent>,
private taskgroupService: TaskgroupService,
private snackbar: MatSnackBar) { }
pending: boolean = false;
ngOnInit(): void {
}
cancel() {
this.dialogRef.close(false);
}
confirm() {
this.pending = true;
this.taskgroupService.taskgroupsTaskgroupIDDelete(this.data.taskgroupID).subscribe({
next: resp => {
this.pending = false;
this.dialogRef.close(true);
},
error: err => {
this.pending = false;
if(err.stats == 403) {
this.snackbar.open("No permission", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "");
}
}
})
}
}