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 691-696
Link Here
|
691 |
} else if (alreadyInDeduped.length === 0) { |
665 |
} else if (alreadyInDeduped.length === 0) { |
692 |
row.metadata = {}; |
666 |
row.metadata = {}; |
693 |
row.failed = {}; |
667 |
row.failed = {}; |
|
|
668 |
row.availability_hits = {}; |
694 |
row.requestId = null; |
669 |
row.requestId = null; |
695 |
deduped.push(row); |
670 |
deduped.push(row); |
696 |
} |
671 |
} |
Lines 741-746
Link Here
|
741 |
} catch (e) { |
716 |
} catch (e) { |
742 |
row.failed = ill_populate_failed; |
717 |
row.failed = ill_populate_failed; |
743 |
} |
718 |
} |
|
|
719 |
|
720 |
if (ill_check_availability_syspref == 1){ |
721 |
try { |
722 |
var availability = await populateAvailability(row); |
723 |
row.availability_hits = availability || {}; |
724 |
} catch (e) { |
725 |
//do nothing |
726 |
} |
727 |
} |
728 |
|
744 |
newData[i] = row; |
729 |
newData[i] = row; |
745 |
tableContent.data = newData; |
730 |
tableContent.data = newData; |
746 |
} |
731 |
} |
Lines 776-781
Link Here
|
776 |
} |
761 |
} |
777 |
}; |
762 |
}; |
778 |
|
763 |
|
|
|
764 |
async function getAvailability(endpoint) { |
765 |
var response = await debounce(doApiRequest)(endpoint); |
766 |
return response.json(); |
767 |
}; |
768 |
|
779 |
async function getMetadata(endpoint) { |
769 |
async function getMetadata(endpoint) { |
780 |
var response = await debounce(doApiRequest)(endpoint); |
770 |
var response = await debounce(doApiRequest)(endpoint); |
781 |
return response.json(); |
771 |
return response.json(); |
Lines 826-840
Link Here
|
826 |
label.innerText = ill_batch_metadata[prop] + ': '; |
816 |
label.innerText = ill_batch_metadata[prop] + ': '; |
827 |
|
817 |
|
828 |
// Add a link to the availability URL if appropriate |
818 |
// Add a link to the availability URL if appropriate |
829 |
var value; |
819 |
var value = document.createElement('span'); |
830 |
if (!data.url) { |
|
|
831 |
value = document.createElement('span'); |
832 |
} else { |
833 |
value = document.createElement('a'); |
834 |
value.setAttribute('href', data.url); |
835 |
value.setAttribute('target', '_blank'); |
836 |
value.setAttribute('title', ill_batch_available_via + ' ' + data.availabilitySupplier); |
837 |
} |
838 |
value.classList.add('metadata-value'); |
820 |
value.classList.add('metadata-value'); |
839 |
value.innerText = meta[prop]; |
821 |
value.innerText = meta[prop]; |
840 |
div.appendChild(label); |
822 |
div.appendChild(label); |
Lines 936-941
Link Here
|
936 |
return data.requestStatus || '-'; |
918 |
return data.requestStatus || '-'; |
937 |
} |
919 |
} |
938 |
|
920 |
|
|
|
921 |
function createRequestAvailability(x, y, data) { |
922 |
|
923 |
// If the fetch failed |
924 |
if (data.failed.length > 0) { |
925 |
return data.failed; |
926 |
} |
927 |
|
928 |
if (Object.keys(data.availability_hits).length === 0){ |
929 |
return ill_populate_waiting; |
930 |
} |
931 |
|
932 |
let str = ''; |
933 |
let has_some = false; |
934 |
for (i = 0; i < data.availability_hits.length; i++) { |
935 |
if (!data.availability_hits[i].empty){ |
936 |
has_some = true; |
937 |
str += "<li><a href=" + data.availability_hits[i].url + " target=\"_blank\">" + data.availability_hits[i].name + "</a></li>" |
938 |
} |
939 |
} |
940 |
if(!has_some){ |
941 |
str = ill_batch_none; |
942 |
} |
943 |
return str; |
944 |
}; |
945 |
|
939 |
function buildTable(identifiers) { |
946 |
function buildTable(identifiers) { |
940 |
table = KohaTable('identifier-table', { |
947 |
table = KohaTable('identifier-table', { |
941 |
processing: true, |
948 |
processing: true, |
Lines 969-976
Link Here
|
969 |
width: '6.5%', |
976 |
width: '6.5%', |
970 |
render: createRequestStatus |
977 |
render: createRequestStatus |
971 |
}, |
978 |
}, |
|
|
979 |
...( ill_check_availability_syspref == 1 ? [{ |
980 |
data: '', |
981 |
width: '13%', |
982 |
render: createRequestAvailability, }] : [] |
983 |
), |
972 |
{ |
984 |
{ |
973 |
width: '18%', |
985 |
width: '6.5%', |
974 |
render: createActions, |
986 |
render: createActions, |
975 |
className: 'action-column noExport' |
987 |
className: 'action-column noExport' |
976 |
} |
988 |
} |
977 |
- |
|
|