| | 1 | | @namespace Syki.Front.Features.Academic.StartClasses |
| | 2 | |
|
| | 3 | | <MudDialog Class="pb-2"> |
| | 4 | | <TitleContent> |
| | 5 | | <SykiDialogTitle Text="Iniciar" Icon="@Icons.Material.Filled.PlayLesson" /> |
| | 6 | | </TitleContent> |
| | 7 | | <DialogContent> |
| | 8 | | <style>.mud-table-toolbar { height: auto }</style> |
| | 9 | | <MudTable |
| | 10 | | T="ClassOut" |
| | 11 | | Class="pa-4 mb-2" |
| | 12 | | Items="@_classes" |
| | 13 | | Filter="@_quickFilter" |
| | 14 | | Hover="true" |
| | 15 | | Dense="true" |
| | 16 | | Loading="@_loading" |
| | 17 | | RowsPerPage="100" |
| | 18 | | ContainerClass="pt-0" |
| | 19 | | > |
| | 20 | | <ToolBarContent> |
| | 21 | | <MudGrid Class="align-center" Spacing="3"> |
| | 22 | | <MudItem xs="12" sm="5" md="5" lg="5"> |
| 0 | 23 | | @if (_showButtons) |
| | 24 | | { |
| | 25 | | <MudStack Row="true" AlignItems="AlignItems.Center" Spacing="3"> |
| | 26 | | <MudButton OnClick="@SelectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Fill |
| | 27 | | <MudButton OnClick="@UnselectAll" Variant="Variant.Filled" StartIcon="@Icons.Material.Fi |
| | 28 | | </MudStack> |
| | 29 | | } |
| | 30 | | </MudItem> |
| | 31 | | <MudItem xs="12" sm="7" md="7" lg="7" Class="d-flex justify-end"> |
| | 32 | | <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome"/> |
| | 33 | | </MudItem> |
| | 34 | | </MudGrid> |
| | 35 | | </ToolBarContent> |
| | 36 | | <HeaderContent> |
| | 37 | | <MudTh>Nome</MudTh> |
| | 38 | | <MudTh>Professor</MudTh> |
| | 39 | | <MudTh>Selecionada</MudTh> |
| | 40 | | </HeaderContent> |
| | 41 | | <RowTemplate> |
| | 42 | | <MudTd DataLabel="Disciplina">@context.Discipline</MudTd> |
| | 43 | | <MudTd DataLabel="Professor">@context.Teacher</MudTd> |
| | 44 | | <MudTd DataLabel="Selecionada"> |
| | 45 | | <MudCheckBox |
| | 46 | | T="bool" |
| | 47 | | Class="pl-7 pr-1" |
| | 48 | | Dense="true" |
| | 49 | | Size="Size.Small" |
| | 50 | | Color="Color.Success" |
| | 51 | | Value="@context.IsSelected" |
| 0 | 52 | | ValueChanged="x => { context.IsSelected = x; }"/> |
| | 53 | | </MudTd> |
| | 54 | | </RowTemplate> |
| | 55 | | <NoRecordsContent> |
| | 56 | | @(GetNotFoundMessage()) |
| | 57 | | </NoRecordsContent> |
| | 58 | | <LoadingContent> |
| 0 | 59 | | @if (_breakpoint == Breakpoint.Xs) |
| | 60 | | { |
| | 61 | | <MudProgressLinear Color="Color.Info" Indeterminate="true" /> |
| | 62 | | } |
| | 63 | | </LoadingContent> |
| | 64 | | <PagerContent> |
| | 65 | | <MudDivider/> |
| 0 | 66 | | @if (_showButtons) |
| | 67 | | { |
| | 68 | | <MudStack Row="true" Class="mt-4"> |
| | 69 | | <DialogCancelButton OnClick="@Cancel" /> |
| | 70 | | <SykiProgressCircular Loading="@_loading" /> |
| | 71 | | <DialogSaveButton Class="mr-2" OnClick="@Submit" Text="Iniciar" /> |
| | 72 | | </MudStack> |
| | 73 | | } |
| | 74 | | </PagerContent> |
| | 75 | | </MudTable> |
| | 76 | | </DialogContent> |
| | 77 | | </MudDialog> |
| | 78 | |
|
| | 79 | | @inject ISnackbar Snackbar |
| | 80 | | @inject StartClassesClient StartClient |
| | 81 | | @inject GetAcademicClassesClient GetClient |
| | 82 | | @inject IBrowserViewportService BrowserViewportService |
| | 83 | |
|
| | 84 | | @code |
| | 85 | | { |
| | 86 | | [CascadingParameter] |
| 0 | 87 | | MudDialogInstance MudDialog { get; set; } |
| | 88 | |
|
| | 89 | | private bool _loading; |
| | 90 | | private bool _showButtons; |
| | 91 | | private string _searchString; |
| 0 | 92 | | private List<ClassOut> _classes = []; |
| | 93 | | private Breakpoint _breakpoint; |
| | 94 | |
|
| | 95 | | protected override async Task OnInitializedAsync() |
| | 96 | | { |
| 0 | 97 | | _loading = true; |
| 0 | 98 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 99 | | _classes = await GetClient.Get(new() { Status = ClassStatus.AwaitingStart }); |
| 0 | 100 | | _loading = false; |
| 0 | 101 | | _showButtons = true; |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | private void SelectAll() |
| | 105 | | { |
| 0 | 106 | | _classes.ForEach(x => x.IsSelected = true); |
| 0 | 107 | | } |
| | 108 | | private void UnselectAll() |
| | 109 | | { |
| 0 | 110 | | _classes.ForEach(x => x.IsSelected = false); |
| 0 | 111 | | } |
| | 112 | |
|
| | 113 | | private async Task Submit() |
| | 114 | | { |
| 0 | 115 | | if (_loading) return; |
| | 116 | |
|
| 0 | 117 | | _loading = true; |
| 0 | 118 | | var ids = _classes.Where(c => c.IsSelected).Select(c => c.Id).ToList(); |
| 0 | 119 | | var response = await StartClient.Start(ids); |
| 0 | 120 | | if (response.IsSuccess()) |
| | 121 | | { |
| 0 | 122 | | MudDialog.Close(DialogResult.Ok(true)); |
| 0 | 123 | | Snackbar.Add("Turmas iniciadas com sucesso!", Severity.Success); |
| | 124 | | } |
| | 125 | | else |
| | 126 | | { |
| 0 | 127 | | Snackbar.Add(response.GetError().Message, Severity.Error); |
| | 128 | | } |
| 0 | 129 | | _loading = false; |
| 0 | 130 | | } |
| | 131 | |
|
| 0 | 132 | | private void Cancel() => MudDialog.Cancel(); |
| | 133 | |
|
| 0 | 134 | | private Func<ClassOut, bool> _quickFilter => x => _searchString.IsIn(x.Discipline); |
| | 135 | |
|
| | 136 | | private string GetNotFoundMessage() |
| | 137 | | { |
| 0 | 138 | | return (_searchString.IsEmpty()) ? "Não existem turmas para serem iniciadas." : "Nenhuma turma encontrada."; |
| | 139 | | } |
| | 140 | | } |