< Summary

Information
Class: Syki.Front.Features.Academic.CreateClass.CreateClassDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateClass/CreateClassDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 204
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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%
<OnInitializedAsync()100%210%
<OnInitializedAsync()100%210%
GetNewScheduleDisabled()100%210%
NewSchedule()100%210%
DeleteSchedule(...)100%210%
SearchDiscipline()0%620%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateClass/CreateClassDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.CreateClass
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <SykiDialogTitle Text="Nova Turma" />
 6    </TitleContent>
 7    <DialogContent>
 08        <MudForm @ref="@_form" Class="pt-1" Spacing="0">
 09            <MudGrid Spacing="2">
 010                <MudItem xs="12" sm="12" md="12" lg="12">
 011                    <MudAutocomplete
 012                        T="DisciplineOut"
 013                        MaxItems="50"
 14                        SearchFunc="@SearchDiscipline"
 15                        Dense="true"
 16                        Margin="Margin.Dense"
 17                        Variant="Variant.Outlined"
 18                        @bind-Value="@_discipline"
 19                        Label="Disciplina"
 20                        Required="true"
 21                        RequiredError="Informe!"
 22                        AdornmentColor="Color.Primary"
 23                    />
 24                </MudItem>
 25                <MudItem xs="12" sm="12" md="12" lg="12">
 26                    <MudSelect
 27                        Dense="true"
 28                        Margin="Margin.Dense"
 29                        Variant="Variant.Outlined"
 30                        @bind-Value="@_teacher"
 31                        Label="Professor"
 32                        Required="true"
 33                        RequiredError="Informe!"
 34                        AdornmentColor="Color.Primary"
 35                    >
 036                        @foreach (TeacherOut? item in _teachers)
 37                        {
 38                            <MudSelectItem Value="@item">@item.Name</MudSelectItem>
 39                        }
 40                    </MudSelect>
 41                </MudItem>
 42                <MudItem xs="6" sm="6" md="6" lg="6">
 43                    <MudNumericField
 44                        MaxLength="2"
 45                        HideSpinButtons="true"
 46                        Margin="Margin.Dense"
 47                        Variant="Variant.Outlined"
 48                        T="byte?"
 49                        @bind-Value="@_vacancies"
 50                        Label="Vagas"
 51                        Required="true"
 52                        RequiredError="Informe!"
 53                    />
 54                </MudItem>
 55                <MudItem xs="6" sm="6" md="6" lg="6">
 56                    <MudSelect
 57                        Dense="true"
 58                        Margin="Margin.Dense"
 59                        Variant="Variant.Outlined"
 60                        @bind-Value="@_period"
 61                        Label="Período"
 62                        Required="true"
 63                        RequiredError="Informe!"
 64                        AdornmentColor="Color.Primary"
 65                    >
 066                        @foreach (string? item in _periods.ConvertAll(p => p.Id))
 67                        {
 68                            <MudSelectItem Value="@item">@item</MudSelectItem>
 69                        }
 70                    </MudSelect>
 71                </MudItem>
 72
 73                <MudDivider Class="my-4"/>
 74
 75                <MudGrid Spacing="0">
 76                    <MudItem xs="12" sm="12" md="12" lg="12">
 077                        @foreach (var schedule in _schedules)
 78                        {
 79                            <ClassSchedule Data="@schedule" OnDeleteClick="@DeleteSchedule" />
 080                            @if (_breakpoint == Breakpoint.Xs)
 81                            {
 82                                <MudDivider Class="my-2"/>
 83                            }
 84                        }
 85                    </MudItem>
 86                    <MudItem xs="12" sm="12" md="12" lg="12">
 87                        <MudButton
 88                            Disabled="(GetNewScheduleDisabled())"
 89                            StartIcon="@Icons.Material.Outlined.Add"
 90                            IconSize="Size.Large"
 91                            Variant="Variant.Outlined"
 92                            FullWidth="true"
 93                            Class="mt-2 border-dashed border-2 mud-border-secundary ml-2"
 94                            Style="max-width: fit-content"
 95                            Color="Color.Primary"
 96                            @onclick="@NewSchedule"
 97                        >
 98                            NOVO HORÁRIO
 99                        </MudButton>
 100                    </MudItem>
 101                </MudGrid>
 102            </MudGrid>
 103        </MudForm>
 104    </DialogContent>
 105    <DialogActions>
 106        <DialogCancelButton OnClick="@Cancel" />
 107        <SykiProgressCircular Loading="@_loading" />
 108        <DialogSaveButton OnClick="@Submit" />
 109    </DialogActions>
 110</MudDialog>
 111
 112@inject ISnackbar Snackbar
 113@inject NavigationManager Nav
 114@inject CreateClassClient CreateClassClient
 115@inject GetTeachersClient GetTeachersClient
 116@inject GetDisciplinesClient GetDisciplinesClient
 117@inject IBrowserViewportService BrowserViewportService
 118@inject GetAcademicPeriodsClient GetAcademicPeriodsClient
 119
 120@code
 121{
 122    [CascadingParameter]
 0123    MudDialogInstance MudDialog { get; set; }
 124
 125    private MudForm _form;
 126    private bool _loading;
 127
 128    private DisciplineOut? _discipline;
 129    private TeacherOut? _teacher;
 130    private string? _period;
 131    private byte? _vacancies;
 0132    private List<ScheduleInFillable> _schedules = [];
 133
 0134    private List<DisciplineOut> _disciplines = [];
 0135    private List<TeacherOut> _teachers = [];
 0136    private List<AcademicPeriodOut> _periods = [];
 137
 138    private Breakpoint _breakpoint;
 139
 140    protected override async Task OnInitializedAsync()
 141    {
 0142        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 0143        NewSchedule();
 0144        _disciplines = await GetDisciplinesClient.Get();
 0145        await Task.WhenAll([
 0146            Task.Run(async () => _teachers = await GetTeachersClient.Get()),
 0147            Task.Run(async () => _periods = await GetAcademicPeriodsClient.Get())
 0148        ]);
 0149    }
 150
 151    private bool GetNewScheduleDisabled()
 152    {
 0153        return _schedules.Count == 3;
 154    }
 155
 156    private void NewSchedule()
 157    {
 0158        _schedules.Add(new());
 0159    }
 160
 161    private void DeleteSchedule(Guid id)
 162    {
 0163        _schedules.Remove(_schedules.First(f => f.Id == id));
 0164    }
 165
 166    private async Task<IEnumerable<DisciplineOut>> SearchDiscipline(string value, CancellationToken cancellationToken)
 167    {
 0168        await Task.Delay(0);
 169
 0170        if (string.IsNullOrEmpty(value))
 0171            return _disciplines;
 172
 0173        return _disciplines.Where(x => value.IsIn(x.Name));
 0174    }
 175
 176    private async Task Submit()
 177    {
 0178        if (_loading) return;
 179
 0180        await _form.Validate();
 0181        if (!_form.IsValid) return;
 182
 0183        var disciplineId = _discipline!.Id;
 0184        var teacherId = _teacher!.Id;
 0185        var period = _period!;
 0186        var vacancies = _vacancies!.Value;
 0187        var schedules = _schedules.ConvertAll(x => new ScheduleIn(x.Day!.Value, x.Start!.Value, x.End!.Value));
 188
 0189        _loading = true;
 0190        var response = await CreateClassClient.Create(disciplineId, teacherId, period, vacancies, schedules);
 0191        if (response.IsSuccess())
 192        {
 0193            Snackbar.Add("Turma cadastrada com sucesso!", Severity.Success);
 0194            Nav.NavigateTo($"/academic/classes/{response.GetSuccess().Id}");
 195        }
 196        else
 197        {
 0198            Snackbar.Add(response.GetError().Message, Severity.Error);
 199        }
 0200        _loading = false;
 0201    }
 202
 0203    private void Cancel() => MudDialog.Cancel();
 204}