| | 1 | | @using Syki.Front.Features.Academic.GetCampi |
| | 2 | | @using Syki.Front.Features.Academic.CreateCampus |
| | 3 | | @using Syki.Front.Features.Academic.UpdateCampus |
| | 4 | |
|
| | 5 | | @namespace Syki.Front.Pages.Academic |
| | 6 | |
|
| | 7 | | @page "/academic/campi" |
| | 8 | | @attribute [Authorize(Roles = "Academic")] |
| | 9 | |
|
| | 10 | | <SykiPageTitle Title="Campi" /> |
| | 11 | |
|
| | 12 | | <MudContainer Class="my-4 px-4"> |
| | 13 | | <SykiPageHeader Icon="@Icons.Material.Filled.GroupWork" Title="Campi" ButtonText="Novo Campus" OnClick="@OpenDialog" |
| | 14 | | <SykiPageAlert Text="Sua instituição pode ser formada por vários campus." /> |
| | 15 | | <MudContainer Class="px-0 mb-4"> |
| | 16 | | <MudDataGrid |
| | 17 | | T="CampusOut" |
| | 18 | | Class="pa-4" |
| | 19 | | Items="@_campi" |
| | 20 | | QuickFilter="@_quickFilter" |
| | 21 | | Dense="true" |
| | 22 | | Hover="true" |
| | 23 | | ReadOnly="true" |
| | 24 | | Loading="@_loading" |
| | 25 | | RowsPerPage="10" |
| | 26 | | > |
| | 27 | | <ToolBarContent> |
| | 28 | | <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome, estado ou cidade |
| | 29 | | </ToolBarContent> |
| | 30 | | <Columns> |
| | 31 | | <PropertyColumn Property="x => x.Name" Title="Nome" /> |
| | 32 | | <PropertyColumn Property="x => x.State" Title="Estado" /> |
| | 33 | | <PropertyColumn Property="x => x.City" Title="Cidade" /> |
| | 34 | | <PropertyColumn Property="x => x.Students.ToThousandSeparated()" Title="Alunos" /> |
| | 35 | | <PropertyColumn Property="x => x.Capacity.ToThousandSeparated()" Title="Capacidade" /> |
| | 36 | | <PropertyColumn Property="x => x.GetFillRate()" Title="Ocupação" /> |
| | 37 | | <PropertyColumn Property="x => x.Teachers.ToThousandSeparated()" Title="Professores" /> |
| | 38 | | <TemplateColumn CellClass="d-flex justify-end"> |
| | 39 | | <CellTemplate> |
| 0 | 40 | | <MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Edit" OnClick="@(() => OpenEdit |
| | 41 | | </CellTemplate> |
| | 42 | | </TemplateColumn> |
| | 43 | | </Columns> |
| | 44 | | <NoRecordsContent> |
| 0 | 45 | | @(GetNotFoundMessage()) |
| | 46 | | </NoRecordsContent> |
| | 47 | | <PagerContent> |
| | 48 | | <SykiDataGridPager T="@CampusOut" /> |
| | 49 | | </PagerContent> |
| | 50 | | </MudDataGrid> |
| | 51 | | </MudContainer> |
| | 52 | | </MudContainer> |
| | 53 | |
|
| | 54 | | @inject GetCampiClient Client |
| | 55 | | @inject IDialogService DialogService |
| | 56 | | @inject IBrowserViewportService BrowserViewportService |
| | 57 | |
|
| | 58 | | @code |
| | 59 | | { |
| | 60 | | private bool _loading; |
| | 61 | | private string _searchString; |
| 0 | 62 | | private List<CampusOut> _campi = []; |
| | 63 | |
|
| | 64 | | protected override async Task OnInitializedAsync() |
| | 65 | | { |
| 0 | 66 | | _loading = true; |
| 0 | 67 | | _campi = await Client.Get(); |
| 0 | 68 | | _loading = false; |
| 0 | 69 | | } |
| | 70 | |
|
| 0 | 71 | | private Func<CampusOut, bool> _quickFilter => x => _searchString.IsIn(x.Name, x.State.ToString(), x.City); |
| | 72 | |
|
| | 73 | | private async Task OpenDialog() |
| | 74 | | { |
| 0 | 75 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 76 | | var options = new DialogOptions { |
| 0 | 77 | | MaxWidth = MaxWidth.Small, |
| 0 | 78 | | FullWidth = true, |
| 0 | 79 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 80 | | }; |
| 0 | 81 | | var dialog = await DialogService.ShowAsync<CreateCampusDialog>("", options); |
| | 82 | |
|
| 0 | 83 | | var result = await dialog.Result; |
| | 84 | |
|
| 0 | 85 | | if (result!.Canceled) return; |
| | 86 | |
|
| 0 | 87 | | await OnInitializedAsync(); |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | private async Task OpenEditDialog(CampusOut item) |
| | 91 | | { |
| 0 | 92 | | var parameters = new DialogParameters<UpdateCampusDialog>(); |
| 0 | 93 | | parameters.Add(x => x.Campus, item); |
| | 94 | |
|
| 0 | 95 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 96 | | var options = new DialogOptions { |
| 0 | 97 | | MaxWidth = MaxWidth.Small, |
| 0 | 98 | | FullWidth = true, |
| 0 | 99 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 100 | | }; |
| 0 | 101 | | var dialog = await DialogService.ShowAsync<UpdateCampusDialog>("", parameters, options); |
| | 102 | |
|
| 0 | 103 | | var result = await dialog.Result; |
| | 104 | |
|
| 0 | 105 | | if (result!.Canceled) return; |
| | 106 | |
|
| 0 | 107 | | await OnInitializedAsync(); |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | private string GetNotFoundMessage() |
| | 111 | | { |
| 0 | 112 | | return (_searchString.IsEmpty()) ? "Não existem campus cadastrados ainda." : "Nenhum campus encontrado."; |
| | 113 | | } |
| | 114 | | } |