< Summary

Information
Class: Syki.Front.Pages.Student.StudentEnrollmentsPage
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Pages/Student/StudentEnrollmentsPage.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 144
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
.ctor()100%210%
OnInitializedAsync()0%620%
HandleCheckedChanged()100%210%
Submit()0%2040%

File(s)

/home/runner/work/syki/syki/Front/Pages/Student/StudentEnrollmentsPage.razor

#LineLine coverage
 1@using Syki.Front.Components.Agenda
 2
 3@namespace Syki.Front.Pages.Student
 4
 5@page "/student/enrollments"
 6@attribute [Authorize(Roles = "Student")]
 7
 8<SykiPageTitle Title="Matrícula" />
 9
 10<MudContainer Class="my-4 px-4">
 11    <SykiPageHeader
 12        Icon="@Icons.Material.Filled.Article"
 13        Title="Matrícula"
 14    />
 15    <MudContainer Class="px-0 my-4">
 016        @if (_loading && _enrollmentPeriod.Id.IsEmpty())
 17        {
 18            <MudContainer Class="px-0">
 19                <MudCard>
 20                    <MudCardContent>
 21                        <MudProgressLinear Color="Color.Info" Indeterminate="true" />
 22                    </MudCardContent>
 23                </MudCard>
 24            </MudContainer>
 25        }
 026        else if (!_loading && _enrollmentPeriod.Id.IsEmpty())
 27        {
 28            <SykiPageAlert Text="A escolha das disciplinas só pode ser feita durante a vigência do Período de Matrícula.
 29        }
 30        else
 31        {
 32            <MudAlert NoIcon="true" Class="mt-4 mb-4 pl-6" Severity="Severity.Normal" Variant="Variant.Text" Elevation="
 33                <MudText>
 34                    Selecione as disciplinas que você irá cursar nesse semestre.
 35                    O período de matrícula vai até <strong>@_enrollmentPeriod.EndAt.FormatBr()</strong>.
 36                </MudText>
 37            </MudAlert>
 38
 39            <CascadingValue Name="Days" Value="@_days">
 40                <WeeklyAgenda Class="px-0 mb-4"/>
 41            </CascadingValue>
 42
 43            <MudContainer Class="px-0 mb-8">
 44                <MudTable
 45                    T="EnrollmentClassOut"
 46                    Items="@_options"
 47                    Class="pa-4"
 48                    Breakpoint="Breakpoint.Sm"
 49                    Dense="true"
 50                    Hover="true"
 51                    Loading="@_loading"
 52                    RowsPerPage="100">
 53                    <HeaderContent>
 54                        <MudTh>Disciplina</MudTh>
 55                        <MudTh>Período</MudTh>
 56                        <MudTh>Créditos</MudTh>
 57                        <MudTh>CH</MudTh>
 58                        <MudTh>Professor</MudTh>
 59                        <MudTh>Selecionada</MudTh>
 60                    </HeaderContent>
 61                    <RowTemplate>
 62                        <MudTd DataLabel="Disciplina">@context.Discipline</MudTd>
 63                        <MudTd DataLabel="Período">@context.Period</MudTd>
 64                        <MudTd DataLabel="Créditos">@context.Credits</MudTd>
 65                        <MudTd DataLabel="CH">@context.Workload</MudTd>
 66                        <MudTd DataLabel="Professor">@context.Teacher</MudTd>
 67                        <MudTd DataLabel="Selecionada">
 68                            <MudCheckBox
 69                                T="bool"
 70                                Class="pl-9 pr-1"
 71                                Dense="true"
 72                                Size="Size.Small"
 73                                Color="Color.Success"
 74                                Value="@context.IsSelected"
 075                                ValueChanged="x => { context.IsSelected = x; HandleCheckedChanged(); }"
 76                            />
 77                        </MudTd>
 78                    </RowTemplate>
 79                    <NoRecordsContent>
 80                        Não existem turmas disponíveis no momento.
 81                    </NoRecordsContent>
 82                    <PagerContent>
 83                        <MudDivider/>
 84                        <MudStack Row="true" Class="mt-4">
 85                            <SykiProgressCircular Loading="@_loading"/>
 86                            <DialogSaveButton OnClick="@Submit"/>
 87                        </MudStack>
 88                    </PagerContent>
 89                </MudTable>
 90            </MudContainer>
 91        }
 92    </MudContainer>
 93</MudContainer>
 94
 95@inject ISnackbar Snackbar
 96@inject CreateStudentEnrollmentClient CreateStudentEnrollmentClient
 97@inject GetCurrentEnrollmentPeriodClient GetCurrentEnrollmentPeriodClient
 98@inject GetStudentEnrollmentClassesClient GetStudentEnrollmentClassesClient
 99
 100@code
 101{
 102    private bool _loading;
 0103    EnrollmentPeriodOut _enrollmentPeriod = new();
 0104    private List<EnrollmentClassOut> _options = [];
 0105    private List<AgendaDayOut> _days = [];
 106
 107    protected override async Task OnInitializedAsync()
 108    {
 0109        _loading = true;
 0110        _enrollmentPeriod = await GetCurrentEnrollmentPeriodClient.Get();
 0111        if (_enrollmentPeriod.Id.IsEmpty())
 112        {
 0113            _loading = false;
 0114            return;
 115        }
 0116        _options = await GetStudentEnrollmentClassesClient.Get();
 0117        HandleCheckedChanged();
 0118        _loading = false;
 0119    }
 120
 121    private void HandleCheckedChanged()
 122    {
 0123        _days = _options.Where(o => o.IsSelected).ToList().ToAgendas();
 0124    }
 125
 126    private async Task Submit()
 127    {
 0128        if (_loading) return;
 129
 0130        _loading = true;
 0131        var classes = _options.Where(o => o.IsSelected).Select(o => o.Id).ToList();
 0132        var response = await CreateStudentEnrollmentClient.Create(classes);
 0133        if (response.IsSuccessStatusCode)
 134        {
 0135            Snackbar.Add("Matrícula salva com sucesso!", Severity.Success);
 136        }
 137        else
 138        {
 0139            var error = await response.ToError();
 0140            Snackbar.Add(error.Message, Severity.Error);
 141        }
 0142        _loading = false;
 0143    }
 144}