import { Component, OnInit } from '@angular/core'; import {MatDialog as MatDialog} from "@angular/material/dialog"; import {TaskgroupCreationComponent} from "../taskgroup-creation/taskgroup-creation.component"; import {TaskgroupEntityInfo, TaskgroupService} from "../../../api"; import {TaskgroupDeletionComponent} from "../taskgroup-deletion/taskgroup-deletion.component"; import {ActivatedRoute} from "@angular/router"; import {TaskEditorComponent} from "../../tasks/task-editor/task-editor.component"; import {TaskEditorData} from "../../tasks/task-editor/TaskEditorData"; @Component({ selector: 'app-taskgroup-dashboard', templateUrl: './taskgroup-dashboard.component.html', styleUrls: ['./taskgroup-dashboard.component.css'] }) export class TaskgroupDashboardComponent implements OnInit { constructor(private dialog: MatDialog, private taskgroupService: TaskgroupService, private activatedRoute: ActivatedRoute) { } taskgroups: TaskgroupEntityInfo[] = [] taskgroupID: number = -1; ngOnInit(): void { this.activatedRoute.paramMap.subscribe(params => { if(params.has('taskgroupID')) { this.taskgroupID = Number(params.get('taskgroupID')); this.taskgroupService.taskgroupsTaskgroupIDGet(this.taskgroupID).subscribe({ next: resp => { this.taskgroups = resp } }) } else { this.taskgroupService.taskgroupsGet().subscribe({ next: resp => { this.taskgroups = resp; } }) } }) } openTaskgroupCreation() { const dialogRef = this.dialog.open(TaskgroupCreationComponent, {data: {taskgroup: undefined, taskgroupID: this.taskgroupID}, minWidth: "400px"}) dialogRef.afterClosed().subscribe(res => { if(res != undefined) { this.taskgroups.push(res); } }) } openTaskgroupEditor(taskgroup: TaskgroupEntityInfo) { const dialogRef = this.dialog.open(TaskgroupCreationComponent, {data: {taskgroup: taskgroup, taskgroupID: this.taskgroupID}, minWidth: "400px"}); dialogRef.afterClosed().subscribe(res => { if(res) { const data = this.taskgroups } }) } openTaskgroupDeletion(taskgroup: TaskgroupEntityInfo) { const dialogRef = this.dialog.open(TaskgroupDeletionComponent, {data: taskgroup, minWidth: "400px"}); dialogRef.afterClosed().subscribe(res => { if(res) { this.taskgroups = this.taskgroups.filter(ctg => ctg.taskgroupID != taskgroup.taskgroupID) } }) } openTaskCreation() { const editorData: TaskEditorData = { task: undefined, taskgroupID: this.taskgroupID } const dialogRef = this.dialog.open(TaskEditorComponent, {data: editorData, minWidth: "400px"}) } }