Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

Allow sorting clusters on dashboard by count, name, or alias #1054

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/public/css/orchestrator.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ body {
padding-right: 10px;
}

#move-instance-method {
#dashboard-sort, #move-instance-method {
padding-bottom: 0px;
}

Expand Down
33 changes: 32 additions & 1 deletion resources/public/js/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,31 @@ $(document).ready(function() {
return cluster1.ClusterName.localeCompare(cluster2.ClusterName);
}

function sortByClusterName(cluster1, cluster2) {
return cluster1.ClusterName.localeCompare(cluster2.ClusterName);
}

function sortByClusterAlias(cluster1, cluster2) {
return cluster1.ClusterAlias.localeCompare(cluster2.ClusterAlias);
}

function displayClusters(clusters, replicationAnalysis, problemInstances) {
hideLoader();

clusters = clusters || [];

clusters.sort(sortByCountInstances);
var dashboardSort = $.cookie("dashboard-sort") || "count"

refreshDashboardSortButton();
$("#li-dashboard-sort").appendTo("ul.navbar-nav").show();
$("#dashboard-sort a").click(function() {
$.cookie("dashboard-sort", $(this).attr("dashboard-sort"), {
path: '/',
expires: 3650
});
location.reload();
});

var clustersProblems = {};
clusters.forEach(function(cluster) {
clustersProblems[cluster.ClusterName] = {};
Expand All @@ -48,6 +67,18 @@ $(document).ready(function() {
});
});

function refreshDashboardSortButton() {
if (dashboardSort == "name") {
clusters.sort(sortByClusterName);
} else if (dashboardSort == "alias") {
clusters.sort(sortByClusterAlias);
} else {
clusters.sort(sortByCountInstances);
}

$("#dashboard-sort-button").html("Sort by " + dashboardSort + ' <span class="caret"></span>')
}

function addInstancesBadge(clusterName, count, badgeClass, title) {
$("#clusters [data-cluster-name='" + clusterName + "'].popover").find(".popover-content .pull-right").append('<span class="badge ' + badgeClass + '" title="' + title + '">' + count + '</span> ');
}
Expand Down
15 changes: 15 additions & 0 deletions resources/templates/clusters.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@
</script>
<script src="{{.prefix}}/js/cluster-analysis-shared.js"></script>
<script src="{{.prefix}}/js/clusters.js"></script>


<li id="li-dashboard-sort" data-nav-page="relocate method" style="display:none">
<div id="dashboard-sort" class="dropdown">
<button class="btn btn-xs dropdown-toggle" type="button" id="dashboard-sort-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Sort
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dashboard-sort">
<li><a href="#" dashboard-sort="count" title="Sort by instance count, most to least">Instance count</a></li>
<li><a href="#" dashboard-sort="name" title="Sort by cluster name">Name</a></li>
<li><a href="#" dashboard-sort="alias" title="Sort by cluster alias">Alias</a></li>
</ul>
</div>
</li>