Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/browse/origin-search.js
/** | /** | ||||
* Copyright (C) 2018-2021 The Software Heritage developers | * Copyright (C) 2018-2021 The Software Heritage developers | ||||
* 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, errorMessageFromResponse, isArchivedOrigin} from 'utils/functions'; | import {handleFetchError, errorMessageFromResponse, isArchivedOrigin} from 'utils/functions'; | ||||
import {initAutocomplete} from 'utils/search-ql-autocomplete'; | |||||
const limit = 100; | const limit = 100; | ||||
const linksPrev = []; | const 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 173 Lines • ▼ Show 20 Lines | if (searchQueryText.startsWith('swh:')) { | ||||
$('#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(() => { | ||||
const inputBox = document.querySelector('#swh-origins-url-patterns'); | |||||
const submitBtn = document.querySelector('#swh-search-submit'); | |||||
const validQueryCallback = (isValid) => { | |||||
submitBtn.disabled = !isValid; | |||||
// if (!isValid) | |||||
// inputBox.classList.add('invalid'); | |||||
// else | |||||
// inputBox.classList.remove('invalid'); | |||||
}; | |||||
initAutocomplete(inputBox, validQueryCallback); | |||||
$('#swh-search-origins').submit(event => { | $('#swh-search-origins').submit(event => { | ||||
event.preventDefault(); | event.preventDefault(); | ||||
if (event.target.checkValidity()) { | if (event.target.checkValidity()) { | ||||
$(event.target).removeClass('was-validated'); | $(event.target).removeClass('was-validated'); | ||||
const searchQueryText = $('#swh-origins-url-patterns').val().trim(); | const searchQueryText = $('#swh-origins-url-patterns').val().trim(); | ||||
const withVisit = $('#swh-search-origins-with-visit').prop('checked'); | const withVisit = $('#swh-search-origins-with-visit').prop('checked'); | ||||
const withContent = $('#swh-filter-empty-visits').prop('checked'); | const withContent = $('#swh-filter-empty-visits').prop('checked'); | ||||
const useSearchQL = $('#swh-search-use-ql').prop('checked'); | const useSearchQL = $('#swh-search-use-ql').prop('checked'); | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |