Skip to content

Commit 99a3ac9

Browse files
authored
Fix XML generator not generating XMLs (#45)
Fix an issue where the XML generator was not allowing the generation of XMLs due to issue with link checking. In addition: - Fixed unit tests not properly testing source files - Add a minification `package.json` script to more reliable minify the JS and CSS files - Removed the unnecessary `py-test` and `py-clean` in the `Makefile`
1 parent dd51d82 commit 99a3ac9

37 files changed

+15861
-14813
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ validate-all: py-validate
88
Rscript -e 'renv::restore()'
99

1010
# === Python Commands for eFP-Seq_Browser ===
11-
.PHONY: py-install py-format py-lint py-test py-clean py-validate
11+
.PHONY: py-install py-format py-lint py-validate
1212

1313
PY_FILES = cgi-bin/*.cgi
1414

@@ -21,4 +21,4 @@ py-format:
2121
py-lint:
2222
uv run ruff check --fix $(PY_FILES)
2323

24-
py-validate: py-install py-format py-lint
24+
py-validate: py-format py-lint

cgi-bin/Submission_page/XMLgenerator.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function correct_ReadMapCount(class_name) {
292292

293293
for (const element of x) {
294294
element.value = element.value.trim();
295-
if (element.value === ("" || null || undefined)) {
295+
if (!element.value) {
296296
element.value = 0;
297297
}
298298
element.value = only_ReadNum(element.value);
@@ -326,55 +326,46 @@ function only_ReadNum(input_string) {
326326
function check_links(bam_name, repo_name) {
327327
const x = document.getElementById("Entries_all").querySelectorAll(repo_name);
328328
const bam_x = document.getElementById("Entries_all").querySelectorAll(bam_name);
329+
let foundBamInput = false;
330+
329331
for (let i = 0; i < x.length; i++) {
330332
if (x[i].id === "bam_input") {
331-
if (x[i].value.length > 0) {
332-
if (bam_x[i].value == "Google Drive") {
333-
// Verify if Google Link
334-
const driveLink = x[i].value.split("//");
335-
if (driveLink.length > 1) {
336-
// If starts with https
337-
const driveURL = driveLink[1];
338-
return (
339-
driveURL.split("/")[0] === "drive.google.com" ||
340-
driveURL.split("/")[0] === "www.drive.google.com"
341-
);
342-
} else if (driveLink.length === 0) {
343-
// If does not start with https
344-
return (
345-
driveLink.split("/")[0] === "drive.google.com" ||
346-
driveLink.split("/")[0] === "www.drive.google.com"
347-
);
348-
} else {
349-
// Not URL
350-
return false;
351-
}
352-
} else if (bam_x[i].value == "Amazon AWS") {
353-
/** Link from string to URL format */
354-
const urlString = new URL(x[i].value);
355-
356-
if (
357-
(urlString.host("s3.amazonaws.com") || x[i].value.includes("araport.cyverse-cdn.tacc.cloud")) &&
358-
check_amazon_for_bam(x[i].value)
359-
) {
360-
return true;
361-
} else if (
362-
(urlString.host("s3.amazonaws.com") ||
363-
x[i].value.includes("araport.cyverse-cdn.tacc.cloud/")) &&
364-
check_amazon_for_bam(x[i].value)
365-
) {
366-
return false;
367-
} else {
368-
return false;
369-
}
370-
} else {
333+
foundBamInput = true;
334+
if (!x[i].value || !bam_x?.[i]?.value) {
335+
return false;
336+
}
337+
338+
let urlString;
339+
try {
340+
urlString = new URL(x[i].value);
341+
} catch {
342+
return false;
343+
}
344+
345+
const hostValue = urlString?.host ?? "";
346+
const bamHostType = bam_x[i].value;
347+
348+
if (bamHostType === "Google Drive") {
349+
if (!["drive.google.com", "www.drive.google.com"].includes(hostValue)) {
350+
return false;
351+
}
352+
} else if (bamHostType === "Amazon AWS") {
353+
if (
354+
!check_amazon_for_bam(x[i].value) ||
355+
!(
356+
["s3.amazonaws.com", "araport.cyverse-cdn.tacc.cloud"].includes(hostValue) ||
357+
x[i].value.includes("araport.cyverse-cdn.tacc.cloud")
358+
)
359+
) {
371360
return false;
372361
}
373362
} else {
374363
return false;
375364
}
376365
}
377366
}
367+
368+
return foundBamInput;
378369
}
379370

380371
/**
@@ -507,19 +498,21 @@ function outline_links(bam_name, repo_name) {
507498

508499
/** URL for the hosted BAM file */
509500
let urlValue;
501+
let hostValue = "";
510502

511-
// Convert the
503+
// Convert the string into a URL object if valid
512504
try {
513505
urlValue = new URL(x[i].value);
506+
hostValue = urlValue.host || "";
514507
} catch {
515508
console.error("Unreadable URL presented: ", x[i].value);
516509
}
517510

518-
if (bamHostType && urlValue) {
511+
if (bamHostType && hostValue) {
519512
if (bamHostType === "Amazon AWS") {
520513
if (
521514
check_amazon_for_bam(x[i].value) &&
522-
["s3.amazonaws.com", "araport.cyverse-cdn.tacc.cloud"].includes(urlValue[host])
515+
["s3.amazonaws.com", "araport.cyverse-cdn.tacc.cloud"].includes(hostValue)
523516
) {
524517
x[i].style.borderColor = null;
525518
x[i].style.boxShadow = null;
@@ -528,7 +521,7 @@ function outline_links(bam_name, repo_name) {
528521
x[i].style.boxShadow = "0 0 10px #ff2626";
529522
}
530523
} else if (bamHostType === "Google Drive") {
531-
if (["drive.google.com"].includes(urlValue[host])) {
524+
if (["drive.google.com", "www.drive.google.com"].includes(hostValue)) {
532525
x[i].style.borderColor = null;
533526
x[i].style.boxShadow = null;
534527
} else {
@@ -1300,3 +1293,12 @@ function initGen() {
13001293
setTimeout(function () {
13011294
initGen();
13021295
}, 1000);
1296+
1297+
// Export functions for testing in Node.js environments
1298+
if (typeof module !== "undefined" && module.exports) {
1299+
module.exports = {
1300+
update,
1301+
check_links,
1302+
check_amazon_for_bam,
1303+
};
1304+
}

cgi-bin/Submission_page/XMLgenerator.min.js

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)