< Summary

Information
Class: MyNet.UI.ViewModels.FileHistory.RecentFilesListOptions
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/FileHistory/RecentFilesListOptions.cs
Tag: 323_28699572109
Line coverage
0%
Covered lines: 0
Uncovered lines: 36
Coverable lines: 36
Total lines: 82
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Create()100%210%
SetSearchText(...)100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/FileHistory/RecentFilesListOptions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="RecentFilesListOptions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using MyNet.UI.ViewModels.List.Filtering;
 8using MyNet.UI.ViewModels.List.Filtering.Filters;
 9using MyNet.UI.ViewModels.List.Sorting;
 10
 11namespace MyNet.UI.ViewModels.FileHistory;
 12
 13/// <summary>
 14/// List configuration for recent files.
 15/// </summary>
 16internal sealed class RecentFilesListOptions(
 17    FiltersViewModel<RecentFileViewModel> filters,
 18    StringFilterViewModel<RecentFileViewModel> nameFilter,
 19    StringFilterViewModel<RecentFileViewModel> pathFilter,
 20    ISortingViewModel<RecentFileViewModel> sorting)
 21{
 22    /// <summary>
 23    /// Creates filtering and sorting view models for <see cref="RecentFilesViewModel"/>.
 24    /// </summary>
 25    public static RecentFilesListOptions Create()
 26    {
 027        StringFilterViewModel<RecentFileViewModel>? nameFilter = null;
 028        StringFilterViewModel<RecentFileViewModel>? pathFilter = null;
 29
 030        var filters = FiltersViewModelBuilder<RecentFileViewModel>.Create(builder =>
 031        {
 032            builder.OrGroup(search =>
 033            {
 034                search.AddStringFilter(
 035                    nameof(RecentFileViewModel.DisplayName),
 036                    x => x.DisplayName,
 037                    filter => nameFilter = filter);
 038
 039                search.AddStringFilter(
 040                    nameof(RecentFileViewModel.Path),
 041                    x => x.Path,
 042                    filter => pathFilter = filter);
 043            });
 044        });
 45
 046        var sorting = SortingViewModelBuilder<RecentFileViewModel>.Create(builder =>
 047        {
 048            builder.AddProperty(
 049                x => x.DisplayName,
 050                property => property
 051                    .WithDisplayName(nameof(RecentFileViewModel.DisplayName))
 052                    .Ascending());
 053
 054            builder.AddProperty(
 055                x => x.LastAccessDate,
 056                property => property
 057                    .WithDisplayName(nameof(RecentFileViewModel.LastAccessDate))
 058                    .Descending());
 059        });
 60
 061        return new(filters, nameFilter!, pathFilter!, sorting);
 62    }
 63
 64    public FiltersViewModel<RecentFileViewModel> Filters { get; } = filters;
 65
 66    public StringFilterViewModel<RecentFileViewModel> NameFilter { get; } = nameFilter;
 67
 68    public StringFilterViewModel<RecentFileViewModel> PathFilter { get; } = pathFilter;
 69
 70    public ISortingViewModel<RecentFileViewModel> Sorting { get; } = sorting;
 71
 72    /// <summary>
 73    /// Updates the shared search text applied to name and path filters.
 74    /// </summary>
 75    public void SetSearchText(string? value)
 76    {
 077        NameFilter.Value = value;
 078        PathFilter.Value = value;
 079        Filters.Apply();
 080    }
 81}
 82