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
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import {AlertService} from '../../../../services/alert.service';
import {JobsService} from '../../../../services/jobs.service';
import {Job} from '../../../../model/job';
@Component({
selector: 'app-execution-detail-planes',
templateUrl: './execution-detail-planes.component.html',
styleUrls: ['./execution-detail-planes.component.scss']
})
export class ExecutionDetailPlanesComponent implements OnInit, OnDestroy {
@Input() job: Job;
planeKeys: string[];
planesFormGroup: FormGroup;
constructor(
private jobService: JobsService,
private alertService: AlertService
) {
// Form group to contain the plane checkboxes
this.planesFormGroup = new FormGroup({});
this.planeKeys = null;
}
ngOnInit(): void {
// Create a form control for each of the plane checkboxes and add them into the same group
this.getPlaneKeys().forEach(control => this.planesFormGroup.addControl(control, new FormControl(true)));
}
ngOnDestroy(): void {
}
// Reads plane names from a JSON file and returns them in a list
getPlaneKeys(): string[] {
// Return the plane names if we already fetched them
if (this.planeKeys !== null) {
return this.planeKeys;
}
this.planeKeys = [];
// Get the plane names from the spectral window numbers in the planes.json file
this.jobService.getPlanes(this.job.job_id).subscribe(response => {
this.planeKeys = Object.keys(JSON.parse(response));
},
error => {
this.alertService.error('Could not retrieve planes from planes.json. ' + error);
});
return this.planeKeys;
}
// Writes to a file in lustre to flag planes to be cached
cachePlanes(): void {
this.alertService.info('Flagging planes to be cached');
// Collect the selected planes and write their names separated by a newline
let planesText = '';
const planes = this.planesFormGroup.value;
Object.keys(planes).forEach(key => {
if (planes[key] === true) {
planesText += key + '\n';
}
});
planesText = planesText.trim();
// Write out the planes string if any are selected
if (planesText.length > 0) {
this.jobService.writePlanes(this.job.job_id, planesText).subscribe(() => {
this.alertService.success('Planes Saved');
},
error => {
this.alertService.error('Planes did not save. ' + error);
});
}
}
}