[Libreoffice-commits] help.git: help3xsl/help.js

Ross Johnson (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 1 18:13:17 UTC 2021


 help3xsl/help.js |   43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

New commits:
commit 8b955ca1d2fa8132a22be12daeb416618277905c
Author:     Ross Johnson <ross.johnson at homemail.com.au>
AuthorDate: Wed Sep 29 23:45:54 2021 +1000
Commit:     Olivier Hallot <olivier.hallot at libreoffice.org>
CommitDate: Fri Oct 1 20:12:57 2021 +0200

    tdf#123506 - focus search results to user's current module
    
    This change focuses the search results on the module the user initially
    called help from and in addition, in the same way that the initial index
    is presented, limits the results to that module plus GLOBAL results.
    
    Explanation:
    Currently, when a user arrives at a help page from a module they begin
    with a blank search term and by default the index is focused on the module
    they came from.
    
    As they enter a search term the results from ALL modules are presented,
    paginated and either, (7.3 current) grouped by modules but in a fixed
    order of modules that often pushes results relative to the user's
    module off the first page of the index or, (7.2 and earlier)
    pseudo randomly with incorrect grouping under modules.
    
    If a user wishes to explor other module results they can choose a module
    from the Modules drop down. Their search term remains and they can
    easily search again.
    
    Change-Id: Ib10dd55d1c68a839938842fe3607a7a7619b3538
    Reviewed-on: https://gerrit.libreoffice.org/c/help/+/122903
    Tested-by: Jenkins
    Reviewed-by: Olivier Hallot <olivier.hallot at libreoffice.org>
    Reviewed-by: Rafael Lima <rafael.palma.lima at gmail.com>

diff --git a/help3xsl/help.js b/help3xsl/help.js
index 1f767a9c1..c67581d7b 100644
--- a/help3xsl/help.js
+++ b/help3xsl/help.js
@@ -11,9 +11,10 @@
 var url = window.location.pathname;
 var moduleRegex = new RegExp('text\\/(\\w+)\\/');
 var regexArray = moduleRegex.exec(url);
+var userModule = currentModule();
 var modules = ['CALC', 'WRITER', 'IMPRESS', 'DRAW', 'BASE', 'MATH', 'CHART', 'BASIC', 'SHARED'];
 var indexEl = document.getElementsByClassName("index")[0];
-var fullLinks = fullLinkify(indexEl, bookmarks, modules, currentModule());
+var fullLinks = fullLinkify(indexEl, bookmarks, modules, userModule);
 var search = document.getElementById('search-bar');
 search.addEventListener('keyup', debounce(filter, 100, indexEl));
 var flexIndex =  new FlexSearch.Document({ document: {
@@ -38,17 +39,29 @@ window.addEventListener('unload', function(event) {
     sessionStorage.setItem('searchsave', search.value);
 });
 
+function getQuery(q) {
+   var pattern = new RegExp('[?&]' + q + '=([^&]+)');
+   var param = window.location.search.match(pattern);
+   if (param) {
+       return param[1];
+   }
+   return null;
+}
+
 function currentModule() {
-    var module = '';
-    // get the module name from the URL and remove the first character,
-    // but first deal with snowflake Base
-    if(url.indexOf('explorer/database/') !== -1) {
-        module = 'BASE';
-    } else {
-        if (null === regexArray){// comes from search or elsewhere, no defined module in URL
-            module = 'HARED'
+    // We need to know the module that the user is using when they call for help
+    var module = getQuery('DbPAR');
+    if (module == null) {
+        // get the module name from the URL and remove the first character,
+        // but first deal with snowflake Base
+        if(url.indexOf('explorer/database/') !== -1) {
+            module = 'BASE';
         } else {
-            module = regexArray[1].toUpperCase().substring(1);
+            if (null === regexArray){// comes from search or elsewhere, no defined module in URL
+                module = 'HARED'
+            } else {
+                module = regexArray[1].toUpperCase().substring(1);
+            }
         }
     }
     return module;
@@ -99,6 +112,14 @@ function filter(indexList) {
     let regex = new RegExp(target.split(/\s+/).filter((i) => i?.length).join("|"), 'gi');
     let results = flexIndex.search(target, { pluck: "text", enrich: true, limit: 1000 });
 
+    // Similarly to fullLinkify(), limit search results to the user's current module + shared
+    // unless they're somehow not coming from a module.
+    if(userModule !== 'HARED') {
+        resultModules = [userModule, 'SHARED'];
+    } else {
+        resultModules = modules;
+    }
+
     // tdf#123506 - Group the filtered list into module groups, keeping the ordering
     modules.forEach(function(module) {
         group[module] = '';
@@ -106,7 +127,7 @@ function filter(indexList) {
     results.forEach(function(result) {
         group[result.doc.app] += '<a href="' + result.doc.url + '" class="' + result.doc.app + '">' + result.doc.text.replace(regex, (match) => `<strong>${match}</strong>`) + '</a>';
     });
-    modules.forEach(function(module) {
+    resultModules.forEach(function(module) {
         if (group[module].length > 0) {
             filtered += group[module];
         }


More information about the Libreoffice-commits mailing list