< Summary

Information
Class: Syki.Front.Features.Academic.FinalizeClasses.FinalizeClassesDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/FinalizeClasses/FinalizeClassesDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 140
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/FinalizeClasses/FinalizeClassesDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.FinalizeClasses
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <SykiDialogTitle Text="Finalizar" Icon="@Icons.Material.Filled.FactCheck" />
 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="Finalizar" />
 72                    </MudStack>
 73                }
 74            </PagerContent>
 75        </MudTable>
 76    </DialogContent>
 77</MudDialog>
 78
 79@inject ISnackbar Snackbar
 80@inject FinalizeClassesClient FinalizeClient
 81@inject GetAcademicClassesClient GetClient
 82@inject IBrowserViewportService BrowserViewportService
 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    private Breakpoint _breakpoint;
 94
 95    protected override async Task OnInitializedAsync()
 96    {
 097        _loading = true;
 098        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 099        _classes = await GetClient.Get(new() { Status = ClassStatus.Started, AllLessonsFinished = true });
 0100        _loading = false;
 0101        _showButtons = true;
 0102    }
 103
 104    private void SelectAll()
 105    {
 0106        _classes.ForEach(x => x.IsSelected = true);
 0107    }
 108    private void UnselectAll()
 109    {
 0110        _classes.ForEach(x => x.IsSelected = false);
 0111    }
 112
 113    private async Task Submit()
 114    {
 0115        if (_loading) return;
 116
 0117        _loading = true;
 0118        var ids = _classes.Where(c => c.IsSelected).Select(c => c.Id).ToList();
 0119        var response = await FinalizeClient.Finalize(ids);
 0120        if (response.IsSuccess())
 121        {
 0122            MudDialog.Close(DialogResult.Ok(true));
 0123            Snackbar.Add("Turmas finalizadas com sucesso!", Severity.Success);
 124        }
 125        else
 126        {
 0127            Snackbar.Add(response.GetError().Message, Severity.Error);
 128        }
 0129        _loading = false;
 0130    }
 131
 0132    private void Cancel() => MudDialog.Cancel();
 133
 0134    private Func<ClassOut, bool> _quickFilter => x => _searchString.IsIn(x.Discipline);
 135
 136    private string GetNotFoundMessage()
 137    {
 0138        return (_searchString.IsEmpty()) ? "Não existem turmas para serem finalizadas." : "Nenhuma turma encontrada.";
 139    }
 140}