< Summary

Information
Class: Pomodoro.Web.Services.NavLinkData
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/LayoutPresenterService.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 131
Line coverage: 100%
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
get_Href()100%11100%
get_Icon()100%11100%
get_Title()100%11100%
get_Match()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/LayoutPresenterService.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Components;
 2using Microsoft.AspNetCore.Components.Routing;
 3
 4namespace Pomodoro.Web.Services
 5{
 6    /// <summary>
 7    /// Service for managing layout-related presentation logic
 8    /// </summary>
 9    public class LayoutPresenterService
 10    {
 11        private bool _collapseNavMenu = true;
 12
 13        /// <summary>
 14        /// Gets the CSS class for the navigation menu based on its collapsed state
 15        /// </summary>
 16        /// <returns>CSS class name or null if not collapsed</returns>
 17        public virtual string? GetNavMenuCssClass()
 18        {
 19            return _collapseNavMenu ? "collapse" : null;
 20        }
 21
 22        /// <summary>
 23        /// Toggles the navigation menu's collapsed state
 24        /// </summary>
 25        /// <returns>New collapsed state</returns>
 26        public virtual bool ToggleNavMenu()
 27        {
 28            _collapseNavMenu = !_collapseNavMenu;
 29            return _collapseNavMenu;
 30        }
 31
 32        /// <summary>
 33        /// Gets the current collapsed state of the navigation menu
 34        /// </summary>
 35        /// <returns>True if collapsed, false if expanded</returns>
 36        public bool GetNavMenuCollapsedState()
 37        {
 38            return _collapseNavMenu;
 39        }
 40
 41        /// <summary>
 42        /// Sets the navigation menu's collapsed state
 43        /// </summary>
 44        /// <param name="collapsed">True to collapse, false to expand</param>
 45        public void SetNavMenuCollapsedState(bool collapsed)
 46        {
 47            _collapseNavMenu = collapsed;
 48        }
 49
 50        /// <summary>
 51        /// Gets the current year for footer copyright display
 52        /// </summary>
 53        /// <returns>Current UTC year</returns>
 54        public virtual int GetCurrentYear()
 55        {
 56            return DateTime.UtcNow.Year;
 57        }
 58
 59        /// <summary>
 60        /// Determines if a navigation link should be highlighted based on the current URI
 61        /// </summary>
 62        /// <param name="href">The href of the navigation link</param>
 63        /// <param name="currentUri">The current page URI</param>
 64        /// <param name="match">The NavLinkMatch behavior</param>
 65        /// <returns>True if the link should be highlighted</returns>
 66        public bool ShouldHighlightNavLink(string href, Uri currentUri, NavLinkMatch match = NavLinkMatch.Prefix)
 67        {
 68            if (string.IsNullOrEmpty(href))
 69                return false;
 70
 71            if (match == NavLinkMatch.All)
 72            {
 73                return currentUri.AbsolutePath == href ||
 74                       (currentUri.AbsolutePath == "/" && href == "");
 75            }
 76
 77            return currentUri.AbsolutePath.StartsWith(href, StringComparison.OrdinalIgnoreCase);
 78        }
 79
 80        /// <summary>
 81        /// Gets navigation link data for the application
 82        /// </summary>
 83        /// <returns>Collection of navigation link information</returns>
 84        public virtual IEnumerable<NavLinkData> GetNavigationLinks()
 85        {
 86            yield return new NavLinkData
 87            {
 88                Href = Constants.Routing.HomeRoute,
 89                Icon = Constants.Layout.TimerNavIcon,
 90                Title = Constants.Layout.TimerNavLinkTitle,
 91                Match = NavLinkMatch.All
 92            };
 93
 94            yield return new NavLinkData
 95            {
 96                Href = Constants.Routing.HistoryRoute,
 97                Icon = Constants.Layout.HistoryNavIcon,
 98                Title = Constants.Layout.HistoryNavLinkTitle,
 99                Match = NavLinkMatch.Prefix
 100            };
 101
 102            yield return new NavLinkData
 103            {
 104                Href = Constants.Routing.SettingsRoute,
 105                Icon = Constants.Layout.SettingsNavIcon,
 106                Title = Constants.Layout.SettingsNavLinkTitle,
 107                Match = NavLinkMatch.Prefix
 108            };
 109
 110            yield return new NavLinkData
 111            {
 112                Href = Constants.Routing.AboutRoute,
 113                Icon = Constants.Layout.AboutNavIcon,
 114                Title = Constants.Layout.AboutNavLinkTitle,
 115                Match = NavLinkMatch.Prefix
 116            };
 117        }
 118
 119    }
 120
 121    /// <summary>
 122    /// Data model for navigation links
 123    /// </summary>
 124    public class NavLinkData
 125    {
 487126        public string Href { get; set; } = string.Empty;
 484127        public string Icon { get; set; } = string.Empty;
 484128        public string Title { get; set; } = string.Empty;
 487129        public NavLinkMatch Match { get; set; } = NavLinkMatch.Prefix;
 130    }
 131}