From 4ff566a7c201f3f1e740500587513792495e5a05 Mon Sep 17 00:00:00 2001 From: Joshua Rodriguez Date: Wed, 17 Jul 2024 22:21:20 -0700 Subject: [PATCH] Fixes colors for failed deployments on Deployments page and broken Workers 'copy to clipboard' function --- cws-ui/src/main/webapp/js/cws.js | 77 +++++++++++++++++++------------- install/cws-ui/deployments.ftl | 8 ++-- install/cws-ui/workers.ftl | 20 ++++----- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/cws-ui/src/main/webapp/js/cws.js b/cws-ui/src/main/webapp/js/cws.js index b771a1b5..d4b9fc21 100644 --- a/cws-ui/src/main/webapp/js/cws.js +++ b/cws-ui/src/main/webapp/js/cws.js @@ -1,47 +1,47 @@ //parses query string. returns null if empty -function getQueryString(){ +function getQueryString() { /* - * PARSE THE QUERY STRING - */ + * PARSE THE QUERY STRING + */ var qstring = document.location.search; qstring = qstring.substring(1); - var keyValPair = qstring.split('&'); + var keyValPair = qstring.split("&"); - if(keyValPair.length == 1 && keyValPair[0] == ""){ + if (keyValPair.length == 1 && keyValPair[0] == "") { return null; } var params = {}; - for(entry in keyValPair){ + for (entry in keyValPair) { var key = keyValPair[entry].split("=")[0]; var val = keyValPair[entry].split("=")[1]; params[key] = val; } - + return params; } //parses query string. returns null if empty -function parseQueryString(qstring){ +function parseQueryString(qstring) { /* - * PARSE THE QUERY STRING - */ + * PARSE THE QUERY STRING + */ qstring = qstring.substring(1); - var keyValPair = qstring.split('&'); + var keyValPair = qstring.split("&"); - if(keyValPair.length == 1 && keyValPair[0] == ""){ + if (keyValPair.length == 1 && keyValPair[0] == "") { return null; } var params = {}; - for(entry in keyValPair){ + for (entry in keyValPair) { var key = keyValPair[entry].split("=")[0]; var val = keyValPair[entry].split("=")[1]; params[key] = val; } - + return params; } @@ -60,10 +60,11 @@ function base64ToBlob(base64Data, mime) { var byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } - return new Blob(byteArrays, {type: mime}); + return new Blob(byteArrays, { type: mime }); } function copyInput(varValue, isImage) { + console.log("Copying String: " + varValue); if (isImage == "true") { var sanitizedB64 = varValue; //if it exists, replace everything between data: and "base64, " with nothing @@ -71,7 +72,7 @@ function copyInput(varValue, isImage) { sanitizedB64 = sanitizedB64.replace(/data:.*base64, /g, ""); } const item = new ClipboardItem({ - "image/png": base64ToBlob(sanitizedB64, "image/png") + "image/png": base64ToBlob(sanitizedB64, "image/png"), }); navigator.clipboard.write([item]); } @@ -79,21 +80,29 @@ function copyInput(varValue, isImage) { } function checkForURL(potentialURL) { - if (potentialURL === undefined || potentialURL === null || potentialURL === "") { + if ( + potentialURL === undefined || + potentialURL === null || + potentialURL === "" + ) { return false; - } else if (potentialURL.startsWith("www.") || potentialURL.startsWith("http://") || potentialURL.startsWith("https://") || potentialURL.startsWith("s3://")) { + } else if ( + potentialURL.startsWith("www.") || + potentialURL.startsWith("http://") || + potentialURL.startsWith("https://") || + potentialURL.startsWith("s3://") + ) { return true; } try { new URL(potentialURL); return true; - } - catch (e) { + } catch (e) { return false; } } -function isEqual (a, b) { +function isEqual(a, b) { for (const key in a) { if (b[key] !== undefined) { if (a[key] !== b[key]) { @@ -108,22 +117,30 @@ function isEqual (a, b) { function autocomplete(inp, arr) { var currentFocus; - inp.addEventListener("input", function(e) { - var a, b, i, val = this.value; + inp.addEventListener("input", function (e) { + var a, + b, + i, + val = this.value; closeAllLists(); - if (!val || val.length < 2) { return false;} + if (!val || val.length < 2) { + return false; + } currentFocus = -1; a = document.createElement("DIV"); a.setAttribute("id", this.id + "autocomplete-list"); a.setAttribute("class", "autocomplete-items autocomplete-items-cws"); this.parentNode.appendChild(a); for (i = 0; i < arr.length; i++) { - if (arr[i].substr(0, val.length).toUpperCase() === val.toUpperCase()) { + if ( + arr[i].substr(0, val.length).toUpperCase() === val.toUpperCase() + ) { b = document.createElement("DIV"); - b.innerHTML = "" + arr[i].substr(0, val.length) + ""; + b.innerHTML = + "" + arr[i].substr(0, val.length) + ""; b.innerHTML += arr[i].substr(val.length); b.innerHTML += ""; - b.addEventListener("click", function(e) { + b.addEventListener("click", function (e) { inp.value = this.getElementsByTagName("input")[0].value; closeAllLists(); }); @@ -131,7 +148,7 @@ function autocomplete(inp, arr) { } } }); - inp.addEventListener("keydown", function(e) { + inp.addEventListener("keydown", function (e) { var x = document.getElementById(this.id + "autocomplete-list"); if (x) x = x.getElementsByTagName("div"); if (e.keyCode === 40) { @@ -153,7 +170,7 @@ function addActive(x) { if (!x) return false; removeActive(x); if (currentFocus >= x.length) currentFocus = 0; - if (currentFocus < 0) currentFocus = (x.length - 1); + if (currentFocus < 0) currentFocus = x.length - 1; x[currentFocus].classList.add("autocomplete-active"); } @@ -170,4 +187,4 @@ function closeAllLists(elmnt, inp) { x[i].parentNode.removeChild(x[i]); } } -} \ No newline at end of file +} diff --git a/install/cws-ui/deployments.ftl b/install/cws-ui/deployments.ftl index db7bad7e..3a37403f 100644 --- a/install/cws-ui/deployments.ftl +++ b/install/cws-ui/deployments.ftl @@ -528,11 +528,11 @@ } else { var html = `
` + `
` - + `
` + `` + `
` - + `
` + `` + `
` @@ -879,12 +879,12 @@
-
-
-
diff --git a/install/cws-ui/workers.ftl b/install/cws-ui/workers.ftl index 8025dac9..689824fc 100644 --- a/install/cws-ui/workers.ftl +++ b/install/cws-ui/workers.ftl @@ -177,6 +177,16 @@ // CALLED WHEN USER CLICKS ON TAGS '+' ICON // function expandTags(workerId) { + $(".copy").on('click', function (e) { + e.preventDefault(); + var copyValue = $(this).attr('data-copyValue'); + copyInput(copyValue, false); + $(this).attr('aria-label', 'Copied!'); + setTimeout(function () { + $('.copy').attr('aria-label', 'Copy'); + }, 2000); + }); + $("#"+workerId+"_plus_tags").hide(); $("#"+workerId+"_minus_tags").show(); $("#"+workerId+"_tagsTable").show(); @@ -279,16 +289,6 @@ $( window ).load(function() { console.log( "window loaded" ); }); - - $(document).on('click', '.copy', function (e) { - e.preventDefault(); - var copyValue = $(this).attr('data-copyValue'); - copyInput(copyValue, false); - $(this).attr('aria-label', 'Copied!'); - setTimeout(function () { - $('.copy').attr('aria-label', 'Copy'); - }, 2000); - });