< Summary - Syki

Information
Class: Syki.Front.Pages.Student.StudentEnrollmentsPage
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Pages/Student/StudentEnrollmentsPage.razor
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 141
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 Icon="@Icons.Material.Filled.Article" Title="Matrícula" />
 12    <MudContainer Class="px-0 my-4">
 013        @if (_loading && _enrollmentPeriod.Id.IsEmpty())
 14        {
 15            <MudContainer Class="px-0">
 16                <MudCard>
 17                    <MudCardContent>
 18                        <MudProgressLinear Color="Color.Info" Indeterminate="true" />
 19                    </MudCardContent>
 20                </MudCard>
 21            </MudContainer>
 22        }
 023        else if (!_loading && _enrollmentPeriod.Id.IsEmpty())
 24        {
 25            <SykiPageAlert Text="A escolha das disciplinas só pode ser feita durante a vigência do Período de Matrícula.
 26        }
 27        else
 28        {
 29            <MudAlert NoIcon="true" Class="mt-4 mb-4 pl-6" Severity="Severity.Normal" Variant="Variant.Text" Elevation="
 30                <MudText>
 31                    Selecione as disciplinas que você irá cursar nesse semestre.
 032                    O período de matrícula vai até <strong>@_enrollmentPeriod.EndAt.FormatBr()</strong>.
 33                </MudText>
 34            </MudAlert>
 35
 36            <CascadingValue Name="Days" Value="@_days">
 37                <WeeklyAgenda Class="px-0 mb-4" />
 38            </CascadingValue>
 39
 40            <MudContainer Class="px-0 mb-8">
 41                <MudTable
 42                    T="EnrollmentClassOut"
 43                    Items="@_options"
 44                    Class="pa-4"
 45                    Breakpoint="Breakpoint.Sm"
 46                    Dense="true"
 47                    Hover="true"
 48                    Loading="@_loading"
 49                    RowsPerPage="100">
 50                    <HeaderContent>
 51                        <MudTh>Disciplina</MudTh>
 52                        <MudTh>Período</MudTh>
 53                        <MudTh>Créditos</MudTh>
 54                        <MudTh>CH</MudTh>
 55                        <MudTh>Professor</MudTh>
 56                        <MudTh>Selecionada</MudTh>
 57                    </HeaderContent>
 58                    <RowTemplate>
 059                        <MudTd DataLabel="Disciplina">@context.Discipline</MudTd>
 060                        <MudTd DataLabel="Período">@context.Period</MudTd>
 061                        <MudTd DataLabel="Créditos">@context.Credits</MudTd>
 062                        <MudTd DataLabel="CH">@context.Workload</MudTd>
 063                        <MudTd DataLabel="Professor">@context.Teacher</MudTd>
 64                        <MudTd DataLabel="Selecionada">
 65                            <MudCheckBox
 66                                T="bool"
 67                                Class="pl-9 pr-1"
 68                                Dense="true"
 69                                Size="Size.Small"
 70                                Color="Color.Success"
 71                                Value="@context.IsSelected"
 072                                ValueChanged="x => { context.IsSelected = x; HandleCheckedChanged(); }"
 73                            />
 74                        </MudTd>
 75                    </RowTemplate>
 76                    <NoRecordsContent>
 77                        Não existem turmas disponíveis no momento.
 78                    </NoRecordsContent>
 79                    <PagerContent>
 80                        <MudDivider/>
 81                        <MudStack Row="true" Class="mt-4">
 82                            <SykiProgressCircular Loading="@_loading"/>
 83                            <DialogSaveButton OnClick="@Submit"/>
 84                        </MudStack>
 85                    </PagerContent>
 86                </MudTable>
 87            </MudContainer>
 88        }
 89    </MudContainer>
 90</MudContainer>
 91
 92@inject ISnackbar Snackbar
 93@inject CreateStudentEnrollmentClient CreateStudentEnrollmentClient
 94@inject GetCurrentEnrollmentPeriodClient GetCurrentEnrollmentPeriodClient
 95@inject GetStudentEnrollmentClassesClient GetStudentEnrollmentClassesClient
 96
 97@code
 98{
 99    private bool _loading;
 0100    EnrollmentPeriodOut _enrollmentPeriod = new();
 0101    private List<EnrollmentClassOut> _options = [];
 0102    private List<AgendaDayOut> _days = [];
 103
 104    protected override async Task OnInitializedAsync()
 105    {
 0106        _loading = true;
 0107        _enrollmentPeriod = await GetCurrentEnrollmentPeriodClient.Get();
 0108        if (_enrollmentPeriod.Id.IsEmpty())
 109        {
 0110            _loading = false;
 0111            return;
 112        }
 0113        _options = await GetStudentEnrollmentClassesClient.Get();
 0114        HandleCheckedChanged();
 0115        _loading = false;
 0116    }
 117
 118    private void HandleCheckedChanged()
 119    {
 0120        _days = _options.Where(o => o.IsSelected).ToList().ToAgendas();
 0121    }
 122
 123    private async Task Submit()
 124    {
 0125        if (_loading) return;
 126
 0127        _loading = true;
 0128        var classes = _options.Where(o => o.IsSelected).Select(o => o.Id).ToList();
 0129        var response = await CreateStudentEnrollmentClient.Create(classes);
 0130        if (response.IsSuccessStatusCode)
 131        {
 0132            Snackbar.Add("Matrícula salva com sucesso!", Severity.Success);
 133        }
 134        else
 135        {
 0136            var error = await response.ToError();
 0137            Snackbar.Add(error.Message, Severity.Error);
 138        }
 0139        _loading = false;
 0140    }
 141}