| | 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> |
| 0 | 11 | | <MudForm @ref="@_form" Class="pt-1"> |
| 0 | 12 | | <MudGrid Justify="Justify.FlexStart" Spacing="2"> |
| 0 | 13 | | <MudItem xs="12" sm="12" md="12" lg="12"> |
| 0 | 14 | | <MudSelect |
| 0 | 15 | | Dense="true" |
| 0 | 16 | | 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 | | > |
| 0 | 26 | | @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 | | > |
| 0 | 44 | | @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 | | > |
| 0 | 62 | | @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 | | > |
| 0 | 94 | | @if (_course == null) |
| | 95 | | { |
| | 96 | | <MudSelectItem Value="@_courseCurriculum" Disabled="true">Selecione o curso!</MudSelectItem> |
| | 97 | | } |
| 0 | 98 | | @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 | | } |
| 0 | 102 | | @if (_course != null) |
| | 103 | | { |
| 0 | 104 | | @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] |
| 0 | 129 | | 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 | |
|
| 0 | 140 | | List<CampusOut> Campi = []; |
| 0 | 141 | | List<CourseOut> Courses = []; |
| 0 | 142 | | List<AcademicPeriodOut> Periods = []; |
| 0 | 143 | | List<CourseCurriculumOut> CourseCurriculums = []; |
| | 144 | |
|
| | 145 | | protected override async Task OnInitializedAsync() |
| | 146 | | { |
| 0 | 147 | | await Task.WhenAll(new Task[] { |
| 0 | 148 | | Task.Run(async () => Campi = await GetCampiClient.Get()), |
| 0 | 149 | | Task.Run(async () => Periods = await GetAcademicPeriodsClient.Get()), |
| 0 | 150 | | Task.Run(async () => Courses = await GetCoursesWithCurriculumsClient.Get()), |
| 0 | 151 | | Task.Run(async () => CourseCurriculums = await GetCourseCurriculumsClient.Get()), |
| 0 | 152 | | }); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | private async Task<IEnumerable<CourseOut>> SearchCourse(string value, CancellationToken cancellationToken) |
| | 156 | | { |
| 0 | 157 | | await Task.Delay(0); |
| | 158 | |
|
| 0 | 159 | | if (string.IsNullOrEmpty(value)) |
| 0 | 160 | | return Courses; |
| | 161 | |
|
| 0 | 162 | | return Courses.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)); |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | async Task Submit() |
| | 166 | | { |
| 0 | 167 | | if (_loading) return; |
| | 168 | |
|
| 0 | 169 | | await _form.Validate(); |
| 0 | 170 | | if (!_form.IsValid) return; |
| | 171 | |
|
| 0 | 172 | | var campusId = _campus!.Id; |
| 0 | 173 | | var courseId = _course!.Id; |
| 0 | 174 | | var courseCurriculumId = _courseCurriculum!.Id; |
| 0 | 175 | | var period = _period!; |
| 0 | 176 | | var shift = _shift!.Value; |
| | 177 | |
|
| 0 | 178 | | _loading = true; |
| 0 | 179 | | var response = await CreateCourseOfferingClient.Create(campusId, courseId, courseCurriculumId, period, shift); |
| 0 | 180 | | if (response.IsSuccess()) |
| | 181 | | { |
| 0 | 182 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 183 | | Snackbar.Add("Oferta cadastrada com sucesso!", Severity.Success); |
| | 184 | | } |
| | 185 | | else |
| | 186 | | { |
| 0 | 187 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 188 | | } |
| 0 | 189 | | _loading = false; |
| 0 | 190 | | } |
| | 191 | |
|
| 0 | 192 | | void Cancel() => MudDialog.Cancel(); |
| | 193 | | } |