Improve database selection when invoking package search from params
* Select all relevant DBs, also when multiple `db` parameters are present * Avoid the architecture filter from interfering by simply selecting "All archs" when starting a package search from query params
This commit is contained in:
parent
f0d9b684df
commit
434e1a8f0c
|
@ -69,21 +69,27 @@ function searchForPackagesFromParams(searchParams)
|
||||||
{
|
{
|
||||||
const form = document.getElementById('package-search-form');
|
const form = document.getElementById('package-search-form');
|
||||||
form.reset();
|
form.reset();
|
||||||
for (const [key, value] of Object.entries(Utils.hashAsObject(searchParams))) {
|
const archFilter = document.getElementById('package-search-db-arch-filter');
|
||||||
|
if (archFilter) {
|
||||||
|
archFilter.selectedIndex = 0;
|
||||||
|
archFilter.onchange();
|
||||||
|
}
|
||||||
|
const params = Utils.hashAsObject(searchParams, true);
|
||||||
|
for (const [key, value] of Object.entries(params)) {
|
||||||
const formElement = form[key];
|
const formElement = form[key];
|
||||||
if (!formElement) {
|
if (!formElement) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (formElement.multiple) {
|
if (!formElement.multiple) {
|
||||||
Array.from(formElement.options).forEach(function(optionElement) {
|
|
||||||
if (optionElement.value === value) {
|
|
||||||
optionElement.selected = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
formElement.value = value;
|
formElement.value = value;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
Array.from(formElement.options).forEach(function(optionElement) {
|
||||||
|
optionElement.selected = Array.isArray(value) ? value.includes(optionElement.value) : value === optionElement.value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!params.db) {
|
||||||
|
form.db.selectedIndex = 0;
|
||||||
}
|
}
|
||||||
const res = AjaxHelper.startFormQueryEx('package-search-form', showPackageSearchResults);
|
const res = AjaxHelper.startFormQueryEx('package-search-form', showPackageSearchResults);
|
||||||
SinglePageHelper.sections['package-search'].state.params = res.params;
|
SinglePageHelper.sections['package-search'].state.params = res.params;
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function splitHashParts()
|
||||||
return hashParts;
|
return hashParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hashAsObject(hash)
|
export function hashAsObject(hash, multipleValuesAsArray)
|
||||||
{
|
{
|
||||||
const hashObject = {};
|
const hashObject = {};
|
||||||
(hash || location.hash.substr(1)).split('&').forEach(function(hashPart) {
|
(hash || location.hash.substr(1)).split('&').forEach(function(hashPart) {
|
||||||
|
@ -17,7 +17,18 @@ export function hashAsObject(hash)
|
||||||
if (parts.length < 1) {
|
if (parts.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hashObject[decodeURIComponent(parts[0])] = parts.length > 1 ? decodeURIComponent(parts[1]) : undefined;
|
const key = decodeURIComponent(parts[0]);
|
||||||
|
const thisValue = parts.length > 1 ? decodeURIComponent(parts[1]) : undefined;
|
||||||
|
const existingValue = hashObject[key];
|
||||||
|
if (multipleValuesAsArray && existingValue !== undefined) {
|
||||||
|
if (Array.isArray(existingValue)) {
|
||||||
|
existingValue.push(thisValue);
|
||||||
|
} else {
|
||||||
|
hashObject[key] = [existingValue, thisValue];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hashObject[key] = thisValue;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return hashObject;
|
return hashObject;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue