| | | 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="GetCampusCourseOfferingsDisciplineOut" |
| | 0 | 13 | | MaxItems="50" |
| | | 14 | | SearchFunc="@SearchDiscipline" |
| | | 15 | | Dense |
| | | 16 | | Margin="Margin.Dense" |
| | | 17 | | Variant="Variant.Outlined" |
| | | 18 | | @bind-Value="@_discipline" |
| | | 19 | | Label="Disciplina" |
| | | 20 | | Required |
| | | 21 | | RequiredError="Informe!" |
| | | 22 | | AdornmentColor="Color.Primary" |
| | | 23 | | /> |
| | | 24 | | </MudItem> |
| | | 25 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| | | 26 | | <MudSelect |
| | | 27 | | Dense |
| | | 28 | | Margin="Margin.Dense" |
| | | 29 | | Variant="Variant.Outlined" |
| | | 30 | | @bind-Value="@_teacher" |
| | | 31 | | Label="Professor" |
| | | 32 | | Required |
| | | 33 | | RequiredError="Informe!" |
| | | 34 | | AdornmentColor="Color.Primary" |
| | | 35 | | Disabled="@(_discipline == null)" |
| | | 36 | | > |
| | 0 | 37 | | @foreach (GetCampusTeachersOut? item in Teachers.Where(t => _discipline != null && t.Disciplines |
| | | 38 | | { |
| | 0 | 39 | | <MudSelectItem Value="@item">@item.Name</MudSelectItem> |
| | | 40 | | } |
| | | 41 | | </MudSelect> |
| | | 42 | | </MudItem> |
| | | 43 | | <MudItem xs="6" sm="6" md="6" lg="6"> |
| | | 44 | | <MudNumericField |
| | | 45 | | MaxLength="2" |
| | | 46 | | HideSpinButtons |
| | | 47 | | Margin="Margin.Dense" |
| | | 48 | | Variant="Variant.Outlined" |
| | | 49 | | T="byte?" |
| | | 50 | | @bind-Value="@_vacancies" |
| | | 51 | | Label="Vagas" |
| | | 52 | | Required |
| | | 53 | | RequiredError="Informe!" |
| | | 54 | | /> |
| | | 55 | | </MudItem> |
| | | 56 | | </MudGrid> |
| | | 57 | | </MudForm> |
| | | 58 | | </DialogContent> |
| | | 59 | | <DialogActions> |
| | | 60 | | <DialogCancelButton OnClick="@Cancel" /> |
| | | 61 | | <SykiProgressCircular Loading="@_loading" /> |
| | | 62 | | <DialogSaveButton OnClick="@Submit" /> |
| | | 63 | | </DialogActions> |
| | | 64 | | </MudDialog> |
| | | 65 | | |
| | | 66 | | @inject ISnackbar Snackbar |
| | | 67 | | @inject CreateClassClient CreateClassClient |
| | | 68 | | @inject GetTeachersClient GetTeachersClient |
| | | 69 | | @inject GetDisciplinesClient GetDisciplinesClient |
| | | 70 | | @inject IBrowserViewportService BrowserViewportService |
| | | 71 | | @inject GetAcademicPeriodsClient GetAcademicPeriodsClient |
| | | 72 | | |
| | | 73 | | @code |
| | | 74 | | { |
| | | 75 | | [CascadingParameter] |
| | 0 | 76 | | IMudDialogInstance MudDialog { get; set; } |
| | | 77 | | |
| | | 78 | | [Parameter] |
| | 0 | 79 | | public string Period { get; set; } |
| | | 80 | | |
| | | 81 | | [Parameter] |
| | 0 | 82 | | public Guid CampusId { get; set; } |
| | | 83 | | |
| | | 84 | | [Parameter] |
| | 0 | 85 | | public List<GetCampusTeachersOut> Teachers { get; set; } = []; |
| | | 86 | | |
| | | 87 | | [Parameter] |
| | 0 | 88 | | public List<GetCampusCourseOfferingsDisciplineOut> Disciplines { get; set; } = []; |
| | | 89 | | |
| | | 90 | | private MudForm _form; |
| | | 91 | | private bool _loading; |
| | | 92 | | private Breakpoint _breakpoint; |
| | | 93 | | |
| | | 94 | | private byte? _vacancies; |
| | | 95 | | private GetCampusTeachersOut? _teacher; |
| | | 96 | | private GetCampusCourseOfferingsDisciplineOut? _discipline; |
| | | 97 | | |
| | | 98 | | protected override async Task OnInitializedAsync() |
| | | 99 | | { |
| | 0 | 100 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| | 0 | 101 | | } |
| | | 102 | | |
| | | 103 | | private async Task<IEnumerable<GetCampusCourseOfferingsDisciplineOut>> SearchDiscipline(string value, CancellationTo |
| | | 104 | | { |
| | 0 | 105 | | await Task.Delay(0); |
| | | 106 | | |
| | 0 | 107 | | if (string.IsNullOrEmpty(value)) |
| | 0 | 108 | | return Disciplines; |
| | | 109 | | |
| | 0 | 110 | | return Disciplines.Where(x => value.IsIn(x.Name)); |
| | 0 | 111 | | } |
| | | 112 | | |
| | | 113 | | private async Task Submit() |
| | | 114 | | { |
| | 0 | 115 | | if (_loading) return; |
| | | 116 | | |
| | 0 | 117 | | await _form.Validate(); |
| | 0 | 118 | | if (!_form.IsValid) return; |
| | | 119 | | |
| | 0 | 120 | | var disciplineId = _discipline!.Id; |
| | 0 | 121 | | var teacherId = _teacher!.Id; |
| | 0 | 122 | | var vacancies = _vacancies!.Value; |
| | | 123 | | |
| | 0 | 124 | | _loading = true; |
| | 0 | 125 | | var response = await CreateClassClient.Create(disciplineId, CampusId, teacherId, Period, vacancies, []); |
| | 0 | 126 | | if (response.IsSuccess) |
| | | 127 | | { |
| | 0 | 128 | | MudDialog.Close(DialogResult.Ok(true)); |
| | 0 | 129 | | Snackbar.Add("Turma cadastrada com sucesso!", Severity.Success); |
| | | 130 | | } |
| | | 131 | | else |
| | | 132 | | { |
| | 0 | 133 | | Snackbar.Add(response.Error.Message, Severity.Error); |
| | | 134 | | } |
| | 0 | 135 | | _loading = false; |
| | 0 | 136 | | } |
| | | 137 | | |
| | 0 | 138 | | private void Cancel() => MudDialog.Cancel(); |
| | | 139 | | } |