]> _ Git - odl.git/commitdiff
wip #5120
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 22 Feb 2022 15:38:38 +0000 (16:38 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 22 Feb 2022 15:38:38 +0000 (16:38 +0100)
resources/js/search.js

index 93e55d76391af45f027f3146d1a524eceac0d8d8..fc97c5fe4e718c75e97d9d00e1a83c6864e9e887 100644 (file)
@@ -14,9 +14,10 @@ export default () => ({
             prefix: true, // Allow partial matches
             processTerm: (term, _fieldName) => term.length < 3 ? null : term.toLowerCase()
         },
-    },
-    querystring: '', // The search query
+    }, querystring: '', // The search query
     query: '', // The search query
+    results:[],
+    resultCount:0,
     medialibrary: '', // Holds URL of the media library that is passed in from the component
 
     async init() {
@@ -51,31 +52,19 @@ export default () => ({
         return `<a href="${URL}" class="${classes}" ${attributes}>${result.title}</a>`;
     },
 
-    doSearch(){
-        this.query=this.querystring;
-    },
-
-    get results() {
-        if (this.query.length < 3) {
-            return [];
+    doSearch() {
+        this.query = this.querystring;
+        this.results = [];
+        if (this.query.length >= 3) {
+            this.results = this.miniSearch.search(this.query);
+            if (this.results.length === 1) {
+                this.resultCount = '1 résultat'
+            } else {
+                this.resultCount = this.results.length + ' résultats';
+            }
+        } else {
+            this.resultCount = "Veuillez taper au moins 3 caractères";
         }
-
-        return this.miniSearch.search(this.query);
-    },
-
-    get showResults() {
-        return false;
-    },
-
-    get resultCount() {
-        if (this.query.length < 3) {
-            return "Veuillez taper au moins 3 caractères";
-        }
-        if (this.results.length === 1) {
-            return '1 résultat'
-        }
-
-        return `${this.results.length} résultats`;
     },
 
 });