Skip to content

Commit

Permalink
added support for grouped and ungrouped presets
Browse files Browse the repository at this point in the history
  • Loading branch information
GyroGearl00se committed Aug 10, 2024
1 parent b08d9ee commit cc18aaa
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 31 deletions.
30 changes: 18 additions & 12 deletions Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetPublish(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetPublish(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
}
@foreach (var preset in ungroupedPresets)
{
<DropdownItem @onclick="() => LoadPresetPublish(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
</div>
Expand Down Expand Up @@ -79,15 +81,17 @@
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetSubscribe(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetSubscribe(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
}
@foreach (var preset in ungroupedPresets)
{
<DropdownItem @onclick="() => LoadPresetSubscribe(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
</div>
Expand Down Expand Up @@ -153,12 +157,14 @@
Dropdown pubPresetDropdown;
Dropdown subPresetDropdown;
private List<PresetGroupModel> presetGroups = new List<PresetGroupModel>();
private List<PresetModel> ungroupedPresets = new List<PresetModel>();

private List<string> messages = new List<string>();

protected override async Task OnInitializedAsync()
{
presetGroups = await PresetService.GetPresetGroupsAsync();
ungroupedPresets = await PresetService.GetUngroupedPresetsAsync();
}

private async Task LoadPresetPublish(PresetModel preset)
Expand Down
22 changes: 13 additions & 9 deletions Components/Pages/QueueBrowser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
<Dropdown @ref="presetDropdown">
<DropdownToggle Color="Color.Primary">@selectedPreset</DropdownToggle>
<DropdownMenu>
@foreach (var group in presetGroups)
{
@foreach (var group in presetGroups)
{
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
}
}
@foreach (var preset in ungroupedPresets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
</div>
Expand Down Expand Up @@ -161,6 +163,7 @@

private string selectedPreset = "Select Preset";
private List<PresetGroupModel> presetGroups = new List<PresetGroupModel>();
private List<PresetModel> ungroupedPresets = new List<PresetModel>();
Dropdown presetDropdown;

private bool isBrowsing = false;
Expand Down Expand Up @@ -215,6 +218,7 @@
protected override async Task OnInitializedAsync()
{
presetGroups = await PresetService.GetPresetGroupsAsync();
ungroupedPresets = await PresetService.GetUngroupedPresetsAsync();
}

protected override void OnInitialized()
Expand Down
16 changes: 10 additions & 6 deletions Components/Pages/SEMP.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
}
@foreach (var preset in ungroupedPresets)
{
<DropdownItem @onclick="() => LoadPreset(preset)">@preset.Name</DropdownItem>
}
</DropdownMenu>
</Dropdown>
</div>
Expand Down Expand Up @@ -105,6 +107,7 @@

private string selectedPreset = "Select Preset";
private List<PresetGroupModel> presetGroups = new List<PresetGroupModel>();
private List<PresetModel> ungroupedPresets = new List<PresetModel>();
Dropdown presetDropdown;

private async Task GetQueues()
Expand Down Expand Up @@ -137,6 +140,7 @@
protected override async Task OnInitializedAsync()
{
presetGroups = await PresetService.GetPresetGroupsAsync();
ungroupedPresets = await PresetService.GetUngroupedPresetsAsync();
}

private void LoadPreset(PresetModel preset)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The Solace Web Client is a .NET (C#) application that offers comprehensive funct

## Presets
The Solace Web Client allows you to manage connection presets, making it easy to switch between different configurations.
You can either create presets directly (i.e. Exampele 5) or group them (i.e. "test" & "prod").

Create a presets.json and mount it in `/app/presets/presets.json`.

Expand Down Expand Up @@ -77,6 +78,16 @@ Example:
"sempUsername": "admin"
}
]
},
{
"Name": "Example 5",
"Host": "tcps://broker.domain:55443",
"VpnName": "default",
"Username": "demo",
"Topic": "a/b/c",
"QueueName": "myqueue",
"SempUrl": "https://broker.domain:1943",
"sempUsername": "admin"
}
]

Expand Down
58 changes: 55 additions & 3 deletions Services/PresetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace SolaceWebClient.Services
public class PresetGroupModel
{
public string GroupName { get; set; }
public List<PresetModel> Presets { get; set; }
public List<PresetModel> Presets { get; set; } = new List<PresetModel>(); // Initialisiere die Liste
}

public class PresetModel
{
public string Name { get; set; }
Expand All @@ -24,6 +25,12 @@ public class PresetModel
public string sempUsername { get; set; }
}

public class UngroupedPresetModel : PresetModel
{

}


public class PresetService
{
private readonly string presetsFilePath = Path.Combine("presets", "presets.json");
Expand All @@ -36,9 +43,54 @@ public async Task<List<PresetGroupModel>> GetPresetGroupsAsync()
}

var json = await File.ReadAllTextAsync(presetsFilePath);
var presetGroups = JsonSerializer.Deserialize<List<PresetGroupModel>>(json);
var allPresets = JsonSerializer.Deserialize<List<JsonElement>>(json);

var groupedPresets = new List<PresetGroupModel>();
var ungroupedPresets = new List<PresetModel>();

foreach (var item in allPresets)
{
if (item.TryGetProperty("Presets", out _))
{
var group = JsonSerializer.Deserialize<PresetGroupModel>(item.GetRawText());
groupedPresets.Add(group);
}
else if (item.TryGetProperty("Name", out _))
{
var preset = JsonSerializer.Deserialize<PresetModel>(item.GetRawText());
ungroupedPresets.Add(preset);
}
}
return groupedPresets;
}

public async Task<List<PresetModel>> GetUngroupedPresetsAsync()
{
if (!File.Exists(presetsFilePath))
{
return new List<PresetModel>();
}

var json = await File.ReadAllTextAsync(presetsFilePath);
var allPresets = JsonSerializer.Deserialize<List<JsonElement>>(json);

var ungroupedPresets = new List<PresetModel>();

foreach (var item in allPresets)
{
if (item.TryGetProperty("Presets", out _))
{
continue;
}

if (item.TryGetProperty("Name", out _))
{
var preset = JsonSerializer.Deserialize<PresetModel>(item.GetRawText());
ungroupedPresets.Add(preset);
}
}

return presetGroups ?? new List<PresetGroupModel>();
return ungroupedPresets;
}
}

Expand Down
12 changes: 11 additions & 1 deletion presets/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@
"sempUsername": "admin"
}
]
},
{
"Name": "Example 5",
"Host": "tcps://broker.domain:55443",
"VpnName": "default",
"Username": "demo",
"Topic": "a/b/c",
"QueueName": "myqueue",
"SempUrl": "https://broker.domain:1943",
"sempUsername": "admin"
}
]
]

0 comments on commit cc18aaa

Please sign in to comment.