From 1f5cdee5f8cd00fc03e527413ea9b4f2ce7f0620 Mon Sep 17 00:00:00 2001 From: Mo Sohani Date: Wed, 13 Nov 2024 23:23:39 -0500 Subject: [PATCH 1/2] refactor reparse js file --- .../admin/js/admin/admin_datafile_model.js | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js index 31d52ae20..be81b2913 100644 --- a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js +++ b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js @@ -2,29 +2,47 @@ $(window).on('load', function() { console.log('loaded'); var submitBtn=document.querySelector('button[type=submit]'); // add the first listener var theForm = submitBtn.parentNode.parentNode; + var action = ""; + var number_of_files_line = ""; - for (var i = 0; i < theForm.childNodes.length; i++) { - if (theForm.childNodes[i].className == "actions") { - form_header = theForm.childNodes[i]; - - for (var i = 0; i < form_header.childNodes.length; i++) { - if (form_header.childNodes[i].className == "action-counter") { - number_of_files = form_header.childNodes[i]; - break; - } - } - - break; - } - } submitBtn.addEventListener('click', function(e) { e.preventDefault(); - if (confirm("You are about to re-parse " + number_of_files.innerHTML.split(/(\s+)/)[0] + " files. Are you sure you want to continue?")) { - console.log('submitting'); - theForm.submit(); + for (var i = 0; i < theForm.childNodes.length; i++) { + if (theForm.childNodes[i].className === "actions") { + form_header = theForm.childNodes[i]; + for (var i = 0; i < form_header.childNodes.length; i++) { + if (form_header.childNodes[i].nodeName === "LABEL") { + var select_node = form_header.childNodes[i].childNodes[1]; + if (select_node.value === "reparse") { // action is reparse + action = select_node.value; + } + } + if (form_header.childNodes[i].className == "action-counter" || form_header.childNodes[i].className == "all") { + number_of_files_line = form_header.childNodes[i]; + break; + } + } + + break; + } + } + if (action === "reparse") { + console.log('reparse'); + var splitted_number_of_files = number_of_files_line.innerHTML.split(/(\s+)/); + if (Number(splitted_number_of_files[0]) > 0 ) { + number_of_files = splitted_number_of_files[0]; + } else { + number_of_files = splitted_number_of_files[2]; + } + if (confirm("You are about to re-parse " + number_of_files + " files. Are you sure you want to continue?")) { + console.log('submitting'); + theForm.submit(); + } else { + console.log('not submitting'); + }; } else { - console.log('not submitting'); - }; + console.log('not reparse'); + } }); }); From f4a1399a3f8f169121a2c19f3ad37e374c69474f Mon Sep 17 00:00:00 2001 From: Mo Sohani Date: Mon, 18 Nov 2024 10:35:30 -0500 Subject: [PATCH 2/2] corrections --- .../admin/js/admin/admin_datafile_model.js | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js index be81b2913..ddde1dbde 100644 --- a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js +++ b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js @@ -7,28 +7,24 @@ $(window).on('load', function() { submitBtn.addEventListener('click', function(e) { e.preventDefault(); - for (var i = 0; i < theForm.childNodes.length; i++) { - if (theForm.childNodes[i].className === "actions") { - form_header = theForm.childNodes[i]; - for (var i = 0; i < form_header.childNodes.length; i++) { - if (form_header.childNodes[i].nodeName === "LABEL") { - var select_node = form_header.childNodes[i].childNodes[1]; - if (select_node.value === "reparse") { // action is reparse - action = select_node.value; - } - } - if (form_header.childNodes[i].className == "action-counter" || form_header.childNodes[i].className == "all") { - number_of_files_line = form_header.childNodes[i]; - break; - } - } - - break; - } + // number of files + action_counter = document.querySelector('span.action-counter') + is_action_counter_hidden = action_counter.className === "action-counter hidden" + + action_counter_all = document.querySelector('span.all') + + if (is_action_counter_hidden) { + number_of_files_line = action_counter_all.innerText; + } else { + number_of_files_line = action_counter.innerText; } + + // what action is selected + action = document.querySelector('select[name=action]').value; + if (action === "reparse") { console.log('reparse'); - var splitted_number_of_files = number_of_files_line.innerHTML.split(/(\s+)/); + var splitted_number_of_files = number_of_files_line.split(/(\s+)/); if (Number(splitted_number_of_files[0]) > 0 ) { number_of_files = splitted_number_of_files[0]; } else { @@ -42,6 +38,7 @@ $(window).on('load', function() { }; } else { console.log('not reparse'); + alert('Please select the "Reparse" action to continue.'); } });