| | 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"> |
| | 18 | | <MudText Typo="Typo.h6">Aula @_lesson.Number <b>·</b> @_lesson.Date.FormatBr() <b>·</b> |
| | 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"> |
| | 25 | | <b>@_lesson.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> |
| | 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> |
| | 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 | |
|
| 0 | 112 | | <ClassLessonsDialog @ref="@_dialog" OnRowClick="@SetLesson" /> |
| 0 | 113 | |
|
| 0 | 114 | | @inject ISnackbar Snackbar |
| 0 | 115 | | @inject GetTeacherClassClient GetTeacherClassClient |
| 0 | 116 | | @inject IBrowserViewportService BrowserViewportService |
| 0 | 117 | | @inject CreateLessonAttendanceClient CreateLessonAttendanceClient |
| | 118 | | @inject GetTeacherLessonAttendancesClient GetTeacherLessonAttendancesClient |
| | 119 | |
|
| | 120 | | @code |
| | 121 | | { |
| | 122 | | [Parameter] |
| 0 | 123 | | public Guid ClassId { get; set; } |
| | 124 | |
|
| | 125 | | private Breakpoint _breakpoint; |
| | 126 | | private ClassLessonsDialog _dialog; |
| | 127 | |
|
| | 128 | | private bool _loading; |
| | 129 | | private bool _showButtons; |
| | 130 | | private string _searchString; |
| 0 | 131 | | private TeacherClassOut _class = new(); |
| 0 | 132 | | private LessonOut _lesson = new(); |
| 0 | 133 | | private List<GetTeacherLessonAttendanceOut> _attendances = []; |
| | 134 | |
|
| 0 | 135 | | private List<Guid> _initialState = []; |
| | 136 | |
|
| | 137 | | protected override async Task OnInitializedAsync() |
| | 138 | | { |
| 0 | 139 | | _loading = true; |
| 0 | 140 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 141 | | _class = await GetTeacherClassClient.Get(ClassId); |
| 0 | 142 | | var id = _class.Lessons.Where(x => x.Date <= DateTime.Now.ToDateOnly()).MaxBy(x => x.Date)?.Id ?? Guid.Empty; |
| 0 | 143 | | await SetLesson(id); |
| 0 | 144 | | _loading = false; |
| 0 | 145 | | _showButtons = true; |
| 0 | 146 | | } |
| | 147 | |
|
| | 148 | | private async Task SetLesson(Guid id) |
| | 149 | | { |
| 0 | 150 | | _lesson = _class.Lessons.FirstOrDefault(x => x.Id == id) ?? new(); |
| 0 | 151 | | _attendances = await GetTeacherLessonAttendancesClient.Get(id); |
| 0 | 152 | | _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | private void SelectAll() |
| | 156 | | { |
| 0 | 157 | | _attendances.ForEach(x => x.Present = true); |
| 0 | 158 | | CheckChanged(); |
| 0 | 159 | | } |
| | 160 | | private void UnselectAll() |
| | 161 | | { |
| 0 | 162 | | _attendances.ForEach(x => x.Present = false); |
| 0 | 163 | | CheckChanged(); |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | | private void CheckChanged() |
| | 167 | | { |
| 0 | 168 | | _lesson.Frequency = GetCurrentFrequency(); |
| 0 | 169 | | } |
| | 170 | |
|
| | 171 | | private decimal GetCurrentFrequency() |
| | 172 | | { |
| 0 | 173 | | var total = _attendances.Count; |
| 0 | 174 | | if (total == 0) return 0.00M; |
| 0 | 175 | | var presences = _attendances.Count(x => x.Present); |
| 0 | 176 | | return 100M*(1M * presences / (1M * total)); |
| | 177 | | } |
| | 178 | |
|
| | 179 | | private async Task OnEditLessonClick() |
| | 180 | | { |
| 0 | 181 | | await _dialog.Open(_class.Lessons); |
| 0 | 182 | | } |
| | 183 | |
|
| | 184 | | private async Task SaveFrequency() |
| | 185 | | { |
| 0 | 186 | | var ids = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 187 | | var result = await CreateLessonAttendanceClient.Create(_lesson.Id, ids); |
| 0 | 188 | | if (result.IsSuccess()) |
| | 189 | | { |
| 0 | 190 | | _class = await GetTeacherClassClient.Get(ClassId); |
| 0 | 191 | | _initialState = _attendances.Where(x => x.Present).Select(x => x.StudentId).ToList(); |
| 0 | 192 | | Snackbar.Add("Frequência salva com sucesso!", Severity.Success); |
| | 193 | | } |
| | 194 | | else |
| | 195 | | { |
| 0 | 196 | | Snackbar.Add(result.GetError().Message, Severity.Error); |
| | 197 | | } |
| 0 | 198 | | } |
| | 199 | |
|
| 0 | 200 | | private Func<GetTeacherLessonAttendanceOut, bool> _quickFilter => x => _searchString.IsIn(x.StudentName); |
| | 201 | |
|
| | 202 | | private string GetNotFoundMessage() |
| | 203 | | { |
| 0 | 204 | | return (_searchString.IsEmpty()) ? "Não existem alunos matriculados ainda." : "Nenhum aluno encontrado."; |
| | 205 | | } |
| | 206 | | } |