Updated WebUI
This commit is contained in:
43
DiscordBotWebUI/Components/Items/Marketplace.razor
Normal file
43
DiscordBotWebUI/Components/Items/Marketplace.razor
Normal file
@@ -0,0 +1,43 @@
|
||||
@using DiscordBotCore
|
||||
@using DiscordBotCore.Plugin
|
||||
@using DiscordBotWebUI.Types
|
||||
|
||||
<RadzenDataGrid AllowColumnResize="true" PageSize="5" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" Data="ListedItems">
|
||||
<Columns>
|
||||
<RadzenDataGridColumn Property="@nameof(MarketItem.Name)" Title="Item Name"></RadzenDataGridColumn>
|
||||
<RadzenDataGridColumn Property="@nameof(MarketItem.Author)" Title="Item Author"></RadzenDataGridColumn>
|
||||
<RadzenDataGridColumn Property="@nameof(MarketItem.Description)" Title="Item Description"></RadzenDataGridColumn>
|
||||
<RadzenDataGridColumn Title="Item Download">
|
||||
<Template Context="item">
|
||||
<RadzenButton Click="() => DownloadPlugin(item.Name)">Download</RadzenButton>
|
||||
</Template>
|
||||
</RadzenDataGridColumn>
|
||||
</Columns>
|
||||
</RadzenDataGrid>
|
||||
|
||||
<RadzenProgressBar Value="_ProgressValue" Visible="_ProgressBarVisible"/>
|
||||
|
||||
@code {
|
||||
private float _ProgressValue = .0f;
|
||||
private bool _ProgressBarVisible = false;
|
||||
|
||||
|
||||
[Parameter]
|
||||
public List<MarketItem> ListedItems { get; set; }
|
||||
|
||||
private async Task DownloadPlugin(string pluginName)
|
||||
{
|
||||
_ProgressBarVisible = true;
|
||||
IProgress<float> downloadProgress = new Progress<float>(p => {
|
||||
_ProgressValue = p;
|
||||
StateHasChanged();
|
||||
});
|
||||
PluginOnlineInfo? pluginInfo = await Application.CurrentApplication.PluginManager.GetPluginDataByName(pluginName);
|
||||
if (pluginInfo is null)
|
||||
return;
|
||||
|
||||
await Application.CurrentApplication.PluginManager.InstallPlugin(pluginInfo, downloadProgress);
|
||||
|
||||
_ProgressBarVisible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@code {
|
||||
[Parameter] public Action CompleteSetup { get; set; }
|
||||
}
|
||||
|
||||
<RadzenHeading Size="H4">Final Setup</RadzenHeading>
|
||||
<p>Your bot is almost ready! Click 'Finish' to complete the setup.</p>
|
||||
|
||||
<RadzenButton Text="Finish" Click="CompleteSetup" Style="margin-top: 20px;" />
|
||||
@@ -0,0 +1,60 @@
|
||||
@using DiscordBotCore
|
||||
@code {
|
||||
[Parameter] public Action NextStep { get; set; }
|
||||
private string BotToken { get; set; }
|
||||
private string BotPrefix { get; set; }
|
||||
private List<ulong> BotServers { get; set; }
|
||||
|
||||
private string BotServersString { get; set; }
|
||||
|
||||
private async void DoNextStep()
|
||||
{
|
||||
if(string.IsNullOrEmpty(BotToken) || string.IsNullOrEmpty(BotPrefix) || string.IsNullOrEmpty(BotServersString))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(BotServersString.Contains(","))
|
||||
{
|
||||
BotServersString = BotServersString.Replace(",", ";");
|
||||
}
|
||||
|
||||
var stringList = BotServersString.Split(';');
|
||||
BotServers = new List<ulong>();
|
||||
foreach(var serverId in stringList)
|
||||
{
|
||||
if(ulong.TryParse(serverId, out ulong id))
|
||||
{
|
||||
BotServers.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!BotServers.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Add("token", BotToken);
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Add("prefix", BotPrefix);
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Add("ServerID", BotServers);
|
||||
|
||||
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
|
||||
|
||||
NextStep.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
<RadzenHeading Size="H4">Basic Configuration</RadzenHeading>
|
||||
<p>Please provide some basic settings to get started.</p>
|
||||
|
||||
<RadzenLabel Text="Token" />
|
||||
<RadzenTextBox @bind-Value="BotToken" Placeholder="Enter bot token here" Style="width: 100%;" />
|
||||
|
||||
<RadzenLabel Text="Prefix" Style="margin-top: 10px;" />
|
||||
<RadzenTextBox @bind-Value="BotPrefix" Placeholder="Enter the prefix here" Style="width: 100%;" />
|
||||
|
||||
<RadzenLabel Text="Server Ids separated by ;" Style="margin-top: 20px;" />
|
||||
<RadzenTextBox @bind-Value="BotServersString" Placeholder="Enter Server Ids here. Separated by commas (;)" Style="width: 100%;" />
|
||||
|
||||
<RadzenButton Text="Next" Click="DoNextStep" Style="margin-top: 30px;" />
|
||||
@@ -0,0 +1,7 @@
|
||||
@code {
|
||||
[Parameter] public Action NextStep { get; set; }
|
||||
}
|
||||
|
||||
<RadzenHeading Size="H4">Welcome to the Bot Setup Wizard</RadzenHeading>
|
||||
<p>This setup wizard will guide you through the process of configuring your bot and downloading the necessary dependencies.</p>
|
||||
<RadzenButton Text="Start Setup" Click="NextStep" Style="margin-top: 20px;" />
|
||||
Reference in New Issue
Block a user