| | 1 | | @using Syki.Front.Features.Academic.CreateTeacher |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Pages.Academic |
| | 4 | |
|
| | 5 | | @page "/academic/teachers" |
| | 6 | | @attribute [Authorize(Roles = "Academic")] |
| | 7 | |
|
| | 8 | | <SykiPageTitle Title="Professores" /> |
| | 9 | |
|
| | 10 | | <MudContainer Class="my-4 px-4"> |
| | 11 | | <SykiPageHeader Icon="@Icons.Material.Filled.Person4" Title="Professores" ButtonText="Novo Professor" OnClick="@Open |
| | 12 | | <SykiPageAlert Text="Um professor pode lecionar várias disciplinas ao longo de um período, inclusive em mais de um c |
| | 13 | | <MudContainer Class="px-0 mb-4"> |
| | 14 | | <MudTable |
| | 15 | | Class="pa-4" |
| | 16 | | Items="@_teachers" |
| | 17 | | Filter="@_quickFilter" |
| | 18 | | Hover="true" |
| | 19 | | Loading="@_loading" |
| | 20 | | Dense="true" |
| | 21 | | RowsPerPage="10" |
| | 22 | | > |
| | 23 | | <ToolBarContent> |
| | 24 | | <SykiDataGridSearchTextField @bind-Value="@_searchString" Placeholder="Busque por qualquer atributo"/> |
| | 25 | | </ToolBarContent> |
| | 26 | | <HeaderContent> |
| | 27 | | <MudTh>Nome</MudTh> |
| | 28 | | <MudTh>Email</MudTh> |
| | 29 | | <AuthorizeView Policy="@FrontPolicy.CrossLogin" Context="authContext"> |
| | 30 | | <MudTh></MudTh> |
| | 31 | | </AuthorizeView> |
| | 32 | | </HeaderContent> |
| | 33 | | <RowTemplate> |
| | 34 | | <MudTd DataLabel="Nome">@context.Name</MudTd> |
| | 35 | | <MudTd DataLabel="Email">@context.Email</MudTd> |
| | 36 | | <AuthorizeView Policy="@FrontPolicy.CrossLogin" Context="authContext"> |
| | 37 | | <MudTd> |
| 0 | 38 | | <MudIconButton Size="@Size.Small" Icon="@Icons.Material.Filled.Login" OnClick="@(() => CrossLogi |
| | 39 | | </MudTd> |
| | 40 | | </AuthorizeView> |
| | 41 | | </RowTemplate> |
| | 42 | | <LoadingContent> |
| 0 | 43 | | @if (_breakpoint == Breakpoint.Xs) |
| | 44 | | { |
| | 45 | | <MudProgressLinear Color="Color.Info" Indeterminate="true" /> |
| | 46 | | } |
| | 47 | | </LoadingContent> |
| | 48 | | <NoRecordsContent> |
| | 49 | | @(GetNotFoundMessage()) |
| | 50 | | </NoRecordsContent> |
| | 51 | | <PagerContent> |
| | 52 | | <SykiTablePager /> |
| | 53 | | </PagerContent> |
| | 54 | | </MudTable> |
| | 55 | | </MudContainer> |
| | 56 | | </MudContainer> |
| | 57 | |
|
| | 58 | | @inject NavigationManager Nav |
| | 59 | | @inject IDialogService DialogService |
| | 60 | | @inject CrossLoginClient CrossLoginClient |
| | 61 | | @inject GetTeachersClient GetTeachersClient |
| | 62 | | @inject IBrowserViewportService BrowserViewportService |
| | 63 | |
|
| | 64 | | @code |
| | 65 | | { |
| | 66 | | private bool _loading; |
| | 67 | | private string _searchString; |
| 0 | 68 | | private List<TeacherOut> _teachers = []; |
| | 69 | |
|
| | 70 | | private Breakpoint _breakpoint; |
| | 71 | |
|
| | 72 | | protected override async Task OnInitializedAsync() |
| | 73 | | { |
| 0 | 74 | | _breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 75 | | _loading = true; |
| 0 | 76 | | _teachers = await GetTeachersClient.Get(); |
| 0 | 77 | | _loading = false; |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | private async Task CrossLogin(TeacherOut teacher) |
| | 81 | | { |
| 0 | 82 | | _loading = true; |
| 0 | 83 | | await CrossLoginClient.Login(teacher.Id); |
| 0 | 84 | | Nav.NavigateTo("/", forceLoad: true); |
| 0 | 85 | | _loading = false; |
| 0 | 86 | | } |
| | 87 | |
|
| 0 | 88 | | private Func<TeacherOut, bool> _quickFilter => x => _searchString.IsIn(x.Name, x.Email); |
| | 89 | |
|
| | 90 | | private async Task OpenDialog() |
| | 91 | | { |
| 0 | 92 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 93 | | var options = new DialogOptions { |
| 0 | 94 | | MaxWidth = MaxWidth.Small, |
| 0 | 95 | | FullWidth = true, |
| 0 | 96 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 97 | | }; |
| 0 | 98 | | var dialog = await DialogService.ShowAsync<CreateTeacherDialog>("", options); |
| | 99 | |
|
| 0 | 100 | | var result = await dialog.Result; |
| | 101 | |
|
| 0 | 102 | | if (result!.Canceled) return; |
| | 103 | |
|
| 0 | 104 | | await OnInitializedAsync(); |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | private string GetNotFoundMessage() |
| | 108 | | { |
| 0 | 109 | | return (_searchString.IsEmpty()) ? "Não existem professores cadastrados ainda." : "Nenhum professor encontrado." |
| | 110 | | } |
| | 111 | | } |