Skip to content

Commit

Permalink
- blazorise dropdown for preset selection
Browse files Browse the repository at this point in the history
- group presets
- additional preset field (SempUrl & SempUsername)
  • Loading branch information
GyroGearl00se committed Aug 10, 2024
1 parent 78d277f commit 04a7143
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 115 deletions.
134 changes: 77 additions & 57 deletions Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@
<div class="form-section">
<h4>Publish Message</h4>
<div class="form-group">
<label>Select Preset</label>
<select class="form-select-sm" @onchange="LoadPresetPublish">
<option value="">Select a preset</option>
@foreach (var preset in presets)
{
<option value="@preset.Name">@preset.Name</option>
}
</select>
<Dropdown @ref="pubPresetDropdown">
<DropdownToggle Color="Color.Primary">@selectedPubPreset</DropdownToggle>
<DropdownMenu>
@foreach (var group in presetGroups)
{
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetPublish(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
</DropdownMenu>
</Dropdown>
}
</DropdownMenu>
</Dropdown>
</div>
<div class="form-group">
<div class="input-with-checkbox">
Expand Down Expand Up @@ -60,14 +71,25 @@
<div class="form-section">
<h4>Subscribe to Topic</h4>
<div class="form-group">
<label>Select Preset</label>
<select class="form-select-sm" @onchange="LoadPresetSubscribe">
<option value="">Select a preset</option>
@foreach (var preset in presets)
{
<option value="@preset.Name">@preset.Name</option>
}
</select>
<Dropdown @ref="subPresetDropdown">
<DropdownToggle Color="Color.Primary">@selectedSubPreset</DropdownToggle>
<DropdownMenu>
@foreach (var group in presetGroups)
{
<Dropdown>
<DropdownToggle> @group.GroupName </DropdownToggle>
<DropdownMenu>
<Dropdown>
@foreach (var preset in group.Presets)
{
<DropdownItem @onclick="() => LoadPresetSubscribe(preset)">@preset.Name</DropdownItem>
}
</Dropdown>
</DropdownMenu>
</Dropdown>
}
</DropdownMenu>
</Dropdown>
</div>
<div class="form-group">
<div class="input-with-checkbox">
Expand Down Expand Up @@ -125,63 +147,51 @@
private string subscribePassword;
private string subscribeTopic;
private bool subscribeSslVerify = true;
private string selectedPresetName;
private string presetName;
private List<PresetModel> presets = new List<PresetModel>();

private string selectedPubPreset = "Select Preset";
private string selectedSubPreset = "Select Preset";
Dropdown pubPresetDropdown;
Dropdown subPresetDropdown;
private List<PresetGroupModel> presetGroups = new List<PresetGroupModel>();

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

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()
{
Expand Down Expand Up @@ -223,4 +233,14 @@
SubscribeService.Dispose();
PublishService.Dispose();
}

Task HidePubDropdownMenu()
{
return pubPresetDropdown.Hide();
}

Task HideSubDropdownMenu()
{
return subPresetDropdown.Hide();
}
}
68 changes: 39 additions & 29 deletions Components/Pages/QueueBrowser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@
<Title>Queue Browser</Title>

<div class="form-group">
<label>Select Preset</label>
<select class="form-select-sm" @onchange="LoadPreset">
<option value="">Select a preset</option>
@foreach (var preset in presets)
{
<option value="@preset.Name">@preset.Name</option>
}
</select>
<Dropdown @ref="presetDropdown">
<DropdownToggle Color="Color.Primary">@selectedPreset</DropdownToggle>
<DropdownMenu>
@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>
</DropdownMenu>
</Dropdown>
}
</DropdownMenu>
</Dropdown>
</div>

<div class="overlay" style="display: @(isDeleting ? "block" : "none")">
Expand Down Expand Up @@ -147,9 +158,10 @@
private bool sslVerify = true;
private List<MessageDetails> messages = new List<MessageDetails>();
private DataGrid<MessageDetails> dataGrid;
private string selectedPresetName;
private string presetName;
private List<PresetModel> presets = new List<PresetModel>();

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

private bool isBrowsing = false;

Expand Down Expand Up @@ -202,7 +214,7 @@

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

protected override void OnInitialized()
Expand Down Expand Up @@ -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();
}

}
50 changes: 50 additions & 0 deletions Components/Pages/SEMP.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
@inject SEMPService SEMPService
@inject Blazored.Toast.Services.IToastService toastService
@inject NavigationManager Navigation
@inject PresetService PresetService

<Layout>
<Title>SEMP API</Title>

<div class="form-container">
<div class="form-section">
<h4>SEMP Configuration</h4>
<div class="form-group">
<Dropdown @ref="presetDropdown">
<DropdownToggle Color="Color.Primary">@selectedPreset</DropdownToggle>
<DropdownMenu>
@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>
</DropdownMenu>
</Dropdown>
}
</DropdownMenu>
</Dropdown>
</div>
<div class="form-group">
<div class="input-with-checkbox">
<div class="input-container">
Expand Down Expand Up @@ -81,6 +103,10 @@
private int smfsPort;
private bool smfsEnabled;

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

private async Task GetQueues()
{
try
Expand All @@ -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();
}
}
Loading

0 comments on commit 04a7143

Please sign in to comment.