Linked Plugin List and Plugin Install endpoints between web and console

This commit is contained in:
2024-12-15 22:49:45 +02:00
parent a12aa66660
commit 424bf2196f
13 changed files with 180 additions and 19 deletions

View File

@@ -2,12 +2,12 @@
<RadzenCard>
<RadzenDataGrid Data="PluginModels" AllowPaging="true" AllowColumnResize="true" PageSize="5">
<Columns>
<RadzenDataGridColumn Property="@nameof(PluginModel.PluginName)" Title="Plugin Name"/>
<RadzenDataGridColumn Property="@nameof(PluginModel.PluginAuthor)" Title="Author"/>
<RadzenDataGridColumn Property="@nameof(PluginModel.PluginDescription)" Title="Version"/>
<RadzenDataGridColumn Property="@nameof(PluginModel.Name)" Title="Plugin Name"/>
<RadzenDataGridColumn Property="@nameof(PluginModel.Author)" Title="Author"/>
<RadzenDataGridColumn Property="@nameof(PluginModel.Description)" Title="Version"/>
<RadzenDataGridColumn Title="Download">
<Template Context="item">
<RadzenButton Click="() => OnPluginDownloadClick!(item.PluginName)" Text="Download"/>
<RadzenButton Click="() => OnPluginDownloadClick!(item.Name)" Text="Download"/>
</Template>
</RadzenDataGridColumn>
</Columns>

View File

@@ -1,24 +1,48 @@
@page "/plugins"
@using DiscordBotWebUI.Components.CustomTags
@using DiscordBotWebUI.Models
@using DiscordBotWebUI.ServerCommunication
<Marketplace PluginModels="_PluginModels" OnPluginDownloadClick="OnModelSelected"/>
@code {
private List<PluginModel> _PluginModels;
[Inject]
public ApiHandler ApiHandler { get; set; }
private async void OnModelSelected(string itemName)
{
Console.WriteLine(itemName);
}
ApiResponse response = await ApiHandler.PostAsync("/api/plugin/install", new Dictionary<string, string>()
{
{"pluginName", itemName}
});
if(!response.Success)
{
Console.WriteLine(response.Message);
return;
}
Console.WriteLine("Plugin installed");
}
protected override async Task OnInitializedAsync()
{
_PluginModels = new List<PluginModel>()
ApiResponse response = await ApiHandler.GetAsync("/api/plugin/list/online");
if (!response.Success)
{
new PluginModel() {PluginName = "Test", PluginAuthor = "Andrei", PluginDescription = "Interesting plugin"}
};
return;
}
string jsonStr = response.Message;
var result = await JsonManager.ConvertFromJson<List<PluginModel>>(jsonStr);
if (result != null)
{
_PluginModels = result;
}
}
}