Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {Job, JobQueue} from "../../model/job";
import {verticleSlide} from "../../animations";
import {faCopy, faExclamationTriangle, faExternalLinkAlt} from "@fortawesome/free-solid-svg-icons";
import {ProductsService} from "../../services/products.service";
import {AlertService} from "../../services/alert.service";
import {ConfigurationService} from "../../env/configuration.service";
@Component({
selector: 'app-execution-job',
templateUrl: './execution.component.html',
styleUrls: ['./execution.component.scss'],
animations: [verticleSlide]
})
export class ExecutionComponent implements OnInit, OnChanges {
@Input() job: Job;
@Input() queue: JobQueue;
@Input() alertThresholdDays: number;
productStatuses: Array<string> = [
'PROCESSING',
'ERROR',
'QA_READY',
'QA_MANUAL',
'QA_REJECTED',
'QA_ACCEPTED',
'QA_ON_HOLD'];
public faCopy = faCopy;
public faExternalLinkAlt = faExternalLinkAlt;
public detailsExposed: boolean = false;
public duration: string = '...';
public faExclamationTriangle = faExclamationTriangle;
constructor(
private productService: ProductsService,
private alertService: AlertService,
private configService: ConfigurationService,
) {
}
ngOnInit() {
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.hasOwnProperty('job')) {
this.getDuration();
}
if (changes.hasOwnProperty('alertThresholdDays')) {
}
}
copyToClipboard(text: string): void {
const selBox = document.createElement('textarea');
selBox.style.position = 'fixed';
selBox.style.left = '0';
selBox.style.top = '0';
selBox.style.opacity = '0';
selBox.value = text;
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
}
getConfigRootDataDirectory(): string {
return this.configService.config.rootDataDirectory;
}
getConfigWebLogBaseUrl(): string {
return this.configService.config.weblogbaseurl;
}
getJobStatusClass() {
switch (this.job.jobspec_status) {
case 'ERROR':
return 'btn-danger';
case 'QA_REJECTED':
return 'btn-secondary';
case 'PROCESSING':
return 'btn-primary';
case 'QA_READY':
return 'btn-success';
case 'QA_ACCEPTED':
return 'btn-info';
case 'QA_MANUAL':
return 'btn-warning';
default:
return 'btn-outline-info';
}
}
showWarning(job: Job): boolean {
if (job.jobspec_status === 'PROCESSING') {
let start_date = new Date(job.job_starttime);
let current_date = new Date();
let diffInDays = (current_date.getTime() - start_date.getTime()) / (1000 * 60 * 60 * 24);
if (diffInDays >= this.alertThresholdDays) {
return true;
}
}
return false;
}
updateStatus(status: string): void {
if (status.toLowerCase() !== this.job.jobspec_status.toLowerCase()) {
this.productService.updateProductStatus(this.job.jobspec_id, status).subscribe(response => {
this.job.jobspec_status = response;
this.alertService.success('Status Updated');
});
}
}
getDuration(): void {
let dur = '';
let diff = this.job.job_endtime ? this.job.job_endtime - this.job.job_starttime : Date.now() - this.job.job_starttime;
const weeksDiff = Math.floor(diff / 1000 / 60 / 60 / 24 / 7);
diff -= weeksDiff * 1000 * 60 * 60 * 24 * 7;
dur += weeksDiff > 0 ? weeksDiff + 'w ' : '';
const daysDiff = Math.floor(diff / 1000 / 60 / 60 / 24);
diff -= daysDiff * 1000 * 60 * 60 * 24;
dur += daysDiff > 0 ? daysDiff + 'd ' : '';
const hoursDiff = Math.floor(diff / 1000 / 60 / 60);
diff -= hoursDiff * 1000 * 60 * 60;
dur += hoursDiff > 0 ? hoursDiff + 'h ' : '';
const minutesDiff = Math.floor(diff / 1000 / 60);
dur += minutesDiff > 0 ? minutesDiff + 'm ' : '';
this.duration = dur;
}
}