< Summary

Class:MUNity.BlazorServer.Shared.Header.HeaderUserSection
Assembly:MUNity.BlazorServer
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Shared\Header\HeaderUserSection.razor
Covered lines:0
Uncovered lines:50
Coverable lines:50
Total lines:133
Line coverage:0% (0 of 50)
Covered branches:0
Total branches:34
Branch coverage:0% (0 of 34)
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_AuthStateTask()100%10%
get_ShowUserSubMenu()100%10%
.ctor()100%10%
get_ShowNotifications()100%10%
ToggleUserMenu()100%10%
ToggleNotifications()100%10%
OnInitializedAsync()0%120%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNity.BlazorServer\Shared\Header\HeaderUserSection.razor

#LineLine coverage
 1@inject Services.UserNotificationService userNotificationService
 2@inject Services.UserService userService
 3
 4<AuthorizeView>
 5    <Authorized>
 6        <div class="navbar-item dropdown">
 07            <a class="navbar-link dropdown-toggle icon @((ShowNotifications) ? "show" : null)" @onclick="() => ToggleNot
 8                <i class="oi oi-bell"></i>
 09                @if (unreadNotificationsCount > 0)
 010                {
 011                    <span class="badge">@unreadNotificationsCount</span>
 012                }
 13
 14            </a>
 15            <div class="dropdown-menu media-list dropdown-menu-end @((ShowNotifications) ? "show" : null)"
 16                 style="@((ShowNotifications) ? NotificationStyle : null)">
 017                <div class="dropdown-header">Benachrichtigungen (@totalNotificationsCount)</div>
 18
 19
 020                @if (notifications.Count > 0)
 021                {
 22
 023                    @foreach (var notification in notifications)
 024                    {
 25                        <a href="javascript:;" class="dropdown-item media">
 26                            <div class="media-left">
 27                                <i class="oi oi-bug media-object bg-gray-500"></i>
 28                            </div>
 29                            <div class="media-body">
 030                                <h6 class="media-heading">@notification.Title</h6>
 031                                <p>@notification.Text</p>
 032                                <div class="text-muted fs-10px">@notification.Timestamp.ToString("dd.MM.yyyy HH:mm")</di
 33                            </div>
 34                        </a>
 035                    }
 36
 37                    <div class="dropdown-footer text-center">
 38                        <a href="javascript:;" class="text-decoration-none">Mehr anzeigen</a>
 39                    </div>
 040                }
 41                else
 042                {
 43                    <div class="dropdown-footer text-center">
 44                        <p>Es liegen keine Benachrichtigungen vor.</p>
 45                    </div>
 046                }
 47
 48            </div>
 49        </div>
 50
 51
 52
 053        <div class="navbar-item navbar-user dropdown" @onclick="() =>  ToggleUserMenu()">
 54            <a class="navbar-link dropdown-toggle d-flex @((ShowUserSubMenu) ? "show" : null)"
 55               style="cursor: pointer;">
 056                <span class="d-none d-md-inline">@userDisplayName</span>
 57                <img src="https://www.profielactueel.nl/content/modules/catalog/1/3800/3759/10_xx_2_1.png" alt="">
 58            </a>
 59            <div class="dropdown-menu dropdown-menu-end me-1 @((ShowUserSubMenu) ? "show" : null)" style="@((ShowUserSub
 60                <a href="@($"/profile/{userName}")" class="dropdown-item">Mein Profil</a>
 61
 62                <a href="/myinbox" class="dropdown-item"><span class="badge bg-danger float-end rounded-pill">2</span> P
 63                <a href="/myOrganizations" class="dropdown-item">Meine Organisationen</a>
 64                <a href="/myconferences" class="dropdown-item">Meine Konferenzen</a>
 65                <a href="/myresolutions" class="dropdown-item">Meine Resolutionen</a>
 66                <a href="/myapplications" class="dropdown-item">Meine Bewerbungen</a>
 067                @if (context.User.IsInRole("Head-Admin") || context.User.IsInRole("Admin"))
 068                {
 69                    <div class="dropdown-divider"></div>
 70                    <a href="/admin/dashboard" class="dropdown-item text-danger">Admin Center</a>
 071                }
 72                <div class="dropdown-divider"></div>
 73                <a href="/Identity/Account/LogOut" class="dropdown-item">Log Out</a>
 74            </div>
 75        </div>
 76    </Authorized>
 77</AuthorizeView>
 78
 79
 80@code {
 081    [CascadingParameter] public Task<AuthenticationState> AuthStateTask { get; set; }
 82
 083    public bool ShowUserSubMenu { get; set; }
 84
 085    private string SubMenuStyle = "position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate(-20px
 86
 087    public bool ShowNotifications { get; set; }
 88
 089    private string NotificationStyle = "position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate(
 90
 91    private List<MUNity.Schema.UserNotification.UserNotificationItem> notifications;
 92
 93    private int unreadNotificationsCount;
 94
 95    private int totalNotificationsCount;
 96
 97    private string userDisplayName;
 98
 99    private string userName;
 100
 101    private void ToggleUserMenu()
 0102    {
 0103        this.ShowNotifications = false;
 0104        this.ShowUserSubMenu = !ShowUserSubMenu;
 0105    }
 106
 107    private void ToggleNotifications()
 0108    {
 0109        this.ShowUserSubMenu = false;
 0110        this.ShowNotifications = !ShowNotifications;
 0111    }
 112
 113    protected override async Task OnInitializedAsync()
 0114    {
 0115        await base.OnInitializedAsync();
 0116        var claim = (await AuthStateTask)?.User;
 0117        if (claim != null)
 0118        {
 0119            this.userName = claim.Identity.Name;
 0120            notifications = await userNotificationService.GetLastFiveIntrestingNotifications(claim);
 0121            unreadNotificationsCount = await userNotificationService.GetCountOfUnreadNotifications(claim);
 0122            totalNotificationsCount = await userNotificationService.GetTotalCountOfNotifications(claim);
 0123            var userForeAndLastName = await userService.GetForeAndLastNameAsync(claim);
 0124            if (string.IsNullOrEmpty(userForeAndLastName) || userForeAndLastName == "-")
 0125                userDisplayName = claim.Identity?.Name ?? "-";
 126            else
 127
 0128                userDisplayName = userForeAndLastName;
 129
 0130        }
 0131    }
 132
 133}