EDA/ERS: Modified API to address multi-level grouping issues
authorJerome St-Louis <jerome@ecere.com>
Sun, 6 Dec 2015 18:07:40 +0000 (13:07 -0500)
committerJerome St-Louis <jerome@ecere.com>
Tue, 22 Dec 2015 06:45:13 +0000 (01:45 -0500)
- All previous levels of groupings should be checked for different IDs,
 now passing groupings array and level to make this possible
- Note: Default Grouping::Advance() implementation does not address the issue
- Should eventually get rid of the 'fieldLink' and other members added for specific
  types of reports as it is all overly complicated, and be addressed much simpler
  with proper queries.

eda/libeda/src/ers.ec
samples/db/MovieCollection/borrowerReport.ec

index 878925f..c5a513d 100644 (file)
@@ -293,7 +293,7 @@ public:
                      break;
                   case groupStart:
                      lastDetail = null;
-                     if(report.Advance(report.groupings[level], level ? report.groupings[level - 1].groupId : 0, &dontAdvance))
+                     if(report.Advance(level, &dontAdvance))
                      {
                         report.ExecuteRowData(level);
                         if(report.groupings[level].header)
@@ -349,7 +349,7 @@ public:
                      renderAction = groupStart;
                      break;
                   case actualRows:
-                     if(report.Advance(report.groupings[level], level ? report.groupings[level - 1].groupId : 0, &dontAdvance))
+                     if(report.Advance(level, &dontAdvance))
                      {
                         Detail detail;
                         if(AddDetailToPage(destination, (detail = eInstance_New(report.rowDetail))))
@@ -749,9 +749,10 @@ public:
       return false;
    }
 
-   virtual bool Advance(Id linkId, bool *dontAdvance)
+   virtual bool Advance(Array<Grouping> groupings, int level, bool *dontAdvance)
    {
       bool result;
+      Id linkId = level ? groupings[level - 1].groupId : 0;
       IdList reverseIdList = null;
 
       if(dontAdvance && *dontAdvance)
@@ -800,6 +801,7 @@ public:
          }
          else if(fieldLink)
          {
+            // WARNING: This implementation may not work properly with more than 1 level of grouping
             Id id = 0;
             row.GetData(fieldLink, id);
             if(id != linkId)
@@ -882,9 +884,9 @@ public:
 
    subclass(Detail) rowDetail;
 
-   virtual bool Advance(Grouping grouping, Id linkId, bool *dontAdvance)
+   virtual bool Advance(int level, bool *dontAdvance)
    {
-      return grouping.Advance(linkId, dontAdvance);
+      return groupings[level].Advance(groupings, level, dontAdvance);
    }
 
    virtual bool ExecuteData(Database db)
index 2ecbddb..2163f3d 100644 (file)
@@ -125,7 +125,7 @@ class BorrowerGrouping : Grouping
    bool ShouldSkip()
    {
       RowBorrowers r = (RowBorrowers)row;
-      int id = r.id;
+      Id id = r.id;
       return !rowMovies.Find(dbfield("Movies", borrower), middle, nil, id);
    }
 }