refactor(central-ui): move Notification List form to /notifications, drop External Systems tab
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
@page "/design/external-systems"
|
||||
@using ScadaLink.Security
|
||||
@using ScadaLink.Commons.Entities.ExternalSystems
|
||||
@using ScadaLink.Commons.Entities.Notifications
|
||||
@using ScadaLink.Commons.Entities.InboundApi
|
||||
@using ScadaLink.Commons.Interfaces.Repositories
|
||||
@attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)]
|
||||
@inject IExternalSystemRepository ExternalSystemRepository
|
||||
@inject INotificationRepository NotificationRepository
|
||||
@inject IInboundApiRepository InboundApiRepository
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IDialogService Dialog
|
||||
@@ -47,15 +45,6 @@
|
||||
Database Connections <span class="badge bg-secondary">@_dbConnections.Count</span>
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link @(_tab == "notif" ? "active" : "")"
|
||||
role="tab"
|
||||
aria-selected="@(_tab == "notif" ? "true" : "false")"
|
||||
aria-controls="int-tab-notif"
|
||||
@onclick='() => _tab = "notif"'>
|
||||
Notification Lists <span class="badge bg-secondary">@_notificationLists.Count</span>
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link @(_tab == "inbound" ? "active" : "")"
|
||||
role="tab"
|
||||
@@ -75,10 +64,6 @@
|
||||
{
|
||||
<div role="tabpanel" id="int-tab-dbconn">@RenderDbConnections()</div>
|
||||
}
|
||||
else if (_tab == "notif")
|
||||
{
|
||||
<div role="tabpanel" id="int-tab-notif">@RenderNotificationLists()</div>
|
||||
}
|
||||
else if (_tab == "inbound")
|
||||
{
|
||||
<div role="tabpanel" id="int-tab-inbound">@RenderInboundApiMethods()</div>
|
||||
@@ -107,15 +92,6 @@
|
||||
? _dbConnections
|
||||
: _dbConnections.Where(dc => dc.Name?.Contains(_dbConnSearch, StringComparison.OrdinalIgnoreCase) ?? false);
|
||||
|
||||
// Notification Lists
|
||||
private List<NotificationList> _notificationLists = new();
|
||||
private Dictionary<int, List<NotificationRecipient>> _recipients = new();
|
||||
private string _notifSearch = "";
|
||||
private IEnumerable<NotificationList> FilteredNotificationLists =>
|
||||
string.IsNullOrWhiteSpace(_notifSearch)
|
||||
? _notificationLists
|
||||
: _notificationLists.Where(n => n.Name?.Contains(_notifSearch, StringComparison.OrdinalIgnoreCase) ?? false);
|
||||
|
||||
// Inbound API Methods
|
||||
private List<ApiMethod> _apiMethods = new();
|
||||
private string _apiMethodSearch = "";
|
||||
@@ -138,15 +114,6 @@
|
||||
{
|
||||
_externalSystems = (await ExternalSystemRepository.GetAllExternalSystemsAsync()).ToList();
|
||||
_dbConnections = (await ExternalSystemRepository.GetAllDatabaseConnectionsAsync()).ToList();
|
||||
_notificationLists = (await NotificationRepository.GetAllNotificationListsAsync()).ToList();
|
||||
|
||||
_recipients.Clear();
|
||||
foreach (var list in _notificationLists)
|
||||
{
|
||||
var recips = await NotificationRepository.GetRecipientsByListIdAsync(list.Id);
|
||||
if (recips.Count > 0) _recipients[list.Id] = recips.ToList();
|
||||
}
|
||||
|
||||
_apiMethods = (await InboundApiRepository.GetAllApiMethodsAsync()).ToList();
|
||||
}
|
||||
catch (Exception ex) { _errorMessage = ex.Message; }
|
||||
@@ -298,87 +265,6 @@
|
||||
catch (Exception ex) { _toast.ShowError(ex.Message); }
|
||||
}
|
||||
|
||||
// ==== Notification Lists ====
|
||||
private RenderFragment RenderNotificationLists() => __builder =>
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h5 class="mb-0">Notification Lists</h5>
|
||||
<button class="btn btn-primary btn-sm" @onclick='() => NavigationManager.NavigateTo("/design/notification-lists/create")'>Add Notification List</button>
|
||||
</div>
|
||||
|
||||
@if (_notificationLists.Count == 0)
|
||||
{
|
||||
<div class="text-center py-5 text-muted">
|
||||
<p class="mb-3">No notification lists configured.</p>
|
||||
<button class="btn btn-primary btn-sm"
|
||||
@onclick='() => NavigationManager.NavigateTo("/design/notification-lists/create")'>
|
||||
Add your first notification list
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="mb-3" style="max-width: 320px;">
|
||||
<input class="form-control form-control-sm"
|
||||
placeholder="Filter by name…"
|
||||
@bind="_notifSearch" @bind:event="oninput" />
|
||||
</div>
|
||||
|
||||
@if (!FilteredNotificationLists.Any())
|
||||
{
|
||||
<p class="text-muted small">No notification lists match the filter.</p>
|
||||
}
|
||||
|
||||
<div class="row g-3">
|
||||
@foreach (var list in FilteredNotificationLists)
|
||||
{
|
||||
var recips = _recipients.GetValueOrDefault(list.Id);
|
||||
<div class="col-lg-6 col-12" @key="list.Id">
|
||||
<div class="card h-100">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-start mb-2">
|
||||
<h5 class="card-title mb-0">@list.Name</h5>
|
||||
<div class="d-flex gap-1">
|
||||
<button class="btn btn-outline-primary btn-sm" @onclick='() => NavigationManager.NavigateTo($"/design/notification-lists/{list.Id}/edit")'>Edit</button>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary btn-sm"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
aria-label="@($"More actions for {list.Name}")">⋮</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li><button class="dropdown-item text-danger" @onclick="() => DeleteNotifList(list)">Delete</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@if (recips == null || recips.Count == 0)
|
||||
{
|
||||
<p class="text-muted small fst-italic mb-0">No recipients.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div>
|
||||
@foreach (var r in recips)
|
||||
{
|
||||
<span class="badge bg-light text-dark me-1 mb-1">@r.Name <@r.EmailAddress></span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
};
|
||||
|
||||
private async Task DeleteNotifList(NotificationList list)
|
||||
{
|
||||
if (!await Dialog.ConfirmAsync("Delete", $"Delete notification list '{list.Name}'?", danger: true)) return;
|
||||
try { await NotificationRepository.DeleteNotificationListAsync(list.Id); await NotificationRepository.SaveChangesAsync(); _toast.ShowSuccess("Deleted."); await LoadAllAsync(); }
|
||||
catch (Exception ex) { _toast.ShowError(ex.Message); }
|
||||
}
|
||||
|
||||
// ==== Inbound API Methods ====
|
||||
private RenderFragment RenderInboundApiMethods() => __builder =>
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@page "/design/notification-lists/create"
|
||||
@page "/design/notification-lists/{Id:int}/edit"
|
||||
@page "/notifications/lists/create"
|
||||
@page "/notifications/lists/{Id:int}/edit"
|
||||
@using ScadaLink.Security
|
||||
@using ScadaLink.Commons.Entities.Notifications
|
||||
@using ScadaLink.Commons.Interfaces.Repositories
|
||||
@@ -147,7 +147,7 @@
|
||||
await NotificationRepository.AddNotificationListAsync(nl);
|
||||
}
|
||||
await NotificationRepository.SaveChangesAsync();
|
||||
NavigationManager.NavigateTo("/design/external-systems");
|
||||
NavigationManager.NavigateTo("/notifications/lists");
|
||||
}
|
||||
catch (Exception ex) { _formError = ex.Message; }
|
||||
}
|
||||
@@ -186,5 +186,5 @@
|
||||
catch (Exception ex) { _recipientFormError = ex.Message; }
|
||||
}
|
||||
|
||||
private void GoBack() => NavigationManager.NavigateTo("/design/external-systems");
|
||||
private void GoBack() => NavigationManager.NavigateTo("/notifications/lists");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user