Skip to content
Snippets Groups Projects
jobspec-execution.component.ts 1.43 KiB
Newer Older
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {JobExecution} from "../../../../model/job";
import {Subscription} from "rxjs";
import {JobsService} from "../../../../services/jobs.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-jobspec-execution',
  templateUrl: './jobspec-execution.component.html',
  styleUrls: ['./jobspec-execution.component.scss']
})
export class JobspecExecutionComponent implements OnInit, OnDestroy {

  @Input() execution: JobExecution;

  public showDetails = false;
  private job$: Subscription;
  public job: JobExecution;

  constructor(private jobService: JobsService, private alertService: AlertService) {
  }

  ngOnInit() {
  }

  getJobStatusClass(status: string) {
    switch (status) {
      case 'ERROR':
        return 'badge-danger';
      case 'QA_REJECTED':
        return 'badge-warning';
      case 'PROCESSING':
        return 'badge-primary';
      default:
        return 'badge-info';
    }
  }

  getJob(jobId: number): void {
    this.showDetails = true;
    this.job$ = this.jobService.getJobExecution(jobId).subscribe((j: JobExecution) => {
      if (j) {
        this.job = j;
      } else {
        this.alertService.error("Job could not be retrieved.");
      }
    });
  }

  ngOnDestroy(): void {
    if (this.job$) {
      this.job$.unsubscribe();
    }
  }

}