136 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import {Component, OnInit, ViewChild} from '@angular/core';
 | 
						|
import {NavigationLink, NavigationLinkListComponent} from "../../navigation-link-list/navigation-link-list.component";
 | 
						|
import {ActivatedRoute, Router} from "@angular/router";
 | 
						|
import {
 | 
						|
  ScheduleInfo,
 | 
						|
  ScheduleService,
 | 
						|
  TaskEntityInfo,
 | 
						|
  TaskgroupEntityInfo,
 | 
						|
  TaskgroupService,
 | 
						|
  TaskService
 | 
						|
} from "../../../api";
 | 
						|
import {TaskDashboardComponent} from "../task-dashboard/task-dashboard.component";
 | 
						|
import {MatDialog} from "@angular/material/dialog";
 | 
						|
import {TaskEditorComponent} from "../task-editor/task-editor.component";
 | 
						|
import {TaskEditorData} from "../task-editor/TaskEditorData";
 | 
						|
import * as moment from "moment";
 | 
						|
import {ScheduleDashboardComponent} from "../../schedules/schedule-dashboard/schedule-dashboard.component";
 | 
						|
 | 
						|
@Component({
 | 
						|
  selector: 'app-task-detail-overview',
 | 
						|
  templateUrl: './task-detail-overview.component.html',
 | 
						|
  styleUrls: ['./task-detail-overview.component.css']
 | 
						|
})
 | 
						|
export class TaskDetailOverviewComponent implements OnInit {
 | 
						|
 | 
						|
  defaultNavigationLinkPath: NavigationLink[] = [
 | 
						|
    {
 | 
						|
      linkText: "Dashboard",
 | 
						|
      routerLink: ['/']
 | 
						|
    },
 | 
						|
    {
 | 
						|
      linkText: "Taskgroups",
 | 
						|
      routerLink: ["/taskgroups"]
 | 
						|
    }
 | 
						|
  ]
 | 
						|
  taskgroups: TaskgroupEntityInfo[] = []
 | 
						|
  taskgroup: TaskgroupEntityInfo | undefined
 | 
						|
  taskgroupPath: TaskgroupEntityInfo[] = []
 | 
						|
  taskgroupID: number = -1;
 | 
						|
  @ViewChild('navLinkList') navLinkListComponent: NavigationLinkListComponent | undefined
 | 
						|
 | 
						|
  task: TaskEntityInfo | undefined
 | 
						|
  schedules: ScheduleInfo[] = []
 | 
						|
 | 
						|
  taskStatus: string = "🟢"
 | 
						|
 | 
						|
  constructor(private activatedRoute: ActivatedRoute,
 | 
						|
              private taskgroupService: TaskgroupService,
 | 
						|
              private taskService: TaskService,
 | 
						|
              private dialog: MatDialog,
 | 
						|
              private scheduleService: ScheduleService,
 | 
						|
              private router: Router) {
 | 
						|
  }
 | 
						|
 | 
						|
  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.children
 | 
						|
            this.taskgroupPath = resp.ancestors
 | 
						|
            this.taskgroup = resp.taskgroupInfo;
 | 
						|
            this.navLinkListComponent!.resetComponent([
 | 
						|
              {
 | 
						|
                linkText: "Dashboard",
 | 
						|
                routerLink: ['/']
 | 
						|
              },
 | 
						|
              {
 | 
						|
                linkText: "Taskgroups",
 | 
						|
                routerLink: ["/taskgroups"]
 | 
						|
              }
 | 
						|
            ]);
 | 
						|
            this.taskgroupPath.forEach(taskgroupEntity => {
 | 
						|
              this.navLinkListComponent!.addNavigationLink(taskgroupEntity.taskgroupName, ['/taskgroups', taskgroupEntity.taskgroupID.toString()]);
 | 
						|
            })
 | 
						|
          }
 | 
						|
        })
 | 
						|
      }
 | 
						|
 | 
						|
      if(params.has('taskID')) {
 | 
						|
        this.taskService.tasksTaskIDGet(Number(params.get('taskID'))).subscribe({
 | 
						|
          next: resp => {
 | 
						|
            this.task = resp;
 | 
						|
            this.taskStatus = this.getStatusOfTask(resp)
 | 
						|
          }
 | 
						|
        });
 | 
						|
        this.scheduleService.schedulesTaskIDGet(Number(params.get('taskID'))).subscribe({
 | 
						|
          next: resp => {
 | 
						|
            this.schedules = resp;
 | 
						|
          }
 | 
						|
        })
 | 
						|
      }
 | 
						|
    });
 | 
						|
  }
 | 
						|
 | 
						|
  getStatusOfTask(task: TaskEntityInfo ) {
 | 
						|
    if(moment(task.deadline, 'YYYY-MM-DDTHH:mm:ss.SSSZ').isBefore(moment())) {
 | 
						|
      return "🔴";
 | 
						|
    } else if(this.schedules.length == 0){
 | 
						|
      return "🟠";
 | 
						|
    } else {
 | 
						|
      return "🟢";
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  openTaskEditor() {
 | 
						|
    if(this.task != undefined) {
 | 
						|
      const taskEditorInfo: TaskEditorData = {
 | 
						|
        task: this.task!,
 | 
						|
        taskgroupID: this.taskgroupID!
 | 
						|
      };
 | 
						|
      this.dialog.open(TaskEditorComponent, {data: taskEditorInfo, width: "600px"})
 | 
						|
    }
 | 
						|
 | 
						|
  }
 | 
						|
 | 
						|
  startTaskNow() {
 | 
						|
    if(this.task != undefined) {
 | 
						|
      this.scheduleService.schedulesTaskIDNowPost(this.task.taskID).subscribe({
 | 
						|
        next: resp => {
 | 
						|
          this.router.navigateByUrl('/');
 | 
						|
        }
 | 
						|
      });
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  finishTask() {
 | 
						|
    this.taskService.tasksTaskIDFinishPost(this.task!.taskID).subscribe({
 | 
						|
      next: resp => {
 | 
						|
        this.task!.finished = !this.task!.finished;
 | 
						|
      }
 | 
						|
    })
 | 
						|
  }
 | 
						|
}
 |