Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort module repo #987

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
using Version = SemVer.Version;

namespace Blish_HUD.Modules.UI.Presenters {
public class ManagePkgPresenter : Presenter<ManagePkgView, IGrouping<string, PkgManifest>> {
public class ManagePkgPresenter : Presenter<ManagePkgView, IOrderedEnumerable<PkgManifest>> {

private ModuleManager _existingModule;

private Func<PkgManifest, ModuleManager, IProgress<string>, Task<(ModuleManager NewModule, bool Success, string Error)>> _packageAction;

private PkgManifest _selectedVersion;

public ManagePkgPresenter(ManagePkgView view, IGrouping<string, PkgManifest> model) : base(view, model) { /* NOOP */ }
public ManagePkgPresenter(ManagePkgView view, IOrderedEnumerable<PkgManifest> model) : base(view, model) { /* NOOP */ }

protected override Task<bool> Load(IProgress<string> progress) {
_existingModule = GameService.Module.Modules.FirstOrDefault(m => m.Manifest.Namespace == this.Model.Key);
_existingModule = GameService.Module.Modules.FirstOrDefault(m => m.Manifest.Namespace == this.Model.LastOrDefault()?.Namespace);

return base.Load(progress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ private void UpdateExtraOptionsView() {
}
}

/// <summary>
/// Gets the currently installed module version.
/// </summary>
/// <param name="moduleNamespace">The namespace of the module to get the installed version of.</param>
/// <returns>The currently installed module version or null if module is not installed.</returns>
private SemVer.Version GetCurrentModuleVersion(string moduleNamespace) {
return GameService.Module.Modules.FirstOrDefault(m => m.Manifest.Namespace == moduleNamespace)?.Manifest?.Version;
}

private void UpdatePackagesView() {
this.View.RepoFlowPanel.ClearChildren();

Expand All @@ -67,7 +76,14 @@ private void UpdatePackagesView() {
foreach (var pkgManifest in this.Model.GetPkgManifests()
.Where(m => GameService.Overlay.ShowPreviews.Value || !m.IsPreview)
.GroupBy(m => m.Namespace)
.OrderBy(pkg => pkg.First().Name)) {
.Select(pkgs => pkgs.OrderBy(x => x.Version))
.OrderByDescending(pkgs => {
var lastManifest = pkgs.Last();
var latestInstalledVersion = this.GetCurrentModuleVersion(lastManifest.Namespace);
var needsUpdate = latestInstalledVersion != null && latestInstalledVersion < lastManifest.Version;
return needsUpdate;
}) // Modules with update at top
.ThenBy(pkgs => pkgs.Last().Name)) {
var nPanel = new ViewContainer {
Size = new Point(this.View.RepoFlowPanel.Width - 25, 64),
ShowTint = (s = !s),
Expand Down
2 changes: 1 addition & 1 deletion Blish HUD/GameServices/Modules/UI/Views/ManagePkgView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public PkgVersionRelationship VersionRelationship {

public ManagePkgView() { /* NOOP */ }

public ManagePkgView(IGrouping<string, PkgManifest> model) {
public ManagePkgView(IOrderedEnumerable<PkgManifest> model) {
this.WithPresenter(new ManagePkgPresenter(this, model));
}

Expand Down
Loading