diff --git a/modules/roblib_search_eds/js/eds_results_article.js b/modules/roblib_search_eds/js/eds_results_article.js index b88695a..adb09a8 100644 --- a/modules/roblib_search_eds/js/eds_results_article.js +++ b/modules/roblib_search_eds/js/eds_results_article.js @@ -1,85 +1,89 @@ Drupal.behaviors.roblib_search_eds_articles = { - attach: function (context, settings) { - $url = settings.roblib_search_eds_articles.search_url; - articles_profile = settings.roblib_search_eds_articles.eds_profile; - proxy_url = "https://proxy.library.upei.ca/login?url="; - jQuery.getJSON($url, function (data) { - var items = []; - var numberOfDocs = 0; - try { - numberOfDocs = data.numFound; - } catch (err) { - // do nothing leave docLength at 0 - } - if (numberOfDocs < 1) { - jQuery('#' + 'roblib-search-content-eds').empty().append('No Results'); - jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-articles').hide(); - } else { - var counter = 0; - var divs = new Array(); - var content = new Array(); - var queries = []; - jQuery.each(data.queries, function (key7, query) { - queries.push(query.query); - }) - var query_str = encodeURI(data.queries[0].query); - var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profile=eds&mode=bool&lang=en&bquery='; - jQuery.each(data.documents, function (key, val) { - id = 'roblib-search-eds-article-' + counter; - divs[counter++] = id; + attach: function (context, settings) { + if (context == document) { + $query = $current_path.replace('roblib_search/', ''); + $url = settings.eds_article_search_url + $query; + profile = settings.eds_article_profile; + proxy_url = "https://proxy.library.upei.ca/login?url="; + jQuery.getJSON($url, function (data) { + var items = []; + var numberOfDocs = 0; + try { + numberOfDocs = data.numFound; + } catch (err) { + // do nothing leave docLength at 0 + } + if (numberOfDocs < 1) { + jQuery('#' + 'roblib-search-content-eds').empty().append('No Results'); + jQuery('.' + 'pane-roblib-search-eds-roblib-search-eds-articles').hide(); + } else { + var counter = 0; + var divs = new Array(); + var content = new Array(); + var queries = []; + jQuery.each(data.queries, function (key7, query) { + queries.push(query.query); + }) + var query_str = encodeURI(data.queries[0].query); + var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profile=eds&mode=bool&lang=en&bquery='; + jQuery.each(data.documents, function (key, val) { + id = 'roblib-search-eds-article-' + counter; + divs[counter++] = id; - if (typeof val.Items !== 'undefined') { - items.push('
- provides a target for the Roblib search module. This target uses javascript + provides a EDSAPI target for the Roblib search module. This target uses javascript to render the results.
' ); diff --git a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php index a3dd6dc..3aa9950 100644 --- a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php +++ b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php @@ -15,13 +15,28 @@ use Drupal\Core\Block\BlockBase; */ class RoblibSearchEdsArticles extends BlockBase { - /** + /** * {@inheritdoc} */ public function build() { - return [ + $host = \Drupal::request()->getSchemeAndHttpHost(); + $search_url = $host . '/roblib_search/eds/articles/'; + $eds_profile = \Drupal::config('roblib_search_eds.settings') + ->get('eds_article_profile'); + $settings = [ + 'eds_article_search_url' => $search_url, + 'eds_article_profile' => $eds_profile, + ]; + return [ '#theme' => 'roblib_search_eds_articles', - '#query' => $query, + 'query' => $query, + 'spinner_path' => 'test', + '#attached' => [ + 'library' => [ + 'roblib_search_eds/eds-article' + ], + 'drupalSettings' => $settings, + ], ]; } } diff --git a/modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig b/modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig index b24bb89..ff6c144 100644 --- a/modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig +++ b/modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig @@ -1,10 +1,8 @@