Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/browse/origin-search.js
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function doSearch() { | function doSearch() { | ||||
$('#swh-no-result').hide(); | $('#swh-no-result').hide(); | ||||
let searchQueryText = $('#origins-url-patterns').val(); | let searchQueryText = $('#origins-url-patterns').val(); | ||||
inSearch = true; | inSearch = true; | ||||
if (searchQueryText.startsWith('swh:')) { | if (searchQueryText.startsWith('swh:')) { | ||||
// searchQueryText may be a PID so sending search queries to PID resolve endpoint | // searchQueryText may be a PID so sending search queries to PID resolve endpoint | ||||
let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); | let resolveSWHIDUrl = Urls.api_1_resolve_swhid(searchQueryText); | ||||
fetch(resolvePidUrl) | fetch(resolveSWHIDUrl) | ||||
.then(handleFetchError) | .then(handleFetchError) | ||||
.then(response => response.json()) | .then(response => response.json()) | ||||
.then(data => { | .then(data => { | ||||
// pid has been successfully resolved, | // SWHID has been successfully resolved, | ||||
// so redirect to browse page | // so redirect to browse page | ||||
window.location = data.browse_url; | window.location = data.browse_url; | ||||
}) | }) | ||||
.catch(response => { | .catch(response => { | ||||
// display a useful error message if the input | // display a useful error message if the input | ||||
// looks like a swh pid | // looks like a SWHID | ||||
response.json().then(data => { | response.json().then(data => { | ||||
$('#swh-origin-search-results').hide(); | $('#swh-origin-search-results').hide(); | ||||
$('.swh-search-pagination').hide(); | $('.swh-search-pagination').hide(); | ||||
$('#swh-no-result').text(data.reason); | $('#swh-no-result').text(data.reason); | ||||
$('#swh-no-result').show(); | $('#swh-no-result').show(); | ||||
}); | }); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |