| | 1 | | @using Syki.Front.Features.Academic.CreateCourse |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Academic |
| | 4 | |
|
| | 5 | | @page "/academic/courses" |
| | 6 | | @attribute [Authorize(Roles = "Academic")] |
| | 7 | |
|
| | 8 | | <SykiPageTitle Title="Cursos" /> |
| | 9 | |
|
| | 10 | | <MudContainer Class="my-4 px-4"> |
| | 11 | | <SykiPageHeader Icon="@Icons.Material.Filled.Class" Title="Cursos" ButtonText="Novo Curso" OnClick="@OpenDialog"/> |
| | 12 | | <SykiPageAlert Text="Note que um mesmo curso pode ser ofertado em mais de um campus." /> |
| | 13 | | <MudContainer Class="px-0 mb-4"> |
| | 14 | | <MudDataGrid |
| | 15 | | Class="pa-4" |
| | 16 | | Items="@_courses" |
| | 17 | | QuickFilter="@_quickFilter" |
| | 18 | | Hover="true" |
| | 19 | | Dense="true" |
| | 20 | | Loading="@_loading" |
| | 21 | | RowsPerPage="10" |
| | 22 | | > |
| | 23 | | <ToolBarContent> |
| | 24 | | <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por nome ou tipo" /> |
| | 25 | | </ToolBarContent> |
| | 26 | | <Columns> |
| | 27 | | <PropertyColumn Property="x => x.Name" Title="Nome" /> |
| | 28 | | <PropertyColumn Property="x => x.Type.GetDescription()" Title="Tipo" /> |
| | 29 | | </Columns> |
| | 30 | | <NoRecordsContent> |
| | 31 | | @(GetNotFoundMessage()) |
| | 32 | | </NoRecordsContent> |
| | 33 | | <PagerContent> |
| | 34 | | <SykiDataGridPager T="CourseOut" /> |
| | 35 | | </PagerContent> |
| | 36 | | </MudDataGrid> |
| | 37 | | </MudContainer> |
| | 38 | | </MudContainer> |
| | 39 | |
|
| | 40 | | @inject GetCoursesClient Client |
| | 41 | | @inject IDialogService DialogService |
| | 42 | | @inject IBrowserViewportService BrowserViewportService |
| | 43 | |
|
| | 44 | | @code |
| | 45 | | { |
| | 46 | | private bool _loading; |
| | 47 | | private string _searchString; |
| 0 | 48 | | private List<CourseOut> _courses = []; |
| | 49 | |
|
| | 50 | | protected override async Task OnInitializedAsync() |
| | 51 | | { |
| 0 | 52 | | _loading = true; |
| 0 | 53 | | _courses = await Client.Get() ?? []; |
| 0 | 54 | | _loading = false; |
| 0 | 55 | | } |
| | 56 | |
|
| 0 | 57 | | private Func<CourseOut, bool> _quickFilter => x => _searchString.IsIn(x.Name, x.Type.GetDescription()); |
| | 58 | |
|
| | 59 | | private async Task OpenDialog() |
| | 60 | | { |
| 0 | 61 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 62 | | var options = new DialogOptions { |
| 0 | 63 | | MaxWidth = MaxWidth.Small, |
| 0 | 64 | | FullWidth = true, |
| 0 | 65 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 66 | | }; |
| 0 | 67 | | var dialog = await DialogService.ShowAsync<CreateCourseDialog>("", options); |
| | 68 | |
|
| 0 | 69 | | var result = await dialog.Result; |
| | 70 | |
|
| 0 | 71 | | if (result!.Canceled) return; |
| | 72 | |
|
| 0 | 73 | | await OnInitializedAsync(); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private string GetNotFoundMessage() |
| | 77 | | { |
| 0 | 78 | | return (_searchString.IsEmpty()) ? "Não existem cursos cadastrados ainda." : "Nenhum curso encontrado."; |
| | 79 | | } |
| | 80 | | } |