114 lines
4.4 KiB
Plaintext
114 lines
4.4 KiB
Plaintext
@page "/Admin/PK/Scheduler"
|
|
|
|
@using System.Security.Claims
|
|
@using Microsoft.AspNetCore.Authorization
|
|
@using OrdersManagementDataModel.Dtos
|
|
@using Syncfusion.Blazor.Grids
|
|
@using Action = Syncfusion.Blazor.Grids.Action
|
|
@using Syncfusion.Blazor.Cards
|
|
|
|
@inject HangfireService HangfireService
|
|
@inject NavigationManager NavigationManager
|
|
@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider
|
|
|
|
<div class="h-100 d-flex justify-content-center align-items-start">
|
|
<SfCard CssClass="shadow" style="width: 100%; max-width: 1200px;">
|
|
<CardHeader>
|
|
<h3 class="text-primary">Zarządzanie Zadaniami</h3>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<SfGrid DataSource="@Tasks"
|
|
AllowPaging="true"
|
|
ShowColumnMenu="true"
|
|
Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
|
|
<GridColumns>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.RowPointer) AllowEditing="false" IsPrimaryKey="true" HeaderText="Id"
|
|
Width="100"></GridColumn>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.Name) HeaderText="Nazwa" Width="150"></GridColumn>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.Path) HeaderText="Ścieżka" Width="200"></GridColumn>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.CronOptions) HeaderText="CRON" Width="120"></GridColumn>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.LastExecution) AllowEditing="false" HeaderText="Ostatnie Uruchomienie"
|
|
Width="150"></GridColumn>
|
|
<GridColumn Field=@nameof(TaskSchedulerDto.NextExecution) AllowEditing="false" HeaderText="Następne Uruchomienie"
|
|
Width="150"></GridColumn>
|
|
</GridColumns>
|
|
<GridEditSettings AllowDeleting="true"
|
|
ShowDeleteConfirmDialog="true"
|
|
AllowAdding="true"
|
|
NewRowPosition="NewRowPosition.Bottom"
|
|
AllowEditing="true">
|
|
</GridEditSettings>
|
|
<GridEvents OnActionBegin="OnActionBegin"
|
|
OnActionComplete="OnActionComplete"
|
|
TValue="TaskSchedulerDto">
|
|
</GridEvents>
|
|
<GridPageSettings PageSize="10"></GridPageSettings>
|
|
</SfGrid>
|
|
</CardContent>
|
|
<CardFooter>
|
|
<small class="text-muted">FA Krosno Manager © @(DateTime.Now.Year)</small>
|
|
</CardFooter>
|
|
</SfCard>
|
|
</div>
|
|
|
|
@code {
|
|
private List<TaskSchedulerDto> Tasks { get; set; } = new();
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
// ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser();
|
|
//
|
|
// if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus")
|
|
// {
|
|
// NavigationManager.NavigateTo("/Unauthorized");
|
|
// }
|
|
// else
|
|
// {
|
|
await LoadTasks();
|
|
StateHasChanged();
|
|
// }
|
|
}
|
|
}
|
|
|
|
public async Task OnActionBegin(ActionEventArgs<TaskSchedulerDto> args)
|
|
{
|
|
if (args.RequestType.Equals(Action.Delete))
|
|
{
|
|
await HangfireService.DeleteTaskSchedulerAsync(args.Data);
|
|
}
|
|
else if (args.RequestType.Equals(Action.Add))
|
|
{
|
|
args.Data.RowPointer = Guid.NewGuid();
|
|
}
|
|
}
|
|
|
|
private async Task AddTask(TaskSchedulerDto taskSchedulerDto)
|
|
{
|
|
var response = await HangfireService.AddTaskSchedulerAsync(taskSchedulerDto);
|
|
if (response == 1)
|
|
{
|
|
await LoadTasks();
|
|
}
|
|
}
|
|
|
|
private async Task LoadTasks()
|
|
{
|
|
Tasks = (await HangfireService.GetTaskSchedulersAsync() ?? Array.Empty<TaskSchedulerDto>()).ToList();
|
|
}
|
|
|
|
private async Task OnActionComplete(ActionEventArgs<TaskSchedulerDto> args)
|
|
{
|
|
switch (args.RequestType)
|
|
{
|
|
case Action.Delete:
|
|
await LoadTasks();
|
|
break;
|
|
case Action.Save when args.Data.Id == 0:
|
|
await AddTask(args.Data);
|
|
break;
|
|
}
|
|
}
|
|
|
|
} |