ahriman/package/share/ahriman/build-status/package-actions-script.jinja2
Evgenii Alekseev 11c03a9041 Add ability to trigger updates from the web (#31)
* add external process spawner and update test cases

* pass no_report to handlers

* provide service api endpoints

* do not spawn process for single architecture run

* pass no report to handlers

* make _call method of handlers public and also simplify process spawn

* move update under add

* implement actions from web page

* clear logging & improve l&f
2021-09-10 00:33:35 +03:00

76 lines
2.5 KiB
Django/Jinja

<script>
const $remove = $("#remove")
const $update = $("#update")
const $table = $("#packages")
$table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table",
function () {
$remove.prop("disabled", !$table.bootstrapTable("getSelections").length)
$update.prop("disabled", !$table.bootstrapTable("getSelections").length)
})
const $successForm = $("#successForm")
$successForm.on("hidden.bs.modal", function() { window.location.reload(); })
const $failedForm = $("#failedForm")
$failedForm.on("hidden.bs.modal", function() { window.location.reload(); })
const $package = $("#package")
const $knownPackages = $("#knownPackages")
$package.keyup(function () {
const $this = $(this);
clearTimeout($this.data("timeout"));
$this.data("timeout", setTimeout($.proxy(function () {
const $value = $package.val();
$.ajax({
url: "/service-api/v1/search",
data: {"for": $value},
type: "GET",
dataType: "json",
success: function (resp) {
const $options = resp.map(function (pkg) {
const $option = document.createElement("option");
$option.value = pkg;
return $option;
});
$knownPackages.empty().append($options);
$this.focus()
},
})
}, this), 500));
})
function doPackageAction($uri, $packages) {
if ($packages.length === 0)
return;
$.ajax({
url: $uri,
data: JSON.stringify({packages: $packages}),
type: "POST",
contentType: "application/json",
success: function (_) { $successForm.modal("show"); },
error: function (_) { $failedForm.modal("show"); },
})
}
function getSelection() {
return $.map($table.bootstrapTable("getSelections"), function(row) {
return row._data["package-base"];
})
}
function addPackages() {
const $packages = [$package.val()]
doPackageAction("/service-api/v1/add", $packages);
}
function removePackages() { doPackageAction("/service-api/v1/remove", getSelection()); }
function updatePackages() { doPackageAction("/service-api/v1/add", getSelection()); }
$(function () {
$table.bootstrapTable("uncheckAll");
})
</script>