import {Component, Inject, OnInit} from '@angular/core'; import {TaskEditorData} from "../task-editor/TaskEditorData"; import {TaskEntityInfo, TaskgroupService, TaskService} from "../../../api"; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; export interface ClearTaskDialogData { taskgroupID: number | undefined, parentTaskID: number | undefined tasks: TaskEntityInfo[], subtasks: boolean } @Component({ selector: 'app-clear-task-dialog', templateUrl: './clear-task-dialog.component.html', styleUrls: ['./clear-task-dialog.component.css'] }) export class ClearTaskDialogComponent implements OnInit{ finishedTasks: number = 0; unfinishedTasks: number = 0; overdueTasks: number = 0; upcomingTasks: number = 0; constructor(@Inject(MAT_DIALOG_DATA) public editorData: ClearTaskDialogData, private taskgroupService: TaskgroupService, private dialogRef: MatDialogRef, private snackbar: MatSnackBar, private taskService: TaskService) { } ngOnInit(): void { this.editorData.tasks.forEach(task => { if(task.overdue) { this.overdueTasks +=1; } else { this.upcomingTasks += 1; } if(task.finished) { this.finishedTasks += 1; } else { this.unfinishedTasks += 1; } }) } cancel() { } clearTasks() { if(this.editorData.subtasks) { this.taskService.tasksTaskIDSubtasksDelete(this.editorData.parentTaskID!).subscribe({ next: resp => { if(resp.status == "success") { const deletedTasks = this.editorData.tasks; this.dialogRef.close(deletedTasks); } }, error: err => { if(err.status == 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", "", {duration: 2000}); } } }) } else { this.taskgroupService.taskgroupsTaskgroupIDClearDelete(this.editorData.taskgroupID!).subscribe({ next: resp => { if(resp.status == "success") { const deletedTasks = this.editorData.tasks; this.dialogRef.close(deletedTasks); } }, error: err => { if(err.status == 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", "", {duration: 2000}); } } }) } } }