-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaskFitsFile.html
executable file
·119 lines (100 loc) · 2.87 KB
/
MaskFitsFile.html
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
<body>
<h3>Mask Definition File (MDF) Fits Table download</h3>
<br><br>
<table>
<tr>
<th>Mask Design Id</th>
<th> - </th>
<th>Mask Blueprint Id</th>
<th> - </th>
<th>Mask Design Name</th>
<th> - </th>
<th>Current Use Date</th>
<th> - </th>
<th>Mask Status</th>
</tr>
<tr>
<td align="center"><div id="design-id"></div></td>
<td> - </td>
<td align="center"><div id="blue-id"></div></td>
<td> - </td>
<td align="center"><div id="design-name-id"></div></td>
<td> - </td>
<td align="center"><div id="use-date-id"></div></td>
<td> - </td>
<td align="center"><div id="mask-status-id"></div></td>
</tr>
</table>
<br><br>
<div id="loadingIndicator" style="display: none;">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<h4>Download the Mask Definition Fits Table File</h4> <br>
<form>
<button type="button" id="downloadBtn" onclick="downloadMdf()">Download</button>
</form>
<script>
let apiRootUrl;
let blueId;
let designId;
function downloadMdf() {
let apiUrl = `${apiRootUrl}/mask-description-file`;
let fullUrl;
if (blueId === null) {
fullUrl = `${apiUrl}?design-id=${designId}`;
} else {
fullUrl = `${apiUrl}?blue-id=${blueId}`;
}
// Disable the button
const downloadBtn = document.getElementById('downloadBtn');
downloadBtn.disabled = true;
showLoadingIndicator();
fetch(fullUrl, {
mode: 'cors',
credentials: 'include'
})
.then(response => {
// check if it is a file, or an error
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/zip')) {
return response.blob(); // Read response body as Blob
} else {
return response.json(); // Read response body as JSON
}
})
.then(data => {
if (data instanceof Blob) {
// If data is a Blob (file), proceed with downloading
const blobUrl = URL.createObjectURL(data);
downloadFiles(blobUrl, blueId);
} else {
// If data is not a Blob, display as JSON (error message)
alert(JSON.stringify(data));
}
})
.catch(error => {
alert(`Error accessing data, check API at ${fullUrl}: ${error}`);
})
.finally(() => {
// Enable the button
downloadBtn.disabled = false;
// Hide loading indicator
hideLoadingIndicator();
});
}
function downloadFiles(fullUrl, blueId) {
let link = document.createElement('a');
link.href = fullUrl;
link.download = `mdf-files-${blueId}.zip`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// expose the downloadMdf to be used in index.html
window.onload = downloadMdf;
// load the Date-Use and Design ID
window.onload = loadParams();
</script>
</body>