117 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import {Component, OnInit, ViewChild} 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";
 | 
						|
import {TaskDashboardComponent} from "../../tasks/task-dashboard/task-dashboard.component";
 | 
						|
import {NavigationLink, NavigationLinkListComponent} from "../../navigation-link-list/navigation-link-list.component";
 | 
						|
 | 
						|
@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[] = []
 | 
						|
  taskgroup: TaskgroupEntityInfo | undefined
 | 
						|
  taskgroupPath: TaskgroupEntityInfo[] = []
 | 
						|
  taskgroupID: number = -1;
 | 
						|
  @ViewChild("taskDashboard") taskDashboard: TaskDashboardComponent | undefined
 | 
						|
  @ViewChild('navLinkList') navLinkListComponent: NavigationLinkListComponent | undefined
 | 
						|
  defaultNavigationLinkPath: NavigationLink[] = [
 | 
						|
    {
 | 
						|
      linkText: "Dashboard",
 | 
						|
      routerLink: ['/']
 | 
						|
    },
 | 
						|
    {
 | 
						|
      linkText: "Taskgroups",
 | 
						|
      routerLink: ["/taskgroups"]
 | 
						|
    }
 | 
						|
  ]
 | 
						|
 | 
						|
  ngOnInit(): void {
 | 
						|
    this.activatedRoute.paramMap.subscribe(params => {
 | 
						|
      if(params.has('taskgroupID')) {
 | 
						|
        console.log("Update of taskgroup")
 | 
						|
        this.taskgroupID = Number(params.get('taskgroupID'));
 | 
						|
        this.taskgroupService.taskgroupsTaskgroupIDGet(this.taskgroupID).subscribe({
 | 
						|
          next: resp => {
 | 
						|
            this.taskgroups = resp.children
 | 
						|
            this.taskgroupPath = resp.ancestors
 | 
						|
            this.taskgroup = resp.taskgroupInfo;
 | 
						|
            this.navLinkListComponent!.resetComponent([
 | 
						|
              {
 | 
						|
                linkText: "Dashboard",
 | 
						|
                routerLink: ['/']
 | 
						|
              },
 | 
						|
              {
 | 
						|
                linkText: "Taskgroups",
 | 
						|
                routerLink: ["/taskgroups"]
 | 
						|
              }
 | 
						|
            ]);
 | 
						|
            console.log(this.taskgroups)
 | 
						|
            this.taskgroupPath.forEach(taskgroupEntity => {
 | 
						|
              this.navLinkListComponent!.addNavigationLink(taskgroupEntity.taskgroupName, ['/taskgroups', taskgroupEntity.taskgroupID.toString()]);
 | 
						|
            })
 | 
						|
          }
 | 
						|
        })
 | 
						|
      } 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, width: "600px"})
 | 
						|
    dialogRef.afterClosed().subscribe(res => {
 | 
						|
      if(res != undefined) {
 | 
						|
        this.taskDashboard!.addTask(res);
 | 
						|
      }
 | 
						|
    })
 | 
						|
  }
 | 
						|
}
 |