Skip to content

Commit

Permalink
Merge pull request #987 from Tharylia/feat/sort-module-repo
Browse files Browse the repository at this point in the history
Sort module repo
  • Loading branch information
dlamkins authored Sep 29, 2024
2 parents 9378850 + df4a22f commit f87e23f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
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

0 comments on commit f87e23f

Please sign in to comment.