Removed HttpContext.Session
This commit is contained in:
parent
4514678556
commit
2481c2b3ff
@ -9,13 +9,11 @@ using System.Text.Json;
|
|||||||
public class PinController : Controller, IPinController<IActionResult>
|
public class PinController : Controller, IPinController<IActionResult>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly IPinRepository _PinRepository;
|
private readonly IPinRepository _PinRepository;
|
||||||
private readonly IMetrologyRepository _MetrologyRepository;
|
private readonly IMetrologyRepository _MetrologyRepository;
|
||||||
|
|
||||||
public PinController(ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IPinRepository pinRepository)
|
public PinController(ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IPinRepository pinRepository)
|
||||||
{
|
{
|
||||||
_Logger = logger;
|
|
||||||
_MetrologyRepository = metrologyRepository;
|
_MetrologyRepository = metrologyRepository;
|
||||||
_PinRepository = pinRepository;
|
_PinRepository = pinRepository;
|
||||||
}
|
}
|
||||||
@ -23,23 +21,13 @@ public class PinController : Controller, IPinController<IActionResult>
|
|||||||
[HttpPost("/api/pin/markAsPinned")]
|
[HttpPost("/api/pin/markAsPinned")]
|
||||||
public IActionResult MarkAsPinned(Shared.DataModels.HeaderCommon headerCommon)
|
public IActionResult MarkAsPinned(Shared.DataModels.HeaderCommon headerCommon)
|
||||||
{
|
{
|
||||||
string toolTypeId = headerCommon.ToolTypeID.ToString();
|
|
||||||
string json = JsonSerializer.Serialize(headerCommon, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
|
||||||
string? was = HttpContext.Session.GetString(toolTypeId);
|
|
||||||
if (was is not null)
|
|
||||||
_Logger.LogDebug($"{toolTypeId} was: {was}");
|
|
||||||
HttpContext.Session.SetString(toolTypeId, json);
|
|
||||||
_PinRepository.SetPinnedTable(headerCommon);
|
_PinRepository.SetPinnedTable(headerCommon);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{id}/pinned/{rds}")]
|
[Route("{id}/pinned")]
|
||||||
public IActionResult GetPinnedTable(int id, string rds = "")
|
public IActionResult GetPinnedTable(int id, string? biorad_id = null, string? cde_id = null, string? rds = null) =>
|
||||||
{
|
Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, biorad_id, cde_id, rds), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
||||||
string? cde = HttpContext.Session.GetString(((int)IPinRepository.ToolId.CDE).ToString());
|
|
||||||
string? bioRad = HttpContext.Session.GetString(((int)IPinRepository.ToolId.BioRad).ToString());
|
|
||||||
return Json(_PinRepository.GetPinnedTable(_MetrologyRepository, id, rds, bioRad, cde), new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -36,15 +36,11 @@ public class PinRepository : IPinRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde)
|
private (HeaderCommon?, HeaderCommon?) GetBoth(string rds, long bioRadId, long cdeId)
|
||||||
{
|
|
||||||
Result<Pinned[]>? r;
|
|
||||||
HeaderCommon? cdeHeader = cde is null ? null : JsonSerializer.Deserialize<HeaderCommon>(cde);
|
|
||||||
long cdeId = cdeHeader is null ? (long)IPinRepository.ToolId.CDE : cdeHeader.ToolTypeID;
|
|
||||||
HeaderCommon? bioRadHeader = bioRad is null ? null : JsonSerializer.Deserialize<HeaderCommon>(bioRad);
|
|
||||||
long bioRadId = bioRadHeader is null ? (long)IPinRepository.ToolId.BioRad : bioRadHeader.ToolTypeID;
|
|
||||||
if (!string.IsNullOrEmpty(rds) && (cdeHeader is null || bioRadHeader is null))
|
|
||||||
{
|
{
|
||||||
|
HeaderCommon? cdeHeader, bioRadHeader;
|
||||||
|
cdeHeader = null;
|
||||||
|
bioRadHeader = null;
|
||||||
Dictionary<long, HeaderCommon>? toolIdToHeader;
|
Dictionary<long, HeaderCommon>? toolIdToHeader;
|
||||||
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
|
if (!_RdsToHeaderCommonCollection.TryGetValue(rds, out toolIdToHeader))
|
||||||
{
|
{
|
||||||
@ -56,11 +52,61 @@ public class PinRepository : IPinRepository
|
|||||||
cdeHeader = toolIdToHeader[cdeId];
|
cdeHeader = toolIdToHeader[cdeId];
|
||||||
if (bioRadHeader is null && toolIdToHeader.ContainsKey(bioRadId))
|
if (bioRadHeader is null && toolIdToHeader.ContainsKey(bioRadId))
|
||||||
bioRadHeader = toolIdToHeader[bioRadId];
|
bioRadHeader = toolIdToHeader[bioRadId];
|
||||||
|
return new(bioRadHeader, cdeHeader);
|
||||||
}
|
}
|
||||||
if (cdeId != id && bioRadId != id)
|
|
||||||
r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 };
|
private static Pinned? GetPinned(IMetrologyRepository metrologyRepository, HeaderCommon bioRadHeader, int points, int column)
|
||||||
|
{
|
||||||
|
Pinned? result;
|
||||||
|
List<string> values;
|
||||||
|
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
|
||||||
|
if (dataTable.Rows.Count <= points || dataTable.Columns.Count <= column)
|
||||||
|
result = null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
values = new();
|
||||||
|
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
|
||||||
|
{
|
||||||
|
if (dataTable.Rows[i]?.ItemArray[column] is null)
|
||||||
|
break;
|
||||||
|
values.Add(string.Concat(dataTable.Rows[i].ItemArray[column]));
|
||||||
|
}
|
||||||
|
if (values.Count <= points)
|
||||||
|
result = null;
|
||||||
|
else
|
||||||
|
result = new(bioRadHeader, values);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Pinned? GetCDE(IMetrologyRepository metrologyRepository, int points, HeaderCommon bioRadHeader)
|
||||||
|
{
|
||||||
|
Pinned? result;
|
||||||
|
List<string> values;
|
||||||
|
const int thickness = 5;
|
||||||
|
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
|
||||||
|
if (dataTable.Rows.Count <= points || dataTable.Columns.Count <= thickness)
|
||||||
|
result = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
values = new();
|
||||||
|
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
|
||||||
|
{
|
||||||
|
if (dataTable.Rows[i]?.ItemArray[thickness] is null)
|
||||||
|
break;
|
||||||
|
values.Add(string.Concat(dataTable.Rows[i].ItemArray[thickness]));
|
||||||
|
}
|
||||||
|
if (values.Count <= points)
|
||||||
|
result = null;
|
||||||
|
else
|
||||||
|
result = new(bioRadHeader, values);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<Pinned[]> IPinRepository.GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? biorad_id, string? cde_id, string? rds)
|
||||||
|
{
|
||||||
|
Result<Pinned[]>? r;
|
||||||
if (!string.IsNullOrEmpty(_MockRoot))
|
if (!string.IsNullOrEmpty(_MockRoot))
|
||||||
{
|
{
|
||||||
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), "GetPinnedTableApi.json"));
|
string json = File.ReadAllText(Path.Combine(string.Concat(AppContext.BaseDirectory, _MockRoot), "GetPinnedTableApi.json"));
|
||||||
@ -70,49 +116,26 @@ public class PinRepository : IPinRepository
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<string> values;
|
if (string.IsNullOrEmpty(rds) || !long.TryParse(biorad_id, out long bioRadId) || !long.TryParse(cde_id, out long cdeId))
|
||||||
|
r = new() { Results = Array.Empty<Pinned>(), TotalRows = 0 };
|
||||||
|
else
|
||||||
|
{
|
||||||
const int points = 9;
|
const int points = 9;
|
||||||
Pinned headerCommond;
|
|
||||||
List<Pinned> results = new();
|
List<Pinned> results = new();
|
||||||
|
(HeaderCommon? cdeHeader, HeaderCommon? bioRadHeader) = GetBoth(rds, bioRadId, cdeId);
|
||||||
if (bioRadHeader is not null)
|
if (bioRadHeader is not null)
|
||||||
{
|
{
|
||||||
const int thickness = 5;
|
const int thickness = 5;
|
||||||
System.Data.DataTable dataTable = metrologyRepository.GetData((int)bioRadHeader.ToolTypeID, bioRadHeader.ID);
|
Pinned? pinned = GetPinned(metrologyRepository, bioRadHeader, points, column: thickness);
|
||||||
if (dataTable.Rows.Count > points && dataTable.Columns.Count > thickness)
|
if (pinned is not null)
|
||||||
{
|
results.Add(pinned);
|
||||||
values = new();
|
|
||||||
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
|
|
||||||
{
|
|
||||||
if (dataTable.Rows[i]?.ItemArray[thickness] is null)
|
|
||||||
break;
|
|
||||||
values.Add(string.Concat(dataTable.Rows[i].ItemArray[thickness]));
|
|
||||||
}
|
|
||||||
if (values.Count > points)
|
|
||||||
{
|
|
||||||
headerCommond = new(bioRadHeader, values);
|
|
||||||
results.Add(headerCommond);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cdeHeader is not null)
|
if (cdeHeader is not null)
|
||||||
{
|
{
|
||||||
const int rs = 6;
|
const int rs = 6;
|
||||||
System.Data.DataTable dataTable = metrologyRepository.GetData((int)cdeHeader.ToolTypeID, cdeHeader.ID);
|
Pinned? pinned = GetPinned(metrologyRepository, cdeHeader, points, column: rs);
|
||||||
if (dataTable.Rows.Count > points && dataTable.Columns.Count > rs)
|
if (pinned is not null)
|
||||||
{
|
results.Add(pinned);
|
||||||
values = new();
|
|
||||||
for (int i = 0; i < dataTable.Rows.Count - 1; i++)
|
|
||||||
{
|
|
||||||
if (dataTable.Rows[i]?.ItemArray[rs] is null)
|
|
||||||
break;
|
|
||||||
values.Add(string.Concat(dataTable.Rows[i].ItemArray[rs]));
|
|
||||||
}
|
|
||||||
if (values.Count > points)
|
|
||||||
{
|
|
||||||
headerCommond = new(cdeHeader, values);
|
|
||||||
results.Add(headerCommond);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
r = new()
|
r = new()
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"ApiUrl": "http://messa010ec.ec.local:50301/api",
|
||||||
"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;",
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
var _CdeId = null;
|
||||||
var _apiUrl = null;
|
var _apiUrl = null;
|
||||||
var _initialHeaderAttachmentId = null;
|
var _BioRadId = null;
|
||||||
var _initialHeaderId = null;
|
|
||||||
var _toolType = null;
|
var _toolType = null;
|
||||||
|
var _initialHeaderId = null;
|
||||||
var _toolTypeMetaData = null;
|
var _toolTypeMetaData = null;
|
||||||
|
var _initialHeaderAttachmentId = null;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
if (location.pathname == "/") {
|
if (location.pathname == "/") {
|
||||||
@ -67,14 +69,16 @@ function initExport(apiUrl, startTimeValue, endTimeValue) {
|
|||||||
_apiUrl = apiUrl;
|
_apiUrl = apiUrl;
|
||||||
var endTime = new Date(endTimeValue);
|
var endTime = new Date(endTimeValue);
|
||||||
var startTime = new Date(startTimeValue);
|
var startTime = new Date(startTimeValue);
|
||||||
|
$.getJSON(_apiUrl + '/tooltypes', function (data) {
|
||||||
$("#ToolType").igCombo({
|
$("#ToolType").igCombo({
|
||||||
dataSource: _apiUrl + '/tooltypes',
|
dataSource: data,
|
||||||
responseDataKey: "Results",
|
responseDataKey: "Results",
|
||||||
textKey: "ToolTypeName",
|
textKey: "ToolTypeName",
|
||||||
valueKey: "ID",
|
valueKey: "ID",
|
||||||
mode: "dropdown",
|
mode: "dropdown",
|
||||||
width: 150
|
width: 150
|
||||||
});
|
});
|
||||||
|
});
|
||||||
$("#StartDateControl").igDatePicker({
|
$("#StartDateControl").igDatePicker({
|
||||||
dateInputFormat: "date",
|
dateInputFormat: "date",
|
||||||
value: startTime,
|
value: startTime,
|
||||||
@ -174,19 +178,6 @@ function loadRunInfoRunHeaders() {
|
|||||||
|
|
||||||
function initRunHeaders(apiUrl) {
|
function initRunHeaders(apiUrl) {
|
||||||
_apiUrl = apiUrl;
|
_apiUrl = apiUrl;
|
||||||
// $("#ToolType").igCombo({
|
|
||||||
// dataSource: _apiUrl + '/tooltypes',
|
|
||||||
// responseDataKey: "Results",
|
|
||||||
// textKey: "ToolTypeName",
|
|
||||||
// valueKey: "ID",
|
|
||||||
// mode: "dropdown",
|
|
||||||
// width: 150,
|
|
||||||
// dataBound: function (evt, ui) {
|
|
||||||
// $("#ToolType").igCombo("index", 0);
|
|
||||||
// loadHeaderGridRunHeaders();
|
|
||||||
// },
|
|
||||||
// selectionChanged: loadHeaderGridRunHeaders,
|
|
||||||
// });
|
|
||||||
loadHeaderGridRunHeaders();
|
loadHeaderGridRunHeaders();
|
||||||
$("#RefreshButton").click(function () {
|
$("#RefreshButton").click(function () {
|
||||||
$("#HeaderGrid").igGrid("dataBind");
|
$("#HeaderGrid").igGrid("dataBind");
|
||||||
@ -480,21 +471,7 @@ 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({
|
$.getJSON(_apiUrl + "/pin/" + rowData.ToolTypeID + "/pinned?biorad_id=" + _BioRadId + "&cde_id=" + _CdeId + "&rds=" + rowData.RDS, function (data) {
|
||||||
// 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({
|
$("#PinnedGrid").igGrid({
|
||||||
dataSource: data,
|
dataSource: data,
|
||||||
responseDataKey: "Results",
|
responseDataKey: "Results",
|
||||||
@ -555,8 +532,17 @@ function initRunInfo(apiUrl, initialToolTypeID, initialHeaderId, initialHeaderAt
|
|||||||
_apiUrl = apiUrl;
|
_apiUrl = apiUrl;
|
||||||
_initialHeaderId = initialHeaderId;
|
_initialHeaderId = initialHeaderId;
|
||||||
_initialHeaderAttachmentId = initialHeaderAttachmentId;
|
_initialHeaderAttachmentId = initialHeaderAttachmentId;
|
||||||
|
$.getJSON(_apiUrl + '/tooltypes', function (data) {
|
||||||
|
for (var i = 0; i < data.Results.length; i++) {
|
||||||
|
if (data.Results[i].ToolTypeName === "CDE") {
|
||||||
|
_CdeId = data.Results[i].ID;
|
||||||
|
}
|
||||||
|
else if (data.Results[i].ToolTypeName === "BioRad") {
|
||||||
|
_BioRadId = data.Results[i].ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
$("#ToolType").igCombo({
|
$("#ToolType").igCombo({
|
||||||
dataSource: _apiUrl + '/tooltypes',
|
dataSource: data,
|
||||||
responseDataKey: "Results",
|
responseDataKey: "Results",
|
||||||
textKey: "ToolTypeName",
|
textKey: "ToolTypeName",
|
||||||
valueKey: "ID",
|
valueKey: "ID",
|
||||||
@ -568,6 +554,7 @@ function initRunInfo(apiUrl, initialToolTypeID, initialHeaderId, initialHeaderAt
|
|||||||
selectionChanged: loadHeaderGridRunInfo,
|
selectionChanged: loadHeaderGridRunInfo,
|
||||||
initialSelectedItems: [{ value: initialToolTypeID }]
|
initialSelectedItems: [{ value: initialToolTypeID }]
|
||||||
});
|
});
|
||||||
|
});
|
||||||
setInitialDateTimesRunInfo();
|
setInitialDateTimesRunInfo();
|
||||||
$("#HeaderGrid").on("dblclick", "tr", loadDetailsRunInfo);
|
$("#HeaderGrid").on("dblclick", "tr", loadDetailsRunInfo);
|
||||||
$("#LoadHeadersButton").click(loadHeaderGridRunInfo);
|
$("#LoadHeadersButton").click(loadHeaderGridRunInfo);
|
||||||
|
@ -5,17 +5,7 @@ namespace OI.Metrology.Shared.Models.Stateless;
|
|||||||
public interface IPinRepository
|
public interface IPinRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
enum ToolId
|
Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? biorad_id, string? cde_id, string? rds);
|
||||||
{
|
|
||||||
BioRad = 1,
|
|
||||||
CDE = 2,
|
|
||||||
Tencor = 3,
|
|
||||||
HgCV = 4,
|
|
||||||
Stratus = 5,
|
|
||||||
SP1 = 6,
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<Pinned[]> GetPinnedTable(IMetrologyRepository metrologyRepository, int id, string? rds, string? bioRad, string? cde);
|
|
||||||
void SetPinnedTable(HeaderCommon headerCommon);
|
void SetPinnedTable(HeaderCommon headerCommon);
|
||||||
|
|
||||||
}
|
}
|
@ -43,9 +43,7 @@ public class UnitTestPinController
|
|||||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||||
IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>();
|
IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>();
|
||||||
string? cde = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 196984, ToolTypeID = 2 });
|
Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, cde_id: null, biorad_id: null, rds: null);
|
||||||
string? bioRad = System.Text.Json.JsonSerializer.Serialize(new HeaderCommon { ID = 321568, ToolTypeID = 1 });
|
|
||||||
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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user