diff --git a/minerva_analysis/client/src/js/services/importFormValidation.js b/minerva_analysis/client/src/js/services/importFormValidation.js index 65709f51e..44dd04c6f 100644 --- a/minerva_analysis/client/src/js/services/importFormValidation.js +++ b/minerva_analysis/client/src/js/services/importFormValidation.js @@ -2,30 +2,30 @@ // Example starter JavaScript for disabling form submissions if there are invalid fields (function () { - 'use strict' - - // Fetch all the forms we want to apply custom Bootstrap validation styles to - var forms = document.querySelectorAll('.needs-validation') - // Loop over them and prevent submission - Array.prototype.slice.call(forms) - .forEach(function (form) { - form.addEventListener('submit', function (event) { - if (!form.checkValidity()) { - event.preventDefault() - event.stopPropagation() - }else{ - onupload(); - } - form.classList.add('was-validated') - }, true) - }) + 'use strict' + + // Fetch all the forms we want to apply custom Bootstrap validation styles to + var forms = document.querySelectorAll('.needs-validation') + // Loop over them and prevent submission + Array.prototype.slice.call(forms) + .forEach(function (form) { + form.addEventListener('submit', function (event) { + if (!form.checkValidity()) { + event.preventDefault() + event.stopPropagation() + } else { + onupload(); + } + form.classList.add('was-validated') + }, true) + }) })() //add listener -d3.select("#import_type").on("change",update); +d3.select("#import_type").on("change", update); -function update(){ - if(d3.select("#import_type").property("checked")){ +function update() { + if (d3.select("#import_type").property("checked")) { console.log('is checked'); d3.select('#mcmicro_form').style("display", 'inline'); d3.select('#custom_form').style("display", 'none'); @@ -36,15 +36,15 @@ function update(){ } //check if path and channel file exist in the specified MCMICRO output foder -async function checkMCOutputFolder(caller){ +async function checkMCOutputFolder(caller) { let path_res = await checkPathExistence(caller); - if (path_res == true){ + if (path_res == true) { let channel_res = await checkChannelExistence(caller) - if (channel_res == false){ - d3.select("#" + 'mcmicro_path_validation_text').html('No image channel file found under this path.') - } - }else{ - d3.select("#" + 'mcmicro_path_validation_text').html('Please provide a valid path.') + if (channel_res == false) { + d3.select("#" + 'mcmicro_path_validation_text').html('No image channel file found under this path.') + } + } else { + d3.select("#" + 'mcmicro_path_validation_text').html('Please provide a valid path.') } } @@ -53,11 +53,11 @@ async function checkCSVFileExistence(caller) { const self = this; //get folder path from the input text field - let maskSelectionField = d3.select('#'+ caller.id); + let maskSelectionField = d3.select('#' + caller.id); let mask = maskSelectionField.property("value"); //get selected mask type from the selection field - let pathInputField = d3.select('#'+ 'mcmicro_output_folder'); + let pathInputField = d3.select('#' + 'mcmicro_output_folder'); let path = pathInputField.property("value"); try { @@ -71,15 +71,15 @@ async function checkCSVFileExistence(caller) { body: JSON.stringify( { path: path, - mask : mask + mask: mask } ) }); let response_data = await response.json(); - if (response_data == true){ + if (response_data == true) { maskSelectionField.attr("class", "form-control is-valid"); maskSelectionField.node().setCustomValidity(''); - }else{ + } else { d3.select("#" + 'mcmicro_mask_validation_text').html('No corresponding csv file found.') maskSelectionField.attr("class", "form-control is-invalid"); maskSelectionField.node().setCustomValidity('Invalid'); @@ -95,9 +95,12 @@ async function checkChannelExistence(caller) { const self = this; //get folder path from the input text field - let pathInputField = d3.select('#'+ caller.id); + let pathInputField = d3.select('#' + caller.id); let path = pathInputField.property("value"); + let imageSelectionField = d3.select('#' + caller.id); + let image = imageSelectionField.property("value"); + try { //check if corresponsindg csv file exists let response = await fetch('/check_mc_channel_file_existence', { @@ -109,14 +112,15 @@ async function checkChannelExistence(caller) { body: JSON.stringify( { path: path, + image: image } ) }); let response_data = await response.json(); - if (response_data == true){ + if (response_data == true) { pathInputField.attr("class", "form-control is-valid"); pathInputField.node().setCustomValidity(''); - }else{ + } else { // d3.select("#" + 'mcmicro_path_validation_text').html('No image channel file found under this path.') pathInputField.attr("class", "form-control is-invalid"); pathInputField.node().setCustomValidity('No image channel file found under this path.'); @@ -132,11 +136,11 @@ async function checkChannelExistence(caller) { //check if path exists (mcmicro naming specific) async function checkFileExistence(caller) { const self = this; - let inputField = d3.select('#'+ caller.id); + let inputField = d3.select('#' + caller.id); //get segmentation folder path from the input text field let path = inputField.property("value"); -try { + try { //get available segmentation masks in mcmicro directory from server let response = await fetch('/check_file_existence', { method: 'POST', @@ -151,12 +155,12 @@ try { ) }); let response_data = await response.json(); - if (response_data == true){ + if (response_data == true) { inputField.attr("class", "form-control is-valid"); inputField.node().setCustomValidity(''); - }else{ - inputField.attr("class", "form-control is-invalid"); - inputField.node().setCustomValidity('Invalid'); + } else { + inputField.attr("class", "form-control is-invalid"); + inputField.node().setCustomValidity('Invalid'); } return response_data; } catch (e) { @@ -169,11 +173,11 @@ try { //check if path exists (mcmicro naming specific) async function checkDatasetExistence(caller) { const self = this; - let inputField = d3.select('#'+ caller.id); + let inputField = d3.select('#' + caller.id); //get segmentation folder path from the input text field let datasetName = inputField.property("value"); -try { + try { //get available segmentation masks in mcmicro directory from server let response = await fetch('/dataset_existence', { method: 'POST', @@ -188,12 +192,12 @@ try { ) }); let response_data = await response.json(); - if (response_data == false){ + if (response_data == false) { inputField.attr("class", "form-control is-valid"); inputField.node().setCustomValidity(''); - }else{ - inputField.attr("class", "form-control is-invalid"); - inputField.node().setCustomValidity('Dataset name already exists. Choose a different name.'); + } else { + inputField.attr("class", "form-control is-invalid"); + inputField.node().setCustomValidity('Dataset name already exists. Choose a different name.'); } // inputField.node().reportValidity(); return response_data; @@ -205,11 +209,11 @@ try { //check if path exists (mcmicro naming specific) async function checkPathExistence(caller) { const self = this; - let inputField = d3.select('#'+ caller.id); + let inputField = d3.select('#' + caller.id); //get segmentation folder path from the input text field let path = inputField.property("value"); -try { + try { //get available segmentation masks in mcmicro directory from server let response = await fetch('/check_path_existence', { method: 'POST', @@ -224,12 +228,12 @@ try { ) }); let response_data = await response.json(); - if (response_data == true){ + if (response_data == true) { inputField.attr("class", "form-control is-valid"); inputField.node().setCustomValidity(''); - }else{ - inputField.attr("class", "form-control is-invalid"); - inputField.node().setCustomValidity('Path does not exist.'); + } else { + inputField.attr("class", "form-control is-invalid"); + inputField.node().setCustomValidity('Path does not exist.'); } // inputField.node().reportValidity(); return response_data; @@ -239,17 +243,56 @@ try { } //get a list of available files in a folder (mcmicro naming specific) -async function fillSegFileList() { +async function fillCSVFileList() { const self = this; //get segmentation folder path from the input text field let path = d3.select('#mcmicro_output_folder').property("value"); //remove old selection options as soon as path changes - var select_field = document.getElementById("mcmicro_masks"); - while (select_field.length > 0) { - select_field.remove(0); + + + try { + //get available segmentation masks in mcmicro directory from server + let response = await fetch('/get_mc_csv_file_list', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify( + { + path: path, + } + ) + }); + let response_data = await response.json(); + var select_field = document.getElementById("mcmicro_masks"); + select_field.innerHTML = ""; + //fill select form field with new options + response_data.forEach(function (option_value) { + var option = document.createElement("option"); + option.text = option_value; + option.value = option_value; + select_field.add(option); + }) + + //return the filled field + return response_data; + } catch (e) { + console.log("Error Getting Segmentation File List", e); } +} + +//get a list of available files in a folder (mcmicro naming specific) +async function fillImgFileList() { + const self = this; + + //get segmentation folder path from the input text field + let path = d3.select('#mcmicro_output_folder').property("value"); + + + try { //get available segmentation masks in mcmicro directory from server @@ -266,9 +309,53 @@ async function fillSegFileList() { ) }); let response_data = await response.json(); + //remove old selection options as soon as path changes + var select_field = document.getElementById("mcmicro_images"); + select_field.innerHTML = ""; + //fill select form field with new options + response_data.forEach(function (option_value) { + var option = document.createElement("option"); + option.text = option_value; + option.value = option_value; + select_field.add(option); + }) + + //return the filled field + return response_data; + } catch (e) { + console.log("Error Getting Channel File List", e); + } +} + +//get a list of available files in a folder (mcmicro naming specific) +async function fillSegFileList() { + const self = this; + //get segmentation folder path from the input text field + let path = d3.select('#mcmicro_output_folder').property("value"); + + //remove old selection options as soon as path changes + + + try { + //get available segmentation masks in mcmicro directory from server + let response = await fetch('/get_mc_segmentation_file_list', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify( + { + path: path, + } + ) + }); + let response_data = await response.json(); + var select_field = document.getElementById("mcmicro_seg"); + select_field.innerHTML = ""; //fill select form field with new options - response_data.forEach(function(option_value){ + response_data.forEach(function (option_value) { var option = document.createElement("option"); option.text = option_value; option.value = option_value; @@ -282,6 +369,7 @@ async function fillSegFileList() { } } + let uploadPercentage = 0; let ajaxForm = $('form').ajaxForm({ uploadProgress: function (event, position, total, percentComplete) { diff --git a/minerva_analysis/client/templates/upload.html b/minerva_analysis/client/templates/upload.html index d745b872d..8a21464f7 100644 --- a/minerva_analysis/client/templates/upload.html +++ b/minerva_analysis/client/templates/upload.html @@ -96,7 +96,7 @@