Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/browse/origin-search.js
/** | /** | ||||
* Copyright (C) 2018-2019 The Software Heritage developers | * Copyright (C) 2018-2020 The Software Heritage developers | ||||
ardumont: update headers to 2018-2020 now | |||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import {handleFetchError} from 'utils/functions'; | import {handleFetchError} from 'utils/functions'; | ||||
Done Inline Actionsplease remove the leading and trailing space anlambert: please remove the leading and trailing space | |||||
const limit = 100; | const limit = 100; | ||||
let linksPrev = []; | let linksPrev = []; | ||||
let linkNext = null; | let linkNext = null; | ||||
let linkCurrent = null; | let linkCurrent = null; | ||||
let inSearch = false; | let inSearch = false; | ||||
function parseLinkHeader(s) { | function parseLinkHeader(s) { | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | .catch(response => { | ||||
$('#swh-no-result').show(); | $('#swh-no-result').show(); | ||||
}); | }); | ||||
} | } | ||||
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; | ||||
// first try to resolve a swh persistent identifier | if (searchQueryText.startsWith('swh:')) { | ||||
// searchQueryText may be a PID so sending search queries to PID resolve endpoint | |||||
let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); | let resolvePidUrl = Urls.api_1_resolve_swh_pid(searchQueryText); | ||||
fetch(resolvePidUrl) | fetch(resolvePidUrl) | ||||
.then(handleFetchError) | .then(handleFetchError) | ||||
.then(response => response.json()) | .then(response => response.json()) | ||||
.then(data => { | .then(data => { | ||||
// pid has been successfully resolved, | // pid 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 => { | ||||
// pid resolving failed | |||||
if (searchQueryText.startsWith('swh:')) { | |||||
// display a useful error message if the input | // display a useful error message if the input | ||||
// looks like a swh pid | // looks like a swh pid | ||||
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(); | ||||
}); | }); | ||||
}); | |||||
} else { | } else { | ||||
// otherwise, proceed with origins search | // otherwise, proceed with origins search | ||||
$('#swh-origin-search-results').show(); | $('#swh-origin-search-results').show(); | ||||
$('.swh-search-pagination').show(); | $('.swh-search-pagination').show(); | ||||
searchOriginsFirst(searchQueryText, limit); | searchOriginsFirst(searchQueryText, limit); | ||||
} | } | ||||
}); | |||||
} | } | ||||
export function initOriginSearch() { | export function initOriginSearch() { | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
$('#swh-search-origins').submit(event => { | $('#swh-search-origins').submit(event => { | ||||
event.preventDefault(); | event.preventDefault(); | ||||
let searchQueryText = $('#origins-url-patterns').val().trim(); | let searchQueryText = $('#origins-url-patterns').val().trim(); | ||||
let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
update headers to 2018-2020 now