Skip to content

Commit

Permalink
Trigger tasks from Home (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-b authored Mar 17, 2024
1 parent cbb6d15 commit 4a24e53
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ else
public int? AreaId { get; set; }
[Parameter]
public int? AssetId { get; set; }
[Parameter]
public EventCallback<bool> OnDataUpdated { get; set; }

private List<TaskDefinition>? taskDefinitions;

Expand Down Expand Up @@ -85,6 +87,10 @@ else
{
await TaskDefinitionService.DeleteAsync(id);
await LoadTaskDefinitions();
if (OnDataUpdated.HasDelegate)
{
await OnDataUpdated.InvokeAsync(true);
}
}
}

Expand All @@ -98,5 +104,9 @@ else
// Status = TaskInstanceStatus.InProgress
};
await TaskInstanceService.AddAsync(taskInstance);
if (OnDataUpdated.HasDelegate)
{
await OnDataUpdated.InvokeAsync(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ else
_userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
}

private async Task LoadTaskInstances()
public async Task LoadTaskInstances()
{
taskInstances = (await TaskInstanceService.GetAsync())
.Where(t => !TaskDefinitionId.HasValue || (t.TaskDefinitionId == TaskDefinitionId))
Expand Down
16 changes: 15 additions & 1 deletion src/MaintenanceLog.Client/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/"
@using MaintenanceLog.Client.Components.TaskDefinitions
@using MaintenanceLog.Client.Components.TaskInstances

@inject Blazored.LocalStorage.ILocalStorageService LocalStorage
Expand All @@ -18,17 +19,30 @@
<h2 class="pt-4">Tasks</h2>
<input type="checkbox" @bind="onlyActive" /> Only Active

<TaskInstanceGrid OnlyShowActive="@onlyActive" />
<TaskInstanceGrid OnlyShowActive="@onlyActive" @ref="taskInstanceGrid" />

<h2 class="pt-4">Definitions</h2>
<TaskDefinitionGrid OnDataUpdated="OnTaskDefinitionsUpdated"/>
</Authorized>
</AuthorizeView>

@code
{
private bool? onlyActive = true;
TaskInstanceGrid? taskInstanceGrid;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
//onlyActive = await LocalStorage.GetItemAsync<bool?>(nameof(onlyActive));
await base.OnAfterRenderAsync(firstRender);
}

private async Task OnTaskDefinitionsUpdated(bool updated)
{
if (taskInstanceGrid is not null)
{
// may be a better way than component reference here
await taskInstanceGrid.LoadTaskInstances();
}
}
}

0 comments on commit 4a24e53

Please sign in to comment.