Changeset 38152 for main/trunk/greenstone3/web
- Timestamp:
- 2023-09-18T14:39:07+12:00 (9 months ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/facet-scripts.js
r33544 r38152 1 2 var facetSortOptions = { 3 valueNames: [ 'facet', 'count' ] 4 } 5 6 7 function getFacetQueryString(facetsThatAreChecked) 8 { 9 10 // if we have come here from eg next/prev page buttons, we won't have options selected in the 11 // facet list, we need to use the cgi param s1.facetQueries 12 if (gs.cgiParams.s1_facetQueries !== undefined) { 13 var facets = gs.cgiParams.s1_facetQueries; 14 // for some reason, we end up with " in here. Replace these back, so then we can call 15 // makeURLComponentSafe, and get back to the same encoded value we had originally 16 facets = facets.replace(/"/g, "\""); 17 return "s1.facetQueries="+makeURLComponentSafe(facets, 0)+"&"; 18 } 19 20 var allCheckBoxes = $("#facetSelector input"); 21 var counts = new Array(); 22 // var facetsThatAreChecked = new Set(); 23 for(var i = 0; i < allCheckBoxes.length; i++) 24 { 25 var current = $(allCheckBoxes[i]); 26 if(current.prop("checked")) 27 { 28 counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")"); 29 if (facetsThatAreChecked !== undefined) { 30 facetsThatAreChecked.add(current.parent().parent().attr("indexName")); 31 } 32 } 33 } 34 35 var countsString = "s1.facetQueries="; 36 if(counts.length > 0) 37 { 38 var countsStringBuffer = "["; 39 for(var i = 0; i < counts.length; i++) 40 { 41 // escape any apostrophes in facet query terms 42 // (ext/solr's Greenstone3SearchHandler does the other half of handling them) 43 //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\""; 44 // calling makeURLSafe() here will ensure percent signs are escaped away too 45 // by the end of makeURLComponentSafe() call below 46 // Note that apostrophe's in URLs should get encoded, https://www.techwalla.com/articles/how-to-encode-an-apostrophe-in-a-url 47 // though the apostrophe is not in that other list of invalid and unsafe chars in urls dealt with in utility_scripts.js 48 countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\""; 49 if(i < counts.length - 1) 50 { 51 countsStringBuffer += ", "; 52 } 53 } 54 55 countsStringBuffer += "]"; 56 // We need to ensure that the *value* of s1.facetQueries (so everything after 57 // s1.facetQueries= and before the connecting &) are safe, which requires escaping, 58 // and are further also escaped to not be mistaken for their reserved meaning. 59 // : is a reserved character in URLs, [] are unsafe characters. All need escaping. 60 // So call makeURLComponentSafe(), not makeURLSafe() 61 countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1); 62 } 63 64 countsString += "&"; 65 return countsString; 66 } 67 1 68 function performRefinedSearch() 69 { 70 var allCheckBoxes = $("#facetSelector input"); 71 var facetsThatAreChecked = new Set(); 72 var facetQueryString = getFacetQueryString(facetsThatAreChecked); 73 74 var searchString = ""; 75 for(var key in gs.cgiParams) 76 { 77 if (gs.cgiParams.hasOwnProperty(key)) 78 { 79 // reset the startPage to 1, as we can't keep the previous value as we are changing the search results list 80 if (key == "s1_startPage") { 81 searchString += "s1.startPage=1&"; 82 } else { 83 searchString += key.replace(/_/g, ".") + "=" + makeURLComponentSafe(gs.cgiParams[key]) + "&"; 84 } 85 // console.log("PARAM FOR key " + key + ":" + gs.cgiParams[key]); 86 // console.log("SAFE PARAM FOR " + key + ":" + makeURLComponentSafe(gs.cgiParams[key])); 87 } 88 } 89 90 $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + facetQueryString + "excerptid=gs_content") 91 .done(function(response) 92 { 93 var $response = $(response); 94 $("#resultsArea").replaceWith($response.find('#resultsArea')); 95 $("#matchdocs").replaceWith($response.find('#matchdocs')); 96 // the term lists don't need to be updated, as we don't get back any term freq info 97 // for facet terms 98 99 // only replace the facets that haven't been selected 100 var $current_facets = $(".facetContainer"); 101 for (var i=0; i<$current_facets.length; i++) { 102 var $current = $($current_facets[i]); 103 var indexName = $current.attr("indexName"); 104 105 if (!facetsThatAreChecked.has(indexName)) { 106 var $newNode =$response.find('#'+indexName); 107 $current.replaceWith($newNode); 108 } 109 } 110 111 if(gs.cgiParams.favouritebasket == "on") { 112 // this will highlight the stars on the docs that are in favourites 113 favouritesCheckout(); 114 } 115 if(typeof mapEnabled !== 'undefined') { 116 117 facetedMapSearch(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + facetQueryString); 118 119 } 120 }); 121 122 } 123 124 function updateNextPrevLinks(facetQueryString) { 125 126 if (facetQueryString === undefined) { 127 facetQueryString = getFacetQueryString(); 128 } 129 130 $("#nextTD,#nextArrowTD,#prevTD,#prevArrowTD").children("a").each(function() { 131 $(this).attr("href", $(this).attr("href") + "&"+facetQueryString); 132 }); 133 134 } 135 136 function performRefinedSearchORIG() 2 137 { 3 138 var allCheckBoxes = $("#facetSelector input"); 4 139 var counts = new Array(); 5 140 for(var i = 0; i < allCheckBoxes.length; i++) 6 141 { 7 142 var current = $(allCheckBoxes[i]); 8 143 if(current.prop("checked")) 9 144 { 10 145 counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")"); 11 146 } 12 147 } … … 54 189 55 190 countsString += "&"; 56 //console.log("STRING IS " + countsString);191 console.log("STRING IS " + countsString); 57 192 58 193 $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea") … … 61 196 $("#resultsArea").html(""); 62 197 $("#resultsArea").html(response.substring(response.indexOf(">") + 1, response.lastIndexOf("<"))); 63 if(gs.cgiParams.berrybasket == "on") {64 berryCheckout(); // called to add back in berries (if berrybasket active)65 }66 198 if(gs.cgiParams.favouritebasket == "on") { 67 199 favouritesCheckout(); // called to add back in favourites icons (if favouritebasket active) … … 73 205 } 74 206 }); 207 75 208 } 76 209 … … 99 232 var morelink = $(".expandFacetList" + indexName); 100 233 morelink.css("display", "none"); 234 var lesslink = $(".collapseFacetList" + indexName); 235 lesslink.css("display", "block"); 236 101 237 102 238 } … … 129 265 var morelink = $(".expandFacetList" + indexName); 130 266 morelink.css("display", "block"); 131 132 } 133 267 var lesslink = $(".collapseFacetList" + indexName); 268 lesslink.css("display", "none"); 269 270 } 271 -
main/trunk/greenstone3/web/interfaces/default/transform/pages/query.xsl
r38084 r38152 118 118 <script type="text/javascript" src="interfaces/{$interface_name}/js/utility_scripts.js"><xsl:text> </xsl:text></script> 119 119 <script type="text/javascript" src="interfaces/{$interface_name}/js/facet-scripts.js"> 120 <xsl:text> </xsl:text> 121 </script>122 120 <xsl:text> </xsl:text></script> 121 <script type="text/javascript" src="interfaces/default/js/List.js"> 122 <xsl:text> </xsl:text></script> 123 123 <div id="facetSelector" > 124 124 <xsl:for-each select="/page/pageResponse/facetList/facet"> 125 125 <xsl:if test="count(count) > 0"> 126 < ul class="facetTable ui-widget-content" indexName="{@name}">126 <div class="facetContainer ui-widget-content" indexName="{@name}" id="{@name}"> 127 127 <xsl:variable name="serviceName"> 128 128 <xsl:value-of select="/page/pageRequest/paramList/param[@name = 's']/@value"/> … … 143 143 <xsl:value-of select="displayItem[@name='name']"/> 144 144 </li> 145 <input class="search" placeholder="Search" /><button class="sort" data-sort="facet">Sort by facet</button><button class="sort" data-sort="count">Sort by count</button> 146 <ul class="list facetTable" indexName="{@name}"> 145 147 <xsl:for-each select="count"> 146 148 <li> … … 150 152 </xsl:attribute> 151 153 <input type="checkbox" onclick="performRefinedSearch();"/> 152 <span> 153 <xsl:value-of select="@name"/> 154 </span>(<xsl:value-of select="."/>) 154 <span class="facet"><xsl:value-of select="@name"/></span> 155 <span class="count"> (<xsl:value-of select="."/>)</span> 155 156 </li> 156 157 </xsl:for-each> 158 </ul> 157 159 <xsl:if test="count(count) > $countSize"> 158 160 <li class="expandFacetList{$indexShortName}"> … … 163 165 </li> 164 166 </xsl:if> 165 </ul> 167 </div> 168 <script type="text/javascript"> 169 <xsl:text disable-output-escaping="yes">var facetList</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes"> = new List('</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">', facetSortOptions);</xsl:text> 170 </script> 171 166 172 </xsl:if> 167 173 </xsl:for-each> … … 439 445 440 446 <xsl:for-each select="/page/pageResponse/termList/term"> 447 <xsl:if test="@freq != -1"> 441 448 <xsl:variable name="levelText"> 442 449 <!-- this gets document, section, documents, sections, depending on level and number --> … … 481 488 </span> 482 489 <br/> 490 </xsl:if> 483 491 </xsl:for-each> 484 492 </xsl:when> 485 493 <xsl:otherwise> 486 494 <xsl:for-each select="/page/pageResponse/termList/term"> 495 <xsl:if test="@freq != -1"> 487 496 <span style="font-style:italic;"> 488 497 <xsl:value-of select="@name"/> 489 498 </span> (<xsl:value-of select="@freq"/>) 499 </xsl:if> 490 500 </xsl:for-each> 491 501 </xsl:otherwise> … … 549 559 <xsl:variable name="startPageName"> 550 560 <xsl:if test="$usesS1 = 'true'">s1.</xsl:if>startPage</xsl:variable> 551 561 <xsl:variable name="queryLink"><xsl:value-of select="$library_name"/>?a=q&sa=<xsl:value-of select="/page/pageRequest/@subaction"/>&c=<xsl:value-of select="$collName"/>&s=<xsl:value-of select="/page/pageResponse/service/@name"/>&rt=rd&qs=<xsl:value-of select="/page/pageRequest/paramList/param[@name='qs']/@value"/></xsl:variable> 552 562 <!-- Previous button --> 553 563 <td id="prevArrowTD"> 554 564 <xsl:if test="$currentPage != 1"> 555 <a href="{$ library_name}?a=q&sa={/page/pageRequest/@subaction}&c={$collName}&s={/page/pageResponse/service/@name}&rt=rd&{$startPageName}={$currentPage - 1}&qs={/page/pageRequest/paramList/param[@name='qs']/@value}">565 <a href="{$queryLink}&{$startPageName}={$currentPage - 1}"> 556 566 <xsl:call-template name="previousArrowImage"/> 557 567 </a> … … 560 570 <td id="prevTD"> 561 571 <xsl:if test="$currentPage != 1"> 562 <a href="{$ library_name}?a=q&sa={/page/pageRequest/@subaction}&c={$collName}&s={/page/pageResponse/service/@name}&rt=rd&{$startPageName}={$currentPage - 1}&qs={/page/pageRequest/paramList/param[@name='qs']/@value}"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.results.previous')"/></a>572 <a href="{$queryLink}&{$startPageName}={$currentPage - 1}"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.results.previous')"/></a> 563 573 </xsl:if> 564 574 </td> … … 597 607 <td id="nextTD"> 598 608 <xsl:if test="$docsPerPage > 0 and ($currentPage * $docsPerPage) < $docMax"> 599 <a href="{$ library_name}?a=q&sa={/page/pageRequest/paramList/param[@name = 'sa']/@value}&c={$collName}&s={/page/pageResponse/service/@name}&rt=rd&{$startPageName}={$currentPage + 1}&qs={/page/pageRequest/paramList/param[@name='qs']/@value}"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.results.next')"/></a>609 <a href="{$queryLink}&{$startPageName}={$currentPage + 1}"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.results.next')"/></a> 600 610 </xsl:if> 601 611 </td> 602 612 <td id="nextArrowTD"> 603 613 <xsl:if test="$docsPerPage > 0 and ($currentPage * $docsPerPage) < $docMax"> 604 <a href="{$ library_name}?a=q&sa={/page/pageRequest/paramList/param[@name = 'sa']/@value}&c={$collName}&s={/page/pageResponse/service/@name}&rt=rd&{$startPageName}={$currentPage + 1}&qs={/page/pageRequest/paramList/param[@name='qs']/@value}">614 <a href="{$queryLink}&{$startPageName}={$currentPage + 1}"> 605 615 <xsl:call-template name="nextArrowImage"/> 606 616 </a> … … 609 619 </tr> 610 620 </table> 621 <xsl:if test="/page/pageResponse/facetList/facet/count"> 622 <script type="text/javascript"> 623 <xsl:text disable-output-escaping="yes"> 624 updateNextPrevLinks(); 625 </xsl:text> 626 </script> 627 </xsl:if> 611 628 </xsl:if> 612 629 </xsl:template>
Note:
See TracChangeset
for help on using the changeset viewer.