diff --git a/src/Recyclarr.Gui/Pages/CustomFormatPage.razor b/src/Recyclarr.Gui/Pages/CustomFormatPage.razor new file mode 100644 index 00000000..f911deac --- /dev/null +++ b/src/Recyclarr.Gui/Pages/CustomFormatPage.razor @@ -0,0 +1,24 @@ +@page "/custom-format" +@inherits ReactiveInjectableComponentBase + +@if (ViewModel is null) +{ + return; +} + + + + + +@code { + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + if (ViewModel != null) + { + await ViewModel.OnInit.Execute(); + } + } + +} diff --git a/src/Recyclarr.Gui/Shared/CustomFormatGroup.razor b/src/Recyclarr.Gui/Shared/CustomFormatGroup.razor new file mode 100644 index 00000000..c1a95198 --- /dev/null +++ b/src/Recyclarr.Gui/Shared/CustomFormatGroup.razor @@ -0,0 +1,20 @@ +@inherits ReactiveComponentBase + +@if (ViewModel is null) +{ + return; +} + + +

@ViewModel.GroupName

+ + @foreach (var cf in ViewModel.CustomFormats) + { +

@cf.Name

+ } +
+ + +@code { + +} diff --git a/src/Recyclarr.Gui/ViewModels/CustomFormatViewModel.cs b/src/Recyclarr.Gui/ViewModels/CustomFormatViewModel.cs index eee7cd18..a54b71cd 100644 --- a/src/Recyclarr.Gui/ViewModels/CustomFormatViewModel.cs +++ b/src/Recyclarr.Gui/ViewModels/CustomFormatViewModel.cs @@ -1,21 +1,41 @@ +using System.Reactive; +using System.Reactive.Linq; using ReactiveUI; using TrashLib.Radarr.CustomFormat.Models; +using TrashLib.Radarr.CustomFormat.Processors; namespace Recyclarr.Gui.ViewModels; public class CustomFormatGroupViewModel : ReactiveObject { - public string GroupName { get; set; } - public ICollection CustomFormats { get; set; } + public string GroupName { get; } + public ICollection CustomFormats { get; } - public CustomFormatGroupViewModel() + public CustomFormatGroupViewModel(string groupName, ICollection customFormats) { + GroupName = groupName; + CustomFormats = customFormats; } } public class CustomFormatViewModel : ReactiveObject { - public CustomFormatViewModel() + private readonly ICustomFormatLookup _cfLookup; + private readonly List _groups = new(); + + public List Groups => _groups; + public ReactiveCommand OnInit; + + public CustomFormatViewModel(ICustomFormatLookup cfLookup) { + _cfLookup = cfLookup; + + OnInit = ReactiveCommand.Create(() => + { + foreach (var (groupName, cfs) in _cfLookup.MapAllCustomFormats()) + { + + } + }); } } diff --git a/src/Recyclarr.Gui/_Imports.razor b/src/Recyclarr.Gui/_Imports.razor index 4914d1a5..fe545e82 100644 --- a/src/Recyclarr.Gui/_Imports.razor +++ b/src/Recyclarr.Gui/_Imports.razor @@ -9,3 +9,6 @@ @using MudBlazor @using Recyclarr.Gui @using Recyclarr.Gui.Shared +@using Recyclarr.Gui.ViewModels +@using ReactiveUI.Blazor +@using System.Reactive.Linq diff --git a/src/TrashLib/Radarr/CustomFormat/Guide/IRadarrGuideService.cs b/src/TrashLib/Radarr/CustomFormat/Guide/IRadarrGuideService.cs index 9f4d4896..91dbd885 100644 --- a/src/TrashLib/Radarr/CustomFormat/Guide/IRadarrGuideService.cs +++ b/src/TrashLib/Radarr/CustomFormat/Guide/IRadarrGuideService.cs @@ -4,5 +4,5 @@ namespace TrashLib.Radarr.CustomFormat.Guide; public interface IRadarrGuideService { - ICollection GetCustomFormatData(); + IObservable GetCustomFormatData(); } diff --git a/src/TrashLib/Radarr/CustomFormat/Guide/LocalRepoCustomFormatJsonParser.cs b/src/TrashLib/Radarr/CustomFormat/Guide/LocalRepoCustomFormatJsonParser.cs index cb7c2916..407aa671 100644 --- a/src/TrashLib/Radarr/CustomFormat/Guide/LocalRepoCustomFormatJsonParser.cs +++ b/src/TrashLib/Radarr/CustomFormat/Guide/LocalRepoCustomFormatJsonParser.cs @@ -23,7 +23,7 @@ public class LocalRepoCustomFormatJsonParser : IRadarrGuideService _fs = fs; } - public ICollection GetCustomFormatData() + public IObservable GetCustomFormatData() { var jsonDir = _paths.RepoDirectory .SubDirectory("docs") @@ -33,9 +33,7 @@ public class LocalRepoCustomFormatJsonParser : IRadarrGuideService return jsonDir.EnumerateFiles("*.json").ToObservable() .Select(x => Observable.Defer(() => LoadJsonFromFile(x))) .Merge(8) - .NotNull() - .ToEnumerable() - .ToList(); + .NotNull(); } private IObservable LoadJsonFromFile(IFileInfo file) diff --git a/src/TrashLib/Radarr/CustomFormat/Processors/CustomFormatLookup.cs b/src/TrashLib/Radarr/CustomFormat/Processors/CustomFormatLookup.cs index de957e8c..e8647aff 100644 --- a/src/TrashLib/Radarr/CustomFormat/Processors/CustomFormatLookup.cs +++ b/src/TrashLib/Radarr/CustomFormat/Processors/CustomFormatLookup.cs @@ -1,10 +1,12 @@ +using System.Collections.ObjectModel; +using System.Reactive.Linq; using Common.Extensions; using TrashLib.Radarr.CustomFormat.Guide; using TrashLib.Radarr.CustomFormat.Models; namespace TrashLib.Radarr.CustomFormat.Processors; -public class CustomFormatLookup +public class CustomFormatLookup : ICustomFormatLookup { private readonly ICustomFormatGroupParser _parser; private readonly IRadarrGuideService _guide; @@ -22,8 +24,17 @@ public class CustomFormatLookup guideCfs.FirstOrDefault(x => x.Name.EqualsIgnoreCase(groupItem.Name)); } + private async Task>> ParseGroupsAsync() + { + } + public Dictionary> MapAllCustomFormats() { + Observable.Defer(() => _parser.Parse().ToObservable()) + .ToDictionary( + x => x.Key, + x => x.Value.Select(y => MatchDataWithCellEntry(guideCfs, y)).NotNull().ToList()); + var guideCfs = _guide.GetCustomFormatData(); var groups = _parser.Parse(); diff --git a/src/TrashLib/Radarr/CustomFormat/Processors/ICustomFormatLookup.cs b/src/TrashLib/Radarr/CustomFormat/Processors/ICustomFormatLookup.cs new file mode 100644 index 00000000..3ae7c70f --- /dev/null +++ b/src/TrashLib/Radarr/CustomFormat/Processors/ICustomFormatLookup.cs @@ -0,0 +1,8 @@ +using TrashLib.Radarr.CustomFormat.Models; + +namespace TrashLib.Radarr.CustomFormat.Processors; + +public interface ICustomFormatLookup +{ + Dictionary> MapAllCustomFormats(); +}