< Summary

Information
Class: Syki.Front.Features.Academic.CreateCourseOffering.CreateCourseOfferingDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateCourseOffering/CreateCourseOfferingDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 193
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
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%
<OnInitializedAsync()100%210%
<OnInitializedAsync()100%210%
SearchCourse()0%620%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateCourseOffering/CreateCourseOfferingDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.CreateCourseOffering
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <MudText Typo="Typo.h6">
 6            <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1 mb-n1" />
 7            Nova Oferta
 8        </MudText>
 9    </TitleContent>
 10    <DialogContent>
 011        <MudForm @ref="@_form" Class="pt-1">
 012            <MudGrid Justify="Justify.FlexStart" Spacing="2">
 013                <MudItem xs="12" sm="12" md="12" lg="12">
 014                    <MudSelect
 015                        Dense="true"
 016                        Margin="Margin.Dense"
 17                        Variant="Variant.Outlined"
 18                        Class="mb-4"
 19                        AutoFocus="true"
 20                        @bind-Value="@_campus"
 21                        Label="Campus"
 22                        Required="true"
 23                        RequiredError="Informe!"
 24                        AdornmentColor="Color.Primary"
 25                    >
 026                        @foreach (CampusOut? item in Campi)
 27                        {
 28                            <MudSelectItem Value="@item">@item.Name</MudSelectItem>
 29                        }
 30                    </MudSelect>
 31                </MudItem>
 32                <MudItem xs="6" sm="6" md="6" lg="6">
 33                    <MudSelect
 34                        Dense="true"
 35                        Margin="Margin.Dense"
 36                        Variant="Variant.Outlined"
 37                        Class="mb-4"
 38                        @bind-Value="@_period"
 39                        Label="Período"
 40                        Required="true"
 41                        RequiredError="Informe!"
 42                        AdornmentColor="Color.Primary"
 43                    >
 044                        @foreach (string? item in Periods.ConvertAll(p => p.Id))
 45                        {
 46                            <MudSelectItem Value="@item">@item</MudSelectItem>
 47                        }
 48                    </MudSelect>
 49                </MudItem>
 50                <MudItem xs="6" sm="6" md="6" lg="6">
 51                    <MudSelect
 52                        Dense="true"
 53                        Margin="Margin.Dense"
 54                        Variant="Variant.Outlined"
 55                        Class="mb-4"
 56                        @bind-Value="@_shift"
 57                        Label="Turno"
 58                        Required="true"
 59                        RequiredError="Informe!"
 60                        AdornmentColor="Color.Primary"
 61                    >
 062                        @foreach (Shift? item in Enum.GetValues<Shift>())
 63                        {
 64                            <MudSelectItem Value="@item">@item.GetDescription()</MudSelectItem>
 65                        }
 66                    </MudSelect>
 67                </MudItem>
 68            </MudGrid>
 69            <MudAutocomplete
 70                T="CourseOut"
 71                MaxItems="50"
 72                SearchFunc="@SearchCourse"
 73                Dense="true"
 74                Margin="Margin.Dense"
 75                Variant="Variant.Outlined"
 76                Class="py-2"
 77                @bind-Value="@_course"
 78                Label="Curso"
 79                Required="true"
 80                RequiredError="Informe!"
 81                AdornmentColor="Color.Primary"
 82            />
 83            <MudSelect
 84                Dense="true"
 85                Margin="Margin.Dense"
 86                Variant="Variant.Outlined"
 87                Class="mb-2"
 88                @bind-Value="@_courseCurriculum"
 89                Label="Grade"
 90                Required="true"
 91                RequiredError="Informe!"
 92                AdornmentColor="Color.Primary"
 93            >
 094                @if (_course == null)
 95                {
 96                    <MudSelectItem Value="@_courseCurriculum" Disabled="true">Selecione o curso!</MudSelectItem>
 97                }
 098                @if (_course != null && CourseCurriculums.Where(x => x.CourseId == _course.Id).Count() == 0)
 99                {
 100                    <MudSelectItem Value="@_courseCurriculum" Disabled="true">Este curso não possui grades vinculadas.</
 101                }
 0102                @if (_course != null)
 103                {
 0104                    @foreach (CourseCurriculumOut? item in CourseCurriculums.Where(x => x.CourseId == _course.Id))
 105                    {
 106                        <MudSelectItem Value="@item">@item.Name</MudSelectItem>
 107                    }
 108                }
 109            </MudSelect>
 110        </MudForm>
 111    </DialogContent>
 112    <DialogActions>
 113        <DialogCancelButton OnClick="@Cancel" />
 114        <SykiProgressCircular Loading="@_loading" />
 115        <DialogSaveButton OnClick="@Submit" />
 116    </DialogActions>
 117</MudDialog>
 118
 119@inject ISnackbar Snackbar
 120@inject GetCampiClient GetCampiClient
 121@inject GetAcademicPeriodsClient GetAcademicPeriodsClient
 122@inject GetCourseCurriculumsClient GetCourseCurriculumsClient
 123@inject CreateCourseOfferingClient CreateCourseOfferingClient
 124@inject GetCoursesWithCurriculumsClient GetCoursesWithCurriculumsClient
 125
 126@code
 127{
 128    [CascadingParameter]
 0129    MudDialogInstance MudDialog { get; set; }
 130
 131    MudForm _form;
 132    private bool _loading;
 133
 134    private CampusOut? _campus;
 135    private CourseOut? _course;
 136    private CourseCurriculumOut? _courseCurriculum;
 137    private string? _period;
 138    private Shift? _shift;
 139
 0140    List<CampusOut> Campi = [];
 0141    List<CourseOut> Courses = [];
 0142    List<AcademicPeriodOut> Periods = [];
 0143    List<CourseCurriculumOut> CourseCurriculums = [];
 144
 145    protected override async Task OnInitializedAsync()
 146    {
 0147        await Task.WhenAll(new Task[] {
 0148            Task.Run(async () => Campi = await GetCampiClient.Get()),
 0149            Task.Run(async () => Periods = await GetAcademicPeriodsClient.Get()),
 0150            Task.Run(async () => Courses = await GetCoursesWithCurriculumsClient.Get()),
 0151            Task.Run(async () => CourseCurriculums = await GetCourseCurriculumsClient.Get()),
 0152        });
 0153    }
 154
 155    private async Task<IEnumerable<CourseOut>> SearchCourse(string value, CancellationToken cancellationToken)
 156    {
 0157        await Task.Delay(0);
 158
 0159        if (string.IsNullOrEmpty(value))
 0160            return Courses;
 161
 0162        return Courses.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase));
 0163    }
 164
 165    async Task Submit()
 166    {
 0167        if (_loading) return;
 168
 0169        await _form.Validate();
 0170        if (!_form.IsValid) return;
 171
 0172        var campusId = _campus!.Id;
 0173        var courseId = _course!.Id;
 0174        var courseCurriculumId = _courseCurriculum!.Id;
 0175        var period = _period!;
 0176        var shift = _shift!.Value;
 177
 0178        _loading = true;
 0179        var response = await CreateCourseOfferingClient.Create(campusId, courseId, courseCurriculumId, period, shift);
 0180        if (response.IsSuccess())
 181        {
 0182            MudDialog.Close(DialogResult.Ok(true));
 0183            Snackbar.Add("Oferta cadastrada com sucesso!", Severity.Success);
 184        }
 185        else
 186        {
 0187            Snackbar.Add(response.GetError().Message, Severity.Error);
 188        }
 0189        _loading = false;
 0190    }
 191
 0192    void Cancel() => MudDialog.Cancel();
 193}