UUID switching, and add new message button fix (#96)

Co-authored-by: mikolaj widla <mikolaj.widla@gmail.com>
Co-authored-by: Adam Bem <adam.bem@zoho.eu>
Reviewed-on: R11/release11-tools-web#96
Co-authored-by: Mikolaj Widla <widlam@noreply.example.com>
Co-committed-by: Mikolaj Widla <widlam@noreply.example.com>
This commit is contained in:
2023-03-06 11:54:40 +01:00
committed by Adam Bem
parent 02f46169d9
commit dcad69d43c
11 changed files with 307 additions and 26 deletions

View File

@@ -102,6 +102,7 @@ const idToDisplay = function(){
}
function refreshData(){
$("#uuid-input").val(clientUUID);
fillMessageList();
console.log("List initiated");
let id = idToDisplay();
@@ -226,12 +227,99 @@ function fillStaticFields(uuid, id, mediaType, body, httpStatus){
let linkHtml = '<a class="hyperlink" target="_blank" href="'+link+'">'+link+'</a>';
$('#messageLink').html(linkHtml);
$('#httpStatus').val(httpStatus);
$('#uuid-input').val(uuid);
$('#typeSelector').val(mediaType);
$('#bodyEditor').val(body);
$('#mockedMessageId').html(id);
}
function changeEditionOfUUID(element){
var inputFieldId= "#uuid-input"
var inputFieldDiv = "#uuid-edit-field"
if(element.checked){
$(inputFieldId).removeAttr('disabled');
$(inputFieldDiv).removeClass('disabled');
} else{
$(inputFieldId).attr('disabled', true);
$(inputFieldDiv).addClass('disabled');
}
}
function copyUUIDToClipboard(){
navigator.clipboard.writeText( document.getElementById('uuid-input').value );
}
async function fetchUUIDCheck(givenUUID , strategy){
var newUUID = "UUID" ;
url = host + "/api/mock/check/";
switch(strategy){
case "new":{
await fetch(url + givenUUID+ "/", { method : "GET" })
.then ( response => response.text() )
.then ( data => {
newUUID = data;
console.log("newUUID: "+newUUID);
} )
break;
}
case "restore":{
await fetch(url + givenUUID + "/" + clientUUID + "/" , { method: "GET" })
.then (response => response.text() )
.then (data => {
newUUID = data;
console.log("restoreUUID: "+newUUID);
} )
break;
}
}
return newUUID ;
}
function checkUUIDChars(uuid) {
console.log("UUID in check: " + uuid);
const regex = new RegExp("^[A-z0-9-]+$");
if(regex.test(uuid)){
return uuid ;
}
return "invalid";
}
function changeUUID(element){
const uuidStrategy = $('input[name="uuid-validation-type"]:checked').val();
// const givenUUID = checkUUIDChars(element.value);
const givenUUID = element.value;
console.log(givenUUID);
if( givenUUID == clientUUID ){
$("#uuid-input").attr("disabled", true);
uuidChangeModalDisplay("noChg");
return;
}
var newUUID = fetchUUIDCheck(givenUUID , uuidStrategy);
var changeMessage = uuidStrategy;
newUUID
.then( data => {
if (givenUUID == data) {
changeMessage = "success";
}
clientUUID = data;
$("#uuid-input").attr("disabled", true);
$("#editable").attr("checked", false);
uuidChangeModalDisplay(changeMessage);
document.cookie = C_UUID + '=' + data ;
} )
loadCookies();
refreshData();
}
function createLink(uuid, id){
var link = host + '/api/mock/r/'+uuid+'/'+id;
return link;