From 35ff19da970a9e2fb7a33116e121c708ae01a3f4 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Tue, 1 Oct 2024 11:49:13 -0500 Subject: [PATCH] modernize/refactor `PairedListCollectionCreator` for input forms - Converted the file(s) to composition API and typescript - Improved styling of the modal and its components Still need to add `extensions` handling for cases where a certain extension is required for the collection. --- .../Collections/PairedElementView.vue | 49 +- .../PairedListCollectionCreator.vue | 1786 +++++++++-------- .../PairedListCollectionCreatorModal.js | 16 +- .../UnpairedDatasetElementView.vue | 63 +- client/src/utils/natural-sort.js | 38 - client/src/utils/naturalSort.ts | 45 + 6 files changed, 1127 insertions(+), 870 deletions(-) delete mode 100644 client/src/utils/natural-sort.js create mode 100644 client/src/utils/naturalSort.ts diff --git a/client/src/components/Collections/PairedElementView.vue b/client/src/components/Collections/PairedElementView.vue index 364832a22db..42cd1d9e8af 100644 --- a/client/src/components/Collections/PairedElementView.vue +++ b/client/src/components/Collections/PairedElementView.vue @@ -1,69 +1,58 @@ diff --git a/client/src/components/Collections/PairedListCollectionCreator.vue b/client/src/components/Collections/PairedListCollectionCreator.vue index d18767c3257..6e9ada15396 100644 --- a/client/src/components/Collections/PairedListCollectionCreator.vue +++ b/client/src/components/Collections/PairedListCollectionCreator.vue @@ -1,115 +1,898 @@ + + - diff --git a/client/src/utils/natural-sort.js b/client/src/utils/natural-sort.js deleted file mode 100644 index c620f169163..00000000000 --- a/client/src/utils/natural-sort.js +++ /dev/null @@ -1,38 +0,0 @@ -// Alphanumeric/natural sort fn -function naturalSort(a, b) { - // setup temp-scope variables for comparison evauluation - var re = /(-?[0-9.]+)/g; - - var x = a.toString().toLowerCase() || ""; - var y = b.toString().toLowerCase() || ""; - var nC = String.fromCharCode(0); - var xN = x.replace(re, `${nC}$1${nC}`).split(nC); - var yN = y.replace(re, `${nC}$1${nC}`).split(nC); - var xD = new Date(x).getTime(); - var yD = xD ? new Date(y).getTime() : null; - // natural sorting of dates - if (yD) { - if (xD < yD) { - return -1; - } else if (xD > yD) { - return 1; - } - } - - // natural sorting through split numeric strings and default strings - var oFxNcL; - - var oFyNcL; - for (var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { - oFxNcL = parseFloat(xN[cLoc]) || xN[cLoc]; - oFyNcL = parseFloat(yN[cLoc]) || yN[cLoc]; - if (oFxNcL < oFyNcL) { - return -1; - } else if (oFxNcL > oFyNcL) { - return 1; - } - } - return 0; -} - -export default naturalSort; diff --git a/client/src/utils/naturalSort.ts b/client/src/utils/naturalSort.ts new file mode 100644 index 00000000000..91a047b90dd --- /dev/null +++ b/client/src/utils/naturalSort.ts @@ -0,0 +1,45 @@ +// Alphanumeric/natural sort fn +export function naturalSort(a = "", b = ""): number { + // setup temp-scope variables for comparison evauluation + const re = /(-?[0-9.]+)/g; + + const x = a.toString().toLowerCase() || ""; + const y = b.toString().toLowerCase() || ""; + const nC = String.fromCharCode(0); + const xN = x.replace(re, `${nC}$1${nC}`).split(nC); + const yN = y.replace(re, `${nC}$1${nC}`).split(nC); + const xD = new Date(x).getTime(); + const yD = xD ? new Date(y).getTime() : null; + // natural sorting of dates + if (yD) { + if (xD < yD) { + return -1; + } else if (xD > yD) { + return 1; + } + } + + // natural sorting through split numeric strings and default strings + let oFxNcL; + + let oFyNcL; + for (let cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { + oFxNcL = parseFloat(xN[cLoc] || "") || xN[cLoc]; + oFyNcL = parseFloat(yN[cLoc] || "") || yN[cLoc]; + + // Check if either part is undefined + if (oFxNcL === undefined) { + return -1; + } + if (oFyNcL === undefined) { + return 1; + } + + if (oFxNcL < oFyNcL) { + return -1; + } else if (oFxNcL > oFyNcL) { + return 1; + } + } + return 0; +}