[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Fix Zotero search results display and scrolling

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68908a2c4db61_2ca2646c917a7@gitlab-sidekiq-low-urgency-cpu-bound-v2-8647874c67-4c8gw.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
fe2e2edc by Espoir Baraka at 2025-08-04T10:16:00+00:00
[FIX] Fix Zotero search results display and scrolling
---
* [FIX] Fix Zotero search results display and scrolling

See merge request tikiwiki/tiki!8171

- - - - -


3 changed files:

- lib/zoterolib.php
- templates/modules/mod-zotero.tpl
- tiki-ajax_services.php


Changes:

=====================================
lib/zoterolib.php
=====================================
@@ -27,46 +27,51 @@ class ZoteroLib extends TikiDb_Bridge
     {
         global $prefs;
 
-        $subset = null;
-        if ($tag) {
-            $subset = '/tags/' . rawurlencode($tag);
-        }
-
-        $arguments = [
-            'content' => 'bib',
-            'limit' => $limit,
-        ];
-
-        if (! empty($prefs['zotero_style'])) {
-            $arguments['style'] = $prefs['zotero_style'];
-        }
+        try {
+            $subset = null;
+            if ($tag) {
+                $subset = '/tags/' . rawurlencode($tag);
+            }
 
-        $oauthlib = TikiLib::lib('oauth');
-        $response = $oauthlib->do_request(
-            'zotero',
-            [
-                'url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}$subset/items",
-                'get' => $arguments,
-            ]
-        );
+            $arguments = [
+                'content' => 'bib',
+                'limit' => $limit,
+            ];
 
-        if ($response && $response->isSuccessful()) {
-            $feed = Laminas\Feed\Reader\Reader::importString($response->getBody());
+            if (! empty($prefs['zotero_style'])) {
+                $arguments['style'] = $prefs['zotero_style'];
+            }
 
-            $data = [];
-            foreach ($feed as $entry) {
-                $data[] = [
-                    'key' => basename($entry->getLink()),
-                    'url' => $entry->getLink(),
-                    'title' => $entry->getTitle(),
-                    'content' => $entry->getDescription(),
-                ];
+            $oauthlib = TikiLib::lib('oauth');
+            $response = $oauthlib->do_request(
+                'zotero',
+                [
+                    'url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}$subset/items",
+                    'get' => $arguments,
+                ]
+            );
+
+            if ($response && $response->isSuccess()) {
+                $feed = Laminas\Feed\Reader\Reader::importString($response->getBody());
+
+                $data = [];
+                foreach ($feed as $entry) {
+                    $data[] = [
+                        'key' => basename($entry->getLink()),
+                        'url' => $entry->getLink(),
+                        'title' => $entry->getTitle(),
+                        'content' => $entry->getDescription(),
+                    ];
+                }
+
+                return $data;
             }
 
-            return $data;
+            return false;
+        } catch (Exception $e) {
+            error_log("Zotero get_references error: " . $e->getMessage());
+            return false;
         }
-
-        return false;
     }
 
     /**
@@ -107,7 +112,7 @@ class ZoteroLib extends TikiDb_Bridge
             ]
         );
 
-        if ($response->isSuccessful()) {
+        if ($response->isSuccess()) {
             $entry = $response->getBody();
             $entry = str_replace('<entry ', '<feed xmlns="http://www.w3.org/2005/Atom"><entry ', $entry) . '</feed>';
             $feed = Laminas\Feed\Reader\Reader::importString($entry);
@@ -157,7 +162,7 @@ class ZoteroLib extends TikiDb_Bridge
             ]
         );
 
-        if ($response->isSuccessful()) {
+        if ($response->isSuccess()) {
             $entry = $response->getBody();
 
             return $entry;


=====================================
templates/modules/mod-zotero.tpl
=====================================
@@ -1,9 +1,18 @@
 {tikimodule error=$module_params.error title=$tpl_module_title name="zotero" flip=$module_params.flip decorations=$module_params.decorations nobox=$module_params.nobox notitle=$module_params.notitle}
     <form class="zoterosearch" method="post" action="tiki-ajax_services.php">
-        <input type="text" name="zotero_tags"/>
-        <input type="submit" class="btn btn-info btn-sm" name="zotero" value="{tr}Search{/tr}"/>
-        <ul class="results">
-        </ul>
+        <div class="input-group">
+            <input type="text" name="zotero_tags" placeholder="Enter a tag to filter (optional)"/>
+            <button type="submit" class="btn btn-info btn-sm" name="zotero">
+                <i class="fas fa-search"></i> {tr}Search{/tr}
+            </button>
+        </div>
+        <small class="form-text text-muted">
+            Leave the field empty to see all your references, or enter a tag to filter
+        </small>
+        <div class="results-container" style="max-height: 400px; overflow-y: auto; border: 1px solid #dee2e6; border-radius: 0.375rem; padding: 10px; background-color: #f8f9fa;">
+            <ul class="results list-unstyled mb-0">
+            </ul>
+        </div>
         <div class="alert alert-warning">
             {remarksbox type="errors" title="{tr}No results!{/tr}"}
                 <p>{tr}No results were found. Are you sure you searched for a tag?{/tr}</p>
@@ -17,32 +26,53 @@
     </form>
     {jq}
     $('.zoterosearch:not(.done)').addClass('done')
-        .find('.results, .error').hide().end()
+        .find('.results-container, .alert').hide().end()
         .on("submit", function (e) {
             var form = this;
 
             e.preventDefault();
-            $.post(this.action, $(this).serialize(), function (data) {
-                var isError = data.type == 'unauthorized';
-                $('.error', form).toggle(isError || data.results.length === 0);
-                $('.results', form).toggle(! isError).empty();
-
-                $.each(data.results, function (k, i) {
-                    var entry = $('<li/>').hide(), link = $('<strong/>');
-                    entry
-                        .append($(i.content))
-                        .append($('<a/>').text('Zotero').attr('href', i.url))
-                        .append($('<input type="text"/>').val('{zotero key=' + i.key + '}'));
+            $.ajax({
+                url: this.action,
+                type: 'POST',
+                data: $(this).serialize(),
+                dataType: 'json',
+                success: function (data) {
+                    var isError = data.type == 'unauthorized' || data.type == 'no_results';
+                    $('.alert', form).toggle(isError || data.results.length === 0);
+                    $('.results-container', form).toggle(! isError);
+                                        $('.results', form).empty();
+                    
+                    if (data.results.length > 0) {
+                        $('.results', form).prepend('<div class="alert alert-success mb-3">Found ' + data.results.length + ' reference(s)</div>');
+                    }
 
-                    link.text(i.title);
-                    link.css('cursor', 'pointer');
-                    link.on("click", function () {
-                        entry.toggle();
-                        $(':text', entry).trigger("select").trigger("focus");
+                    $.each(data.results, function (k, i) {
+                        var entry = $('<li/>').hide().addClass('mb-3 p-2 border-bottom'), link = $('<strong/>');
+                        
+                        var contentDiv = $('<div/>').addClass('mt-2');
+                        if (i.content) {
+                            contentDiv.append($('<div/>').html(i.content));
+                        }
+                        
+                        var zoteroLink = $('<a/>').text('View in Zotero').attr('href', i.url).addClass('btn btn-sm btn-outline-primary me-2');
+                        var copyInput = $('<input type="text"/>').val('{zotero key=' + i.key + '}').addClass('form-control form-control-sm d-inline-block w-auto me-2');
+                        entry.append(contentDiv).append(zoteroLink).append(copyInput);
+                        link.text(i.title);
+                        link.css('cursor', 'pointer').addClass('text-primary d-block mb-1');
+                        link.on("click", function () {
+                            entry.toggle();
+                            copyInput.trigger("select").trigger("focus");
+                        });
+                        
+                        $('.results', form).append(link).append(entry);
                     });
-                    $('.results', form).append(link).append(entry);
-                });
-            }, 'jsonp');
+                },
+                error: function(xhr, status, error) {
+                    console.error('Zotero search error:', error);
+                    $('.alert', form).show();
+                    $('.results-container', form).hide();
+                }
+            });
 
             return false;
         });


=====================================
tiki-ajax_services.php
=====================================
@@ -184,14 +184,24 @@ if ($access->is_serializable_request() && $jitRequest->offsetExists('listonly'))
     }
 } elseif ($access->is_serializable_request() && isset($_REQUEST['zotero_tags'])) { // Handle Zotero Requests
     $access->check_feature([ 'zotero_enabled' ]);
-    $zoterolib = TikiLib::lib('zotero');
 
-    $references = $zoterolib->get_references($_REQUEST['zotero_tags']);
+    try {
+        $zoterolib = TikiLib::lib('zotero');
+        $references = $zoterolib->get_references($_REQUEST['zotero_tags']);
 
-    if ($references === false) {
-        $access->output_serialized(['type' => 'unauthorized', 'results' => []]);
-    } else {
-        $access->output_serialized(['type' => 'success', 'results' => $references]);
+        if ($references === false) {
+            $oauthlib = TikiLib::lib('oauth');
+            if (! $oauthlib->is_authorized('zotero')) {
+                $access->output_serialized(['type' => 'unauthorized', 'results' => []]);
+            } else {
+                $access->output_serialized(['type' => 'no_results', 'results' => []]);
+            }
+        } else {
+            $access->output_serialized(['type' => 'success', 'results' => $references]);
+        }
+    } catch (Exception $e) {
+        error_log("Zotero error: " . $e->getMessage());
+        $access->output_serialized(['type' => 'error', 'message' => $e->getMessage(), 'results' => []]);
     }
 } elseif (isset($_REQUEST['geocode']) && $access->is_serializable_request()) {
     $access->output_serialized(TikiLib::lib('geo')->geocode($_REQUEST['geocode']));



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fe2e2edc4c1763b7a9743e9def1281b4abc0160b

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fe2e2edc4c1763b7a9743e9def1281b4abc0160b
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.