Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/browse/origin-search.js
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function escapeStringRegexp(str) { | function escapeStringRegexp(str) { | ||||
let matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; | let matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; | ||||
return str.replace(matchOperatorsRe, '\\\\\\$&'); | return str.replace(matchOperatorsRe, '\\\\\\$&'); | ||||
} | } | ||||
function searchOrigins(patterns, limit, searchOffset, offset) { | function searchOrigins(patterns, limit, searchOffset, offset) { | ||||
let baseSearchUrl; | |||||
let searchMetadata = $('#swh-search-origin-metadata').prop('checked'); | |||||
anlambert: debug statement here | |||||
if (searchMetadata) { | |||||
baseSearchUrl = Urls.api_origin_metadata_search() + `?fulltext=${patterns}`; | |||||
} | |||||
else { | |||||
originPatterns = patterns; | originPatterns = patterns; | ||||
let patternsArray = patterns.trim().replace(/\s+/g, ' ').split(' '); | let patternsArray = patterns.trim().replace(/\s+/g, ' ').split(' '); | ||||
for (let i = 0; i < patternsArray.length; ++i) { | for (let i = 0; i < patternsArray.length; ++i) { | ||||
patternsArray[i] = escapeStringRegexp(patternsArray[i]); | patternsArray[i] = escapeStringRegexp(patternsArray[i]); | ||||
} | } | ||||
let patternsPermut = []; | let patternsPermut = []; | ||||
heapsPermute(patternsArray, p => patternsPermut.push(p.join('.*'))); | heapsPermute(patternsArray, p => patternsPermut.push(p.join('.*'))); | ||||
let regex = patternsPermut.join('|'); | let regex = patternsPermut.join('|'); | ||||
baseSearchUrl = Urls.browse_origin_search(regex) + `?regexp=true`; | |||||
} | |||||
let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | ||||
let searchUrl = Urls.browse_origin_search(regex) + `?limit=${limit}&offset=${searchOffset}®exp=true&with_visit=${withVisit}`; | let searchUrl = baseSearchUrl + `&limit=${limit}&offset=${searchOffset}&with_visit=${withVisit}`; | ||||
clearOriginSearchResultsTable(); | clearOriginSearchResultsTable(); | ||||
$('.swh-loading').addClass('show'); | $('.swh-loading').addClass('show'); | ||||
fetch(searchUrl) | fetch(searchUrl) | ||||
.then(handleFetchError) | .then(handleFetchError) | ||||
.then(response => response.json()) | .then(response => response.json()) | ||||
.then(data => { | .then(data => { | ||||
currentData = data; | currentData = data; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
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 patterns = $('#origins-url-patterns').val().trim(); | let patterns = $('#origins-url-patterns').val().trim(); | ||||
let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | let withVisit = $('#swh-search-origins-with-visit').prop('checked'); | ||||
let withContent = $('#swh-filter-empty-visits').prop('checked'); | let withContent = $('#swh-filter-empty-visits').prop('checked'); | ||||
let searchMetadata = $('#swh-search-origin-metadata').prop('checked'); | |||||
let queryParameters = '?q=' + encodeURIComponent(patterns); | let queryParameters = '?q=' + encodeURIComponent(patterns); | ||||
if (withVisit) { | if (withVisit) { | ||||
queryParameters += '&with_visit'; | queryParameters += '&with_visit'; | ||||
} | } | ||||
if (withContent) { | if (withContent) { | ||||
queryParameters += '&with_content'; | queryParameters += '&with_content'; | ||||
} | } | ||||
if (searchMetadata) { | |||||
Not Done Inline ActionsI would call that parameter search_metadata instead (shorter and we known that we are searching origins) anlambert: I would call that parameter `search_metadata` instead (shorter and we known that we are… | |||||
queryParameters += '&search_metadata'; | |||||
} | |||||
// Update the url, triggering page reload and effective search | // Update the url, triggering page reload and effective search | ||||
window.location.search = queryParameters; | window.location.search = queryParameters; | ||||
}); | }); | ||||
$('#origins-next-results-button').click(event => { | $('#origins-next-results-button').click(event => { | ||||
if ($('#origins-next-results-button').hasClass('disabled') || inSearch) { | if ($('#origins-next-results-button').hasClass('disabled') || inSearch) { | ||||
return; | return; | ||||
} | } | ||||
Show All 26 Lines | $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', e => { | ||||
fixTableRowsStyle(); | fixTableRowsStyle(); | ||||
} | } | ||||
}); | }); | ||||
let urlParams = new URLSearchParams(window.location.search); | let urlParams = new URLSearchParams(window.location.search); | ||||
let query = urlParams.get('q'); | let query = urlParams.get('q'); | ||||
let withVisit = urlParams.has('with_visit'); | let withVisit = urlParams.has('with_visit'); | ||||
let withContent = urlParams.has('with_content'); | let withContent = urlParams.has('with_content'); | ||||
let searchMetadata = urlParams.has('search_metadata'); | |||||
if (query) { | if (query) { | ||||
$('#origins-url-patterns').val(query); | $('#origins-url-patterns').val(query); | ||||
$('#swh-search-origins-with-visit').prop('checked', withVisit); | $('#swh-search-origins-with-visit').prop('checked', withVisit); | ||||
$('#swh-search-origins-with-content').prop('checked', withContent); | $('#swh-search-origins-with-content').prop('checked', withContent); | ||||
$('#swh-search-origin-metadata').prop('checked', searchMetadata); | |||||
doSearch(); | doSearch(); | ||||
} | } | ||||
}); | }); | ||||
} | } |
debug statement here