Skip to content

Commit

Permalink
feat(netrunner/plugins): Rework plugins page
Browse files Browse the repository at this point in the history
- Refactored the `BotPlugins.razor` page to improve readability and maintainability.
- Added a new `PluginCard.razor` component to display information about each plugin.
- Updated the layout of the `BotPlugins.razor` page to use the new `PluginCard` component.
- Created a new SVG file (`plugin.svg`) for displaying placeholder plugin icons.

This commit improves the structure and presentation of the plugins section in YumeChan.NetRunner application, making it easier to manage and navigate through loaded plugins.
  • Loading branch information
SakuraIsayeki committed Sep 8, 2024
1 parent 1a82789 commit 177d9bb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/YumeChan.NetRunner/Pages/BotPlugins.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,28 @@

@using YumeChan.PluginBase;
@using YumeChan.Core.Services.Plugins
@using YumeChan.NetRunner.Shared.Plugins

@inject AuthenticationStateProvider AuthStateProvider;
@inject PluginsLoader PluginsLoader;



<h1>Plugins</h1>
<br />
<h3>Currently Loaded : @PluginsLoader.PluginManifests.Count Plugins</h3>
<br />

<table class="table table-hover">
<thead>
<tr>
<th>Assembly</th>
<th>Plugin Name</th>
<th>Version</th>
<th>Active</th>
</tr>
</thead>

<tbody>
@foreach (IPlugin pluginManifest in PluginsLoader.PluginManifests.Values.Where(p => _isAdmin || !p.StealthMode))
{
<tr>
<td><a href="/p/@pluginManifest.AssemblyName/">@pluginManifest.AssemblyName</a></td>
<td>@pluginManifest.DisplayName</td>
<td>@pluginManifest.Version</td>
<td>@(pluginManifest.Loaded ? "Yes" : "No")</td>
</tr>
}
</tbody>
</table>
<div class="d-flex justify-content-between align-items-end mb-4">
<h1><i class="bi bi-plugin me-3"></i>Plugins</h1>
<p class="lead">Currently Loaded : @PluginsLoader.PluginManifests.Count Plugins</p>
</div>

<div id="plugin-cards" class="row">
@foreach (IPlugin pluginManifest in PluginsLoader.PluginManifests.Values.Where(p => _isAdmin || !p.StealthMode))
{
<div class="col-12 col-md-6 col-lg-4">
<PluginCard PluginManifest="pluginManifest" />
</div>
}

</div>


@code {

Expand Down
86 changes: 86 additions & 0 deletions src/YumeChan.NetRunner/Shared/Plugins/PluginCard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@using YumeChan.PluginBase

@*
Structure:
- Plugin Icon
- Plugin Name
- Plugin Description
- Plugin Version / Author(s)
- Plugin Status
*@


<div id="plugin-card-@(PluginManifest.AssemblyName.ToLowerInvariant())"
class="card bg-body border-@(PluginManifest.Loaded ? "success" : "secondary") p-4 d-flex flex-column align-items-center h-100"
>
<img src="@(PluginManifest.IconUri?.ToString() ?? "/plugin.svg")" class="card-img p-3 img-fluid ratio-1x1" alt="@PluginManifest.DisplayName">

<div class="my-2 text-center">
<h3 class="card-title text-center mb-0">@PluginManifest.DisplayName</h3>
<small class="text-muted text-center">
<code>@PluginManifest.AssemblyName</code>
</small>
</div>

<p class="card-text text-center">@PluginManifest.Description</p>

<div class="w-100 mt-auto">
@* Dashboard: Centre button *@
<a class="btn btn-primary w-100 px-2" href="/p/@PluginManifest.AssemblyName/" title="Dashboard">
<i inert class="bi me-2 bi-speedometer2"></i>Dashboard
</a>

<div class="btn-group btn-group-sm my-2 w-100" role="group">
@if (PluginManifest.ProjectHomepage is not null)
{
<a href="@PluginManifest.ProjectHomepage" target="_blank" rel="noopener" class="btn btn-secondary px-2">
<i inert class="bi me-2 bi-globe"></i>Homepage
</a>
}

@if (PluginManifest.SourceCodeRepository is not null)
{
<a href="@PluginManifest.SourceCodeRepository" target="_blank" rel="noopener" class="btn btn-secondary px-2">
<i inert class="bi me-2 bi-code-slash"></i>Repository
</a>
}

@if (PluginManifest.AuthorContact is not null)
{
bool isEmail = PluginManifest.AuthorContact.Contains('@');
bool isUrl = Uri.TryCreate(PluginManifest.AuthorContact, UriKind.Absolute, out _);
string builtUrl = isUrl ? PluginManifest.AuthorContact : isEmail ? $"mailto:{PluginManifest.AuthorContact}" : null;

<a href="@builtUrl" target="_blank" rel="noopener" class="btn btn-secondary px-2">
<i inert class="bi me-2 @(isEmail ? "bi-envelope" : "bi-person")"></i>@(isEmail ? "Contact" : "Author")
</a>
}
</div>

<div class="d-flex justify-content-between gap-3">
<small class="text-muted" title="Commit hash: @(VersionInfo.Item2 ?? "N/A")">@VersionInfo.Item1</small>
<small class="text-muted">@(PluginManifest.Author ?? "Unknown")</small>
</div>
</div>
</div>

@code {
[Parameter]
public IPlugin PluginManifest { get; set; }

public (string, string?) VersionInfo { get; set; } = ("", "");

protected override void OnParametersSet()
{
if (PluginManifest.Version is { Length: not 0 } version)
{
// Try splitting the version string into two parts
VersionInfo = version.LastIndexOf('+') is var hashIndex and not -1
? (version[..hashIndex], version[(hashIndex + 1)..])
: (version, null);
}

base.OnParametersSet();
}

}
3 changes: 3 additions & 0 deletions src/YumeChan.NetRunner/wwwroot/plugin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 177d9bb

Please # to comment.