< Summary

Information
Class: Syki.Front.Features.Academic.CreateCourseCurriculum.CreateCourseCurriculumDialog
Assembly: Front
File(s): /home/runner/work/syki/syki/Front/Features/Academic/CreateCourseCurriculum/CreateCourseCurriculumDialog.razor
Tag: 22_11348620282
Line coverage
0%
Covered lines: 0
Uncovered lines: 51
Coverable lines: 51
Total lines: 162
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
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%
NewGradeDiscipline()100%210%
DeleteGradeDiscipline(...)0%620%
GetNewDisciplineDisabled()0%620%
HandleSelectCourse()100%210%
Submit()0%4260%
Cancel()100%210%

File(s)

/home/runner/work/syki/syki/Front/Features/Academic/CreateCourseCurriculum/CreateCourseCurriculumDialog.razor

#LineLine coverage
 1@namespace Syki.Front.Features.Academic.CreateCourseCurriculum
 2
 3<MudDialog Class="pb-2">
 4    <TitleContent>
 5        <SykiDialogTitle Text="Nova Grade" />
 6    </TitleContent>
 7    <DialogContent>
 08        <MudForm @ref="@_form" Class="pt-1" Spacing="0">
 09            <MudGrid Spacing="2">
 010                <MudItem xs="12" sm="12" md="6" lg="6">
 011                    <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@data.Name" Class="pb-0"/>
 012                </MudItem>
 013                <MudItem xs="12" sm="12" md="6" lg="6">
 14                    <MudSelect
 15                        Dense="true"
 16                        Margin="Margin.Dense"
 17                        Variant="Variant.Outlined"
 18                        Value="@_course"
 019                        ValueChanged="@((CourseOut newValue) => HandleSelectCourse(newValue))"
 20                        Label="Curso"
 21                        Required="true"
 22                        RequiredError="Informe!"
 23                        AdornmentColor="Color.Primary">
 024                        @foreach (CourseOut? item in Courses)
 25                        {
 26                            <MudSelectItem Value="@item">@item.Name</MudSelectItem>
 27                        }
 028                        @if (Courses.Count == 0)
 29                        {
 30                            <MudSelectItem Value="@_course" Disabled="true">Não existem cursos com disciplinas ainda.</M
 31                        }
 32                    </MudSelect>
 33                </MudItem>
 34            </MudGrid>
 35
 36            <MudDivider Class="my-4"/>
 37
 38            <MudGrid Spacing="0">
 39                <MudItem xs="12" sm="12" md="12" lg="12">
 40                    <CascadingValue Name="Options" Value="@Options">
 041                        @foreach (var discipline in Disciplines)
 42                        {
 43                            <CourseCurriculumDiscipline Data="@discipline" OnDeleteClick="@DeleteGradeDiscipline"/>
 044                            @if (_breakpoint == Breakpoint.Xs)
 45                            {
 46                                <MudDivider Class="my-2"/>
 47                            }
 48                        }
 49                    </CascadingValue>
 50                </MudItem>
 51                <MudItem xs="12" sm="12" md="12" lg="12">
 52                    <MudButton
 53                        Disabled="(GetNewDisciplineDisabled())"
 54                        StartIcon="@Icons.Material.Outlined.Add"
 55                        IconSize="Size.Large"
 56                        Variant="Variant.Outlined"
 57                        FullWidth="true"
 58                        Class="mt-2 border-dashed border-2 mud-border-secundary"
 59                        Style="max-width: fit-content"
 60                        Color="Color.Primary"
 61                        @onclick="@NewGradeDiscipline">
 62                        NOVA DISCIPLINA
 63                    </MudButton>
 64                </MudItem>
 65            </MudGrid>
 66        </MudForm>
 67    </DialogContent>
 68    <DialogActions>
 69        <DialogCancelButton OnClick="@Cancel" />
 70        <SykiProgressCircular Loading="@_loading" />
 71        <DialogSaveButton OnClick="@Submit" />
 72    </DialogActions>
 73</MudDialog>
 74
 75@inject ISnackbar Snackbar
 76@inject IBrowserViewportService BrowserViewportService
 77@inject GetCourseDisciplinesClient GetCourseDisciplinesClient
 78@inject CreateCourseCurriculumClient CreateCourseCurriculumClient
 79@inject GetCoursesWithDisciplinesClient GetCoursesWithDisciplinesClient
 80
 81@code
 82{
 83    [CascadingParameter]
 084    MudDialogInstance MudDialog { get; set; }
 85
 86    private MudForm _form;
 87    private bool _loading;
 88
 89    private CourseOut? _course;
 090    List<CourseOut> Courses = [];
 91
 092    List<CourseDisciplineOut> Options = [];
 093    List<CourseCurriculumDisciplineFillable> Disciplines = [];
 94
 95    private Breakpoint _breakpoint;
 096    CreateCourseCurriculumIn data = new();
 97
 98    protected override async Task OnInitializedAsync()
 99    {
 0100        _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync();
 0101        Courses = await GetCoursesWithDisciplinesClient.Get();
 0102    }
 103
 104    void NewGradeDiscipline()
 105    {
 0106        Disciplines.Add(new() { Id = Guid.NewGuid() });
 0107    }
 108
 109    void DeleteGradeDiscipline(Guid id)
 110    {
 0111        Disciplines.Remove(Disciplines.First(f => f.Id == id));
 0112        if (Options.Any(x => x.Id == id))
 113        {
 0114            Options.First(d => d.Id == id).IsSelected = false;
 115        }
 0116    }
 117
 118    bool GetNewDisciplineDisabled()
 119    {
 0120        return _course == null || Options.Count == Disciplines.Count;
 121    }
 122
 123    async Task HandleSelectCourse(CourseOut newValue)
 124    {
 0125        _course = newValue;
 0126        Options = await GetCourseDisciplinesClient.Get(_course!.Id);
 0127        Disciplines = [];
 0128    }
 129
 130    async Task Submit()
 131    {
 0132        if (_loading) return;
 133
 0134        await _form.Validate();
 0135        if (!_form.IsValid) return;
 136
 0137        data.CourseId = _course!.Id;
 0138        data.Disciplines = Disciplines
 0139            .ConvertAll(d => new CreateCourseCurriculumDisciplineIn
 0140            (
 0141                d.Id,
 0142                d.Period!.Value,
 0143                d.Credits!.Value,
 0144                d.Workload!.Value
 0145            ));
 146
 0147        _loading = true;
 0148        var response = await CreateCourseCurriculumClient.Create(data.Name, data.CourseId, data.Disciplines);
 0149        if (response.IsSuccess())
 150        {
 0151            MudDialog.Close(DialogResult.Ok(true));
 0152            Snackbar.Add("Grade cadastrada com sucesso!", Severity.Success);
 153        }
 154        else
 155        {
 0156            Snackbar.Add(response.GetError().Message, Severity.Error);
 157        }
 0158        _loading = false;
 0159    }
 160
 0161    void Cancel() => MudDialog.Cancel();
 162}