From a296bc9b4f31afcf7920052ac516ce1e500abed0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 21 Apr 2023 18:01:43 +0000 Subject: [PATCH] --- server/biz/ReportBiz.cs | 10 +++++----- server/biz/SubscriptionBiz.cs | 32 ++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/server/biz/ReportBiz.cs b/server/biz/ReportBiz.cs index bea9a5d..1c72364 100644 --- a/server/biz/ReportBiz.cs +++ b/server/biz/ReportBiz.cs @@ -590,23 +590,23 @@ namespace Sockeye.Biz //Add Handlebars JS for compiling and presenting //https://handlebarsjs.com/ - await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "sock-hb.js") }); + await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb.js") }); //add Marked for markdown processing //https://github.com/markedjs/marked - await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "sock-md.js") }); + await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-md.js") }); //add DOM Purify for markdown template sanitization processing //https://github.com/cure53/DOMPurify - await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "sock-pf.js") }); + await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-pf.js") }); //add Bar code library if our bar code helper is referenced //https://github.com/metafloor/bwip-js if (report.Template.Contains("ayBC ") || report.JsHelpers.Contains("ayBC ")) - await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "sock-bc.js") }); + await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-bc.js") }); //add stock helpers - await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "sock-report.js") }); + await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-report.js") }); //execute to add to handlebars await page.EvaluateExpressionAsync("ayRegisterHelpers();"); diff --git a/server/biz/SubscriptionBiz.cs b/server/biz/SubscriptionBiz.cs index 935beab..a3e7ea0 100644 --- a/server/biz/SubscriptionBiz.cs +++ b/server/biz/SubscriptionBiz.cs @@ -66,11 +66,12 @@ namespace Sockeye.Biz //////////////////////////////////////////////////////////////////////////////////////////////// //GET // - internal async Task GetAsync(long id, bool logTheGetEvent = true, bool populateForReporting = false) + internal async Task GetAsync(long id, bool logTheGetEvent = true) { - var ret = await ct.Subscription.Include(z => z.Items.OrderByDescending(x=>x.Active).ThenBy(x => x.ExpireDate)).AsNoTracking().SingleOrDefaultAsync(z => z.Id == id); + var ret = await ct.Subscription.Include(z => z.Items.OrderByDescending(x => x.Active).ThenBy(x => x.ExpireDate)).AsNoTracking().SingleOrDefaultAsync(z => z.Id == id); if (logTheGetEvent && ret != null) await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, SockEvent.Retrieved), ct); + await PopulateVizFields(ret); return ret; } @@ -236,6 +237,20 @@ namespace Sockeye.Biz await Task.CompletedTask; } + //////////////////////////////////////////////////////////////////////////////////////////////// + // + // + // + internal async Task SubscriptionGetForReportingAsync(SockType sType, long id) + { + + //if it's the entire workorder just get, populate and return as normal + if (sType == SockType.Subscription) + return await GetAsync(id, false); + var subId = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == id).Select(z => z.SubscriptionId).FirstOrDefaultAsync(); + return await GetAsync(subId, false); + + } //////////////////////////////////////////////////////////////////////////////////////////////// //REPORTING @@ -244,13 +259,19 @@ namespace Sockeye.Biz { var idList = dataListSelectedRequest.SelectedRowIds; JArray ReportData = new JArray(); + List batchResults = new List(); while (idList.Any()) { + if (!ReportRenderManager.KeepGoing(jobId)) return null; + var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE); idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray(); - - //query for this batch, comes back in db natural order unfortunately - var batchResults = await ct.Subscription.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync(); + batchResults.Clear(); + foreach (long batchId in batch) + { + if (!ReportRenderManager.KeepGoing(jobId)) return null; + batchResults.Add(await SubscriptionGetForReportingAsync(dataListSelectedRequest.SockType, batchId)); + } //order the results back into original //What is happening here: @@ -265,7 +286,6 @@ namespace Sockeye.Biz foreach (Subscription w in orderedList) { if (!ReportRenderManager.KeepGoing(jobId)) return null; - await PopulateVizFields(w); var jo = JObject.FromObject(w); if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"])) jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);