Test Pinned via API ||

This commit is contained in:
2023-02-08 13:11:11 -07:00
parent 8e471e278e
commit 4514678556
17 changed files with 107 additions and 52 deletions

2
.vscode/tasks.json vendored
View File

@ -44,7 +44,7 @@
"args": [ "args": [
"watch", "watch",
"--launch-profile", "--launch-profile",
"https", "http",
"run", "run",
"--project", "--project",
"${workspaceFolder}/Server/OI.Metrology.Server.csproj", "${workspaceFolder}/Server/OI.Metrology.Server.csproj",

View File

@ -29,16 +29,17 @@ public class PinController : Controller, IPinController<IActionResult>
if (was is not null) if (was is not null)
_Logger.LogDebug($"{toolTypeId} was: {was}"); _Logger.LogDebug($"{toolTypeId} was: {was}");
HttpContext.Session.SetString(toolTypeId, json); HttpContext.Session.SetString(toolTypeId, json);
_PinRepository.SetPinnedTable(headerCommon);
return Ok(); return Ok();
} }
[HttpGet] [HttpGet]
[Route("{id}/pinned")] [Route("{id}/pinned/{rds}")]
public IActionResult GetPinnedTable(int id) public IActionResult GetPinnedTable(int id, string rds = "")
{ {
string? cde = HttpContext.Session.GetString(((int)IPinRepository.ToolId.CDE).ToString()); string? cde = HttpContext.Session.GetString(((int)IPinRepository.ToolId.CDE).ToString());
string? bioRad = HttpContext.Session.GetString(((int)IPinRepository.ToolId.BioRad).ToString()); string? bioRad = HttpContext.Session.GetString(((int)IPinRepository.ToolId.BioRad).ToString());
return Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, bioRad, cde), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true }); return Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, rds, bioRad, cde), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
} }
} }

View File

@ -11,6 +11,8 @@ namespace OI.Metrology.Server.Controllers;
public class ExportController : Controller public class ExportController : Controller
{ {
private readonly string _ApiUrl;
private readonly ILogger _Logger; private readonly ILogger _Logger;
private readonly bool _IsTestDatabase; private readonly bool _IsTestDatabase;
private readonly AppSettings _AppSettings; private readonly AppSettings _AppSettings;
@ -22,6 +24,7 @@ public class ExportController : Controller
_AppSettings = appSettings; _AppSettings = appSettings;
_MetrologyRepository = metrologyRepository; _MetrologyRepository = metrologyRepository;
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase); _IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
_ApiUrl = string.IsNullOrEmpty(appSettings.ApiUrl) ? Url.Content("~/") : appSettings.ApiUrl[0] == '~' ? Url.Content(appSettings.ApiUrl) : appSettings.ApiUrl;
} }
public override void OnActionExecuted(ActionExecutedContext context) public override void OnActionExecuted(ActionExecutedContext context)
@ -41,6 +44,7 @@ public class ExportController : Controller
}; };
MonIn monIn = MonIn.GetInstance(); MonIn monIn = MonIn.GetInstance();
_ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Up); _ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Up);
ViewBag.ApiUrl = _ApiUrl;
return View(model); return View(model);
} }
@ -81,6 +85,7 @@ public class ExportController : Controller
_ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Warning); _ = monIn.SendStatus(_AppSettings.MonASite, _AppSettings.MonAResource, "Heartbeat", State.Warning);
} }
} }
ViewBag.ApiUrl = _ApiUrl;
return View("Index", model); return View("Index", model);
} }

View File

@ -8,6 +8,8 @@ namespace OI.Metrology.Server.Controllers;
public class PagesController : Controller public class PagesController : Controller
{ {
private readonly string _ApiUrl;
private readonly bool _IsTestDatabase; private readonly bool _IsTestDatabase;
private readonly IMetrologyRepository _MetrologyRepository; private readonly IMetrologyRepository _MetrologyRepository;
@ -15,6 +17,7 @@ public class PagesController : Controller
{ {
_MetrologyRepository = metrologyRepository; _MetrologyRepository = metrologyRepository;
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase); _IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
_ApiUrl = string.IsNullOrEmpty(appSettings.ApiUrl) ? Url.Content("~/") : appSettings.ApiUrl[0] == '~' ? Url.Content(appSettings.ApiUrl) : appSettings.ApiUrl;
} }
public override void OnActionExecuted(ActionExecutedContext context) public override void OnActionExecuted(ActionExecutedContext context)
@ -25,14 +28,20 @@ public class PagesController : Controller
[HttpGet] [HttpGet]
[Route("/")] [Route("/")]
public IActionResult Index() => public IActionResult Index()
View("AwaitingDispo"); {
ViewBag.ApiUrl = _ApiUrl;
return View("AwaitingDispo");
}
[HttpGet] [HttpGet]
[Route("/AwaitingDispo")] [Route("/AwaitingDispo")]
[Route("/Metrology/AwaitingDispo")] [Route("/Metrology/AwaitingDispo")]
public IActionResult AwaitingDispo() => public IActionResult AwaitingDispo()
View(); {
ViewBag.ApiUrl = _ApiUrl;
return View();
}
[HttpGet] [HttpGet]
[Route("/RunInfo")] [Route("/RunInfo")]
@ -49,14 +58,18 @@ public class PagesController : Controller
{ {
m.HeaderAttachmentID = _MetrologyRepository.GetHeaderAttachmentID(tooltypeid, headerid); m.HeaderAttachmentID = _MetrologyRepository.GetHeaderAttachmentID(tooltypeid, headerid);
} }
ViewBag.ApiUrl = _ApiUrl;
return View(m); return View(m);
} }
[HttpGet] [HttpGet]
[Route("/RunHeaders")] [Route("/RunHeaders")]
[Route("/Metrology/RunHeaders")] [Route("/Metrology/RunHeaders")]
public IActionResult RunHeaders() => public IActionResult RunHeaders()
View(); {
ViewBag.ApiUrl = _ApiUrl;
return View();
}
[HttpGet] [HttpGet]
[Route("/Crash")] [Route("/Crash")]

View File

@ -5,6 +5,7 @@ namespace OI.Metrology.Server.Models;
public record AppSettings(string ApiLoggingContentTypes, public record AppSettings(string ApiLoggingContentTypes,
string ApiLoggingPathPrefixes, string ApiLoggingPathPrefixes,
string ApiLogPath, string ApiLogPath,
string ApiUrl,
string AttachmentPath, string AttachmentPath,
string BuildNumber, string BuildNumber,
string Company, string Company,

View File

@ -11,6 +11,7 @@ public class AppSettings
[Display(Name = "Api Logging Content Types"), Required] public string ApiLoggingContentTypes { get; set; } [Display(Name = "Api Logging Content Types"), Required] public string ApiLoggingContentTypes { get; set; }
[Display(Name = "Api Logging Path Prefixes"), Required] public string ApiLoggingPathPrefixes { get; set; } [Display(Name = "Api Logging Path Prefixes"), Required] public string ApiLoggingPathPrefixes { get; set; }
[Display(Name = "Api Log Path"), Required] public string ApiLogPath { get; set; } [Display(Name = "Api Log Path"), Required] public string ApiLogPath { get; set; }
[Display(Name = "Api URL"), Required] public string ApiUrl { get; set; }
[Display(Name = "Attachment Path"), Required] public string AttachmentPath { get; set; } [Display(Name = "Attachment Path"), Required] public string AttachmentPath { get; set; }
[Display(Name = "Build Number"), Required] public string BuildNumber { get; set; } [Display(Name = "Build Number"), Required] public string BuildNumber { get; set; }
[Display(Name = "Company"), Required] public string Company { get; set; } [Display(Name = "Company"), Required] public string Company { get; set; }
@ -46,6 +47,8 @@ public class AppSettings
throw new NullReferenceException(nameof(ApiLoggingPathPrefixes)); throw new NullReferenceException(nameof(ApiLoggingPathPrefixes));
if (appSettings.ApiLogPath is null) if (appSettings.ApiLogPath is null)
throw new NullReferenceException(nameof(ApiLogPath)); throw new NullReferenceException(nameof(ApiLogPath));
if (appSettings.ApiUrl is null)
throw new NullReferenceException(nameof(ApiUrl));
if (appSettings.AttachmentPath is null) if (appSettings.AttachmentPath is null)
throw new NullReferenceException(nameof(AttachmentPath)); throw new NullReferenceException(nameof(AttachmentPath));
if (appSettings.BuildNumber is null) if (appSettings.BuildNumber is null)
@ -80,6 +83,7 @@ public class AppSettings
appSettings.ApiLoggingContentTypes, appSettings.ApiLoggingContentTypes,
appSettings.ApiLoggingPathPrefixes, appSettings.ApiLoggingPathPrefixes,
appSettings.ApiLogPath, appSettings.ApiLogPath,
appSettings.ApiUrl,
appSettings.AttachmentPath, appSettings.AttachmentPath,
appSettings.BuildNumber, appSettings.BuildNumber,
appSettings.Company, appSettings.Company,

View File

@ -102,6 +102,7 @@ public class Program
if (!webApplicationBuilder.Environment.IsDevelopment()) if (!webApplicationBuilder.Environment.IsDevelopment())
{ {
_ = webApplication.UseExceptionHandler("/Error"); _ = webApplication.UseExceptionHandler("/Error");
_ = webApplication.UseHttpsRedirection();
_ = webApplication.UseHsts(); _ = webApplication.UseHsts();
} }
else else
@ -120,7 +121,6 @@ public class Program
_ = webApplication.UseFileServer(enableDirectoryBrowsing: true); _ = webApplication.UseFileServer(enableDirectoryBrowsing: true);
_ = webApplication.UseStaticFiles(); _ = webApplication.UseStaticFiles();
_ = webApplication.UseSession(); _ = webApplication.UseSession();
_ = webApplication.UseHttpsRedirection();
_ = webApplication.UseMiddleware<ApiLoggingMiddleware>(); _ = webApplication.UseMiddleware<ApiLoggingMiddleware>();
_ = webApplication.MapControllers(); _ = webApplication.MapControllers();
log.Information("Starting Web Application"); log.Information("Starting Web Application");

View File

@ -9,20 +9,54 @@ public class PinRepository : IPinRepository
private readonly string _MockRoot; private readonly string _MockRoot;
private readonly Serilog.ILogger _Log; private readonly Serilog.ILogger _Log;
private readonly Dictionary<string, Dictionary<long, HeaderCommon>> _RdsToHeaderCommonCollection;
public PinRepository(string mockRoot) public PinRepository(string mockRoot)
{ {
_MockRoot = mockRoot; _MockRoot = mockRoot;
_RdsToHeaderCommonCollection = new();
_Log = Serilog.Log.ForContext<PinRepository>(); _Log = Serilog.Log.ForContext<PinRepository>();
} }
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? bioRad, string? cde) void IPinRepository.SetPinnedTable(HeaderCommon headerCommon)
{
Dictionary<long, HeaderCommon>? toolIdToHeader;
if (!string.IsNullOrEmpty(headerCommon.RDS))
{
if (!_RdsToHeaderCommonCollection.TryGetValue(headerCommon.RDS, out toolIdToHeader))
{
_RdsToHeaderCommonCollection.Add(headerCommon.RDS, new());
if (!_RdsToHeaderCommonCollection.TryGetValue(headerCommon.RDS, out toolIdToHeader))
throw new Exception();
}
if (toolIdToHeader.ContainsKey(headerCommon.ToolTypeID))
toolIdToHeader[headerCommon.ToolTypeID] = headerCommon;
else
toolIdToHeader.Add(headerCommon.ToolTypeID, headerCommon);
}
}
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde)
{ {
Result<Pinned[]>? r; Result<Pinned[]>? r;
HeaderCommon? cdeHeader = cde is null ? null : JsonSerializer.Deserialize<HeaderCommon>(cde); HeaderCommon? cdeHeader = cde is null ? null : JsonSerializer.Deserialize<HeaderCommon>(cde);
long cdeId = cdeHeader is null ? (long)IPinRepository.ToolId.CDE : cdeHeader.ToolTypeID; long cdeId = cdeHeader is null ? (long)IPinRepository.ToolId.CDE : cdeHeader.ToolTypeID;
HeaderCommon? bioRadHeader = bioRad is null ? null : JsonSerializer.Deserialize<HeaderCommon>(bioRad); HeaderCommon? bioRadHeader = bioRad is null ? null : JsonSerializer.Deserialize<HeaderCommon>(bioRad);
long bioRadId = bioRadHeader is null ? (long)IPinRepository.ToolId.BioRad : bioRadHeader.ToolTypeID; long bioRadId = bioRadHeader is null ? (long)IPinRepository.ToolId.BioRad : bioRadHeader.ToolTypeID;
if (!string.IsNullOrEmpty(rds) && (cdeHeader is null || bioRadHeader is null))
{
Dictionary<long, HeaderCommon>? toolIdToHeader;
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
{
_RdsToHeaderCommonCollection.Add(rds, new());
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
throw new Exception();
}
if (cdeHeader is null && toolIdToHeader.ContainsKey(cdeId))
cdeHeader = toolIdToHeader[cdeId];
if (bioRadHeader is null && toolIdToHeader.ContainsKey(bioRadId))
bioRadHeader = toolIdToHeader[bioRadId];
}
if (cdeId != id && bioRadId != id) if (cdeId != id && bioRadId != id)
r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 }; r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 };
else else

View File

@ -48,8 +48,10 @@
$(document).ready(function () { $(document).ready(function () {
var apiUrl = "@ViewBag.ApiUrl";
$("#ToolType").igCombo({ $("#ToolType").igCombo({
dataSource: '@Url.Content("~/api/tooltypes")', dataSource: apiUrl + '/tooltypes',
responseDataKey: "Results", responseDataKey: "Results",
textKey: "ToolTypeName", textKey: "ToolTypeName",
valueKey: "ID", valueKey: "ID",

View File

@ -21,7 +21,7 @@
$(document).ready(function () { $(document).ready(function () {
initAwaitingDisposition("@Url.Content("~/api")"); initAwaitingDisposition("@ViewBag.ApiUrl");
}); });

View File

@ -50,7 +50,7 @@
$(document).ready(function () { $(document).ready(function () {
initRunHeaders("@Url.Content("~/api")"); initRunHeaders("@ViewBag.ApiUrl");
}); });

View File

@ -52,6 +52,9 @@
<div class="col-xs-1"> <div class="col-xs-1">
<input type="button" class="btn" id="PinButton" value="Pin" disabled /> <input type="button" class="btn" id="PinButton" value="Pin" disabled />
</div> </div>
<div class="col-xs-1">
<table style="min-width:600px; min-height:300px;" id="PinnedGrid"></table>
</div>
</div> </div>
<div id="DetailsDiv" hidden> <div id="DetailsDiv" hidden>
@ -74,17 +77,11 @@
</div> </div>
<div id="PinnedDiv">
<div style="padding-bottom: 20px;" id="PinnedGridDiv">
<table id="PinnedGrid"></table>
</div>
</div>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
initRunInfo("@Url.Content("~/api")", "@Model.ToolTypeID", "@Model.HeaderID", "@Model.HeaderAttachmentID"); initRunInfo("@ViewBag.ApiUrl", "@Model.ToolTypeID", "@Model.HeaderID", "@Model.HeaderAttachmentID");
}); });

View File

@ -2,6 +2,7 @@
"ConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Integrated Security=True;Initial Catalog=Metrology;", "ConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Integrated Security=True;Initial Catalog=Metrology;",
"IsDevelopment": true, "IsDevelopment": true,
"xMockRoot": "/Data/Tests", "xMockRoot": "/Data/Tests",
"ApiUrl": "http://messa010ec.ec.local:50301/api",
"MockRoot": "", "MockRoot": "",
"MonAResource": "OI_Metrology_Viewer_IFX", "MonAResource": "OI_Metrology_Viewer_IFX",
"Oi2SqlConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;", "Oi2SqlConnectionString": "Data Source=MESSAD1001\\TEST1,59583;Initial Catalog=LSL2SQL;Persist Security Info=True;User ID=srpadmin;Password=0okm9ijn;",

View File

@ -2,6 +2,7 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"ApiLoggingContentTypes": "application/json", "ApiLoggingContentTypes": "application/json",
"ApiLoggingPathPrefixes": "/api/inbound", "ApiLoggingPathPrefixes": "/api/inbound",
"ApiUrl": "~/api",
"ApiLogPath": "D:\\Metrology\\MetrologyAPILogs", "ApiLogPath": "D:\\Metrology\\MetrologyAPILogs",
"AttachmentPath": "\\\\messv02ecc1.ec.local\\EC_Metrology_Si\\MetrologyAttachments", "AttachmentPath": "\\\\messv02ecc1.ec.local\\EC_Metrology_Si\\MetrologyAttachments",
"BuildNumber": "1", "BuildNumber": "1",

View File

@ -221,31 +221,6 @@ function loadHeaderGridRunInfo() {
DisplayWSMessage("error", "There was an error getting tooltype info.", e); DisplayWSMessage("error", "There was an error getting tooltype info.", e);
} }
}); });
// $.ajax({
// type: "GET",
// url: _apiUrl + "/pin/" + toolTypeID + "/pinned",
// success: function (r) {
// if ((r.Results == null) || (r.Results.HeaderId == null))
// DisplayWSMessage("error", "B) There was an error getting pinned info.");
// else
// DisplayWSMessage("info", r.Results.HeaderId);
// },
// error: function (e) {
// DisplayWSMessage("error", "There was an error getting pinned info.", e);
// }
// });
$("#PinnedGrid").igGrid({
width: "70%",
height: "100%",
dataSource: _apiUrl + "/pin/" + toolTypeID + "/pinned",
responseDataKey: "Results",
tabIndex: 1,
features: [
{ name: "Selection", mode: "row", multipleSelection: false },
{ name: "Filtering", type: "local" },
{ name: "Sorting", type: "local" },
]
});
} }
function disableHeaderButtonsRunInfo() { function disableHeaderButtonsRunInfo() {
@ -505,6 +480,26 @@ function pinButtonRunInfo() {
success: function (e) { success: function (e) {
DisplayWSMessage("info", "Marked as pinned", e); DisplayWSMessage("info", "Marked as pinned", e);
$("#PinButton").prop("disabled", false); $("#PinButton").prop("disabled", false);
// $.ajax({
// type: "GET",
// url: _apiUrl + "/pin/" + toolTypeID + "/pinned",
// success: function (r) {
// if ((r.Results == null) || (r.Results.HeaderId == null))
// DisplayWSMessage("error", "B) There was an error getting pinned info.");
// else
// DisplayWSMessage("info", r.Results.HeaderId);
// },
// error: function (e) {
// DisplayWSMessage("error", "There was an error getting pinned info.", e);
// }
// });
// $.getJSON(_apiUrl + "/awaitingdispo/", function (data) {
$.getJSON(_apiUrl + "/pin/" + rowData.ToolTypeID + "/pinned?rds=" + rowData.RDS, function (data) {
$("#PinnedGrid").igGrid({
dataSource: data,
responseDataKey: "Results",
});
});
}, },
error: function (e, ajaxOptions, ex) { error: function (e, ajaxOptions, ex) {
DisplayWSMessage("error", "There was an error marking header as pinned.", e, ex); DisplayWSMessage("error", "There was an error marking header as pinned.", e, ex);

View File

@ -15,6 +15,7 @@ public interface IPinRepository
SP1 = 6, SP1 = 6,
} }
Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? bioRad, string? cde); Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde);
void SetPinnedTable(HeaderCommon headerCommon);
} }

View File

@ -45,7 +45,7 @@ public class UnitTestPinController
IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>(); IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>();
string? cde = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 196984, ToolTypeID = 2 }); string? cde = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 196984, ToolTypeID = 2 });
string? bioRad = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 321568, ToolTypeID = 1 }); string? bioRad = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 321568, ToolTypeID = 1 });
Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, bioRad, cde); Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, rds: string.Empty, bioRad, cde);
Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results);
Assert.IsTrue(result.Results.Any()); Assert.IsTrue(result.Results.Any());
_Logger.Information($"{_TestContext?.TestName} completed"); _Logger.Information($"{_TestContext?.TestName} completed");