Improved web ui
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
@page "/"
|
||||
|
||||
@using DiscordBotCore.Others.Exceptions
|
||||
@using DiscordBotWebUI.Components.Pages.Setup
|
||||
@using DiscordBotWebUI.DiscordBot
|
||||
|
||||
@inject DialogService DialogService
|
||||
|
||||
<RadzenButton Text="Start" Click="Initialize"/>
|
||||
<RadzenTextArea Placeholder="Logs..." Value="@_TextValue" Style="width: 100%; height: 80%"/>
|
||||
|
||||
|
||||
@code {
|
||||
private string? _TextValue;
|
||||
|
||||
private DiscordBotStartup _DiscordBotStartup = null!;
|
||||
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
// Only run after the first render
|
||||
if(!firstRender)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_DiscordBotStartup = new DiscordBotStartup {RequirementsSolver = FixModules};
|
||||
await _DiscordBotStartup.CreateApplication();
|
||||
}
|
||||
|
||||
private async Task FixModules(ModuleRequirement requirements)
|
||||
{
|
||||
if(!requirements.RequireAny)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await DialogService.OpenAsync<InstallRequiredModules>("Some required modules are not installed. Please install before using the bot ...", new Dictionary<string, object>()
|
||||
{
|
||||
{"Requirements", requirements}
|
||||
}, new DialogOptions() { Width = "75%", Height = "75%" });
|
||||
}
|
||||
|
||||
private async void Initialize()
|
||||
{
|
||||
_DiscordBotStartup.Log = async (str, type) => {
|
||||
_TextValue += $"[{type}] {str} \n";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
Console.WriteLine(str);
|
||||
};
|
||||
|
||||
if (_DiscordBotStartup.LoadComponents())
|
||||
{
|
||||
await _DiscordBotStartup.PrepareBot();
|
||||
await _DiscordBotStartup.RefreshPlugins(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while (await DialogService.OpenAsync<Settings>("Please complete this setup before starting the bot") == false)
|
||||
{
|
||||
Console.WriteLine("Failed to complete the setup. Invalid data acquired ...");
|
||||
}
|
||||
|
||||
|
||||
|
||||
await _DiscordBotStartup.PrepareBot();
|
||||
await _DiscordBotStartup.RefreshPlugins(false);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
@using DiscordBotCore
|
||||
@using DiscordBotCore.Modules
|
||||
@using DiscordBotCore.Others.Exceptions
|
||||
@using DiscordBotWebUI.Components.Items
|
||||
@using DiscordBotWebUI.Types
|
||||
|
||||
@if(MarketItems.Count > 0)
|
||||
{
|
||||
<Marketplace ListedItems="MarketItems"/>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public ModuleRequirement Requirements { get; set; }
|
||||
private List<MarketItem> MarketItems = new List<MarketItem>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
foreach(var requirement in Requirements.RequiredModulesWithTypes)
|
||||
{
|
||||
var modulesWithType = await Application.CurrentApplication.ModuleManager.ServerGetAllModules(requirement);
|
||||
AppendToList(modulesWithType);
|
||||
}
|
||||
|
||||
foreach (var moduleName in Requirements.RequiredModulesWithNames)
|
||||
{
|
||||
var module = await Application.CurrentApplication.ModuleManager.ServerGetModuleWithName(moduleName);
|
||||
MarketItem item = new MarketItem(module.ModuleName, module.ModuleAuthor, module.ModuleDescription, ItemType.Module);
|
||||
MarketItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendToList(List<ModuleOnlineData> listOfModules)
|
||||
{
|
||||
foreach (var module in listOfModules)
|
||||
{
|
||||
MarketItem item = new MarketItem(module.ModuleName, module.ModuleAuthor, module.ModuleDescription, ItemType.Module);
|
||||
MarketItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
DiscordBotWebUI/Components/Pages/Setup/SetupWizard.razor
Normal file
51
DiscordBotWebUI/Components/Pages/Setup/SetupWizard.razor
Normal file
@@ -0,0 +1,51 @@
|
||||
@page "/setup-wizard"
|
||||
@inject DialogService DialogService
|
||||
|
||||
@using DiscordBotCore
|
||||
@using DiscordBotCore.Others.Exceptions
|
||||
@using DiscordBotWebUI.Components.Items.Setup
|
||||
|
||||
<RadzenCard Style="max-width: 600px; margin: auto; margin-top: 50px; padding: 20px;">
|
||||
<RadzenSteps @bind-Value="currentStep" ShowStepsButtons="false">
|
||||
<RadzenStepsItem Text="Welcome" />
|
||||
<RadzenStepsItem Text="Basic Configuration" />
|
||||
<RadzenStepsItem Text="Download Dependencies" />
|
||||
<RadzenStepsItem Text="Final Setup" />
|
||||
</RadzenSteps>
|
||||
|
||||
<div>
|
||||
@if (currentStep == 0)
|
||||
{
|
||||
<WelcomeComponent NextStep="NextStep" />
|
||||
}
|
||||
else if (currentStep == 1)
|
||||
{
|
||||
<StartupConfigurationComponent NextStep="NextStep" />
|
||||
}
|
||||
else if (currentStep == 2)
|
||||
{
|
||||
<ModuleSetupComponent ModuleRequirementReference="RequirementsToDownload" NextStep="NextStep" />
|
||||
}
|
||||
else if (currentStep == 3)
|
||||
{
|
||||
<FinishSetupComponent CompleteSetup="FinishSetup" />
|
||||
}
|
||||
</div>
|
||||
</RadzenCard>
|
||||
|
||||
@code {
|
||||
[Parameter] public ModuleRequirement RequirementsToDownload { get; set; }
|
||||
|
||||
private int currentStep = 0;
|
||||
|
||||
private void NextStep()
|
||||
{
|
||||
currentStep++;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void FinishSetup()
|
||||
{
|
||||
DialogService.Close(true);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
@page "/welcome"
|
||||
@using DiscordBotWebUI.Components.Items.Setup
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<WelcomeComponent/>
|
||||
|
||||
<RadzenButton
|
||||
Icon="arrow_forward"
|
||||
ButtonStyle="ButtonStyle.Dark"
|
||||
Style="position: absolute; right: -50px; top: 50%; transform: translateY(-50%); background-color: #2d3748; border: none; color: #63b3ed;"
|
||||
Click="GoToNextPage" />
|
||||
|
||||
@code {
|
||||
// Method to navigate to a new page
|
||||
private void GoToNextPage()
|
||||
{
|
||||
Navigation.NavigateTo("/settings");
|
||||
}
|
||||
}
|
||||
64
DiscordBotWebUI/Components/Pages/SidebarPages/Home.razor
Normal file
64
DiscordBotWebUI/Components/Pages/SidebarPages/Home.razor
Normal file
@@ -0,0 +1,64 @@
|
||||
@page "/"
|
||||
|
||||
@using DiscordBotCore.Others
|
||||
@using DiscordBotCore.Others.Exceptions
|
||||
@using DiscordBotWebUI.Components.Pages.Setup
|
||||
@using DiscordBotWebUI.DiscordBot
|
||||
|
||||
@inject DialogService DialogService
|
||||
|
||||
<RadzenButton Text="Start" Click="Initialize"/>
|
||||
<RadzenTextArea Placeholder="Logs..." Value="@_TextValue" Style="width: 100%; height: 80%"/>
|
||||
|
||||
|
||||
@code {
|
||||
private string? _TextValue;
|
||||
|
||||
private async Task Solver(ModuleRequirement moduleRequirement)
|
||||
{
|
||||
while (await DialogService.OpenAsync<SetupWizard>("Setup Wizard", new Dictionary<string, object> {{"RequirementsToDownload", moduleRequirement}}) != true)
|
||||
{
|
||||
Console.WriteLine("Failed to complete the setup. Invalid data acquired ...");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Initialize()
|
||||
{
|
||||
Action<string, LogType> logging = async (str, type) => {
|
||||
_TextValue += $"[{type}] {str} \n";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
};
|
||||
|
||||
var discordApplication = new DiscordApplication(logging, Solver);
|
||||
await discordApplication.Start();
|
||||
}
|
||||
|
||||
// private async void Initialize()
|
||||
// {
|
||||
// _DiscordBotStartup = new DiscordBotStartup { RequirementsSolver = default! };
|
||||
// await _DiscordBotStartup.CreateApplication();
|
||||
//
|
||||
// _DiscordBotStartup.Log = async (str, type) => {
|
||||
// _TextValue += $"[{type}] {str} \n";
|
||||
// await InvokeAsync(StateHasChanged);
|
||||
//
|
||||
// Console.WriteLine(str);
|
||||
// };
|
||||
//
|
||||
// if (_DiscordBotStartup.LoadComponents())
|
||||
// {
|
||||
// await _DiscordBotStartup.PrepareBot();
|
||||
// await _DiscordBotStartup.RefreshPlugins(false);
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// while (await DialogService.OpenAsync<Settings>("Please complete this setup before starting the bot") == false)
|
||||
// {
|
||||
// Console.WriteLine("Failed to complete the setup. Invalid data acquired ...");
|
||||
// }
|
||||
//
|
||||
// await _DiscordBotStartup.PrepareBot();
|
||||
// await _DiscordBotStartup.RefreshPlugins(false);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user