|
Lines 86-92
Link Here
|
| 86 |
updateTable(); |
86 |
updateTable(); |
| 87 |
updateRowCount(); |
87 |
updateRowCount(); |
| 88 |
updateProcessTotals(); |
88 |
updateProcessTotals(); |
| 89 |
checkAvailability(); |
|
|
| 90 |
} |
89 |
} |
| 91 |
} |
90 |
} |
| 92 |
); |
91 |
); |
|
Lines 235-287
Link Here
|
| 235 |
}); |
234 |
}); |
| 236 |
}; |
235 |
}; |
| 237 |
|
236 |
|
| 238 |
// Identify items that can have their availability checked, and do it |
237 |
async function populateAvailability(row) { |
| 239 |
function checkAvailability() { |
238 |
let metadata = row.metadata; |
| 240 |
// Only proceed if we've got services that can check availability |
|
|
| 241 |
if (!batch_availability_services || batch_availability_services.length === 0) return; |
| 242 |
var toCheck = tableContent.data; |
| 243 |
toCheck.forEach(function (row) { |
| 244 |
if ( |
| 245 |
!row.url && |
| 246 |
Object.keys(row.metadata).length > 0 && |
| 247 |
!availabilitySent[row.value] |
| 248 |
) { |
| 249 |
availabilitySent[row.value] = 1; |
| 250 |
getAvailability(row.value, row.metadata); |
| 251 |
} |
| 252 |
}); |
| 253 |
}; |
| 254 |
|
239 |
|
| 255 |
// Check availability services for immediate availability, if found, |
|
|
| 256 |
// create a link in the table linking to the item |
| 257 |
function getAvailability(identifier, metadata) { |
| 258 |
// Prep the metadata for passing to the availability plugins |
| 259 |
let availability_object = {}; |
240 |
let availability_object = {}; |
| 260 |
if (metadata.issn) availability_object['issn'] = metadata.issn; |
241 |
if (metadata.issn) availability_object['issn'] = metadata.issn; |
| 261 |
if (metadata.doi) availability_object['doi'] = metadata.doi; |
242 |
if (metadata.doi) availability_object['doi'] = metadata.doi; |
| 262 |
if (metadata.pubmedid) availability_object['pubmedid'] = metadata.pubmedid; |
243 |
if (metadata.pubmedid) availability_object['pubmedid'] = metadata.pubmedid; |
| 263 |
var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object))); |
244 |
|
| 264 |
for (i = 0; i < batch_availability_services.length; i++) { |
245 |
// Check each service and use the first results we get, if any |
| 265 |
var service = batch_availability_services[i]; |
246 |
var av_hits = []; |
| 266 |
window.doApiRequest( |
247 |
for (const service of batch_availability_services){ |
| 267 |
service.endpoint + prepped |
248 |
var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object))); |
| 268 |
) |
249 |
|
| 269 |
.then(function (response) { |
250 |
var endpoint = service.endpoint + prepped; |
| 270 |
return response.json(); |
251 |
var availability = await getAvailability(endpoint); |
| 271 |
}) |
252 |
if (availability.results.search_results && availability.results.search_results.length > 0) { |
| 272 |
.then(function (data) { |
253 |
av_hits.push({name: service.name, url: availability.results.search_results[0].url}); |
| 273 |
if (data.results.search_results && data.results.search_results.length > 0) { |
254 |
}else{ |
| 274 |
var result = data.results.search_results[0]; |
255 |
av_hits.push({ name: service.name, empty:1 }); |
| 275 |
tableContent.data = tableContent.data.map(function (row) { |
256 |
} |
| 276 |
if (row.value === identifier) { |
257 |
}; |
| 277 |
row.url = result.url; |
258 |
return av_hits; |
| 278 |
row.availabilitySupplier = service.name; |
|
|
| 279 |
} |
| 280 |
return row; |
| 281 |
}); |
| 282 |
} |
| 283 |
}); |
| 284 |
} |
| 285 |
}; |
259 |
}; |
| 286 |
|
260 |
|
| 287 |
// Help btoa with > 8 bit strings |
261 |
// Help btoa with > 8 bit strings |
|
Lines 685-690
Link Here
|
| 685 |
} else if (alreadyInDeduped.length === 0) { |
659 |
} else if (alreadyInDeduped.length === 0) { |
| 686 |
row.metadata = {}; |
660 |
row.metadata = {}; |
| 687 |
row.failed = {}; |
661 |
row.failed = {}; |
|
|
662 |
row.availability_hits = {}; |
| 688 |
row.requestId = null; |
663 |
row.requestId = null; |
| 689 |
deduped.push(row); |
664 |
deduped.push(row); |
| 690 |
} |
665 |
} |
|
Lines 735-740
Link Here
|
| 735 |
} catch (e) { |
710 |
} catch (e) { |
| 736 |
row.failed = ill_populate_failed; |
711 |
row.failed = ill_populate_failed; |
| 737 |
} |
712 |
} |
|
|
713 |
|
| 714 |
if (ill_check_availability_syspref == 1){ |
| 715 |
try { |
| 716 |
var availability = await populateAvailability(row); |
| 717 |
row.availability_hits = availability || {}; |
| 718 |
} catch (e) { |
| 719 |
//do nothing |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 738 |
newData[i] = row; |
723 |
newData[i] = row; |
| 739 |
tableContent.data = newData; |
724 |
tableContent.data = newData; |
| 740 |
} |
725 |
} |
|
Lines 770-775
Link Here
|
| 770 |
} |
755 |
} |
| 771 |
}; |
756 |
}; |
| 772 |
|
757 |
|
|
|
758 |
async function getAvailability(endpoint) { |
| 759 |
var response = await debounce(doApiRequest)(endpoint); |
| 760 |
return response.json(); |
| 761 |
}; |
| 762 |
|
| 773 |
async function getMetadata(endpoint) { |
763 |
async function getMetadata(endpoint) { |
| 774 |
var response = await debounce(doApiRequest)(endpoint); |
764 |
var response = await debounce(doApiRequest)(endpoint); |
| 775 |
return response.json(); |
765 |
return response.json(); |
|
Lines 820-834
Link Here
|
| 820 |
label.innerText = ill_batch_metadata[prop] + ': '; |
810 |
label.innerText = ill_batch_metadata[prop] + ': '; |
| 821 |
|
811 |
|
| 822 |
// Add a link to the availability URL if appropriate |
812 |
// Add a link to the availability URL if appropriate |
| 823 |
var value; |
813 |
var value = document.createElement('span'); |
| 824 |
if (!data.url) { |
|
|
| 825 |
value = document.createElement('span'); |
| 826 |
} else { |
| 827 |
value = document.createElement('a'); |
| 828 |
value.setAttribute('href', data.url); |
| 829 |
value.setAttribute('target', '_blank'); |
| 830 |
value.setAttribute('title', ill_batch_available_via + ' ' + data.availabilitySupplier); |
| 831 |
} |
| 832 |
value.classList.add('metadata-value'); |
814 |
value.classList.add('metadata-value'); |
| 833 |
value.innerText = meta[prop]; |
815 |
value.innerText = meta[prop]; |
| 834 |
div.appendChild(label); |
816 |
div.appendChild(label); |
|
Lines 930-935
Link Here
|
| 930 |
return data.requestStatus || '-'; |
912 |
return data.requestStatus || '-'; |
| 931 |
} |
913 |
} |
| 932 |
|
914 |
|
|
|
915 |
function createRequestAvailability(x, y, data) { |
| 916 |
|
| 917 |
// If the fetch failed |
| 918 |
if (data.failed.length > 0) { |
| 919 |
return data.failed; |
| 920 |
} |
| 921 |
|
| 922 |
if (Object.keys(data.availability_hits).length === 0){ |
| 923 |
return ill_populate_waiting; |
| 924 |
} |
| 925 |
|
| 926 |
let str = ''; |
| 927 |
let has_some = false; |
| 928 |
for (i = 0; i < data.availability_hits.length; i++) { |
| 929 |
if (!data.availability_hits[i].empty){ |
| 930 |
has_some = true; |
| 931 |
str += "<li><a href=" + data.availability_hits[i].url + " target=\"_blank\">" + data.availability_hits[i].name + "</a></li>" |
| 932 |
} |
| 933 |
} |
| 934 |
if(!has_some){ |
| 935 |
str = ill_batch_none; |
| 936 |
} |
| 937 |
return str; |
| 938 |
}; |
| 939 |
|
| 933 |
function buildTable(identifiers) { |
940 |
function buildTable(identifiers) { |
| 934 |
table = KohaTable('identifier-table', { |
941 |
table = KohaTable('identifier-table', { |
| 935 |
processing: true, |
942 |
processing: true, |
|
Lines 963-970
Link Here
|
| 963 |
width: '6.5%', |
970 |
width: '6.5%', |
| 964 |
render: createRequestStatus |
971 |
render: createRequestStatus |
| 965 |
}, |
972 |
}, |
|
|
973 |
...( ill_check_availability_syspref == 1 ? [{ |
| 974 |
data: '', |
| 975 |
width: '13%', |
| 976 |
render: createRequestAvailability, }] : [] |
| 977 |
), |
| 966 |
{ |
978 |
{ |
| 967 |
width: '18%', |
979 |
width: '6.5%', |
| 968 |
render: createActions, |
980 |
render: createActions, |
| 969 |
className: 'action-column noExport' |
981 |
className: 'action-column noExport' |
| 970 |
} |
982 |
} |
| 971 |
- |
|
|