660387765d7bd58729c204580b26bd016b0afeaa chmalee Mon Nov 21 14:30:49 2022 -0800 Do a quick async chromosome name lookup before sending a full search request from hgTracks/hgGateway diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js index 8447060..94ab3a1 100644 --- src/hg/js/hgTracks.js +++ src/hg/js/hgTracks.js @@ -4489,40 +4489,65 @@ var url = "../cgi-bin/hgTracks?position=" + newPos + "&" + cart.varsToUrlData({ 'db': getDb(), 'hgsid': getHgsid() }); window.location.assign(url); return false; } // redirect to hgBlat if the input looks like a DNA sequence // minimum length=19 so we do not accidentally redirect to hgBlat for a gene identifier // like ATG5 var dnaRe = new RegExp("^(>[^\n\r ]+[\n\r ]+)?(\\s*[actgnACTGN \n\r]{19,}\\s*)$"); if (dnaRe.test(newPos)) { var blatUrl = "hgBlat?type=BLAT%27s+guess&userSeq="+newPos; window.location.href = blatUrl; return false; } + // helper functions for checking whether a plain chrom name was searched for + term = encodeURIComponent(genomePos.get()); + function onSuccess(jqXHR, textStatus) { + if (jqXHR.chromName !== null) { + imageV2.markAsDirtyPage(); + imageV2.navigateInPlace("position=" + encodeURIComponent(newPos), null, false); + window.scrollTo(0,0); + } else { + window.location.assign("../cgi-bin/hgSearch?search=" + term + "&hgsid="+ getHgsid()); + } + } + function onFail(jqXHR, textStatus) { + window.location.assign("../cgi-bin/hgSearch?search=" + term + "&hgsid="+ getHgsid()); + } + // redirect to search disambiguation page if it looks like we didn't enter a regular position: var canonMatch = newPos.match(canonicalRangeExp); var gbrowserMatch = newPos.match(gbrowserRangeExp); var lengthMatch = newPos.match(lengthRangeExp); var bedMatch = newPos.match(bedRangeExp); var sqlMatch = newPos.match(sqlRangeExp); var singleMatch = newPos.match(singleBaseExp); var positionMatch = canonMatch || gbrowserMatch || lengthMatch || bedMatch || sqlMatch || singleMatch; if (positionMatch === null) { - window.location.assign("../cgi-bin/hgSearch?search=" + encodeURIComponent(genomePos.get()) + "&hgsid=" + getHgsid()); + // user may have entered a full chromosome name, check for that asynchronosly: + $.ajax({ + type: "GET", + url: "../cgi-bin/hgSearch", + data: cart.varsToUrlData({ 'cjCmd': '{"getChromName": {"db": "' + getDb() + '", "searchTerm": "' + term + '"}}' }), + dataType: "json", + trueSuccess: onSuccess, + success: onSuccess, + error: onFail, + cache: true + }); return false; } return true; }); // Have vis box changes update cart through ajax. This helps keep page/cart in sync. vis.initForAjax(); // We reach here from these possible paths: // A) Forward: Full page retrieval: hgTracks is first navigated to (or chrom change) // B) Back-button past a full retrieval (B in: ->A,->b,->c(full page),->d,<-c,<-B(again)) // B1) Dirty page: at least one non-position change (e.g. 1 track vis changed in b) // B2) Clean page: only position changes from A->b->| var curPos = encodeURIComponent(genomePos.get().replace(/,/g,'')); var curDbPos = hgTracks.lastDbPos;