mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Repository-related functions (#19)
* Roadmap item * Start building repo view * Section switcher * Show repo list * Adding chart repo works * Showing the pane * Couple of buttons * Listing items * Styling * Enriching repo view * Navigate from repo to installed * Tuning install popup * Working on install * Cosmetics
This commit is contained in:
@@ -30,17 +30,6 @@ function checkUpgradeable(name) {
|
||||
}
|
||||
|
||||
const verCur = $("#specRev").data("last-chart-ver");
|
||||
$('#upgradeModal select').empty()
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const opt = $("<option value='" + data[i].version + "'></option>");
|
||||
if (data[i].version === verCur) {
|
||||
opt.html(data[i].version + " ·")
|
||||
} else {
|
||||
opt.html(data[i].version)
|
||||
}
|
||||
$('#upgradeModal select').append(opt)
|
||||
}
|
||||
|
||||
const elm = data[0]
|
||||
$("#btnUpgradeCheck").data("repo", elm.name.split('/').shift())
|
||||
$("#btnUpgradeCheck").data("chart", elm.name.split('/').pop())
|
||||
@@ -56,55 +45,86 @@ function checkUpgradeable(name) {
|
||||
}
|
||||
|
||||
$("#btnUpgrade").off("click").click(function () {
|
||||
popUpUpgrade($(this), verCur, elm)
|
||||
popUpUpgrade(elm, getHashParam("namespace"), getHashParam("chart"), verCur, $("#specRev").data("last-rev"))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function popUpUpgrade(self, verCur, elm) {
|
||||
const name = getHashParam("chart");
|
||||
const qstr = "?namespace=" + getHashParam("namespace") + "&name=" + name + "&chart=" + elm.name;
|
||||
let url = "/api/helm/charts/install" + qstr
|
||||
$('#upgradeModal select').data("qstr", qstr).data("url", url).data("chart", elm.name)
|
||||
function popUpUpgrade(elm, ns, name, verCur, lastRev) {
|
||||
$("#upgradeModal .btn-confirm").prop("disabled", true)
|
||||
|
||||
$("#upgradeModalLabel .name").text(name)
|
||||
$("#upgradeModal .ver-old").text(verCur)
|
||||
$('#upgradeModal').data("chart", elm.name).data("initial", !verCur)
|
||||
|
||||
$('#upgradeModal select').val(elm.version).trigger("change")
|
||||
$("#upgradeModalLabel .name").text(elm.name)
|
||||
|
||||
const myModal = new bootstrap.Modal(document.getElementById('upgradeModal'), {});
|
||||
myModal.show()
|
||||
if (verCur) {
|
||||
$("#upgradeModal .ver-old").show().find("span").text(verCur)
|
||||
$("#upgradeModal .rel-name").prop("disabled", true).val(name)
|
||||
$("#upgradeModal .rel-ns").prop("disabled", true).val(ns)
|
||||
} else {
|
||||
$("#upgradeModal .ver-old").hide()
|
||||
$("#upgradeModal .rel-name").prop("disabled", false).val(elm.name.split("/").pop())
|
||||
$("#upgradeModal .rel-ns").prop("disabled", false).val("")
|
||||
}
|
||||
|
||||
const btnConfirm = $("#upgradeModal .btn-confirm");
|
||||
btnConfirm.prop("disabled", true).off('click').click(function () {
|
||||
btnConfirm.prop("disabled", true).prepend('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>')
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url + "&version=" + $('#upgradeModal select').val() + "&flag=true",
|
||||
data: $("#upgradeModal textarea").data("dirty") ? $("#upgradeModal form").serialize() : null,
|
||||
}).fail(function (xhr) {
|
||||
reportError("Failed to upgrade the chart", xhr)
|
||||
}).done(function (data) {
|
||||
if (data.version) {
|
||||
setHashParam("revision", data.version)
|
||||
window.location.reload()
|
||||
$.getJSON("/api/helm/repo/search?name=" + elm.name).fail(function (xhr) {
|
||||
reportError("Failed to find chart in repo", xhr)
|
||||
}).done(function (vers) {
|
||||
// fill versions
|
||||
$('#upgradeModal select').empty()
|
||||
for (let i = 0; i < vers.length; i++) {
|
||||
const opt = $("<option value='" + vers[i].version + "'></option>");
|
||||
if (vers[i].version === verCur) {
|
||||
opt.html(vers[i].version + " ·")
|
||||
} else {
|
||||
reportError("Failed to get new revision number")
|
||||
opt.html(vers[i].version)
|
||||
}
|
||||
})
|
||||
})
|
||||
$('#upgradeModal select').append(opt)
|
||||
}
|
||||
|
||||
// fill current values
|
||||
const lastRev = $("#specRev").data("last-rev")
|
||||
$.get("/api/helm/charts/values?namespace=" + getHashParam("namespace") + "&revision=" + lastRev + "&name=" + getHashParam("chart") + "&flag=true").fail(function (xhr) {
|
||||
reportError("Failed to get charts values info", xhr)
|
||||
}).done(function (data) {
|
||||
$("#upgradeModal textarea").val(data).data("dirty", false)
|
||||
$('#upgradeModal select').val(elm.version).trigger("change")
|
||||
|
||||
const myModal = new bootstrap.Modal(document.getElementById('upgradeModal'), {});
|
||||
myModal.show()
|
||||
|
||||
if (verCur) {
|
||||
// fill current values
|
||||
$.get("/api/helm/charts/values?namespace=" + ns + "&revision=" + lastRev + "&name=" + name + "&flag=true").fail(function (xhr) {
|
||||
reportError("Failed to get charts values info", xhr)
|
||||
}).done(function (data) {
|
||||
$("#upgradeModal textarea").val(data).data("dirty", false)
|
||||
})
|
||||
} else {
|
||||
$("#upgradeModal textarea").val("").data("dirty", true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$("#upgradeModal .btn-confirm").click(function () {
|
||||
const btnConfirm = $("#upgradeModal .btn-confirm")
|
||||
btnConfirm.prop("disabled", true).prepend('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>')
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "/api/helm/charts/install" + upgradeModalQstr() + "&flag=true",
|
||||
data: $("#upgradeModal textarea").data("dirty") ? $("#upgradeModal form").serialize() : null,
|
||||
}).fail(function (xhr) {
|
||||
reportError("Failed to upgrade the chart", xhr)
|
||||
}).done(function (data) {
|
||||
if (data.version) {
|
||||
setHashParam("section", null)
|
||||
setHashParam("namespace", $("#upgradeModal .rel-ns").val())
|
||||
setHashParam("chart", $("#upgradeModal .rel-name").val())
|
||||
setHashParam("revision", data.version)
|
||||
window.location.reload()
|
||||
} else {
|
||||
reportError("Failed to get new revision number")
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
let reconfigTimeout = null;
|
||||
$("#upgradeModal textarea").keyup(function () {
|
||||
|
||||
function changeTimer() {
|
||||
const self = $(this);
|
||||
self.data("dirty", true)
|
||||
if (reconfigTimeout) {
|
||||
@@ -113,7 +133,11 @@ $("#upgradeModal textarea").keyup(function () {
|
||||
reconfigTimeout = window.setTimeout(function () {
|
||||
requestChangeDiff()
|
||||
}, 500)
|
||||
})
|
||||
}
|
||||
|
||||
$("#upgradeModal textarea").keyup(changeTimer)
|
||||
$("#upgradeModal .rel-name").keyup(changeTimer)
|
||||
$("#upgradeModal .rel-ns").keyup(changeTimer)
|
||||
|
||||
$('#upgradeModal select').change(function () {
|
||||
const self = $(this)
|
||||
@@ -122,7 +146,7 @@ $('#upgradeModal select').change(function () {
|
||||
|
||||
// fill reference values
|
||||
$("#upgradeModal .ref-vals").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>')
|
||||
$.get("/api/helm/repo/values?chart=" + self.data("chart") + "&version=" + self.val()).fail(function (xhr) {
|
||||
$.get("/api/helm/repo/values?chart=" + $("#upgradeModal").data("chart") + "&version=" + self.val()).fail(function (xhr) {
|
||||
reportError("Failed to get upgrade info", xhr)
|
||||
}).done(function (data) {
|
||||
data = hljs.highlight(data, {language: 'yaml'}).value
|
||||
@@ -134,10 +158,9 @@ $('#upgradeModal .btn-scan').click(function () {
|
||||
const self = $(this)
|
||||
|
||||
self.prop("disabled", true).prepend('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>')
|
||||
const qstr = $('#upgradeModal select').data("qstr")
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/api/scanners/manifests" + qstr + "&version=" + $('#upgradeModal select').val(),
|
||||
url: "/api/scanners/manifests" + upgradeModalQstr(),
|
||||
data: $("#upgradeModal form").serialize(),
|
||||
}).fail(function (xhr) {
|
||||
reportError("Failed to scan the manifest", xhr)
|
||||
@@ -186,7 +209,7 @@ function requestChangeDiff() {
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: self.data("url") + "&version=" + self.val(),
|
||||
url: "/api/helm/charts/install" + upgradeModalQstr(),
|
||||
data: values,
|
||||
}).fail(function (xhr) {
|
||||
$("#upgradeModalBody").html("<p class='text-danger'>Failed to get upgrade info: " + xhr.responseText + "</p>")
|
||||
@@ -207,6 +230,20 @@ function requestChangeDiff() {
|
||||
})
|
||||
}
|
||||
|
||||
function upgradeModalQstr() {
|
||||
let qstr = "?" +
|
||||
"namespace=" + $("#upgradeModal .rel-ns").val() +
|
||||
"&name=" + $("#upgradeModal .rel-name").val() +
|
||||
"&chart=" + $("#upgradeModal").data("chart") +
|
||||
"&version=" + $('#upgradeModal select').val()
|
||||
|
||||
if ($("#upgradeModal").data("initial")) {
|
||||
qstr += "&initial=true"
|
||||
}
|
||||
|
||||
return qstr
|
||||
}
|
||||
|
||||
const btnConfirm = $("#confirmModal .btn-confirm");
|
||||
$("#btnUninstall").click(function () {
|
||||
const chart = getHashParam('chart');
|
||||
|
||||
Reference in New Issue
Block a user