View | Details | Raw Unified | Return to bug 34282
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js (-59 / +45 lines)
Lines 86-94 Link Here
86
                updateTable();
86
                updateTable();
87
                updateRowCount();
87
                updateRowCount();
88
                updateProcessTotals();
88
                updateProcessTotals();
89
                if (ill_check_availability_syspref == 1){
90
                    checkAvailability();
91
                }
92
            }
89
            }
93
        }
90
        }
94
    );
91
    );
Lines 237-291 Link Here
237
        });
234
        });
238
    };
235
    };
239
236
240
    // Identify items that can have their availability checked, and do it
237
    async function populateAvailability(row) {
241
    function checkAvailability() {
242
        // Only proceed if we've got services that can check availability
243
        if (!batch_availability_services || batch_availability_services.length === 0) return;
244
        var toCheck = tableContent.data;
245
        toCheck.forEach(function (row) {
246
            if (
247
                !row.url &&
248
                Object.keys(row.metadata).length > 0 &&
249
                !availabilitySent[row.value]
250
            ) {
251
                availabilitySent[row.value] = 1;
252
                getAvailability(row);
253
            }
254
        });
255
    };
256
257
    // Check availability services for immediate availability, if found,
258
    // create a link in the table linking to the item
259
    function getAvailability(row) {
260
        let metadata = row.metadata;
238
        let metadata = row.metadata;
261
        // Prep the metadata for passing to the availability plugins
239
262
        let availability_object = {};
240
        let availability_object = {};
263
        if (metadata.issn) availability_object['issn'] = metadata.issn;
241
        if (metadata.issn) availability_object['issn'] = metadata.issn;
264
        if (metadata.doi) availability_object['doi'] = metadata.doi;
242
        if (metadata.doi) availability_object['doi'] = metadata.doi;
265
        if (metadata.pubmedid) availability_object['pubmedid'] = metadata.pubmedid;
243
        if (metadata.pubmedid) availability_object['pubmedid'] = metadata.pubmedid;
266
        var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object)));
244
267
        row.av_hits = [];
245
        // Check each service and use the first results we get, if any
268
        batch_availability_services.map(async (service) => {
246
            var av_hits = [];
269
            window.doApiRequest(
247
        for (const service of batch_availability_services){
270
                service.endpoint + prepped
248
            var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object)));
271
            )
249
272
                .then(function (response) {
250
            var endpoint = service.endpoint + prepped;
273
                    return response.json();
251
            var availability = await getAvailability(endpoint);
274
                })
252
            if (availability.results.search_results && availability.results.search_results.length > 0) {
275
                .then(function (data) {
253
                av_hits.push({name: service.name, url: availability.results.search_results[0].url});
276
                    if (data.results.search_results && data.results.search_results.length > 0) {
254
            }else{
277
                        var result = data.results.search_results[0];
255
                av_hits.push({ name: service.name, empty:1 });
278
                        row.av_hits.push({name:service.name, url:result.url});
256
            }
279
                        return row;
257
        };
280
                    }else {
258
        return av_hits;
281
                        row.av_hits.push({ name: service.name, empty: 1 })
282
                    }
283
                })
284
                .then(function (response) {
285
                    updateTable();
286
                });
287
            });
288
        // }
289
    };
259
    };
290
260
291
    // Help btoa with > 8 bit strings
261
    // Help btoa with > 8 bit strings
Lines 689-694 Link Here
689
            } else if (alreadyInDeduped.length === 0) {
659
            } else if (alreadyInDeduped.length === 0) {
690
                row.metadata = {};
660
                row.metadata = {};
691
                row.failed = {};
661
                row.failed = {};
662
                row.availability_hits = {};
692
                row.requestId = null;
663
                row.requestId = null;
693
                deduped.push(row);
664
                deduped.push(row);
694
            }
665
            }
Lines 739-744 Link Here
739
            } catch (e) {
710
            } catch (e) {
740
                row.failed = ill_populate_failed;
711
                row.failed = ill_populate_failed;
741
            }
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
742
            newData[i] = row;
723
            newData[i] = row;
743
            tableContent.data = newData;
724
            tableContent.data = newData;
744
        }
725
        }
Lines 774-779 Link Here
774
        }
755
        }
775
    };
756
    };
776
757
758
    async function getAvailability(endpoint) {
759
        var response = await debounce(doApiRequest)(endpoint);
760
        return response.json();
761
    };
762
777
    async function getMetadata(endpoint) {
763
    async function getMetadata(endpoint) {
778
        var response = await debounce(doApiRequest)(endpoint);
764
        var response = await debounce(doApiRequest)(endpoint);
779
        return response.json();
765
        return response.json();
Lines 933-953 Link Here
933
            return data.failed;
919
            return data.failed;
934
        }
920
        }
935
921
922
        if (Object.keys(data.availability_hits).length === 0){
923
            return ill_populate_waiting;
924
        }
925
936
        let str = '';
926
        let str = '';
937
        let has_some = false;
927
        let has_some = false;
938
        if(typeof data.av_hits !== 'undefined' && data.av_hits.length>0){
928
        for (i = 0; i < data.availability_hits.length; i++) {
939
            data.av_hits.forEach((av_hit) => {
929
            if (!data.availability_hits[i].empty){
940
                if(!av_hit.empty){
930
                has_some = true;
941
                    has_some = true;
931
                str += "<li><a href=" + data.availability_hits[i].url + ">" + data.availability_hits[i].name + "</a></li>"
942
                    str += '<li><a target="_blank" href="' + av_hit.url + '">' + av_hit.name + '</a></li>'
943
                }
944
            });
945
946
            if(!has_some){
947
                str = ill_batch_none;
948
            }
932
            }
933
        } 
934
        if(!has_some){
935
            str = ill_batch_none;
949
        }
936
        }
950
        return str || ill_populate_waiting;
937
        return str;
951
    };
938
    };
952
939
953
    function buildTable(identifiers) {
940
    function buildTable(identifiers) {
954
- 

Return to bug 34282