< Summary

Information
Class: Syki.Front.Pages.Teacher.TeacherClassFrequencyTab
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Pages/Teacher/TeacherClassFrequencyTab.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 52
Coverable lines: 52
Total lines: 206
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ClassId()100%210%
.ctor()100%210%
OnInitializedAsync()0%620%
SetLesson()0%620%
SelectAll()100%210%
UnselectAll()100%210%
CheckChanged()100%210%
GetCurrentFrequency()0%620%
OnEditLessonClick()100%210%
SaveFrequency()0%620%
get__quickFilter()100%210%
GetNotFoundMessage()0%620%

File(s)

/home/runner/work/syki/syki/Front/Pages/Teacher/TeacherClassFrequencyTab.razor

#LineLine coverage
 1@using Syki.Front.Features.Teacher.CreateLessonAttendance
 2
 3@namespace Syki.Front.Pages.Teacher
 4
 5<MudContainer Class="mb-4 px-0">
 6    <MudCard Class="mb-4 py-2 px-2">
 7        <MudCardContent Class="py-1">
 08            @if (_loading)
 9            {
 10                <MudSkeleton Animation="Animation.Wave" />
 11            }
 12            else
 13            {
 14                <MudGrid Class="align-center">
 15                    <MudItem xs="12" sm="6" md="6" lg="6">
 16                        <MudStack Row="true" AlignItems="AlignItems.Center">
 17                            <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
 18                                <MudText Typo="Typo.h6">Aula @_lesson.Number <b>·</b> @_lesson.Date.FormatBr() <b>·</b> 
 19                            </MudStack>
 20                        </MudStack>
 21                    </MudItem>
 22                    <MudItem xs="12" sm="4" md="4" lg="4">
 23                        <MudProgressLinear Color="Color.Primary" Rounded="true" Size="Size.Large" Value="@decimal.ToDoub
 24                            <MudText Typo="Typo.body1">
 25                                <b>@_lesson.Frequency.Format()%</b>
 26                            </MudText>
 27                        </MudProgressLinear>
 28                    </MudItem>
 29                    <MudItem xs="12" sm="2" md="2" lg="2" Class="d-flex justify-end">
 30                        <MudButton
 31                            StartIcon="@Icons.Material.Outlined.Edit"
 32                            IconSize="Size.Large"
 33                            Variant="Variant.Filled"
 34                            Style="height: 40px;"
 35                            Color="Color.Primary"
 36                            @onclick="@OnEditLessonClick">
 37                            Editar
 38                        </MudButton>
 39                    </MudItem>
 40                </MudGrid>
 41            }
 42        </MudCardContent>
 43    </MudCard>
 44
 45    <style>.mud-table-toolbar { height: auto }</style>
 46    <MudTable
 47        T="GetTeacherLessonAttendanceOut"
 48        Class="pa-4"
 49        Items="@_attendances"
 50        Filter="@_quickFilter"
 51        Hover="true"
 52        Dense="true"
 53        Loading="@_loading"
 54        RowsPerPage="100"
 55        ContainerClass="pt-0"
 56    >
 57        <ToolBarContent>
 58            <MudGrid Class="align-center" Spacing="3">
 59                <MudItem xs="12" sm="5" md="5" lg="5">
 060                    @if (_showButtons)
 61                    {
 62                        <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
 63                            <MudButton OnClick="@SelectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.C
 64                            <MudButton OnClick="@UnselectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled
 65                        </MudStack>
 66                    }
 67                </MudItem>
 68                <MudItem xs="12" sm="7" md="7" lg="7" Class="d-flex justify-end">
 69                    <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome"/>
 70                </MudItem>
 71            </MudGrid>
 72        </ToolBarContent>
 73        <HeaderContent>
 74            <MudTh>Nome</MudTh>
 75            <MudTh>Presente</MudTh>
 76        </HeaderContent>
 77        <RowTemplate>
 78            <MudTd DataLabel="Nome">@context.StudentName</MudTd>
 79            <MudTd DataLabel="Presente">
 80                <MudCheckBox
 81                    T="bool"
 82                    Class="pl-7 pr-1"
 83                    Dense="true"
 84                    Size="Size.Small"
 85                    Color="Color.Success"
 86                    Value="@context.Present"
 087                    ValueChanged="x => { context.Present = x; CheckChanged(); }"/>
 88            </MudTd>
 89        </RowTemplate>
 90        <NoRecordsContent>
 91            @(GetNotFoundMessage())
 92        </NoRecordsContent>
 93        <LoadingContent>
 094            @if (_breakpoint == Breakpoint.Xs)
 95            {
 96                <MudProgressLinear Color="Color.Info" Indeterminate="true" />
 97            }
 98        </LoadingContent>
 99        <PagerContent>
 100            <MudDivider/>
 0101            @if (_showButtons)
 102            {
 103                <MudStack Row="true" Class="mt-4">
 104                    <MudSpacer/>
 105                    <DialogSaveButton Class="mr-2" OnClick="@SaveFrequency"/>
 106                </MudStack>
 107            }
 108        </PagerContent>
 109    </MudTable>
 110</MudContainer>
 111
 0112<ClassLessonsDialog @ref="@_dialog" OnRowClick="@SetLesson" />
 0113
 0114@inject ISnackbar Snackbar
 0115@inject GetTeacherClassClient GetTeacherClassClient
 0116@inject IBrowserViewportService BrowserViewportService
 0117@inject CreateLessonAttendanceClient CreateLessonAttendanceClient
 118@inject GetTeacherLessonAttendancesClient GetTeacherLessonAttendancesClient
 119
 120@code
 121{
 122  [Parameter]
 0123  public Guid ClassId { get; set; }
 124
 125    private Breakpoint _breakpoint;
 126    private ClassLessonsDialog _dialog;
 127
 128    private bool _loading;
 129    private bool _showButtons;
 130    private string _searchString;
 0131    private TeacherClassOut _class = new();
 0132    private LessonOut _lesson = new();
 0133    private List<GetTeacherLessonAttendanceOut> _attendances = [];
 134
 0135    private List<Guid> _initialState = [];
 136
 137    protected override async Task OnInitializedAsync()
 138    {
 0139        _loading = true;
 0140        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 0141        _class = await GetTeacherClassClient.Get(ClassId);
 0142        var id = _class.Lessons.Where(x => x.Date <= DateTime.Now.ToDateOnly()).MaxBy(x => x.Date)?.Id ?? Guid.Empty;
 0143        await SetLesson(id);
 0144        _loading = false;
 0145        _showButtons = true;
 0146    }
 147
 148    private async Task SetLesson(Guid id)
 149    {
 0150        _lesson = _class.Lessons.FirstOrDefault(x => x.Id == id) ?? new();
 0151        _attendances = await GetTeacherLessonAttendancesClient.Get(id);
 0152        _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0153    }
 154
 155    private void SelectAll()
 156    {
 0157        _attendances.ForEach(x => x.Present = true);
 0158        CheckChanged();
 0159    }
 160    private void UnselectAll()
 161    {
 0162        _attendances.ForEach(x => x.Present = false);
 0163        CheckChanged();
 0164    }
 165
 166    private void CheckChanged()
 167    {
 0168        _lesson.Frequency = GetCurrentFrequency();
 0169    }
 170
 171    private decimal GetCurrentFrequency()
 172    {
 0173        var total = _attendances.Count;
 0174        if (total == 0) return 0.00M;
 0175        var presences = _attendances.Count(x => x.Present);
 0176        return 100M*(1M * presences / (1M * total));
 177    }
 178
 179    private async Task OnEditLessonClick()
 180    {
 0181        await _dialog.Open(_class.Lessons);
 0182    }
 183
 184    private async Task SaveFrequency()
 185    {
 0186        var ids = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0187        var result = await CreateLessonAttendanceClient.Create(_lesson.Id, ids);
 0188        if (result.IsSuccess())
 189        {
 0190            _class = await GetTeacherClassClient.Get(ClassId);
 0191            _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0192            Snackbar.Add("Frequência salva com sucesso!", Severity.Success);
 193        }
 194        else
 195        {
 0196            Snackbar.Add(result.GetError().Message, Severity.Error);
 197        }
 0198    }
 199
 0200    private Func<GetTeacherLessonAttendanceOut, bool> _quickFilter => x => _searchString.IsIn(x.StudentName);
 201
 202    private string GetNotFoundMessage()
 203    {
 0204        return (_searchString.IsEmpty()) ? "Não existem alunos matriculados ainda." : "Nenhum aluno encontrado.";
 205    }
 206}