Added ability to add alerts onto the page via controller
This commit is contained in:
parent
65f43577b2
commit
f2dfc90de8
3 changed files with 83 additions and 1 deletions
31
LANCommander/Controllers/BaseController.cs
Normal file
31
LANCommander/Controllers/BaseController.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace LANCommander.Controllers
|
||||||
|
{
|
||||||
|
public class BaseController : Controller
|
||||||
|
{
|
||||||
|
public void Alert(string message, string type = "info", bool dismissable = true)
|
||||||
|
{
|
||||||
|
List<AlertViewModel> alerts;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
alerts = JsonSerializer.Deserialize<List<AlertViewModel>>((string)TempData["Alerts"]);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
alerts = new List<AlertViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
alerts.Add(new AlertViewModel()
|
||||||
|
{
|
||||||
|
Message = message,
|
||||||
|
Type = type,
|
||||||
|
Dismissable = dismissable
|
||||||
|
});
|
||||||
|
|
||||||
|
TempData["Alerts"] = JsonSerializer.Serialize(alerts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
LANCommander/Models/AlertViewModel.cs
Normal file
6
LANCommander/Models/AlertViewModel.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
public class AlertViewModel
|
||||||
|
{
|
||||||
|
public string Message { get; set; }
|
||||||
|
public bool Dismissable { get; set; }
|
||||||
|
public string Type { get; set; }
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor _HttpContext
|
@using System.Text.Json
|
||||||
|
@inject Microsoft.AspNetCore.Http.IHttpContextAccessor _HttpContext
|
||||||
@{
|
@{
|
||||||
_HttpContext.HttpContext.Response.Headers["Cache-Control"] = "no-store";
|
_HttpContext.HttpContext.Response.Headers["Cache-Control"] = "no-store";
|
||||||
}
|
}
|
||||||
|
@ -93,6 +94,31 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="alert-container">
|
||||||
|
@if (TempData["Alerts"] != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var alert in JsonSerializer.Deserialize<List<AlertViewModel>>((string)TempData["Alerts"]))
|
||||||
|
{
|
||||||
|
<div class="alert alert-important alert-@alert.Type @(alert.Dismissable ? "alert-dismissable" : "")" role="alert">
|
||||||
|
<div class="d-flex">
|
||||||
|
<div>
|
||||||
|
@alert.Message
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (alert.Dismissable)
|
||||||
|
{
|
||||||
|
<a class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="close"></a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
<script src="~/lib/selectize.js/js/selectize.min.js"></script>
|
<script src="~/lib/selectize.js/js/selectize.min.js"></script>
|
||||||
<script src="~/lib/tabler/core/dist/js/tabler.min.js"></script>
|
<script src="~/lib/tabler/core/dist/js/tabler.min.js"></script>
|
||||||
|
@ -100,6 +126,25 @@
|
||||||
<script src="~/js/Select.js"></script>
|
<script src="~/js/Select.js"></script>
|
||||||
<script src="~/_framework/blazor.server.js"></script>
|
<script src="~/_framework/blazor.server.js"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.alert-container {
|
||||||
|
position: fixed;
|
||||||
|
top: 2rem;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
min-width: 400px;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-dismissable .btn-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 2;
|
||||||
|
padding: 1.25rem 1rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
@await RenderSectionAsync("Scripts", required: false)
|
@await RenderSectionAsync("Scripts", required: false)
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue