29ac56006d
- Add pipeline registry with JSON-based configuration and hot-reload support - Implement manual sync request feature with API, client UI, and database - Improve ConfigManager: connection string dropdown in pipeline editor, step delete/reorder functionality, and fix JSON parsing for ConnectionStrings
115 lines
3.3 KiB
C#
115 lines
3.3 KiB
C#
using System.Net.Http.Json;
|
|
using JdeScoping.Core.ViewModels;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Radzen;
|
|
|
|
namespace JdeScoping.Client.Components.DataSync;
|
|
|
|
/// <summary>
|
|
/// Dialog component for creating new manual sync requests.
|
|
/// </summary>
|
|
public partial class NewSyncRequestDialog : ComponentBase
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets the Radzen dialog service for closing the dialog.
|
|
/// </summary>
|
|
[Inject]
|
|
private DialogService DialogService { get; set; } = default!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the HTTP client for API calls.
|
|
/// </summary>
|
|
[Inject]
|
|
private HttpClient HttpClient { get; set; } = default!;
|
|
|
|
/// <summary>
|
|
/// Gets or sets the available pipelines to select from.
|
|
/// </summary>
|
|
[Parameter]
|
|
public List<PipelineInfoViewModel> Pipelines { get; set; } = new();
|
|
|
|
private string? _selectedPipeline;
|
|
private string? _selectedSyncType;
|
|
private List<string> _availableSyncTypes = new();
|
|
private bool _isCreating;
|
|
|
|
/// <summary>
|
|
/// Determines if the Create button should be enabled.
|
|
/// </summary>
|
|
private bool CanCreate => !string.IsNullOrEmpty(_selectedPipeline) &&
|
|
!string.IsNullOrEmpty(_selectedSyncType) &&
|
|
!_isCreating;
|
|
|
|
/// <summary>
|
|
/// Handles pipeline selection change by filtering available sync types.
|
|
/// </summary>
|
|
private void OnPipelineChanged()
|
|
{
|
|
// Reset sync type when pipeline changes
|
|
_selectedSyncType = null;
|
|
|
|
if (string.IsNullOrEmpty(_selectedPipeline))
|
|
{
|
|
_availableSyncTypes = new();
|
|
return;
|
|
}
|
|
|
|
// Find the selected pipeline and get its supported sync types
|
|
var pipeline = Pipelines.FirstOrDefault(p => p.Name == _selectedPipeline);
|
|
_availableSyncTypes = pipeline?.SupportedSyncTypes ?? new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the Cancel button click by closing the dialog with null result.
|
|
/// </summary>
|
|
private void OnCancelAsync()
|
|
{
|
|
DialogService.Close(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the Create button click by calling the API and closing with the result.
|
|
/// </summary>
|
|
private async Task OnCreateAsync()
|
|
{
|
|
if (!CanCreate)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_isCreating = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
var createDto = new CreateManualSyncRequestDto
|
|
{
|
|
PipelineName = _selectedPipeline!,
|
|
SyncType = _selectedSyncType!
|
|
};
|
|
|
|
var response = await HttpClient.PostAsJsonAsync("api/manual-sync", createDto);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var createdRequest = await response.Content.ReadFromJsonAsync<ManualSyncRequestViewModel>();
|
|
DialogService.Close(createdRequest);
|
|
}
|
|
else
|
|
{
|
|
// On error, close with null (parent can show notification if needed)
|
|
DialogService.Close(null);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// On exception, close with null
|
|
DialogService.Close(null);
|
|
}
|
|
finally
|
|
{
|
|
_isCreating = false;
|
|
}
|
|
}
|
|
}
|