Skip to content

Commit

Permalink
Module manager installed, unkown, installable split
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Jan 8, 2025
1 parent 9b72c63 commit f03e275
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
@page "/dash/modules"
@using OpenShock.Desktop.ModuleManager
@using OpenShock.Desktop.ModuleManager.Repository
@using OpenShock.Desktop.Ui.Pages.Dash.Components
@inject RepositoryManager RepositoryManager
@inject ModuleManager ModuleManager

<div class="d-flex gap-3 flex-column">
@foreach (var (repoUri, repoContext) in RepositoryManager.Repositories.Where(x => x.Value.Repository != null))

<MudText Typo="Typo.h1">Installed</MudText>

@foreach (var module in InstalledModules)
{
foreach (var module in repoContext.Repository!.Modules)
{
<ModuleManagerItem ModulePair="module"/>
}
<ModuleManagerItem ModuleId="@module.Key" RepoModule="@module.Value.Key" LoadedModule="@module.Value.Value"/>
}

<MudText Typo="Typo.h1">Unknown Loaded Modules</MudText>

@foreach (var module in UnknownModules)
{
<ModuleManagerItem ModuleId="@module.Key" LoadedModule="module.Value"/>
}

<MudText Typo="Typo.h1">Installable Modules</MudText>

@foreach (var module in InstallableModules)
{
<ModuleManagerItem ModuleId="@module.Key" RepoModule="@module.Value"/>
}

</div>

@code {

private IEnumerable<KeyValuePair<string, LoadedModule>> UnknownModules;

Check warning on line 35 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'UnknownModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 35 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'UnknownModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private IEnumerable<KeyValuePair<string, Module>> InstallableModules;

Check warning on line 36 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'InstallableModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 36 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'InstallableModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private Dictionary<string, KeyValuePair<Module, LoadedModule>> InstalledModules;

Check warning on line 37 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'InstalledModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 37 in Desktop/Ui/Pages/Dash/Tabs/ModuleManagerTab.razor

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'InstalledModules' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

protected override void OnInitialized()
{
PopulateModuleLists();
}

private void PopulateModuleLists()
{
var loadedModules = ModuleManager.Modules;

var modulesFromRepos = RepositoryManager.Repositories
.Where(x => x.Value.Repository != null)
.SelectMany(x => x.Value.Repository!.Modules).ToDictionary();

UnknownModules = loadedModules.Where(x => modulesFromRepos.All(y => y.Key != x.Key));
InstallableModules = modulesFromRepos.Where(x => !loadedModules.Keys.Contains(x.Key));

var installedModules = new Dictionary<string, KeyValuePair<Module, LoadedModule>>();

foreach (var loadedModule in loadedModules)
{
if (!modulesFromRepos.TryGetValue(loadedModule.Key, out var repoModule)) continue;

installedModules.Add(loadedModule.Key, new KeyValuePair<Module, LoadedModule>(repoModule, loadedModule.Value));
}

InstalledModules = installedModules;
}
}

0 comments on commit f03e275

Please sign in to comment.