| | 1 | | @using Syki.Front.Components.Agenda |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Student |
| | 4 | |
|
| | 5 | | @page "/student/enrollments" |
| | 6 | | @attribute [Authorize(Roles = "Student")] |
| | 7 | |
|
| | 8 | | <SykiPageTitle Title="Matrícula" /> |
| | 9 | |
|
| | 10 | | <MudContainer Class="my-4 px-4"> |
| | 11 | | <SykiPageHeader |
| | 12 | | Icon="@Icons.Material.Filled.Article" |
| | 13 | | Title="Matrícula" |
| | 14 | | /> |
| | 15 | | <MudContainer Class="px-0 my-4"> |
| 0 | 16 | | @if (_loading && _enrollmentPeriod.Id.IsEmpty()) |
| | 17 | | { |
| | 18 | | <MudContainer Class="px-0"> |
| | 19 | | <MudCard> |
| | 20 | | <MudCardContent> |
| | 21 | | <MudProgressLinear Color="Color.Info" Indeterminate="true" /> |
| | 22 | | </MudCardContent> |
| | 23 | | </MudCard> |
| | 24 | | </MudContainer> |
| | 25 | | } |
| 0 | 26 | | else if (!_loading && _enrollmentPeriod.Id.IsEmpty()) |
| | 27 | | { |
| | 28 | | <SykiPageAlert Text="A escolha das disciplinas só pode ser feita durante a vigência do Período de Matrícula. |
| | 29 | | } |
| | 30 | | else |
| | 31 | | { |
| | 32 | | <MudAlert NoIcon="true" Class="mt-4 mb-4 pl-6" Severity="Severity.Normal" Variant="Variant.Text" Elevation=" |
| | 33 | | <MudText> |
| | 34 | | Selecione as disciplinas que você irá cursar nesse semestre. |
| | 35 | | O período de matrícula vai até <strong>@_enrollmentPeriod.EndAt.FormatBr()</strong>. |
| | 36 | | </MudText> |
| | 37 | | </MudAlert> |
| | 38 | |
|
| | 39 | | <CascadingValue Name="Days" Value="@_days"> |
| | 40 | | <WeeklyAgenda Class="px-0 mb-4"/> |
| | 41 | | </CascadingValue> |
| | 42 | |
|
| | 43 | | <MudContainer Class="px-0 mb-8"> |
| | 44 | | <MudTable |
| | 45 | | T="EnrollmentClassOut" |
| | 46 | | Items="@_options" |
| | 47 | | Class="pa-4" |
| | 48 | | Breakpoint="Breakpoint.Sm" |
| | 49 | | Dense="true" |
| | 50 | | Hover="true" |
| | 51 | | Loading="@_loading" |
| | 52 | | RowsPerPage="100"> |
| | 53 | | <HeaderContent> |
| | 54 | | <MudTh>Disciplina</MudTh> |
| | 55 | | <MudTh>Período</MudTh> |
| | 56 | | <MudTh>Créditos</MudTh> |
| | 57 | | <MudTh>CH</MudTh> |
| | 58 | | <MudTh>Professor</MudTh> |
| | 59 | | <MudTh>Selecionada</MudTh> |
| | 60 | | </HeaderContent> |
| | 61 | | <RowTemplate> |
| | 62 | | <MudTd DataLabel="Disciplina">@context.Discipline</MudTd> |
| | 63 | | <MudTd DataLabel="Período">@context.Period</MudTd> |
| | 64 | | <MudTd DataLabel="Créditos">@context.Credits</MudTd> |
| | 65 | | <MudTd DataLabel="CH">@context.Workload</MudTd> |
| | 66 | | <MudTd DataLabel="Professor">@context.Teacher</MudTd> |
| | 67 | | <MudTd DataLabel="Selecionada"> |
| | 68 | | <MudCheckBox |
| | 69 | | T="bool" |
| | 70 | | Class="pl-9 pr-1" |
| | 71 | | Dense="true" |
| | 72 | | Size="Size.Small" |
| | 73 | | Color="Color.Success" |
| | 74 | | Value="@context.IsSelected" |
| 0 | 75 | | ValueChanged="x => { context.IsSelected = x; HandleCheckedChanged(); }" |
| | 76 | | /> |
| | 77 | | </MudTd> |
| | 78 | | </RowTemplate> |
| | 79 | | <NoRecordsContent> |
| | 80 | | Não existem turmas disponíveis no momento. |
| | 81 | | </NoRecordsContent> |
| | 82 | | <PagerContent> |
| | 83 | | <MudDivider/> |
| | 84 | | <MudStack Row="true" Class="mt-4"> |
| | 85 | | <SykiProgressCircular Loading="@_loading"/> |
| | 86 | | <DialogSaveButton OnClick="@Submit"/> |
| | 87 | | </MudStack> |
| | 88 | | </PagerContent> |
| | 89 | | </MudTable> |
| | 90 | | </MudContainer> |
| | 91 | | } |
| | 92 | | </MudContainer> |
| | 93 | | </MudContainer> |
| | 94 | |
|
| | 95 | | @inject ISnackbar Snackbar |
| | 96 | | @inject CreateStudentEnrollmentClient CreateStudentEnrollmentClient |
| | 97 | | @inject GetCurrentEnrollmentPeriodClient GetCurrentEnrollmentPeriodClient |
| | 98 | | @inject GetStudentEnrollmentClassesClient GetStudentEnrollmentClassesClient |
| | 99 | |
|
| | 100 | | @code |
| | 101 | | { |
| | 102 | | private bool _loading; |
| 0 | 103 | | EnrollmentPeriodOut _enrollmentPeriod = new(); |
| 0 | 104 | | private List<EnrollmentClassOut> _options = []; |
| 0 | 105 | | private List<AgendaDayOut> _days = []; |
| | 106 | |
|
| | 107 | | protected override async Task OnInitializedAsync() |
| | 108 | | { |
| 0 | 109 | | _loading = true; |
| 0 | 110 | | _enrollmentPeriod = await GetCurrentEnrollmentPeriodClient.Get(); |
| 0 | 111 | | if (_enrollmentPeriod.Id.IsEmpty()) |
| | 112 | | { |
| 0 | 113 | | _loading = false; |
| 0 | 114 | | return; |
| | 115 | | } |
| 0 | 116 | | _options = await GetStudentEnrollmentClassesClient.Get(); |
| 0 | 117 | | HandleCheckedChanged(); |
| 0 | 118 | | _loading = false; |
| 0 | 119 | | } |
| | 120 | |
|
| | 121 | | private void HandleCheckedChanged() |
| | 122 | | { |
| 0 | 123 | | _days = _options.Where(o => o.IsSelected).ToList().ToAgendas(); |
| 0 | 124 | | } |
| | 125 | |
|
| | 126 | | private async Task Submit() |
| | 127 | | { |
| 0 | 128 | | if (_loading) return; |
| | 129 | |
|
| 0 | 130 | | _loading = true; |
| 0 | 131 | | var classes = _options.Where(o => o.IsSelected).Select(o => o.Id).ToList(); |
| 0 | 132 | | var response = await CreateStudentEnrollmentClient.Create(classes); |
| 0 | 133 | | if (response.IsSuccessStatusCode) |
| | 134 | | { |
| 0 | 135 | | Snackbar.Add("Matrícula salva com sucesso!", Severity.Success); |
| | 136 | | } |
| | 137 | | else |
| | 138 | | { |
| 0 | 139 | | var error = await response.ToError(); |
| 0 | 140 | | Snackbar.Add(error.Message, Severity.Error); |
| | 141 | | } |
| 0 | 142 | | _loading = false; |
| 0 | 143 | | } |
| | 144 | | } |