00f1aed7796ee719e3468d4b4acfebfd4d542d1b hiram Thu Aug 29 18:36:10 2024 -0700 correctly follow URL arguments and better state save and restore refs #32589 diff --git src/hg/js/assemblySearch.js src/hg/js/assemblySearch.js index 37b1fc1..f6f8332 100644 --- src/hg/js/assemblySearch.js +++ src/hg/js/assemblySearch.js @@ -58,30 +58,31 @@ } } // add extra element to the help text bullet list for API example if (debug) { var searchTipList = document.getElementById("searchTipList"); // Create a new list item var li = document.createElement("li"); li.innerHTML = "example API call: n/a"; // Append the new list item to the ordered list searchTipList.appendChild(li); } // default starts as hidden stateObject.advancedSearchVisible = false; + advancedSearchVisible(false); var searchForm = document.getElementById('searchForm'); var advancedSearchButton = document.getElementById('advancedSearchButton'); var searchInput = document.getElementById('searchBox'); var clearButton = document.getElementById('clearSearch'); asmIdText = document.getElementById("formAsmId"); betterCommonName = document.getElementById("betterCommonName"); comment = document.getElementById("comment"); requestSubmitButton = document.getElementById("submitButton"); document.getElementById("modalFeedback").addEventListener("submit", checkForm, false); modalInit(); var tableBody = document.getElementById('tableBody'); tableBody.innerHTML = '(empty table)'; clearButton.addEventListener('click', function() { @@ -107,30 +108,31 @@ advancedSearchButton.addEventListener('click', function() { var searchOptions = document.getElementById("advancedSearchOptions"); // I don't know why it is false the first time ? if (! searchOptions.style.display || searchOptions.style.display === "none") { advancedSearchVisible(true); } else { advancedSearchVisible(false); } }); // restore history on back button window.addEventListener('popstate', function(e) { var state = event.state; if (state) { stateObject.queryString = state.queryString; + stateObject.advancedSearchVisible = state.advancedSearchVisible; stateObject.maxItemsOutput = state.maxItemsOutput; stateObject.browser = state.browser; stateObject.debug = state.debug; stateObject.measureTiming = state.measureTiming; stateObject.wordMatch = state.wordMatch; stateObject.asmStatus = state.asmStatus; stateObject.refSeqCategory = state.refSeqCategory; stateObject.asmLevel = state.asmLevel; stateObject.jsonData = state.jsonData; document.getElementById('mustExist').checked = false; document.getElementById('notExist').checked = false; if (stateObject.browser === "mustExist") { document.getElementById('mustExist').checked = true; } if (stateObject.browser === "notExist") { @@ -582,53 +584,56 @@ queryPlus += " +" + word; } }); queryString = queryPlus.trim(); } } // remove stray white space from beginning or end queryString = queryString.trim(); // Show the wait spinner document.querySelector(".submitContainer").classList.add("loading"); document.getElementById("loadingSpinner").style.display = "block"; var xhr = new XMLHttpRequest(); var urlPrefix = "/cgi-bin/hubApi"; - var url = "/findGenome?q=" + encodeURIComponent(queryString); - url += ";browser=" + browserExist; - url += ";maxItemsOutput=" + resultLimit; + var historyUrl = "?q=" + encodeURIComponent(queryString); + historyUrl += ";browser=" + browserExist; + historyUrl += ";maxItemsOutput=" + resultLimit; if (asmStatus !== "statusAny") // default is any assembly status - url += ";status=" + asmStatus; // something specific is being requested + historyUrl += ";status=" + asmStatus; // something specific is being requested if (refSeqCategory !== "refSeqAny") // default is any RefSeq category - url += ";category=" + refSeqCategory; // something specific + historyUrl += ";category=" + refSeqCategory; // something specific if (asmLevel !== "asmLevelAny") // default is any level of assembly - url += ";level=" + asmLevel; // something specific - - var historyUrl = "?q=" + encodeURIComponent(queryString) + ";browser=" + browserExist + ";maxItemsOutput=" + resultLimit; - if (debug) { + historyUrl += ";level=" + asmLevel; // something specific + if (debug) historyUrl += ";debug=1"; - } - if (measureTiming) { + if (measureTiming) historyUrl += ";measureTiming=1"; - } + + var url = "/findGenome" + historyUrl; if (debug) { var apiUrl = "" + url + ""; document.getElementById("recentAjax").innerHTML = apiUrl; } stateObject.queryString = queryString; + var searchOptions = document.getElementById("advancedSearchOptions"); + if (searchOptions.style.display === "flex") + stateObject.advancedSearchVisible = true; + else + stateObject.advancedSearchVisible = false; stateObject.maxItemsOutput = maxItemsOutput; stateObject.browser = browserExist; stateObject.debug = debug; stateObject.measureTiming = measureTiming; stateObject.wordMatch = wordMatch; stateObject.asmStatus = asmStatus; stateObject.refSeqCategory = refSeqCategory; stateObject.asmLevel = asmLevel; xhr.open('GET', urlPrefix + url, true); xhr.onload = function() { if (xhr.status === 200) { // Hide the wait spinner once the AJAX request is complete document.querySelector(".submitContainer").classList.remove("loading");