< Summary

Information
Class: Syki.Front.Features.Academic.ReleaseClassesForEnrollment.ReleaseClassesForEnrollmentDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/ReleaseClassesForEnrollment/ReleaseClassesForEnrollmentDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 141
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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_MudDialog()100%210%
.ctor()100%210%
OnInitializedAsync()100%210%
SelectAll()100%210%
UnselectAll()100%210%
Submit()0%2040%
Cancel()100%210%
get__quickFilter()100%210%
GetNotFoundMessage()0%620%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/ReleaseClassesForEnrollment/ReleaseClassesForEnrollmentDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.ReleaseClassesForEnrollment
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <SykiDialogTitle Text="Liberar matrícula" Icon="@Icons.Material.Filled.Article" />
 6    </TitleContent>
 7    <DialogContent>
 8        <style>.mud-table-toolbar { height: auto }</style>
 9        <MudTable
 10            T="ClassOut"
 11            Class="pa-4 mb-2"
 12            Items="@_classes"
 13            Filter="@_quickFilter"
 14            Hover="true"
 15            Dense="true"
 16            Loading="@_loading"
 17            RowsPerPage="100"
 18            ContainerClass="pt-0"
 19        >
 20            <ToolBarContent>
 21                <MudGrid Class="align-center" Spacing="3">
 22                    <MudItem xs="12" sm="5" md="5" lg="5">
 023                        @if (_showButtons)
 24                        {
 25                            <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3">
 26                                <MudButton OnClick="@SelectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Fill
 27                                <MudButton OnClick="@UnselectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Fi
 28                            </MudStack>
 29                        }
 30                    </MudItem>
 31                    <MudItem xs="12" sm="7" md="7" lg="7" Class="d-flex justify-end">
 32                        <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome"/>
 33                    </MudItem>
 34                </MudGrid>
 35            </ToolBarContent>
 36            <HeaderContent>
 37                <MudTh>Nome</MudTh>
 38                <MudTh>Professor</MudTh>
 39                <MudTh>Selecionada</MudTh>
 40            </HeaderContent>
 41            <RowTemplate>
 42                <MudTd DataLabel="Disciplina">@context.Discipline</MudTd>
 43                <MudTd DataLabel="Professor">@context.Teacher</MudTd>
 44                <MudTd DataLabel="Selecionada">
 45                    <MudCheckBox
 46                        T="bool"
 47                        Class="pl-7 pr-1"
 48                        Dense="true"
 49                        Size="Size.Small"
 50                        Color="Color.Success"
 51                        Value="@context.IsSelected"
 052                        ValueChanged="x => { context.IsSelected = x; }"/>
 53                </MudTd>
 54            </RowTemplate>
 55            <NoRecordsContent>
 56                @(GetNotFoundMessage())
 57            </NoRecordsContent>
 58            <LoadingContent>
 059                @if (_breakpoint == Breakpoint.Xs)
 60                {
 61                    <MudProgressLinear Color="Color.Info" Indeterminate="true" />
 62                }
 63            </LoadingContent>
 64            <PagerContent>
 65                <MudDivider/>
 066                @if (_showButtons)
 67                {
 68                    <MudStack Row="true" Class="mt-4">
 69                        <DialogCancelButton OnClick="@Cancel" />
 70                        <SykiProgressCircular Loading="@_loading" />
 71                        <DialogSaveButton Class="mr-2" OnClick="@Submit" Text="Liberar" />
 72                    </MudStack>
 73                }
 74            </PagerContent>
 75        </MudTable>
 76    </DialogContent>
 77</MudDialog>
 78
 79@inject ISnackbar Snackbar
 80@inject GetAcademicClassesClient GetClient
 81@inject IBrowserViewportService BrowserViewportService
 82@inject ReleaseClassesForEnrollmentClient ReleaseClient
 83
 84@code
 85{
 86    [CascadingParameter]
 087    MudDialogInstance MudDialog { get; set; }
 88
 89    private bool _loading;
 90    private bool _showButtons;
 91    private string _searchString;
 092    private List<ClassOut> _classes = [];
 93
 94    private Breakpoint _breakpoint;
 95
 96    protected override async Task OnInitializedAsync()
 97    {
 098        _loading = true;
 099        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 0100        _classes = await GetClient.Get(new() { Status = ClassStatus.OnPreEnrollment });
 0101        _loading = false;
 0102        _showButtons = true;
 0103    }
 104
 105    private void SelectAll()
 106    {
 0107        _classes.ForEach(x => x.IsSelected = true);
 0108    }
 109    private void UnselectAll()
 110    {
 0111        _classes.ForEach(x => x.IsSelected = false);
 0112    }
 113
 114    private async Task Submit()
 115    {
 0116        if (_loading) return;
 117
 0118        _loading = true;
 0119        var ids = _classes.Where(c => c.IsSelected).Select(c => c.Id).ToList();
 0120        var response = await ReleaseClient.Release(ids);
 0121        if (response.IsSuccess())
 122        {
 0123            MudDialog.Close(DialogResult.Ok(true));
 0124            Snackbar.Add("Turmas liberadas com sucesso!", Severity.Success);
 125        }
 126        else
 127        {
 0128            Snackbar.Add(response.GetError().Message, Severity.Error);
 129        }
 0130        _loading = false;
 0131    }
 132
 0133    private void Cancel() => MudDialog.Cancel();
 134
 0135    private Func<ClassOut, bool> _quickFilter => x => _searchString.IsIn(x.Discipline);
 136
 137    private string GetNotFoundMessage()
 138    {
 0139        return (_searchString.IsEmpty()) ? "Não existem turmas para liberar." : "Nenhuma turma encontrada.";
 140    }
 141}