| | 1 | | @using Syki.Front.Features.Teacher.CreateLessonAttendance |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Teacher |
| | 4 | |
|
| | 5 | | <MudContainer Class="mb-4 px-0"> |
| | 6 | | <MudCard Class="mb-4 py-2 px-2"> |
| | 7 | | <MudCardContent Class="py-1"> |
| 0 | 8 | | @if (_loading) |
| | 9 | | { |
| | 10 | | <MudSkeleton Animation="Animation.Wave" /> |
| | 11 | | } |
| | 12 | | else |
| | 13 | | { |
| | 14 | | <MudGrid Class="align-center"> |
| | 15 | | <MudItem xs="12" sm="6" md="6" lg="6"> |
| | 16 | | <MudStack Row="true" AlignItems="AlignItems.Center"> |
| | 17 | | <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3"> |
| 0 | 18 | | <MudText Typo="Typo.h6">Aula @_classLesson.Number <b>·</b> @_classLesson.Date.FormatBr() |
| | 19 | | </MudStack> |
| | 20 | | </MudStack> |
| | 21 | | </MudItem> |
| | 22 | | <MudItem xs="12" sm="4" md="4" lg="4"> |
| | 23 | | <MudProgressLinear Color="Color.Primary" Rounded="true" Size="Size.Large" Value="@decimal.ToDoub |
| | 24 | | <MudText Typo="Typo.body1"> |
| 0 | 25 | | <b>@_classLesson.Frequency.Format()%</b> |
| | 26 | | </MudText> |
| | 27 | | </MudProgressLinear> |
| | 28 | | </MudItem> |
| | 29 | | <MudItem xs="12" sm="2" md="2" lg="2" Class="d-flex justify-end"> |
| | 30 | | <MudButton |
| | 31 | | StartIcon="@Icons.Material.Outlined.Edit" |
| | 32 | | IconSize="Size.Large" |
| | 33 | | Variant="Variant.Filled" |
| | 34 | | Style="height: 40px;" |
| | 35 | | Color="Color.Primary" |
| | 36 | | @onclick="@OnEditLessonClick"> |
| | 37 | | Editar |
| | 38 | | </MudButton> |
| | 39 | | </MudItem> |
| | 40 | | </MudGrid> |
| | 41 | | } |
| | 42 | | </MudCardContent> |
| | 43 | | </MudCard> |
| | 44 | |
|
| | 45 | | <style>.mud-table-toolbar { height: auto }</style> |
| | 46 | | <MudTable |
| | 47 | | T="GetTeacherLessonAttendanceOut" |
| | 48 | | Class="pa-4" |
| | 49 | | Items="@_attendances" |
| | 50 | | Filter="@_quickFilter" |
| | 51 | | Hover="true" |
| | 52 | | Dense="true" |
| | 53 | | Loading="@_loading" |
| | 54 | | RowsPerPage="100" |
| | 55 | | ContainerClass="pt-0" |
| | 56 | | > |
| | 57 | | <ToolBarContent> |
| | 58 | | <MudGrid Class="align-center" Spacing="3"> |
| | 59 | | <MudItem xs="12" sm="5" md="5" lg="5"> |
| 0 | 60 | | @if (_showButtons) |
| | 61 | | { |
| | 62 | | <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3"> |
| | 63 | | <MudButton OnClick="@SelectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.C |
| | 64 | | <MudButton OnClick="@UnselectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Filled |
| | 65 | | </MudStack> |
| | 66 | | } |
| | 67 | | </MudItem> |
| | 68 | | <MudItem xs="12" sm="7" md="7" lg="7" Class="d-flex justify-end"> |
| | 69 | | <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome"/> |
| | 70 | | </MudItem> |
| | 71 | | </MudGrid> |
| | 72 | | </ToolBarContent> |
| | 73 | | <HeaderContent> |
| | 74 | | <MudTh>Nome</MudTh> |
| | 75 | | <MudTh>Presente</MudTh> |
| | 76 | | </HeaderContent> |
| | 77 | | <RowTemplate> |
| 0 | 78 | | <MudTd DataLabel="Nome">@context.StudentName</MudTd> |
| | 79 | | <MudTd DataLabel="Presente"> |
| | 80 | | <MudCheckBox |
| | 81 | | T="bool" |
| | 82 | | Class="pl-7 pr-1" |
| | 83 | | Dense="true" |
| | 84 | | Size="Size.Small" |
| | 85 | | Color="Color.Success" |
| | 86 | | Value="@context.Present" |
| 0 | 87 | | ValueChanged="x => { context.Present = x; CheckChanged(); }"/> |
| | 88 | | </MudTd> |
| | 89 | | </RowTemplate> |
| | 90 | | <NoRecordsContent> |
| 0 | 91 | | @(GetNotFoundMessage()) |
| | 92 | | </NoRecordsContent> |
| | 93 | | <LoadingContent> |
| 0 | 94 | | @if (_breakpoint == Breakpoint.Xs) |
| | 95 | | { |
| | 96 | | <MudProgressLinear Color="Color.Info" Indeterminate="true" /> |
| | 97 | | } |
| | 98 | | </LoadingContent> |
| | 99 | | <PagerContent> |
| | 100 | | <MudDivider/> |
| 0 | 101 | | @if (_showButtons) |
| | 102 | | { |
| | 103 | | <MudStack Row="true" Class="mt-4"> |
| | 104 | | <MudSpacer/> |
| | 105 | | <DialogSaveButton Class="mr-2" OnClick="@SaveFrequency"/> |
| | 106 | | </MudStack> |
| | 107 | | } |
| | 108 | | </PagerContent> |
| | 109 | | </MudTable> |
| | 110 | | </MudContainer> |
| | 111 | |
|
| | 112 | | @inject ISnackbar Snackbar |
| | 113 | | @inject IDialogService DialogService |
| | 114 | | @inject IBrowserViewportService BrowserViewportService |
| | 115 | | @inject GetTeacherClassLessonsClient GetTeacherClassLessonsClient |
| | 116 | | @inject CreateLessonAttendanceClient CreateLessonAttendanceClient |
| | 117 | | @inject GetTeacherLessonAttendancesClient GetTeacherLessonAttendancesClient |
| | 118 | |
|
| | 119 | | @code |
| | 120 | | { |
| | 121 | | [Parameter] |
| 0 | 122 | | public Guid ClassId { get; set; } |
| | 123 | |
|
| | 124 | | private Breakpoint _breakpoint; |
| | 125 | |
|
| | 126 | | private bool _loading; |
| | 127 | | private bool _showButtons; |
| | 128 | | private string _searchString; |
| 0 | 129 | | private ClassLessonOut _classLesson = new(); |
| 0 | 130 | | private List<ClassLessonOut> _lessons = []; |
| 0 | 131 | | private List<GetTeacherLessonAttendanceOut> _attendances = []; |
| | 132 | |
|
| 0 | 133 | | private List<Guid> _initialState = []; |
| | 134 | |
|
| | 135 | | protected override async Task OnInitializedAsync() |
| | 136 | | { |
| 0 | 137 | | _loading = true; |
| 0 | 138 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 139 | | _lessons = (await GetTeacherClassLessonsClient.Get(ClassId)).Success; |
| 0 | 140 | | var id = _lessons.Where(x => x.Date <= DateTime.UtcNow.ToDateOnly()).MaxBy(x => x.Date)?.Id ?? Guid.Empty; |
| 0 | 141 | | await SetLesson(id); |
| 0 | 142 | | _loading = false; |
| 0 | 143 | | _showButtons = true; |
| 0 | 144 | | } |
| | 145 | |
|
| | 146 | | private async Task SetLesson(Guid id) |
| | 147 | | { |
| 0 | 148 | | _classLesson = _lessons.FirstOrDefault(x => x.Id == id) ?? new(); |
| 0 | 149 | | _attendances = await GetTeacherLessonAttendancesClient.Get(id); |
| 0 | 150 | | _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 151 | | } |
| | 152 | |
|
| | 153 | | private void SelectAll() |
| | 154 | | { |
| 0 | 155 | | _attendances.ForEach(x => x.Present = true); |
| 0 | 156 | | CheckChanged(); |
| 0 | 157 | | } |
| | 158 | | private void UnselectAll() |
| | 159 | | { |
| 0 | 160 | | _attendances.ForEach(x => x.Present = false); |
| 0 | 161 | | CheckChanged(); |
| 0 | 162 | | } |
| | 163 | |
|
| | 164 | | private void CheckChanged() |
| | 165 | | { |
| 0 | 166 | | _classLesson.Frequency = GetCurrentFrequency(); |
| 0 | 167 | | } |
| | 168 | |
|
| | 169 | | private decimal GetCurrentFrequency() |
| | 170 | | { |
| 0 | 171 | | var total = _attendances.Count; |
| 0 | 172 | | if (total == 0) return 0.00M; |
| 0 | 173 | | var presences = _attendances.Count(x => x.Present); |
| 0 | 174 | | return 100M*(1M * presences / (1M * total)); |
| | 175 | | } |
| | 176 | |
|
| | 177 | | private Task OnEditLessonClick() |
| | 178 | | { |
| 0 | 179 | | var parameters = new DialogParameters<ClassLessonsDialog>() |
| 0 | 180 | | { |
| 0 | 181 | | { x => x.Lessons, _lessons }, |
| 0 | 182 | | { x => x.OnRowClick, EventCallback.Factory.Create<Guid>(this, SetLesson) } |
| 0 | 183 | | }; |
| | 184 | |
|
| 0 | 185 | | return DialogService.ShowAsync<ClassLessonsDialog>("", parameters); |
| | 186 | | } |
| | 187 | |
|
| | 188 | | private async Task SaveFrequency() |
| | 189 | | { |
| 0 | 190 | | var ids = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 191 | | var result = await CreateLessonAttendanceClient.Create(_classLesson.Id, ids); |
| 0 | 192 | | if (result.IsSuccess) |
| | 193 | | { |
| 0 | 194 | | _lessons = (await GetTeacherClassLessonsClient.Get(ClassId)).Success; |
| 0 | 195 | | _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 196 | | Snackbar.Add("Frequência salva com sucesso!", Severity.Success); |
| | 197 | | } |
| | 198 | | else |
| | 199 | | { |
| 0 | 200 | | Snackbar.Add(result.Error.Message, Severity.Error); |
| | 201 | | } |
| 0 | 202 | | } |
| | 203 | |
|
| 0 | 204 | | private Func<GetTeacherLessonAttendanceOut, bool> _quickFilter => x => _searchString.IsIn(x.StudentName); |
| | 205 | |
|
| | 206 | | private string GetNotFoundMessage() |
| | 207 | | { |
| 0 | 208 | | return (_searchString.IsEmpty()) ? "Não existem alunos matriculados ainda." : "Nenhum aluno encontrado."; |
| | 209 | | } |
| | 210 | | } |