* Changed Grid to Add new records for Scheduler

This commit is contained in:
2025-02-16 20:17:33 +01:00
parent 06efb220dc
commit db06837ce9

View File

@@ -1,23 +1,11 @@
@page "/Admin/Scheduler"
@using OrdersManagementDataModel.Dtos
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.Buttons
@using OrdersManagement.Components
@using Action = Syncfusion.Blazor.Grids.Action
@inject HangfireService HangfireService
<h3>Zarządzanie Zadaniami</h3>
<br />
<div id="wrapper">
<SfTextBox @bind-Value="NewTask.Name" Placeholder="Nazwa zadania"></SfTextBox>
<SfTextBox @bind-Value="NewTask.Path" Placeholder="Ścieżka do aplikacji"></SfTextBox>
<SfTextBox @bind-Value="NewTask.CronOptions" Placeholder="CRON"></SfTextBox>
<br />
<div>
<SfButton Content="Dodaj Zadanie" @onclick="AddTask"></SfButton>
</div>
</div>
<br />
<SfGrid DataSource="@Tasks" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridColumns>
<GridColumn Field=@nameof(TaskSchedulerDto.RowPointer) IsPrimaryKey="true" HeaderText="Id"></GridColumn>
@@ -27,34 +15,35 @@
<GridColumn Field=@nameof(TaskSchedulerDto.LastExecution) HeaderText="Ostatnie Uruchomienie"></GridColumn>
<GridColumn Field=@nameof(TaskSchedulerDto.NextExecution) HeaderText="Następne Uruchomienie"></GridColumn>
</GridColumns>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true"></GridEditSettings>
<GridEvents OnActionBegin="OnActionBegin" TValue="TaskSchedulerDto"></GridEvents>
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" NewRowPosition="NewRowPosition.Bottom" AllowEditing="true"></GridEditSettings>
<GridEvents OnActionBegin="OnActionBegin" TValue="TaskSchedulerDto" OnActionComplete="OnActionComplete"></GridEvents>
</SfGrid>
@code {
private List<TaskSchedulerDto> Tasks { get; set; } = new();
private TaskSchedulerDto NewTask { get; set; } = new();
protected override async Task OnInitializedAsync()
{
await LoadTasks();
}
public async Task OnActionBegin(ActionEventArgs<TaskSchedulerDto> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
if (args.RequestType.Equals(Action.Delete))
{
await HangfireService.DeleteTaskSchedulerAsync(args.Data);
await LoadTasks();
}
else if (args.RequestType.Equals(Action.Add))
{
args.Data.RowPointer = Guid.NewGuid();
}
}
private async Task AddTask()
private async Task AddTask(TaskSchedulerDto taskSchedulerDto)
{
var response = await HangfireService.AddTaskSchedulerAsync(NewTask);
var response = await HangfireService.AddTaskSchedulerAsync(taskSchedulerDto);
if (response == 1)
{
NewTask = new TaskSchedulerDto();
await LoadTasks();
}
}
@@ -64,4 +53,15 @@
Tasks = (await HangfireService.GetTaskSchedulersAsync() ?? Array.Empty<TaskSchedulerDto>()).ToList();
}
private async Task OnActionComplete(ActionEventArgs<TaskSchedulerDto> args)
{
if (args.RequestType.Equals(Action.Delete))
{
await LoadTasks();
}
else if (args.RequestType.Equals(Action.Save) && args.Data.Id == 0)
{
await AddTask(args.Data);
}
}
}