Skip to content

Commit c91f4c3

Browse files
Enable RecordCount retrieval in data provider for grid panel (#843)
* Temporary implementation to enable RecordCount retrieval in data provider for grid panel. * Define the GXDataGridProcedure class as the base class for REST services handling panels with data grids. * Set the 'RecordCount' header when the 'RecordCount' routine is executed, regardless of whether 'RecordCount' is present in the request headers. * Set RecordCountSupported when RecorCount is not available. * RecordCount header must be set before opening cursor for loading data because it executes a stmt. Otherwise, it should be done after closing cursors. * Remove unused using.
1 parent 60da3b3 commit c91f4c3

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

dotnet/src/dotnetframework/GxClasses/Model/gxproc.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,86 @@ protected void initialize(int objClass, int objId, int dbgLines, long hash)
349349
protected void trkrng(int lineNro, int lineNro2) => dbgInfo?.TrkRng(lineNro, 0, lineNro2, 0);
350350
protected void trkrng(int lineNro, int colNro, int lineNro2, int colNro2) => dbgInfo?.TrkRng(lineNro, colNro, lineNro2, colNro2);
351351
}
352+
public class GXDataGridProcedure : GXProcedure
353+
{
354+
static readonly ILog log = log4net.LogManager.GetLogger(typeof(GXDataGridProcedure));
355+
356+
const string HAS_NEXT_PAGE = "HasNextPage";
357+
const string RECORD_COUNT = "RecordCount";
358+
const string RECORD_COUNT_SUPPORTED = "RecordCountSupported";
359+
long totalRecordCount = -1;
360+
protected virtual long RecordCount()
361+
{
362+
return -1;
363+
}
364+
protected virtual bool RecordCountSupported()
365+
{
366+
return true;
367+
}
368+
protected void SetPaginationHeaders(bool hasNextPage)
369+
{
370+
try
371+
{
372+
SetHasNextPageHeader(hasNextPage);
373+
SetRecordCountSupportedHeader();
374+
}
375+
catch (Exception ex)
376+
{
377+
GXLogging.Warn(log, $"A processing error occurred while setting pagination headers", ex);
378+
}
379+
}
380+
private void SetRecordCountSupportedHeader()
381+
{
382+
if (!RecordCountSupported())
383+
{
384+
GXLogging.Debug(log, $"Adding '{RECORD_COUNT_SUPPORTED}' header");
385+
context.SetHeader(RECORD_COUNT_SUPPORTED, false.ToString());
386+
}
387+
}
352388

389+
private void SetHasNextPageHeader(bool hasNextPage)
390+
{
391+
context.SetHeader(HAS_NEXT_PAGE, StringUtil.BoolToStr(hasNextPage));
392+
}
393+
394+
private void SetRecordCountHeader()
395+
{
396+
bool recordCountHeaderRequired = false;
397+
bool setHeader = false;
398+
if (context.HttpContext != null)
399+
{
400+
recordCountHeaderRequired = !string.IsNullOrEmpty(context.HttpContext.Request.Headers[RECORD_COUNT]);
401+
}
402+
if (totalRecordCount != -1)
403+
{
404+
setHeader = true;
405+
}
406+
else if (recordCountHeaderRequired)
407+
{
408+
totalRecordCount = RecordCount();
409+
setHeader = true;
410+
}
411+
if (setHeader)
412+
{
413+
GXLogging.Debug(log, $"Adding '{RECORD_COUNT}' header:", totalRecordCount.ToString());
414+
context.SetHeader(RECORD_COUNT, totalRecordCount.ToString());
415+
}
416+
}
417+
protected long GetPaginationStart(long start, long count)
418+
{
419+
if (start < 0) //last page
420+
{
421+
totalRecordCount = RecordCount();
422+
long lastPageRecords = totalRecordCount % count;
423+
if (lastPageRecords == 0)
424+
start = totalRecordCount - count;
425+
else
426+
start = totalRecordCount - lastPageRecords;
427+
}
428+
SetRecordCountHeader();
429+
return start;
430+
}
431+
}
353432
public class GxReportUtils
354433
{
355434
public static int OUTPUT_RVIEWER_NATIVE = 1;

dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ string dateTimeToHTMLDate(DateTime dt)
709709
}
710710
public Task WebException(Exception ex)
711711
{
712-
#if NETCORE
712+
#if NETCORE
713713
GxHttpActivitySourceHelper.SetException(Activity.Current, ex);
714714
#endif
715715
GXLogging.Error(log, "WebException", ex);

0 commit comments

Comments
 (0)