From 808c4e5b1fb9b30840ae51ad461fc71493259824 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Tue, 1 Jul 2025 12:16:15 +0300 Subject: [PATCH] add cookies support --- .../ahriman/templates/build-status.jinja2 | 1 - .../build-status/package-info-modal.jinja2 | 12 +++ .../templates/build-status/table.jinja2 | 102 +++++++++++------- .../templates/utils/bootstrap-scripts.jinja2 | 21 ++-- 4 files changed, 88 insertions(+), 48 deletions(-) diff --git a/package/share/ahriman/templates/build-status.jinja2 b/package/share/ahriman/templates/build-status.jinja2 index 8b8c4134..828eacf7 100644 --- a/package/share/ahriman/templates/build-status.jinja2 +++ b/package/share/ahriman/templates/build-status.jinja2 @@ -117,7 +117,6 @@ data-sortable="true" data-sort-name="base" data-sort-order="asc" - data-toggle="table" data-toolbar="#toolbar"> diff --git a/package/share/ahriman/templates/build-status/package-info-modal.jinja2 b/package/share/ahriman/templates/build-status/package-info-modal.jinja2 index 1ba2556c..cb018ea5 100644 --- a/package/share/ahriman/templates/build-status/package-info-modal.jinja2 +++ b/package/share/ahriman/templates/build-status/package-info-modal.jinja2 @@ -539,5 +539,17 @@ clearInterval(packageInfoAutoReloadTask); packageInfoAutoReloadTask = null; // not really required (?) but lets clear everything }); + + // set refresh interval + for (let refreshEnabled = Cookies.get(`ahriman-${packageInfoAutoReloadButton.id}-refresh-enabled`); + !!refreshEnabled; + refreshEnabled = undefined) { + packageInfoAutoReloadButton.checked = refreshEnabled === "true"; + } + for (let refreshInterval = Cookies.get(`ahriman-${packageInfoAutoReloadButton.id}-refresh-interval`); + !!refreshInterval; + refreshInterval = undefined) { + toggleActiveElement(packageInfoAutoReloadInput, "interval", refreshInterval); + } }); diff --git a/package/share/ahriman/templates/build-status/table.jinja2 b/package/share/ahriman/templates/build-status/table.jinja2 index 7aeb9c7d..07a6194a 100644 --- a/package/share/ahriman/templates/build-status/table.jinja2 +++ b/package/share/ahriman/templates/build-status/table.jinja2 @@ -250,6 +250,12 @@ } ready(_ => { + const onCheckFunction = function () { + if (packageRemoveButton) { + packageRemoveButton.disabled = !getSelection().length; + } + }; + document.querySelectorAll("#repositories a").forEach(element => { element.onclick = _ => { repository = { @@ -264,49 +270,63 @@ }; }); - table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table", _ => { - if (packageRemoveButton) { - packageRemoveButton.disabled = !table.bootstrapTable("getSelections").length; - } - }); - table.on("click-row.bs.table", (self, data, row, cell) => { - if (0 === cell || "base" === cell) { - const method = data[0] === true ? "uncheckBy" : "checkBy"; // fck javascript - table.bootstrapTable(method, {field: "id", values: [data.id]}); - } else showPackageInfo(data.id); - }); - table.on("created-controls.bs.table", _ => { - new easepick.create({ - element: document.querySelector(".bootstrap-table-filter-control-timestamp"), - css: [ - "https://cdn.jsdelivr.net/npm/@easepick/bundle@1.2.1/dist/index.css", - ], - grid: 2, - calendars: 2, - autoApply: false, - locale: { - cancel: "Clear", - }, - RangePlugin: { - tooltip: false, - }, - plugins: [ - "RangePlugin", - ], - setup: picker => { - picker.on("select", _ => { table.bootstrapTable("triggerSearch"); }); - // replace "Cancel" behaviour to "Clear" - picker.onClickCancelButton = element => { - if (picker.isCancelButton(element)) { - picker.clear(); - picker.hide(); - table.bootstrapTable("triggerSearch"); - } - }; - }, - }); + table.bootstrapTable({ + onCheck: onCheckFunction, + onCheckAll: onCheckFunction, + onClickRow: (data, row, cell) => { + if (0 === cell || "base" === cell) { + const method = data[0] === true ? "uncheckBy" : "checkBy"; // fck javascript + table.bootstrapTable(method, {field: "id", values: [data.id]}); + } else showPackageInfo(data.id); + }, + onCreatedControls: _ => { + new easepick.create({ + element: document.querySelector(".bootstrap-table-filter-control-timestamp"), + css: [ + "https://cdn.jsdelivr.net/npm/@easepick/bundle@1.2.1/dist/index.css", + ], + grid: 2, + calendars: 2, + autoApply: false, + locale: { + cancel: "Clear", + }, + RangePlugin: { + tooltip: false, + }, + plugins: [ + "RangePlugin", + ], + setup: picker => { + picker.on("select", _ => { table.bootstrapTable("triggerSearch"); }); + // replace "Cancel" behaviour to "Clear" + picker.onClickCancelButton = element => { + if (picker.isCancelButton(element)) { + picker.clear(); + picker.hide(); + table.bootstrapTable("triggerSearch"); + } + }; + }, + }); + }, + onPageChange: (_, size) => { Cookies.set(`ahriman-${table.attr("id")}-page-size`, size); }, + onUncheck: onCheckFunction, + onUncheckAll: onCheckFunction, }); + // set refresh interval + for (let refreshEnabled = Cookies.get(`ahriman-${tableAutoReloadButton.id}-refresh-enabled`); + !!refreshEnabled; + refreshEnabled = undefined) { + tableAutoReloadButton.checked = refreshEnabled === "true"; + } + for (let refreshInterval = Cookies.get(`ahriman-${tableAutoReloadButton.id}-refresh-interval`); + !!refreshInterval; + refreshInterval = undefined) { + toggleActiveElement(tableAutoReloadInput, "interval", refreshInterval); + } + selectRepository(); {% if autorefresh_intervals %} toggleTableAutoReload(); diff --git a/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 b/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 index 52a3639c..648ab2e5 100644 --- a/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 +++ b/package/share/ahriman/templates/utils/bootstrap-scripts.jinja2 @@ -19,6 +19,8 @@ + +