Add dynamic operations change UI
This commit is contained in:
@ -11,6 +11,8 @@
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject HeadquartersService HeadquartersService
|
||||
@inject CampaignManagementState CampaignManagementState
|
||||
@inject OperationExecutionState OperationExecutionState
|
||||
@inject ResultWaitState ResultWaitState
|
||||
|
||||
<PageTitle>Кампании</PageTitle>
|
||||
|
||||
@ -24,7 +26,7 @@
|
||||
</RadzenRow>
|
||||
<RadzenRow>
|
||||
<RadzenColumn SizeMD="12">
|
||||
<RadzenDataGrid @ref="@dataGrid" TItem="Campaign" Data="@campaigns" RowExpand="@RowExpandAsync" IsLoading="@(state != CampaignsPageState.Idle)" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true" ExpandMode="DataGridExpandMode.Single">
|
||||
<RadzenDataGrid @ref="@dataGrid" TItem="Campaign" Data="@campaigns" RowExpand="@RowExpandAsync" RowCollapse="@RowCollapse" IsLoading="@(state != CampaignsPageState.Idle)" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true" ExpandMode="DataGridExpandMode.Single">
|
||||
<Template Context="campaign">
|
||||
<RadzenDataGrid Data="@campaign.Operations" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true">
|
||||
<Columns>
|
||||
@ -41,7 +43,7 @@
|
||||
<Columns>
|
||||
<RadzenDataGridColumn TItem="Campaign" Property="Id" Title="ID" SortOrder="SortOrder.Descending" Resizable="false" Width="100px" MaxWidth="100px" />
|
||||
<RadzenDataGridColumn TItem="Campaign" Property="Type" Title="Тип кампании" />
|
||||
<RadzenDataGridColumn Title="Состояние" Filterable="false" Sortable="false" Resizable="false" Width="70px" MaxWidth="70px">
|
||||
<RadzenDataGridColumn Title="Прогресс" Filterable="false" Sortable="false" Resizable="false" Width="70px" MaxWidth="70px">
|
||||
<Template Context="campaign">
|
||||
<RadzenProgressBar ProgressBarStyle="@(campaign.EndedAt.HasValue ? (string.IsNullOrEmpty(campaign.FailureReason) ? ProgressBarStyle.Success : ProgressBarStyle.Danger) : ProgressBarStyle.Primary)" Value="@campaign.Progress" ShowValue="false" />
|
||||
</Template>
|
||||
@ -88,6 +90,12 @@
|
||||
CampaignManagementState.OnCampaignStarted += OnCampaignStarted;
|
||||
CampaignManagementState.OnCampaignProgressStep += OnCampaignProgressStep;
|
||||
CampaignManagementState.OnCampaignEnded += OnCampaignEnded;
|
||||
|
||||
OperationExecutionState.OnOperationStarted += OnOperationStarted;
|
||||
OperationExecutionState.OnOperationExecuted += OnOperationExecuted;
|
||||
OperationExecutionState.OnOperationEnded += OnOperationEnded;
|
||||
|
||||
ResultWaitState.OnOperationEnded += OnOperationEnded;
|
||||
}
|
||||
|
||||
ChangeState(CampaignsPageState.Idle);
|
||||
@ -104,6 +112,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
void RowCollapse(Campaign campaign)
|
||||
{
|
||||
if (expandedCampaign != null && expandedCampaign.Id == campaign.Id)
|
||||
{
|
||||
expandedCampaign = null;
|
||||
}
|
||||
|
||||
campaign.Operations = null;
|
||||
}
|
||||
|
||||
void ChangeState(CampaignsPageState state)
|
||||
{
|
||||
if (this.state == state) return;
|
||||
@ -131,8 +149,6 @@
|
||||
if (expandedCampaign != null && expandedCampaign.Id == campaign.Id)
|
||||
{
|
||||
dataGrid.CollapseAll();
|
||||
|
||||
expandedCampaign.Operations = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -150,8 +166,6 @@
|
||||
if (expandedCampaign != null && expandedCampaign.Id == campaign.Id)
|
||||
{
|
||||
dataGrid.CollapseAll();
|
||||
|
||||
expandedCampaign.Operations = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -162,6 +176,52 @@
|
||||
Task.Run(RefreshCampaigns);
|
||||
}
|
||||
|
||||
void OnOperationStarted(Operation operation)
|
||||
{
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
if (expandedCampaign != null && expandedCampaign.Id == operation.CampaignId)
|
||||
{
|
||||
var targetOperation = expandedCampaign.Operations?.FirstOrDefault(x => x.Id == operation.Id);
|
||||
if (targetOperation != null)
|
||||
{
|
||||
targetOperation.StartedAt = operation.StartedAt;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void OnOperationExecuted(Operation operation)
|
||||
{
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
if (expandedCampaign != null && expandedCampaign.Id == operation.CampaignId)
|
||||
{
|
||||
var targetOperation = expandedCampaign.Operations?.FirstOrDefault(x => x.Id == operation.Id);
|
||||
if (targetOperation != null)
|
||||
{
|
||||
targetOperation.MessageGuid = operation.MessageGuid;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void OnOperationEnded(Operation operation)
|
||||
{
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
if (expandedCampaign != null && expandedCampaign.Id == operation.CampaignId)
|
||||
{
|
||||
var targetOperation = expandedCampaign.Operations?.FirstOrDefault(x => x.Id == operation.Id);
|
||||
if (targetOperation != null)
|
||||
{
|
||||
targetOperation.EndedAt = operation.EndedAt;
|
||||
targetOperation.FailureReason = operation.FailureReason;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async Task RefreshCampaigns()
|
||||
{
|
||||
await InvokeAsync(() => ChangeState(CampaignsPageState.Loading));
|
||||
@ -183,5 +243,11 @@
|
||||
CampaignManagementState.OnCampaignStarted -= OnCampaignStarted;
|
||||
CampaignManagementState.OnCampaignProgressStep -= OnCampaignProgressStep;
|
||||
CampaignManagementState.OnCampaignEnded -= OnCampaignEnded;
|
||||
|
||||
OperationExecutionState.OnOperationStarted -= OnOperationStarted;
|
||||
OperationExecutionState.OnOperationExecuted -= OnOperationExecuted;
|
||||
OperationExecutionState.OnOperationEnded -= OnOperationEnded;
|
||||
|
||||
ResultWaitState.OnOperationEnded -= OnOperationEnded;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user