Skip to content

Commit

Permalink
Fixes colors for failed deployments on Deployments page and broken Wo…
Browse files Browse the repository at this point in the history
…rkers 'copy to clipboard' function
  • Loading branch information
jdrodjpl committed Jul 18, 2024
1 parent 06dcd93 commit 4ff566a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
77 changes: 47 additions & 30 deletions cws-ui/src/main/webapp/js/cws.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -60,40 +60,49 @@ 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
if (sanitizedB64.indexOf("data:") !== -1) {
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]);
}
navigator.clipboard.writeText(varValue);
}

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]) {
Expand All @@ -108,30 +117,38 @@ 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 = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
b.innerHTML =
"<strong>" + arr[i].substr(0, val.length) + "</strong>";
b.innerHTML += arr[i].substr(val.length);
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
b.addEventListener("click", function(e) {
b.addEventListener("click", function (e) {
inp.value = this.getElementsByTagName("input")[0].value;
closeAllLists();
});
a.appendChild(b);
}
}
});
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) {
Expand All @@ -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");
}

Expand All @@ -170,4 +187,4 @@ function closeAllLists(elmnt, inp) {
x[i].parentNode.removeChild(x[i]);
}
}
}
}
8 changes: 4 additions & 4 deletions install/cws-ui/deployments.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@
} else {
var html = `<div id="stat-txt-` + data + `" class="stat-txt"></div>`
+ `<div id="stat-bar-` + data + `" class="progress" data-pdk="` + data + `">`
+ `<div class="progress-bar progress-bar-danger bar-error"`
+ `<div class="progress-bar bg-danger bar-error"`
+ `data-bs-toggle="tooltip" data-bs-title="0 Errors">`
+ `<span class="sr-only"></span>`
+ `</div>`
+ `<div class="progress-bar progress-bar-warning bar-pending"`
+ `<div class="progress-bar bg-warning bar-pending"`
+ `data-bs-toggle="tooltip" data-bs-title="0 Pending">`
+ `<span class="sr-only"></span>`
+ `</div>`
Expand Down Expand Up @@ -879,12 +879,12 @@
<label>Process status summary:</label>
<div id="stat-txt-cws-reserved-total" class="stat-txt">-</div>
<div id="stat-bar-cws-reserved-total" class="progress">
<div class="progress-bar progress-bar-danger bar-error" data-bs-toggle="tooltip"
<div class="progress-bar bg-danger bar-error" data-bs-toggle="tooltip"
data-bs-title="0 Errors">
<span class="sr-only"></span>
</div>

<div class="progress-bar progress-bar-warning bar-pending" data-bs-toggle="tooltip"
<div class="progress-bar bg-warning bar-pending" data-bs-toggle="tooltip"
data-bs-title="0 Pending">
<span class="sr-only"></span>
</div>
Expand Down
20 changes: 10 additions & 10 deletions install/cws-ui/workers.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
</script>
<!-- Just for debugging purposes. Don''t actually copy this line! -->
Expand Down

0 comments on commit 4ff566a

Please sign in to comment.