diff --git a/MacUtilGUI.Tests/InstallTabTests.fs b/MacUtilGUI.Tests/InstallTabTests.fs index 023e786..f8c92ce 100644 --- a/MacUtilGUI.Tests/InstallTabTests.fs +++ b/MacUtilGUI.Tests/InstallTabTests.fs @@ -59,8 +59,51 @@ module InstallTabTests = vm.SearchText <- "brave" Assert.Equal(1, vm.Apps.Count) - Assert.Equal("brave-browser", Seq.exactlyOne vm.Apps |> fun row -> row.Id) + Assert.Equal("brave-browser", Seq.exactlyOne vm.Apps |> (fun row -> row.Id)) Assert.Equal(26, Seq.length vm.AllApps) vm.SearchText <- "" Assert.Equal(26, vm.Apps.Count) + + [] + let InstallGroupsByCategory () = + let brew = BrewClientTests.FakeBrew([], []) + let vm = makeVm brew + + let names = vm.AppGroups |> Seq.map (fun group -> group.Name) |> Seq.toList + + Assert.Equal( + [ "Communication Apps" + "Developer Tools" + "Web Browsers" + "Terminal" + "Shell" + "Utilities" ], + names + ) + + Assert.Equal(26, vm.AppGroups |> Seq.sumBy (fun group -> group.Apps.Count)) + Assert.Equal(26, vm.Apps.Count) + + vm.SearchText <- "brave" + Assert.Equal(1, vm.AppGroups.Count) + let browsers = Seq.exactlyOne vm.AppGroups + Assert.Equal("Web Browsers", browsers.Name) + Assert.Equal("brave-browser", (Seq.exactlyOne browsers.Apps).Id) + Assert.Equal(1, vm.Apps.Count) + + vm.SearchText <- "no-such-app" + Assert.Empty(vm.AppGroups) + Assert.Equal(0, vm.Apps.Count) + + vm.SearchText <- "" + uncheckAll vm + let comm = vm.AppGroups |> Seq.find (fun group -> group.Name = "Communication Apps") + + comm.AllSelected <- true + Assert.True(comm.Apps |> Seq.forall (fun row -> row.IsChecked)) + Assert.True(comm.AllSelected) + + comm.AllSelected <- false + Assert.True(comm.Apps |> Seq.forall (fun row -> not row.IsChecked)) + Assert.False(comm.AllSelected) diff --git a/MacUtilGUI/App.axaml b/MacUtilGUI/App.axaml index 94ce1c1..8b3688c 100644 --- a/MacUtilGUI/App.axaml +++ b/MacUtilGUI/App.axaml @@ -176,5 +176,11 @@ + + diff --git a/MacUtilGUI/MacUtilGUI.fsproj b/MacUtilGUI/MacUtilGUI.fsproj index d4041e8..9566ce7 100644 --- a/MacUtilGUI/MacUtilGUI.fsproj +++ b/MacUtilGUI/MacUtilGUI.fsproj @@ -51,6 +51,7 @@ + diff --git a/MacUtilGUI/ViewModels/AppGroupViewModel.fs b/MacUtilGUI/ViewModels/AppGroupViewModel.fs new file mode 100644 index 0000000..1a268d9 --- /dev/null +++ b/MacUtilGUI/ViewModels/AppGroupViewModel.fs @@ -0,0 +1,20 @@ +namespace MacUtilGUI.ViewModels + +open System.Collections.ObjectModel + +type AppGroupViewModel(name: string, rows: AppRowViewModel seq) = + inherit ViewModelBase() + + let apps = ObservableCollection(rows) + + member _.Name = name + + member _.Apps = apps + + member this.AllSelected + with get () = apps.Count > 0 && Seq.forall (fun (row: AppRowViewModel) -> row.IsChecked) apps + and set v = + for row in apps do + row.IsChecked <- v + + this.OnPropertyChanged("AllSelected") diff --git a/MacUtilGUI/ViewModels/MainWindowViewModel.fs b/MacUtilGUI/ViewModels/MainWindowViewModel.fs index e3f59e9..9e34bb4 100644 --- a/MacUtilGUI/ViewModels/MainWindowViewModel.fs +++ b/MacUtilGUI/ViewModels/MainWindowViewModel.fs @@ -36,6 +36,7 @@ type MainWindowViewModel let cautionTweaks = ObservableCollection() let allApps = ResizeArray() let apps = ObservableCollection() + let appGroups = ObservableCollection() let appleUpdates = ObservableCollection() let brewOutdated = ObservableCollection() @@ -92,12 +93,30 @@ type MainWindowViewModel hit row.Content || hit row.Id || hit row.Category || hit row.Description + let appCategoryRank category = + match category with + | "Communication Apps" -> 0 + | "Developer Tools" -> 1 + | "Web Browsers" -> 2 + | "Terminal" -> 3 + | "Shell" -> 4 + | "Utilities" -> 5 + | _ -> 6 + let applyFilter () = apps.Clear() + appGroups.Clear() - for row in allApps do - if matches row searchText then - apps.Add(row) + let visible = + allApps |> Seq.filter (fun row -> matches row searchText) |> Seq.toList + + for row in visible do + apps.Add(row) + + visible + |> List.groupBy (fun row -> row.Category) + |> List.sortBy (fun (category, _) -> appCategoryRank category, category) + |> List.iter (fun (category, rows) -> appGroups.Add(AppGroupViewModel(category, rows))) let installSelected () = let selected = selectedAppRows () @@ -213,16 +232,6 @@ type MainWindowViewModel | "Privacy" -> 4 | _ -> 5 - let appCategoryRank category = - match category with - | "Communication Apps" -> 0 - | "Developer Tools" -> 1 - | "Web Browsers" -> 2 - | "Terminal" -> 3 - | "Shell" -> 4 - | "Utilities" -> 5 - | _ -> 6 - do catalog.Tweaks |> Map.toSeq @@ -270,6 +279,8 @@ type MainWindowViewModel member _.Apps = apps + member _.AppGroups = appGroups + member _.AllApps = allApps :> seq member _.StatusText = statusText diff --git a/MacUtilGUI/Views/MainWindow.axaml b/MacUtilGUI/Views/MainWindow.axaml index f55ac7f..09e6d95 100644 --- a/MacUtilGUI/Views/MainWindow.axaml +++ b/MacUtilGUI/Views/MainWindow.axaml @@ -130,20 +130,43 @@ Classes="macos-search" Margin="24,16,24,8"/> - + - - + - - - - - + + + + + + + + + + + + + + + + + + +