| | 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 ou cidade" /> |
| | 29 | | </ToolBarContent> |
| | 30 | | <Columns> |
| | 31 | | <PropertyColumn Property="x => x.Name" Title="Nome" /> |
| | 32 | | <PropertyColumn Property="x => x.City" Title="Cidade" /> |
| | 33 | | <TemplateColumn CellClass="d-flex justify-end"> |
| | 34 | | <CellTemplate> |
| 0 | 35 | | <MudIconButton Size="@Size.Small" Icon="@Icons.Material.Outlined.Edit" OnClick="@(() => OpenEdit |
| | 36 | | </CellTemplate> |
| | 37 | | </TemplateColumn> |
| | 38 | | </Columns> |
| | 39 | | <NoRecordsContent> |
| | 40 | | @(GetNotFoundMessage()) |
| | 41 | | </NoRecordsContent> |
| | 42 | | <PagerContent> |
| | 43 | | <SykiDataGridPager T="@CampusOut" /> |
| | 44 | | </PagerContent> |
| | 45 | | </MudDataGrid> |
| | 46 | | </MudContainer> |
| | 47 | | </MudContainer> |
| | 48 | |
|
| | 49 | | @inject GetCampiClient Client |
| | 50 | | @inject IDialogService DialogService |
| | 51 | | @inject IBrowserViewportService BrowserViewportService |
| | 52 | |
|
| | 53 | | @code |
| | 54 | | { |
| | 55 | | private bool _loading; |
| | 56 | | private string _searchString; |
| 0 | 57 | | private List<CampusOut> _campi = []; |
| | 58 | |
|
| | 59 | | protected override async Task OnInitializedAsync() |
| | 60 | | { |
| 0 | 61 | | _loading = true; |
| 0 | 62 | | _campi = await Client.Get(); |
| 0 | 63 | | _loading = false; |
| 0 | 64 | | } |
| | 65 | |
|
| 0 | 66 | | private Func<CampusOut, bool> _quickFilter => x => _searchString.IsIn(x.Name, x.City); |
| | 67 | |
|
| | 68 | | private async Task OpenDialog() |
| | 69 | | { |
| 0 | 70 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 71 | | var options = new DialogOptions { |
| 0 | 72 | | MaxWidth = MaxWidth.Small, |
| 0 | 73 | | FullWidth = true, |
| 0 | 74 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 75 | | }; |
| 0 | 76 | | var dialog = await DialogService.ShowAsync<CreateCampusDialog>("", options); |
| | 77 | |
|
| 0 | 78 | | var result = await dialog.Result; |
| | 79 | |
|
| 0 | 80 | | if (result!.Canceled) return; |
| | 81 | |
|
| 0 | 82 | | await OnInitializedAsync(); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | private async Task OpenEditDialog(CampusOut item) |
| | 86 | | { |
| 0 | 87 | | var parameters = new DialogParameters<UpdateCampusDialog>(); |
| 0 | 88 | | parameters.Add(x => x.Campus, item); |
| | 89 | |
|
| 0 | 90 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 91 | | var options = new DialogOptions { |
| 0 | 92 | | MaxWidth = MaxWidth.Small, |
| 0 | 93 | | FullWidth = true, |
| 0 | 94 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 95 | | }; |
| 0 | 96 | | var dialog = await DialogService.ShowAsync<UpdateCampusDialog>("", parameters, options); |
| | 97 | |
|
| 0 | 98 | | var result = await dialog.Result; |
| | 99 | |
|
| 0 | 100 | | if (result!.Canceled) return; |
| | 101 | |
|
| 0 | 102 | | await OnInitializedAsync(); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | private string GetNotFoundMessage() |
| | 106 | | { |
| 0 | 107 | | return (_searchString.IsEmpty()) ? "Não existem campus cadastrados ainda." : "Nenhum campus encontrado."; |
| | 108 | | } |
| | 109 | | } |