< Summary - Syki

Information
Class: Syki.Front.Pages.Teacher.TeacherClassFrequencyTab
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Pages/Teacher/TeacherClassFrequencyTab.razor
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 54
Coverable lines: 54
Total lines: 210
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">
 018                                <MudText Typo="Typo.h6">Aula @_classLesson.Number <b>·</b> @_classLesson.Date.FormatBr()
 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">
 025                                <b>@_classLesson.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>
 078            <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>
 091            @(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
 112@inject ISnackbar Snackbar
 113@inject IDialogService DialogService
 114@inject IBrowserViewportService BrowserViewportService
 115@inject GetTeacherClassLessonsClient GetTeacherClassLessonsClient
 116@inject CreateLessonAttendanceClient CreateLessonAttendanceClient
 117@inject GetTeacherLessonAttendancesClient GetTeacherLessonAttendancesClient
 118
 119@code
 120{
 121  [Parameter]
 0122  public Guid ClassId { get; set; }
 123
 124    private Breakpoint _breakpoint;
 125
 126    private bool _loading;
 127    private bool _showButtons;
 128    private string _searchString;
 0129    private ClassLessonOut _classLesson = new();
 0130    private List<ClassLessonOut> _lessons = [];
 0131    private List<GetTeacherLessonAttendanceOut> _attendances = [];
 132
 0133    private List<Guid> _initialState = [];
 134
 135    protected override async Task OnInitializedAsync()
 136    {
 0137        _loading = true;
 0138        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 0139        _lessons = (await GetTeacherClassLessonsClient.Get(ClassId)).Success;
 0140        var id = _lessons.Where(x => x.Date <= DateTime.UtcNow.ToDateOnly()).MaxBy(x => x.Date)?.Id ?? Guid.Empty;
 0141        await SetLesson(id);
 0142        _loading = false;
 0143        _showButtons = true;
 0144    }
 145
 146    private async Task SetLesson(Guid id)
 147    {
 0148        _classLesson = _lessons.FirstOrDefault(x => x.Id == id) ?? new();
 0149        _attendances = await GetTeacherLessonAttendancesClient.Get(id);
 0150        _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0151    }
 152
 153    private void SelectAll()
 154    {
 0155        _attendances.ForEach(x => x.Present = true);
 0156        CheckChanged();
 0157    }
 158    private void UnselectAll()
 159    {
 0160        _attendances.ForEach(x => x.Present = false);
 0161        CheckChanged();
 0162    }
 163
 164    private void CheckChanged()
 165    {
 0166        _classLesson.Frequency = GetCurrentFrequency();
 0167    }
 168
 169    private decimal GetCurrentFrequency()
 170    {
 0171        var total = _attendances.Count;
 0172        if (total == 0) return 0.00M;
 0173        var presences = _attendances.Count(x => x.Present);
 0174        return 100M*(1M * presences / (1M * total));
 175    }
 176
 177    private Task OnEditLessonClick()
 178    {
 0179        var parameters = new DialogParameters<ClassLessonsDialog>()
 0180        {
 0181            { x => x.Lessons, _lessons },
 0182            { x => x.OnRowClick, EventCallback.Factory.Create<Guid>(this, SetLesson) }
 0183        };
 184
 0185        return DialogService.ShowAsync<ClassLessonsDialog>("", parameters);
 186    }
 187
 188    private async Task SaveFrequency()
 189    {
 0190        var ids = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0191        var result = await CreateLessonAttendanceClient.Create(_classLesson.Id, ids);
 0192        if (result.IsSuccess)
 193        {
 0194            _lessons = (await GetTeacherClassLessonsClient.Get(ClassId)).Success;
 0195            _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList();
 0196            Snackbar.Add("Frequência salva com sucesso!", Severity.Success);
 197        }
 198        else
 199        {
 0200            Snackbar.Add(result.Error.Message, Severity.Error);
 201        }
 0202    }
 203
 0204    private Func<GetTeacherLessonAttendanceOut, bool> _quickFilter => x => _searchString.IsIn(x.StudentName);
 205
 206    private string GetNotFoundMessage()
 207    {
 0208        return (_searchString.IsEmpty()) ? "Não existem alunos matriculados ainda." : "Nenhum aluno encontrado.";
 209    }
 210}