const clusterSelect = $("#cluster");
const chartsCards = $("#charts");
function reportError(err) {
alert(err) // TODO: nice modal/baloon/etc
}
function revisionClicked(namespace, name, self) {
const elm = self.data("elm")
const parts = window.location.hash.split("&")
parts[2] = elm.revision
window.location.hash = parts.join("&")
$("#sectionDetails h1 span.rev").text(elm.revision)
let qstr = "chart=" + name + "&namespace=" + namespace + "&revision1=" + (elm.revision - 1) + "&revision2=" + elm.revision
let url = "/api/helm/charts/manifest/diff?" + qstr;
$.getJSON(url).fail(function () {
reportError("Failed to get diff of manifests")
}).done(function (data) {
if (data === "") {
$("#manifestText").text("No differences to display")
} else {
const targetElement = document.getElementById('manifestText');
const configuration = {
inputFormat: 'diff',
outputFormat: 'side-by-side',
drawFileList: false,
showFiles: false,
//matching: 'lines',
};
const diff2htmlUi = new Diff2HtmlUI(targetElement, data, configuration);
diff2htmlUi.draw()
}
})
}
function fillChartDetails(namespace, name) {
$("#sectionDetails").show()
$("#sectionDetails h1 span.name").text(name)
$.getJSON("/api/helm/charts/history?chart=" + name + "&namespace=" + namespace).fail(function () {
reportError("Failed to get list of clusters")
}).done(function (data) {
let revRow = $("#sectionDetails .row");
for (let x = 0; x < data.length; x++) {
const elm = data[x]
const rev = $(`
#' + elm.revision + '
' + elm.status + "
"))
// TODO: for pending- and uninstalling, add the spinner
if (elm.status === "failed") {
header.find(".badge").addClass("bg-danger text-light")
} else if (elm.status === "deployed" || elm.status === "superseded") {
header.find(".badge").addClass("bg-info")
} else {
header.find(".badge").addClass("bg-light text-dark")
}
header.append($('
').text(elm.name))
header.append($('
').append("Chart: " + elm.chart))
const body = $("
")
body.append($('
').append("Namespace: " + elm.namespace))
body.append($('
').append("Version: " + elm.app_version))
body.append($('
').append("Updated: " + elm.updated))
let card = $("
").append(header).append(body);
card.data("chart", elm)
card.click(function () {
const self = $(this)
$("#sectionList").hide()
let chart = self.data("chart");
window.location.hash = chart.namespace + "&" + chart.name
fillChartDetails(chart.namespace, chart.name)
})
chartsCards.append($("
").append(card))
})
})
}
$(function () {
// cluster list
$.getJSON("/api/kube/contexts").fail(function () {
reportError("Failed to get list of clusters")
}).done(function (data) {
data.forEach(function (elm) {
// aws CLI uses complicated context names, the suffix does not work well
// maybe we should have an `if` statement here
let label = elm.Name //+ " (" + elm.Cluster + "/" + elm.AuthInfo + "/" + elm.Namespace + ")"
let opt = $("
").val(elm.Name).text(label)
if (elm.IsCurrent) {
opt.attr("selected", "selected")
}
clusterSelect.append(opt)
})
})
clusterSelect.change(function () {
// TODO: remember it, respect it in the function above and in all other places
})
const parts = window.location.hash.substring(1).split("&")
if (parts[0] === "") {
loadChartsList()
} else {
fillChartDetails(parts[0], parts[1])
}
})