| | 1 | | @namespace Syki.Front.Features.Academic.CreateClass |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Nova Turma" /> |
| | 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="12" lg="12"> |
| 0 | 11 | | <MudAutocomplete |
| 0 | 12 | | T="DisciplineOut" |
| 0 | 13 | | 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 | | > |
| 0 | 36 | | @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 | | > |
| 0 | 66 | | @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"> |
| 0 | 77 | | @foreach (var schedule in _schedules) |
| | 78 | | { |
| | 79 | | <ClassSchedule Data="@schedule" OnDeleteClick="@DeleteSchedule" /> |
| 0 | 80 | | @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] |
| 0 | 123 | | 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; |
| 0 | 132 | | private List<ScheduleInFillable> _schedules = []; |
| | 133 | |
|
| 0 | 134 | | private List<DisciplineOut> _disciplines = []; |
| 0 | 135 | | private List<TeacherOut> _teachers = []; |
| 0 | 136 | | private List<AcademicPeriodOut> _periods = []; |
| | 137 | |
|
| | 138 | | private Breakpoint _breakpoint; |
| | 139 | |
|
| | 140 | | protected override async Task OnInitializedAsync() |
| | 141 | | { |
| 0 | 142 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 143 | | NewSchedule(); |
| 0 | 144 | | _disciplines = await GetDisciplinesClient.Get(); |
| 0 | 145 | | await Task.WhenAll([ |
| 0 | 146 | | Task.Run(async () => _teachers = await GetTeachersClient.Get()), |
| 0 | 147 | | Task.Run(async () => _periods = await GetAcademicPeriodsClient.Get()) |
| 0 | 148 | | ]); |
| 0 | 149 | | } |
| | 150 | |
|
| | 151 | | private bool GetNewScheduleDisabled() |
| | 152 | | { |
| 0 | 153 | | return _schedules.Count == 3; |
| | 154 | | } |
| | 155 | |
|
| | 156 | | private void NewSchedule() |
| | 157 | | { |
| 0 | 158 | | _schedules.Add(new()); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | private void DeleteSchedule(Guid id) |
| | 162 | | { |
| 0 | 163 | | _schedules.Remove(_schedules.First(f => f.Id == id)); |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | | private async Task<IEnumerable<DisciplineOut>> SearchDiscipline(string value, CancellationToken cancellationToken) |
| | 167 | | { |
| 0 | 168 | | await Task.Delay(0); |
| | 169 | |
|
| 0 | 170 | | if (string.IsNullOrEmpty(value)) |
| 0 | 171 | | return _disciplines; |
| | 172 | |
|
| 0 | 173 | | return _disciplines.Where(x => value.IsIn(x.Name)); |
| 0 | 174 | | } |
| | 175 | |
|
| | 176 | | private async Task Submit() |
| | 177 | | { |
| 0 | 178 | | if (_loading) return; |
| | 179 | |
|
| 0 | 180 | | await _form.Validate(); |
| 0 | 181 | | if (!_form.IsValid) return; |
| | 182 | |
|
| 0 | 183 | | var disciplineId = _discipline!.Id; |
| 0 | 184 | | var teacherId = _teacher!.Id; |
| 0 | 185 | | var period = _period!; |
| 0 | 186 | | var vacancies = _vacancies!.Value; |
| 0 | 187 | | var schedules = _schedules.ConvertAll(x => new ScheduleIn(x.Day!.Value, x.Start!.Value, x.End!.Value)); |
| | 188 | |
|
| 0 | 189 | | _loading = true; |
| 0 | 190 | | var response = await CreateClassClient.Create(disciplineId, teacherId, period, vacancies, schedules); |
| 0 | 191 | | if (response.IsSuccess()) |
| | 192 | | { |
| 0 | 193 | | Snackbar.Add("Turma cadastrada com sucesso!", Severity.Success); |
| 0 | 194 | | Nav.NavigateTo($"/academic/classes/{response.GetSuccess().Id}"); |
| | 195 | | } |
| | 196 | | else |
| | 197 | | { |
| 0 | 198 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 199 | | } |
| 0 | 200 | | _loading = false; |
| 0 | 201 | | } |
| | 202 | |
|
| 0 | 203 | | private void Cancel() => MudDialog.Cancel(); |
| | 204 | | } |