From 3abae8e49e0a34adc1b88bee0b086bde15ec52de Mon Sep 17 00:00:00 2001 From: ronahk <74967920+ronahk@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:38:09 +0200 Subject: [PATCH] Filter installed charts by namespace (#101) * filter by namespace * exists * Some improvements, one thing resolved * cleanup * merge * allow filtering by name * filter by namespace * changes * change url parameter name * keep filtered namespaces when refreshing and combine inpt and namespace filtering * Refactoring * Cleanup * Forced NS handle * remove else Co-authored-by: Andrei Pohilko --- pkg/dashboard/static/index.html | 13 ++- pkg/dashboard/static/list-view.js | 25 +++-- pkg/dashboard/static/repo.js | 2 +- pkg/dashboard/static/scripts.js | 164 ++++++++++++++++++++++-------- pkg/dashboard/static/styles.css | 7 ++ 5 files changed, 157 insertions(+), 54 deletions(-) diff --git a/pkg/dashboard/static/index.html b/pkg/dashboard/static/index.html index c1bbd14..993702b 100644 --- a/pkg/dashboard/static/index.html +++ b/pkg/dashboard/static/index.html @@ -130,12 +130,10 @@ - - @@ -145,9 +143,12 @@
-
+

Installed ChartsInstalled Charts ()

+
+ +
Name
@@ -163,6 +164,8 @@ +
diff --git a/pkg/dashboard/static/list-view.js b/pkg/dashboard/static/list-view.js index 1db4745..9847f0c 100644 --- a/pkg/dashboard/static/list-view.js +++ b/pkg/dashboard/static/list-view.js @@ -6,19 +6,21 @@ function loadChartsList() { $.getJSON("/api/helm/charts").fail(function (xhr) { reportError("Failed to get list of charts", xhr) }).done(function (data) { - chartsCards.empty() + chartsCards.empty().hide() $("#installedList .header h2 span").text(data.length) data.forEach(function (elm) { let card = buildChartCard(elm); chartsCards.append(card) }) - + filterInstalledList(chartsCards.find(".row")) + chartsCards.show() if (!data.length) { $("#installedList .no-charts").show() } }) } + function buildChartCard(elm) { const card = $(`
release-name
@@ -28,21 +30,21 @@ function buildChartCard(elm) {
default
Namespace
today
Updated
`) - + const chartName = elm.chart.substring(0, elm.chart.lastIndexOf("-")) $.getJSON("/api/helm/repo/search?name=" + chartName).fail(function (xhr) { reportError("Failed to get repo name for charts", xhr) }).done(function (data) { - if(data.length > 0) { + if (data.length > 0) { $.getJSON("/api/helm/charts/show?name=" + data[0].name).fail(function (xhr) { reportError("Failed to get list of charts", xhr) }).done(function (data) { - if(data) { - var res = data[0] - if(res.icon) { + if (data) { + const res = data[0]; + if (res.icon) { card.find(".rel-name").attr("style", "background-image: url(" + res.icon + ")") } - if(res.description) { + if (res.description) { card.find(".rel-name div").text(res.description) } } @@ -57,6 +59,10 @@ function buildChartCard(elm) { card.find(".rel-chart span").text(elm.chart) card.find(".rel-date span").text(getAge(elm)) + card.data("namespace", elm.namespace) + card.data("name", elm.name) + card.data("chart", elm.chart) + statusStyle(elm.status, card, card.find(".rel-status span")) card.find("a").attr("href", '#context=' + getHashParam('context') + '&namespace=' + elm.namespace + '&name=' + elm.name) @@ -74,3 +80,6 @@ function buildChartCard(elm) { return card; } +$("#installedSearch").keyup(function () { + filterInstalledList($("#installedList .body .row")) +}) diff --git a/pkg/dashboard/static/repo.js b/pkg/dashboard/static/repo.js index 9b9be9e..1e1ac63 100644 --- a/pkg/dashboard/static/repo.js +++ b/pkg/dashboard/static/repo.js @@ -131,7 +131,7 @@ function repoChartClicked() { window.location.reload() } else { const contexts = $("body").data("contexts") - contextNamespace = contexts.filter(obj => {return obj.Name === getHashParam("context")})[0].Namespace + const contextNamespace = contexts.filter(obj => {return obj.Name === getHashParam("context")})[0].Namespace popUpUpgrade(elm, contextNamespace) } } \ No newline at end of file diff --git a/pkg/dashboard/static/scripts.js b/pkg/dashboard/static/scripts.js index 1539762..0d55145 100644 --- a/pkg/dashboard/static/scripts.js +++ b/pkg/dashboard/static/scripts.js @@ -1,33 +1,16 @@ $(function () { - const clusterSelect = $("#cluster"); - clusterSelect.change(function () { - window.location.href = "/#context=" + clusterSelect.find("input:radio:checked").val() - window.location.reload() - }) - $.getJSON("/api/kube/contexts").fail(function (xhr) { - reportError("Failed to get list of clusters", xhr) + let limNS = null + $.getJSON("/status").fail(function (xhr) { // maybe /options call in the future + reportError("Failed to get tool version", xhr) }).done(function (data) { - $("body").data("contexts", data) - const context = getHashParam("context") - data.sort((a, b) => (getCleanClusterName(a.Name) > getCleanClusterName(b.Name)) - (getCleanClusterName(a.Name) < getCleanClusterName(b.Name))) - fillClusterList(data, context); - - initView(); // can only do it after loading cluster list - - $.getJSON("/api/kube/namespaces").fail(function (xhr) { - reportError("Failed to get namespaces", xhr) - }).done(function (res) { - const ns = res.items.map(i => i.metadata.name) - $.each(ns, function (i, item) { - $("#upgradeModal #ns-datalist").append($("