diff --git a/daliuge-translator/dlg/dropmake/web/main.js b/daliuge-translator/dlg/dropmake/web/main.js index d99ffe220..d8c31a9f8 100644 --- a/daliuge-translator/dlg/dropmake/web/main.js +++ b/daliuge-translator/dlg/dropmake/web/main.js @@ -107,6 +107,58 @@ function updateDeployOptionsDropdown() { } +async function checkUrlStatus (url) { + return new Promise((resolve, reject) => { + $.ajax({url: url, + type: 'HEAD', + dataType: 'jsonp', + complete: function(jqXHR, textStatus){ + if(jqXHR.status === 200){ + resolve(true) + }else{ + resolve(false) + } + }, + timeout: 2000 + }); + }) +} + +async function manualCheckUrlStatus (clickPos) { + var badUrl = false + //if the event is triggered by click the check icon manually + if(clickPos === "icon"){ + var url = $(event.target).parent().find($('.deployMethodUrl')).val() + var target = $(event.target) + }else{ + //if the event is triggered by focus leave on the input + var url = $(event.target).parent().parent().find($('.deployMethodUrl')).val() + var target = $(event.target).parent().parent().find($('.urlStatusIcon')) + } + + + //check if jquery deems the url constructed properly + try { + new URL(url); + } catch (error) { + badUrl = true + } + + if(badUrl){ + $("#settingsModalErrorMessage").html('Please ensure deploy methods URLs are valid') + return + }else{ + //if the url is deemed contructed well, here we use an ajax call to see if the url is reachable + var urlStatus = await checkUrlStatus(url) + $("#settingsModalErrorMessage").html('') + if(urlStatus){ + target.replaceWith(`
done
`) + }else{ + target.replaceWith(`
close
`) + } + } +} + function saveSettings() { //need a check function to confirm settings have been filled out correctly @@ -130,7 +182,6 @@ function saveSettings() { new URL($(this).find(".deployMethodUrl").val()); } catch (error) { console.log("faulty Url: ",$(this).find(".deployMethodUrl").val()) - console.log(error) badUrl = true } @@ -215,7 +266,17 @@ function fillOutSettings() { //fill out settings list rom deploy methods array var deployMethodManagerDiv = $("#DeployMethodManager") deployMethodManagerDiv.empty() - deployMethodsArray.forEach(element => { + console.log("filling out settings, GET Errors and Cors warning from Url check") + deployMethodsArray.forEach(async element => { + + var urlReachable = await checkUrlStatus(element.url) + var ReachableIcon = "" + + if(urlReachable){ + ReachableIcon = `
done
` + }else{ + ReachableIcon = `
close
` + } var directOption = '' var helmOption = '' @@ -231,7 +292,8 @@ function fillOutSettings() { var deplpoyMethodRow = '
'+ '
'+ - '
'+ + `
`+ + ReachableIcon+ '
'+ - '
'+ + `
`+ + `
?
`+ '