Skip to content

Commit

Permalink
- added paging for Queues List (SEMP)
Browse files Browse the repository at this point in the history
- added count parameter for SEMP API call of retrieved queues
- added loop/check if nextPageUri exists and aggregate results
- code cleanup (removed some comments)
  • Loading branch information
GyroGearl00se committed Jun 17, 2024
1 parent fd72632 commit 7ebb896
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 61 deletions.
2 changes: 0 additions & 2 deletions Components/Layout/NavMenu.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
}

.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
}
Expand Down
58 changes: 55 additions & 3 deletions Components/Pages/SEMP.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@
</div>
</div>



<div>
<h4>Queues</h4>

<input type="text" @bind="QueueNameFilterText" placeholder="Filter Queue Name..." @oninput="ApplyFilter" />
<input type="text" @bind="QueueOwnerFilterText" placeholder="Filter Queue Owner..." @oninput="ApplyFilter" />


<table class="table">
<thead>
<tr>
Expand All @@ -48,7 +55,7 @@
</tr>
</thead>
<tbody>
@foreach (var queue in getQueuesList)
@foreach (var queue in PagedQueues)
{
<tr>
<td>@queue.queueName</td>
Expand All @@ -58,6 +65,10 @@
}
</tbody>
</table>

<button @onclick="PreviousPage" disabled="@(!HasPreviousPage)">Previous</button>
<button @onclick="NextPage" disabled="@(!HasNextPage)">Next</button>

</div>

@code {
Expand All @@ -66,13 +77,32 @@
private string sempUsername;
private string sempPassword;
private bool sempSslVerify = true;
private List<SEMPService.GetQueuesDetails> getQueuesList = new List<SEMPService.GetQueuesDetails>();

private string hostname;
private int smfPort;
private int smfsPort;
private bool smfsEnabled;

private List<SEMPService.GetQueuesDetails> Queues = new List<SEMPService.GetQueuesDetails>();
private List<SEMPService.GetQueuesDetails> FilteredQueues =>
string.IsNullOrEmpty(QueueNameFilterText) && string.IsNullOrEmpty(QueueOwnerFilterText) ?
Queues :
Queues.Where(q =>
(string.IsNullOrEmpty(QueueNameFilterText) || q.queueName.Contains(QueueNameFilterText, StringComparison.OrdinalIgnoreCase)) &&
(string.IsNullOrEmpty(QueueOwnerFilterText) || q.queueOwner.Contains(QueueOwnerFilterText, StringComparison.OrdinalIgnoreCase))
).ToList();
private List<SEMPService.GetQueuesDetails> PagedQueues => FilteredQueues.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList();

private string QueueNameFilterText { get; set; }
private string QueueOwnerFilterText { get; set; }

private int CurrentPage { get; set; } = 1;
private int PageSize { get; set; } = 10;
private bool HasPreviousPage => CurrentPage > 1;
private bool HasNextPage => CurrentPage * PageSize < FilteredQueues.Count;



private async Task GetQueues()
{
try
Expand All @@ -82,7 +112,7 @@
smfPort = config.SmfPort;
smfsPort = config.SmfsPort;

getQueuesList = await SEMPService.GetQueuesAsync(sempUrl, sempMessageVpn, sempUsername, sempPassword, sempSslVerify);
Queues = await SEMPService.GetQueuesAsync(sempUrl, sempMessageVpn, sempUsername, sempPassword, sempSslVerify);
toastService.ShowSuccess("Queues retrieved successfully");
}
catch (Exception ex)
Expand All @@ -91,6 +121,28 @@
}
}

private void ApplyFilter(ChangeEventArgs e)
{
CurrentPage = 1;
StateHasChanged();
}

private void PreviousPage()
{
if (HasPreviousPage)
{
CurrentPage--;
}
}

private void NextPage()
{
if (HasNextPage)
{
CurrentPage++;
}
}

private void BrowseQueue(string queueName, string queueOwner)
{
string hostname = new Uri(sempUrl).Host;
Expand Down
72 changes: 44 additions & 28 deletions Services/SEMPService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,65 @@ public SEMPService(HttpClient httpClient, ILogger<SEMPService> logger)

public async Task<List<GetQueuesDetails>> GetQueuesAsync(string url, string messageVpn, string username, string password, bool sslVerify)
{
string requestUrl = $"{url}/SEMP/v2/config/msgVpns/{messageVpn}/queues";
var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
var authToken = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authToken);
var getQueuesList = new List<GetQueuesDetails>();
string requestUrl = $"{url}/SEMP/v2/config/msgVpns/{messageVpn}/queues?count=100";

if (!sslVerify)
while (!string.IsNullOrEmpty(requestUrl))
{
// Bypass SSL certificate validation
_httpClient.DefaultRequestHeaders.Add("IgnoreSslErrors", "true");
}
var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
var authToken = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authToken);

HttpResponseMessage response;
try
{
response = await _httpClient.SendAsync(request);
}
catch (HttpRequestException e)
{
_logger.LogError($"Request error: {e.Message}");
throw;
}
if (!sslVerify)
{
// Bypass SSL certificate validation
_httpClient.DefaultRequestHeaders.Add("IgnoreSslErrors", "true");
}
_httpClient.DefaultRequestHeaders.Add("count", "100");
HttpResponseMessage response;
try
{
response = await _httpClient.SendAsync(request);
}
catch (HttpRequestException e)
{
_logger.LogError($"Request error: {e.Message}");
throw;
}

response.EnsureSuccessStatusCode();
response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync();
List<GetQueuesDetails> getQueuesList = new List<GetQueuesDetails>();
var responseBody = await response.Content.ReadAsStringAsync();

using (JsonDocument doc = JsonDocument.Parse(responseBody))
{
foreach (var element in doc.RootElement.GetProperty("data").EnumerateArray())
using (JsonDocument doc = JsonDocument.Parse(responseBody))
{
getQueuesList.Add(new GetQueuesDetails
foreach (var element in doc.RootElement.GetProperty("data").EnumerateArray())
{
queueName = element.GetProperty("queueName").GetString(),
queueOwner = element.GetProperty("owner").GetString()
});
getQueuesList.Add(new GetQueuesDetails
{
queueName = element.GetProperty("queueName").GetString(),
queueOwner = element.GetProperty("owner").GetString()
});
}

if (doc.RootElement.TryGetProperty("meta", out JsonElement metaElement) &&
metaElement.TryGetProperty("paging", out JsonElement pagingElement) &&
pagingElement.TryGetProperty("nextPageUri", out JsonElement nextPageUriElement))
{
requestUrl = nextPageUriElement.GetString();
}
else
{
requestUrl = null;
}
}
}

return getQueuesList;
}



public class ListenerPorts
{
public int SmfPort { get; set; }
Expand Down
55 changes: 27 additions & 28 deletions wwwroot/app.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
background-color: #121212; /* Dark background */
color: #e0e0e0; /* Light text color */
background-color: #121212;
color: #e0e0e0;
}

a, .btn-link {
color: #00C895; /* Akzentfarbe */
color: #00C895;
}

.btn-primary {
color: #121212; /* Dark background */
background-color: #00C895; /* Akzentfarbe */
border-color: #00C895; /* Akzentfarbe */
color: #121212;
background-color: #00C895;
border-color: #00C895;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem #121212, 0 0 0 0.25rem #00C895; /* Dark background and Akzentfarbe */
box-shadow: 0 0 0 0.1rem #121212, 0 0 0 0.25rem #00C895;
}

.content {
Expand All @@ -40,51 +40,51 @@ h1:focus {

.blazor-error-boundary::after {
content: "An error has occurred.";
color: #e50000; /* Error message color */
color: #e50000;
}

.darker-border-checkbox.form-check-input {
border-color: #929292;
}

.navbar {
background-color: #1c1c1c; /* Darker navbar background */
background-color: #1c1c1c;
}

.nav-link {
color: #e0e0e0; /* Light text color for nav links */
color: #e0e0e0;
}

.nav-link:hover {
color: #00C895; /* Akzentfarbe on hover */
color: #00C895;
}

.navbar-brand {
color: #00C895; /* Akzentfarbe for brand */
color: #00C895;
}

.page {
background-color: #121212; /* Dark background */
background-color: #121212;
}

.top-row {
border-bottom: 1px solid #333; /* Light border */
border-bottom: 1px solid #333;
background-color: #1c1c1c;
}

.nav-scrollable {
background-color: #1c1c1c; /* Darker nav background */
color: #e0e0e0; /* Light text color */
background-color: #1c1c1c;
color: #e0e0e0;
}

.main {
background-color: #121212; /* Dark background */
color: #e0e0e0; /* Light text color */
background-color: #121212;
color: #e0e0e0;
}

.article {
background-color: #1c1c1c; /* Darker background for articles */
color: #e0e0e0; /* Light text color */
background-color: #1c1c1c;
color: #e0e0e0;
}

.form-container {
Expand Down Expand Up @@ -130,8 +130,8 @@ h1:focus {
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Halbtransparentes Schwarz */
z-index: 9999; /* Stellen Sie sicher, dass das Overlay über allen anderen Elementen liegt */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
}

.loading-message-delete {
Expand Down Expand Up @@ -167,18 +167,17 @@ h1:focus {
}

.table {
background-color: #1c1c1c; /* Dunkler Hintergrund */
color: #e0e0e0; /* Hellere Textfarbe */
}
background-color: #1c1c1c;
color: #e0e0e0;

.table th,
.table td {
border-color: #333; /* Farbe der Tabellenlinien */
border-color: #333;
}

.table th {
background-color: #333; /* Farbe für Tabellenkopf */
color: #e0e0e0; /* Textfarbe für Tabellenkopf */
background-color: #333;
color: #e0e0e0;
}


Expand Down

0 comments on commit 7ebb896

Please sign in to comment.