2022-01-23 01:56:17 +01:00
|
|
|
import * as AjaxHelper from './ajaxhelper.js';
|
|
|
|
import * as GenericRendering from './genericrendering.js';
|
2022-04-17 14:07:10 +02:00
|
|
|
import * as PackageRendering from './packagerendering.js';
|
2022-01-23 01:56:17 +01:00
|
|
|
import * as SinglePageHelper from './singlepage.js';
|
|
|
|
import * as Utils from './utils.js';
|
|
|
|
|
|
|
|
export function initPackageSearch(sectionElement, sectionData, newParams)
|
2021-03-22 16:51:57 +01:00
|
|
|
{
|
2022-01-23 01:56:17 +01:00
|
|
|
const searchForm = document.getElementById('package-search-form');
|
|
|
|
if (!searchForm.dataset.initialized) {
|
|
|
|
searchForm.onsubmit = function() {
|
|
|
|
searchForPackages();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
const packageResultsFormElements = document.getElementById('package-results-form').elements;
|
|
|
|
packageResultsFormElements.selectall.onclick = function () {
|
|
|
|
Utils.alterFormSelection(this.form, 'check-all');
|
|
|
|
};
|
|
|
|
packageResultsFormElements.unselectall.onclick = function () {
|
|
|
|
Utils.alterFormSelection(this.form, 'uncheck-all');
|
|
|
|
};
|
|
|
|
packageResultsFormElements.startselected.onclick = function () {
|
|
|
|
fillBuildActionFromPackageSearch();
|
|
|
|
};
|
|
|
|
searchForm.dataset.initialized = true;
|
|
|
|
}
|
2022-04-17 14:04:06 +02:00
|
|
|
let currentParams = sectionData.state.params;
|
|
|
|
if (currentParams && currentParams.startsWith('?')) {
|
|
|
|
currentParams = currentParams.substr(1);
|
|
|
|
}
|
2021-03-22 16:51:57 +01:00
|
|
|
const hasNewParams = newParams.length >= 1;
|
|
|
|
if (!hasNewParams) {
|
|
|
|
if (currentParams !== undefined) {
|
2022-01-23 01:56:17 +01:00
|
|
|
SinglePageHelper.updateHashPreventingChangeHandler('#package-search-section?' + encodeURIComponent(currentParams));
|
2021-03-22 16:51:57 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2022-01-23 01:56:17 +01:00
|
|
|
const searchParams = SinglePageHelper.sections['package-search'].state.params = newParams[0];
|
2021-03-22 16:51:57 +01:00
|
|
|
if (currentParams === searchParams) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!window.globalInfo) {
|
|
|
|
window.functionsPostponedUntilGlobalInfo.push(searchForPackagesFromParams.bind(this, searchParams));
|
|
|
|
} else {
|
|
|
|
searchForPackagesFromParams(searchParams);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-23 01:56:17 +01:00
|
|
|
function fillBuildActionFromPackageSearch()
|
|
|
|
{
|
|
|
|
const packageNamesTextArea = document.getElementById('build-action-form')['package-names'];
|
|
|
|
const data = Utils.getFormTableData('package-results-form');
|
|
|
|
if (data === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
packageNamesTextArea.value = Utils.getSelectedRowProperties(data, 'name').join(' ');
|
|
|
|
location.hash = '#build-action-section';
|
|
|
|
}
|
|
|
|
|
2021-03-22 16:51:57 +01:00
|
|
|
function searchForPackagesFromParams(searchParams)
|
|
|
|
{
|
|
|
|
const params = new URLSearchParams(searchParams);
|
|
|
|
const form = document.getElementById('package-search-form');
|
|
|
|
form.reset();
|
|
|
|
params.forEach(function(value, key) {
|
|
|
|
const formElement = form[key];
|
|
|
|
if (!formElement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (formElement.multiple) {
|
|
|
|
Array.from(formElement.options).forEach(function(optionElement) {
|
|
|
|
if (optionElement.value === value) {
|
|
|
|
optionElement.selected = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
formElement.value = value;
|
|
|
|
}
|
|
|
|
});
|
2022-01-23 01:56:17 +01:00
|
|
|
const res = AjaxHelper.startFormQueryEx('package-search-form', showPackageSearchResults);
|
|
|
|
SinglePageHelper.sections['package-search'].state.params = res.params;
|
2021-03-22 16:51:57 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-01-25 00:24:31 +01:00
|
|
|
function searchForPackages()
|
|
|
|
{
|
2022-01-23 01:56:17 +01:00
|
|
|
const res = AjaxHelper.startFormQueryEx('package-search-form', showPackageSearchResults);
|
|
|
|
const params = SinglePageHelper.sections['package-search'].state.params = res.params.substr(1);
|
|
|
|
SinglePageHelper.updateHashPreventingSectionInitializer('#package-search-section?' + encodeURIComponent(params));
|
2021-03-22 16:51:57 +01:00
|
|
|
return res.ajaxRequest;
|
2021-01-25 00:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function showPackageSearchResults(ajaxRequest)
|
|
|
|
{
|
2022-01-23 01:56:17 +01:00
|
|
|
const packageSearchResults = Utils.getAndEmptyElement('package-search-results');
|
2021-01-25 00:24:31 +01:00
|
|
|
if (ajaxRequest.status !== 200) {
|
|
|
|
packageSearchResults.appendChild(document.createTextNode('unable search for packages: ' + ajaxRequest.responseText));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const responseJson = JSON.parse(ajaxRequest.responseText);
|
2022-01-23 01:56:17 +01:00
|
|
|
const table = GenericRendering.renderTableFromJsonArray({
|
2021-01-25 00:24:31 +01:00
|
|
|
rows: responseJson,
|
|
|
|
columnHeaders: ['', 'Arch', 'Repo', 'Name', 'Version', 'Description', 'Build date'],
|
|
|
|
columnAccessors: ['checkbox', 'arch', 'db', 'name', 'version', 'description', 'buildDate'],
|
|
|
|
rowsPerPage: 40,
|
|
|
|
customRenderer: {
|
|
|
|
name: function (value, row) {
|
2022-04-17 14:07:10 +02:00
|
|
|
return PackageRendering.renderPackageDetailsLink(row);
|
2021-01-25 00:24:31 +01:00
|
|
|
},
|
|
|
|
checkbox: function(value, row) {
|
2022-01-23 01:56:17 +01:00
|
|
|
return GenericRendering.renderCheckBoxForTableRow(value, row, function(row) {
|
2021-01-25 00:24:31 +01:00
|
|
|
return [row.db, row.name].join('/');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
note: function (rows) {
|
|
|
|
const note = document.createElement("p");
|
|
|
|
note.appendChild(document.createTextNode("Found " + rows.length + " packages"));
|
|
|
|
return note;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
packageSearchResults.appendChild(table);
|
2021-02-13 17:14:49 +01:00
|
|
|
}
|