| | 1 | | @namespace Syki.Front.Features.Academic.CreateCourseCurriculum |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Nova Grade" /> |
| | 6 | | </TitleContent> |
| | 7 | | <DialogContent> |
| 0 | 8 | | <MudForm @ref="@_form" Class="pt-1" Spacing="0"> |
| 0 | 9 | | <MudGrid Spacing="2"> |
| 0 | 10 | | <MudItem xs="12" sm="12" md="6" lg="6"> |
| 0 | 11 | | <SykiTextField Label="Nome" AutoFocus="true" @bind-Value="@data.Name" Class="pb-0"/> |
| 0 | 12 | | </MudItem> |
| 0 | 13 | | <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" |
| 0 | 19 | | ValueChanged="@((CourseOut newValue) => HandleSelectCourse(newValue))" |
| | 20 | | Label="Curso" |
| | 21 | | Required="true" |
| | 22 | | RequiredError="Informe!" |
| | 23 | | AdornmentColor="Color.Primary"> |
| 0 | 24 | | @foreach (CourseOut? item in Courses) |
| | 25 | | { |
| | 26 | | <MudSelectItem Value="@item">@item.Name</MudSelectItem> |
| | 27 | | } |
| 0 | 28 | | @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"> |
| 0 | 41 | | @foreach (var discipline in Disciplines) |
| | 42 | | { |
| | 43 | | <CourseCurriculumDiscipline Data="@discipline" OnDeleteClick="@DeleteGradeDiscipline"/> |
| 0 | 44 | | @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] |
| 0 | 84 | | MudDialogInstance MudDialog { get; set; } |
| | 85 | |
|
| | 86 | | private MudForm _form; |
| | 87 | | private bool _loading; |
| | 88 | |
|
| | 89 | | private CourseOut? _course; |
| 0 | 90 | | List<CourseOut> Courses = []; |
| | 91 | |
|
| 0 | 92 | | List<CourseDisciplineOut> Options = []; |
| 0 | 93 | | List<CourseCurriculumDisciplineFillable> Disciplines = []; |
| | 94 | |
|
| | 95 | | private Breakpoint _breakpoint; |
| 0 | 96 | | CreateCourseCurriculumIn data = new(); |
| | 97 | |
|
| | 98 | | protected override async Task OnInitializedAsync() |
| | 99 | | { |
| 0 | 100 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 101 | | Courses = await GetCoursesWithDisciplinesClient.Get(); |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | void NewGradeDiscipline() |
| | 105 | | { |
| 0 | 106 | | Disciplines.Add(new() { Id = Guid.NewGuid() }); |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | void DeleteGradeDiscipline(Guid id) |
| | 110 | | { |
| 0 | 111 | | Disciplines.Remove(Disciplines.First(f => f.Id == id)); |
| 0 | 112 | | if (Options.Any(x => x.Id == id)) |
| | 113 | | { |
| 0 | 114 | | Options.First(d => d.Id == id).IsSelected = false; |
| | 115 | | } |
| 0 | 116 | | } |
| | 117 | |
|
| | 118 | | bool GetNewDisciplineDisabled() |
| | 119 | | { |
| 0 | 120 | | return _course == null || Options.Count == Disciplines.Count; |
| | 121 | | } |
| | 122 | |
|
| | 123 | | async Task HandleSelectCourse(CourseOut newValue) |
| | 124 | | { |
| 0 | 125 | | _course = newValue; |
| 0 | 126 | | Options = await GetCourseDisciplinesClient.Get(_course!.Id); |
| 0 | 127 | | Disciplines = []; |
| 0 | 128 | | } |
| | 129 | |
|
| | 130 | | async Task Submit() |
| | 131 | | { |
| 0 | 132 | | if (_loading) return; |
| | 133 | |
|
| 0 | 134 | | await _form.Validate(); |
| 0 | 135 | | if (!_form.IsValid) return; |
| | 136 | |
|
| 0 | 137 | | data.CourseId = _course!.Id; |
| 0 | 138 | | data.Disciplines = Disciplines |
| 0 | 139 | | .ConvertAll(d => new CreateCourseCurriculumDisciplineIn |
| 0 | 140 | | ( |
| 0 | 141 | | d.Id, |
| 0 | 142 | | d.Period!.Value, |
| 0 | 143 | | d.Credits!.Value, |
| 0 | 144 | | d.Workload!.Value |
| 0 | 145 | | )); |
| | 146 | |
|
| 0 | 147 | | _loading = true; |
| 0 | 148 | | var response = await CreateCourseCurriculumClient.Create(data.Name, data.CourseId, data.Disciplines); |
| 0 | 149 | | if (response.IsSuccess()) |
| | 150 | | { |
| 0 | 151 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 152 | | Snackbar.Add("Grade cadastrada com sucesso!", Severity.Success); |
| | 153 | | } |
| | 154 | | else |
| | 155 | | { |
| 0 | 156 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 157 | | } |
| 0 | 158 | | _loading = false; |
| 0 | 159 | | } |
| | 160 | |
|
| 0 | 161 | | void Cancel() => MudDialog.Cancel(); |
| | 162 | | } |