Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AvailabilityPlus: updated AJAX-Request-Handling / added Unpaywall Rule #141

Open
wants to merge 2 commits into
base: develop-5-aplus-h
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions config/vufind/availabilityplus-resolver-Unpaywall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# In this file rules can be configured to change the output of a resolver.
# These rules are used in function applyCustomChanges in the resolver class.
#
#TestRule: # name of the rule, required
# descripton: 'description' # optional
# reason: 'reason for rule' # optional
# date: 'date yyyy-mm-dd' # optional
# creator: 'John Doe' # optional
# examples: 'e.g. an id in the index' # optional
# details: 'http://www.more-details.vufind' # optional, a url
# conditions: # one or multiple conditions can be specified that need to match for the actions to take place
# - { field: 'field1->subfield1', content: '(.*)' } #field: specifies the path to a field that needs to be checked, use -> to indicate a subfield, subsubfield ... / content: can be a string or regular expression
# actions: # indicate what actions are to be taken, if all conditions are fullfilled
# - { field: 'field1->subfield1->subsubfield1', content: '' } # complete string replacement by indicating a field and the new content
# - { field: 'field1->subfield1', content_field: 'field2->contentfromsubfield2', pattern: '(.*?):(.*)', replacement: '$2'} # regex-based replacement, content can be from the same field or another field
# - { function: 'removeItem'} # a function in the resolver can be specified, currently only one function is supported for all resolvers: removeItem
# - { function: 'adjustScore', score: 200} # DAIA also supports the function adjustScore, requiring a score parameter with an integer
# Example
RemoveItemForUrl1:
description: 'Entfernung eines Items, mit URL, die nicht zum Volltext führt'
reason: ''
date: ''
creator: ''
examples: 'PPN 517096420'
detailsLink: ''
conditions:
- { field: 'url', content: 'https://www.degruyter.com/document/doi/10.1515/jag-2021-frontmatter3/pdf' }
actions:
- { function: 'removeItem'}
108 changes: 32 additions & 76 deletions themes/availabilityplus/js/check_item_statuses.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
/*global Hunt, VuFind */
/*exported checkItemStatuses, itemStatusFail */

function linkCallnumbers(callnumber, callnumber_handler) {
if (callnumber_handler) {
var cns = callnumber.split(',\t');
for (var i = 0; i < cns.length; i++) {
cns[i] = '<a href="' + VuFind.path + '/Alphabrowse/Home?source=' + encodeURI(callnumber_handler) + '&amp;from=' + encodeURI(cns[i]) + '">' + cns[i] + '</a>';
}
return cns.join(',\t');
}
return callnumber;
}

function displayItemStatus(results, item) {
item.removeClass('js-item-pending');
item.find('.ajax-availability').removeClass('ajax-availability hidden');
item.find('.status').empty();
var id = item.attr('data-id');
let id = item.attr('data-id');
$.each(results, function(index, result){
if (typeof(result.error) != 'undefined'
&& result.error.length > 0
@@ -48,18 +37,16 @@ function itemStatusFail(response, textStatus) {
.append(typeof response.responseJSON.data === 'string' ? response.responseJSON.data : VuFind.translate('error_occurred'));
}

var itemStatusIds = [];
var itemStatusEls = {};
var itemStatusTimer = null;
var itemStatusDelay = 200;
var itemStatusRunning = false;
var itemStatusList = false;
var itemStatusSource = '';
var itemStatusHideLink = '';
var itemStatusType = '';
var itemStatusMediatype = '';
var itemLanguage = '';
var itemStatusDebug = '';
let itemStatusIds = [];
let itemStatusEls = {};
let itemStatusTimer = null;
let itemStatusDelay = 200;
let itemStatusRunning = false;
let itemStatusList = false;
let itemStatusSource = '';
let itemStatusMediatype = '';
let itemLanguage = '';
let itemStatusDebug = '';

function runItemAjaxForQueue() {
// Only run one item status AJAX request at a time:
@@ -69,8 +56,8 @@ function runItemAjaxForQueue() {
}
itemStatusRunning = true;

for (var i=0; i<itemStatusIds.length; i++) {
var item = itemStatusEls[itemStatusIds[i]];
for (let i=0; i<itemStatusIds.length; i++) {
let item = itemStatusEls[itemStatusIds[i]];
itemStatusSource = item.attr('data-src');
itemStatusList = (item.attr('data-list') == 1);
itemStatusMediatype = item.attr('data-mediatype');
@@ -83,8 +70,8 @@ function runItemAjaxForQueue() {
data: {id:[itemStatusIds[i]], list:itemStatusList, source:itemStatusSource, mediatype:itemStatusMediatype, language:itemLanguage, debug:itemStatusDebug}
})
.done(function checkItemStatusDone(response) {
for (var j = 0; j < response.data.statuses.length; j++) {
var status = response.data.statuses[j];
for (let j = 0; j < response.data.statuses.length; j++) {
let status = response.data.statuses[j];
displayItemStatus(status, itemStatusEls[status.id]);
itemStatusIds.splice(itemStatusIds.indexOf(status.id), 1);
}
@@ -104,7 +91,7 @@ function itemQueueAjax(id, el) {
clearTimeout(itemStatusTimer);
itemStatusIds.push(id);
itemStatusEls[id] = el;
var item = $(el);
let item = $(el);
itemStatusSource = item.attr('data-src');
itemStatusList = (item.attr('data-list') == 1);
itemStatusMediatype = item.attr('data-mediatype');
@@ -117,55 +104,24 @@ function itemQueueAjax(id, el) {
el.find('.status').removeClass('hidden');
}

//Listenansicht
function checkItemStatus(el) {
var item = $(el);
var id = item.attr('data-id');
itemStatusSource = item.attr('data-src');
itemStatusList = (item.attr('data-list') == 1);
itemStatusMediatype = item.attr('data-mediatype');
itemLanguage = item.attr('data-language');
itemStatusDebug = item.attr('data-debug');
itemQueueAjax(id + '', item);
}

var itemStatusObserver = null;

function checkItemStatuses(_container) {
var container = typeof _container === 'undefined'
? document.body
: _container;

var availabilityItems = $(container).find('.availabilityItem');
for (var i = 0; i < availabilityItems.length; i++) {
var id = $(availabilityItems[i]).attr('data-id');
itemStatusSource = $(availabilityItems[i]).attr('data-src');
itemStatusList = ($(availabilityItems[i]).attr('data-list') == 1);
itemStatusMediatype = $(availabilityItems[i]).attr('data-mediatype');
itemLanguage = $(availabilityItems[i]).attr('data-language');
itemStatusDebug = $(availabilityItems[i]).attr('data-debug');
itemQueueAjax(id, $(availabilityItems[i]));
}
// Stop looking for a scroll loader
if (itemStatusObserver) {
itemStatusObserver.disconnect();
}
function checkItemStatuses() {
$('.availabilityItem').each(function() {
if ($(this).offset().top < $(window).scrollTop() + $(window).height() && $(this).offset().top + $(this).height() > $(window).scrollTop() && $(this).find('.ajax-availability').length !== 0 ) {
let id = $(this).attr('data-id');
itemStatusSource = $(this).attr('data-src');
itemStatusList = ($(this).attr('data-list') == 1);
itemStatusMediatype = $(this).attr('data-mediatype');
itemLanguage = $(this).attr('data-language');
itemStatusDebug = $(this).attr('data-debug');
itemQueueAjax(id, $(this));
}
});
}
$(document).ready(function() {
function checkItemStatusReady() {
if (typeof Hunt === 'undefined') {
checkItemStatuses();
} else {
itemStatusObserver = new Hunt(
$('.availabilityItem').toArray(),
{
enter: checkItemStatus,
offset: 100000
}
);
}
}
checkItemStatusReady();
checkItemStatuses();
$(window).on('scroll resize', function() {
checkItemStatuses();
});
});

function initDaiaPlusOverlay () {