diff --git a/Components/Pages/Home.razor b/Components/Pages/Home.razor index 974503e..930dcf8 100644 --- a/Components/Pages/Home.razor +++ b/Components/Pages/Home.razor @@ -13,14 +13,25 @@

Publish Message

- - + + @selectedPubPreset + + @foreach (var group in presetGroups) + { + + @group.GroupName + + + @foreach (var preset in group.Presets) + { + @preset.Name + } + + + + } + +
@@ -60,14 +71,25 @@

Subscribe to Topic

- - + + @selectedSubPreset + + @foreach (var group in presetGroups) + { + + @group.GroupName + + + @foreach (var preset in group.Presets) + { + @preset.Name + } + + + + } + +
@@ -125,63 +147,51 @@ private string subscribePassword; private string subscribeTopic; private bool subscribeSslVerify = true; - private string selectedPresetName; - private string presetName; - private List presets = new List(); + + private string selectedPubPreset = "Select Preset"; + private string selectedSubPreset = "Select Preset"; + Dropdown pubPresetDropdown; + Dropdown subPresetDropdown; + private List presetGroups = new List(); private List messages = new List(); protected override async Task OnInitializedAsync() { - presets = await PresetService.GetPresetsAsync(); + presetGroups = await PresetService.GetPresetGroupsAsync(); } - private async Task LoadPresetPublish(ChangeEventArgs e) + private async Task LoadPresetPublish(PresetModel preset) { - selectedPresetName = e.Value?.ToString(); - Console.WriteLine($"Selected Preset Name: {selectedPresetName}"); - if (!string.IsNullOrEmpty(selectedPresetName)) + if (preset != null) { - var preset = presets.FirstOrDefault(p => p.Name == selectedPresetName); - if (preset != null) - { - publishHost = preset.Host; - publishVpnName = preset.VpnName; - publishUsername = preset.Username; - publishTopic = preset.Topic; - - Console.WriteLine($"Loaded Preset: {preset.Name}"); - } - else - { - Console.WriteLine($"Preset with name '{selectedPresetName}' not found."); - } + publishHost = preset.Host; + publishVpnName = preset.VpnName; + publishUsername = preset.Username; + publishTopic = preset.Topic; + selectedPubPreset = preset.Name; + + Console.WriteLine($"Loaded Preset: {preset.Name}"); } + HidePubDropdownMenu(); + } - private async Task LoadPresetSubscribe(ChangeEventArgs e) + private async Task LoadPresetSubscribe(PresetModel preset) { - selectedPresetName = e.Value?.ToString(); - Console.WriteLine($"Selected Preset Name: {selectedPresetName}"); - if (!string.IsNullOrEmpty(selectedPresetName)) + if (preset != null) { - var preset = presets.FirstOrDefault(p => p.Name == selectedPresetName); - if (preset != null) - { - subscribeHost = preset.Host; - subscribeVpnName = preset.VpnName; - subscribeUsername = preset.Username; - subscribeTopic = preset.Topic; - - Console.WriteLine($"Loaded Preset: {preset.Name}"); - } - else - { - Console.WriteLine($"Preset with name '{selectedPresetName}' not found."); - } + subscribeHost = preset.Host; + subscribeVpnName = preset.VpnName; + subscribeUsername = preset.Username; + subscribeTopic = preset.Topic; + selectedSubPreset = preset.Name; + + Console.WriteLine($"Loaded Preset: {preset.Name}"); } - } + HideSubDropdownMenu(); + } private void ConnectAndPublish() { @@ -223,4 +233,14 @@ SubscribeService.Dispose(); PublishService.Dispose(); } + + Task HidePubDropdownMenu() + { + return pubPresetDropdown.Hide(); + } + + Task HideSubDropdownMenu() + { + return subPresetDropdown.Hide(); + } } diff --git a/Components/Pages/QueueBrowser.razor b/Components/Pages/QueueBrowser.razor index 8e2f17a..8fe39b5 100644 --- a/Components/Pages/QueueBrowser.razor +++ b/Components/Pages/QueueBrowser.razor @@ -12,14 +12,25 @@ Queue Browser
- - + + @selectedPreset + + @foreach (var group in presetGroups) + { + + @group.GroupName + + + @foreach (var preset in group.Presets) + { + @preset.Name + } + + + + } + +
@@ -147,9 +158,10 @@ private bool sslVerify = true; private List messages = new List(); private DataGrid dataGrid; - private string selectedPresetName; - private string presetName; - private List presets = new List(); + + private string selectedPreset = "Select Preset"; + private List presetGroups = new List(); + Dropdown presetDropdown; private bool isBrowsing = false; @@ -202,7 +214,7 @@ protected override async Task OnInitializedAsync() { - presets = await PresetService.GetPresetsAsync(); + presetGroups = await PresetService.GetPresetGroupsAsync(); } protected override void OnInitialized() @@ -238,26 +250,24 @@ password = string.Empty; } - private async Task LoadPreset(ChangeEventArgs e) + private void LoadPreset(PresetModel preset) { - selectedPresetName = e.Value?.ToString(); - Console.WriteLine($"Selected Preset Name: {selectedPresetName}"); - if (!string.IsNullOrEmpty(selectedPresetName)) + if (preset != null) { - var preset = presets.FirstOrDefault(p => p.Name == selectedPresetName); - if (preset != null) - { - host = preset.Host; - vpnName = preset.VpnName; - username = preset.Username; - queueName = preset.QueueName; + host = preset.Host; + vpnName = preset.VpnName; + username = preset.Username; + queueName = preset.QueueName; + selectedPreset = preset.Name; - Console.WriteLine($"Loaded Preset: {preset.Name}"); - } - else - { - Console.WriteLine($"Preset with name '{selectedPresetName}' not found."); - } + Console.WriteLine($"Loaded Preset: {preset.Name}"); } + HideDropdownMenu(); } + + Task HideDropdownMenu() + { + return presetDropdown.Hide(); + } + } diff --git a/Components/Pages/SEMP.razor b/Components/Pages/SEMP.razor index 8fab016..74679fa 100644 --- a/Components/Pages/SEMP.razor +++ b/Components/Pages/SEMP.razor @@ -5,6 +5,7 @@ @inject SEMPService SEMPService @inject Blazored.Toast.Services.IToastService toastService @inject NavigationManager Navigation +@inject PresetService PresetService SEMP API @@ -12,6 +13,27 @@

SEMP Configuration

+
+ + @selectedPreset + + @foreach (var group in presetGroups) + { + + @group.GroupName + + + @foreach (var preset in group.Presets) + { + @preset.Name + } + + + + } + + +
@@ -81,6 +103,10 @@ private int smfsPort; private bool smfsEnabled; + private string selectedPreset = "Select Preset"; + private List presetGroups = new List(); + Dropdown presetDropdown; + private async Task GetQueues() { try @@ -107,4 +133,28 @@ var uri = $"queue-browser?&vpn={sempMessageVpn}&hostname={hostname}&queue={queueName}&username={queueOwner}"; Navigation.NavigateTo(uri); } + + protected override async Task OnInitializedAsync() + { + presetGroups = await PresetService.GetPresetGroupsAsync(); + } + + private void LoadPreset(PresetModel preset) + { + if (preset != null) + { + sempUrl = preset.SempUrl; + sempMessageVpn = preset.VpnName; + sempUsername = preset.sempUsername; + selectedPreset = preset.Name; + + Console.WriteLine($"Loaded Preset: {preset.Name}"); + } + HideDropdownMenu(); + } + + Task HideDropdownMenu() + { + return presetDropdown.Hide(); + } } diff --git a/Services/PresetService.cs b/Services/PresetService.cs index 95b6ab2..2e763bf 100644 --- a/Services/PresetService.cs +++ b/Services/PresetService.cs @@ -7,6 +7,11 @@ namespace SolaceWebClient.Services { + public class PresetGroupModel + { + public string GroupName { get; set; } + public List Presets { get; set; } + } public class PresetModel { public string Name { get; set; } @@ -15,36 +20,26 @@ public class PresetModel public string Username { get; set; } public string QueueName { get; set; } public string Topic { get; set; } + public string SempUrl { get; set; } + public string sempUsername { get; set; } } public class PresetService { private readonly string presetsFilePath = Path.Combine("presets", "presets.json"); - public async Task> GetPresetsAsync() + public async Task> GetPresetGroupsAsync() { if (!File.Exists(presetsFilePath)) { - return new List(); + return new List(); } var json = await File.ReadAllTextAsync(presetsFilePath); - var presets = JsonSerializer.Deserialize>(json); - - return presets ?? new List(); - } - - public async Task SavePresetsAsync(List presets) - { - var json = JsonSerializer.Serialize(presets, new JsonSerializerOptions { WriteIndented = true }); - var directory = Path.GetDirectoryName(presetsFilePath); + var presetGroups = JsonSerializer.Deserialize>(json); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - - await File.WriteAllTextAsync(presetsFilePath, json); + return presetGroups ?? new List(); } } + } diff --git a/presets/example.json b/presets/example.json index 051f06f..1f9316d 100644 --- a/presets/example.json +++ b/presets/example.json @@ -1,17 +1,50 @@ [ { - "Name": "Example 1", - "Host": "broker.domain:5555", - "VpnName": "default", - "Username": "demo", - "QueueName": "demo" + "GroupName": "test", + "Presets": [ + { + "Name": "Example 1", + "Host": "broker.domain:5555", + "VpnName": "default", + "Username": "demo", + "QueueName": "demo", + "SempUrl": "http://broker.domain:8080", + "sempUsername": "admin" + }, + { + "Name": "Example 2", + "Host": "tcps://broker.domain:55443", + "VpnName": "default", + "Username": "demo", + "Topic": "a/b/c", + "QueueName": "myqueue", + "SempUrl": "https://broker.domain:1943", + "sempUsername": "admin" + } + ] }, { - "Name": "Example 1", - "Host": "tcps://broker.domain:55443", - "VpnName": "default", - "Username": "demo", - "Topic": "a/b/c", - "QueueName": "myqueue" + "GroupName": "prod", + "Presets": [ + { + "Name": "Example 3", + "Host": "prod.domain:5555", + "VpnName": "default", + "Username": "demo", + "QueueName": "demo", + "SempUrl": "http://prod.domain:8080", + "sempUsername": "admin" + }, + { + "Name": "Example 4", + "Host": "tcps://prod.domain:55443", + "VpnName": "default", + "Username": "demo", + "Topic": "a/b/c", + "QueueName": "myqueue", + "SempUrl": "https://prod.domain:1943", + "sempUsername": "admin" + } + ] } -] \ No newline at end of file +]