-
Reid Givens authoredReid Givens authored
jobspec.component.ts 3.28 KiB
import {Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges} from '@angular/core';
import {Job, JobSpec} from "../../model/job";
import {Subscription} from "rxjs";
import {JobsService} from "../../services/jobs.service";
import {verticleSlide} from "../../animations";
import {AlertService} from "../../services/alert.service";
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
import {faCaretDown, faCaretUp} from "@fortawesome/free-solid-svg-icons";
@Component({
selector: 'app-jobspec',
providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}],
templateUrl: './jobspec.component.html',
styleUrls: ['./jobspec.component.scss'],
animations: [verticleSlide]
})
export class JobspecComponent implements OnInit, OnChanges, OnDestroy {
@Input() job: Job;
@Input() canDeleteJob: boolean;
@Output() refreshJobs = new EventEmitter<boolean>();
detailsExposed: boolean = false;
public jobspec$: Subscription;
public jobspec: JobSpec;
public faCaretDown = faCaretDown;
public faCaretUp = faCaretUp;
constructor(private jobService: JobsService, private alertService: AlertService, private location: Location) {
}
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges) {
if (changes.hasOwnProperty('job')) {
this.jobService.getJobSpec(changes.job.currentValue.jobspec_id).subscribe((js: JobSpec) => {
if (js) {
this.jobspec = js;
}
});
}
}
/**
* is this component being shown in its root tab, or included into another tab for details
* this is used to change the UI and click behaviors in the template
*/
isHomePath(): boolean {
return !!this.location.path(false).match(/jobs/);
}
toggleDetails(): void {
if (this.detailsExposed) {
this.detailsExposed = false;
} else {
this.showDetails();
}
}
showDetails(): void {
this.detailsExposed = true;
this.jobspec$ = this.jobService.getJobSpec(this.job.jobspec_id).subscribe((js: JobSpec) => {
if (js) {
this.jobspec = js;
} else {
this.alertService.error('Job Spec could not be retrieved');
}
});
}
getJobStatusClass(status: string) {
switch (status) {
case 'ERROR':
return 'badge-danger';
case 'QA_REJECTED':
return 'badge-secondary';
case 'PROCESSING':
return 'badge-primary';
case 'QA_READY':
return 'badge-success';
case 'QA_ACCEPTED':
return 'badge-info';
case 'QA_MANUAL':
return 'badge-warning';
default:
return 'border border-info text-info';
}
}
deleteJobSpec(): void {
if (this.canDeleteJob) {
let confirmed = confirm('Are you sure you want to delete ' + this.job.jobspec_id);
if (confirmed) {
console.log('job', this.job, 'jobSpec', this.jobspec);
this.alertService.info('Deleting Job');
this.jobService.deleteJobSpec(this.job.jobspec_id, this.jobspec.queueName).subscribe(response => {
this.alertService.success('Job Deleted');
this.refreshJobs.emit(true);
}, error => {
this.alertService.error('Job deletion failed');
});
}
}
}
ngOnDestroy(): void {
if (this.jobspec$) {
this.jobspec$.unsubscribe();
}
}
}