feat: add Deploy Artifacts button to Sites admin page
This commit is contained in:
@@ -2,13 +2,25 @@
|
||||
@using ScadaLink.Security
|
||||
@using ScadaLink.Commons.Entities.Sites
|
||||
@using ScadaLink.Commons.Interfaces.Repositories
|
||||
@using ScadaLink.DeploymentManager
|
||||
@attribute [Authorize(Policy = AuthorizationPolicies.RequireAdmin)]
|
||||
@inject ISiteRepository SiteRepository
|
||||
@inject ArtifactDeploymentService ArtifactDeploymentService
|
||||
|
||||
<div class="container-fluid mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0">Site Management</h4>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddForm">Add Site</button>
|
||||
<div>
|
||||
<button class="btn btn-outline-warning btn-sm me-1" @onclick="DeployArtifactsToAllSites"
|
||||
disabled="@_deploying">
|
||||
@if (_deploying)
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm me-1" role="status"></span>
|
||||
}
|
||||
Deploy Artifacts to All Sites
|
||||
</button>
|
||||
<button class="btn btn-primary btn-sm" @onclick="ShowAddForm">Add Site</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ToastNotification @ref="_toast" />
|
||||
@@ -64,7 +76,7 @@
|
||||
<th>Identifier</th>
|
||||
<th>Description</th>
|
||||
<th>Data Connections</th>
|
||||
<th style="width: 160px;">Actions</th>
|
||||
<th style="width: 260px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -100,6 +112,9 @@
|
||||
<td>
|
||||
<button class="btn btn-outline-primary btn-sm py-0 px-1 me-1"
|
||||
@onclick="() => EditSite(site)">Edit</button>
|
||||
<button class="btn btn-outline-warning btn-sm py-0 px-1 me-1"
|
||||
@onclick="() => DeployArtifacts(site)"
|
||||
disabled="@_deploying">Deploy Artifacts</button>
|
||||
<button class="btn btn-outline-danger btn-sm py-0 px-1"
|
||||
@onclick="() => DeleteSite(site)">Delete</button>
|
||||
</td>
|
||||
@@ -123,6 +138,8 @@
|
||||
private string? _formDescription;
|
||||
private string? _formError;
|
||||
|
||||
private bool _deploying;
|
||||
|
||||
private ToastNotification _toast = default!;
|
||||
private ConfirmDialog _confirmDialog = default!;
|
||||
|
||||
@@ -246,4 +263,57 @@
|
||||
_toast.ShowError($"Delete failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeployArtifacts(Site site)
|
||||
{
|
||||
_deploying = true;
|
||||
try
|
||||
{
|
||||
var command = await ArtifactDeploymentService.BuildDeployArtifactsCommandAsync();
|
||||
var result = await ArtifactDeploymentService.RetryForSiteAsync(
|
||||
site.SiteIdentifier, command, "system");
|
||||
|
||||
if (result.IsSuccess)
|
||||
_toast.ShowSuccess($"Artifacts deployed to '{site.Name}'.");
|
||||
else
|
||||
_toast.ShowError($"Deploy to '{site.Name}' failed: {result.Error}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_toast.ShowError($"Deploy to '{site.Name}' failed: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_deploying = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeployArtifactsToAllSites()
|
||||
{
|
||||
_deploying = true;
|
||||
try
|
||||
{
|
||||
var command = await ArtifactDeploymentService.BuildDeployArtifactsCommandAsync();
|
||||
var result = await ArtifactDeploymentService.DeployToAllSitesAsync(command, "system");
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
var summary = result.Value!;
|
||||
_toast.ShowSuccess(
|
||||
$"Artifacts deployed: {summary.SuccessCount} succeeded, {summary.FailureCount} failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_toast.ShowError($"Artifact deployment failed: {result.Error}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_toast.ShowError($"Artifact deployment failed: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_deploying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user