pict-section-recordset 1.0.48 → 1.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -490,7 +490,7 @@ module.exports.default_configuration.pict_configuration = (
490
490
  "RecordSetType": "MeadowEndpoint", // Could be "Custom" which would require a provider to already be created for the record set.
491
491
  "RecordSetMeadowEntity": "Book", // This leverages the /Schema endpoint to get the record set columns.
492
492
 
493
- "RecordSetListManifestOnly": true,
493
+ "RecordSetDashboardManifestOnly": true,
494
494
 
495
495
  "RecordSetDashboardManifests": [ "Bestsellers", "Underdogs", "NewReleases" ],
496
496
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-recordset",
3
- "version": "1.0.48",
3
+ "version": "1.0.50",
4
4
  "description": "Pict dynamic record set management views",
5
5
  "main": "source/Pict-Section-RecordSet.js",
6
6
  "directories": {
@@ -742,7 +742,7 @@ class MeadowEndpointsRecordSetProvider extends libRecordSetProviderBase
742
742
  {
743
743
  tmpFieldFilterSchema.AvailableClauses = [];
744
744
  }
745
- tmpFieldFilterSchema.AvailableClauses.push(tmpFilterClause);
745
+ tmpFieldFilterSchema.AvailableClauses.push(tmpFilterClause.ClauseName ? Object.assign(tmpFilterClause, { DisplayName: tmpFilterClause.ClauseName }) : tmpFilterClause);
746
746
  if (!tmpFilterClause.FilterKey)
747
747
  {
748
748
  tmpFilterClause.FilterKey = tmpFilterKey;
@@ -408,12 +408,12 @@ class viewRecordSetDashboard extends libPictRecordSetRecordView
408
408
  {
409
409
  // Put code here to preprocess columns into other data parts.
410
410
  /*
411
- "RecordSetListManifestOnly": false,
411
+ "RecordSetDashboardManifestOnly": false,
412
412
 
413
413
  "RecordSetListManifests": [ "Bestsellers", "Underdogs", "NewReleases" ],
414
414
  "RecordSetDashboardManifests": [ "Bestsellers" ],
415
415
  */
416
- if (pRecordSetConfiguration.RecordSetListManifestOnly)
416
+ if (pRecordSetConfiguration.RecordSetDashboardManifestOnly)
417
417
  {
418
418
  const tmpManifestHash = pRecordSetConfiguration.RecordSetDashboardDefaultManifest || pRecordSetConfiguration.RecordSetDashboardManifests?.[0];
419
419
  const tmpManifest = this.pict.PictSectionRecordSet.getManifest(tmpManifestHash);
@@ -509,7 +509,7 @@ class viewRecordSetDashboard extends libPictRecordSetRecordView
509
509
  this.pict.log.error(`RecordSetDashboard: No provider found for ${pProviderHash} in ${pRecordSetConfiguration.RecordSet}. List Render failed.`);
510
510
  return;
511
511
  }
512
- if (pRecordSetConfiguration.RecordSetListManifestOnly)
512
+ if (pRecordSetConfiguration.RecordSetDashboardManifestOnly)
513
513
  {
514
514
  const tmpManifestHash = pRecordSetConfiguration.RecordSetDashboardDefaultManifest || pRecordSetConfiguration.RecordSetDashboardManifests?.[0];
515
515
  const tmpManifest = this.pict.PictSectionRecordSet.getManifest(tmpManifestHash);
@@ -689,7 +689,7 @@ class viewRecordSetDashboard extends libPictRecordSetRecordView
689
689
 
690
690
  // Put code here to preprocess columns into other data parts.
691
691
  /*
692
- "RecordSetListManifestOnly": false,
692
+ "RecordSetDashboardManifestOnly": false,
693
693
 
694
694
  "RecordSetListManifests": [ "Bestsellers", "Underdogs", "NewReleases" ],
695
695
  "RecordSetDashboardManifests": [ "Bestsellers" ],
@@ -193,6 +193,20 @@ class viewRecordSetList extends libPictRecordSetRecordView
193
193
  return;
194
194
  }
195
195
 
196
+ if (pRecordSetConfiguration.RecordSetListManifestOnly)
197
+ {
198
+ const tmpManifestHash = pRecordSetConfiguration.RecordSetListDefaultManifest || pRecordSetConfiguration.RecordSetListManifests?.[0];
199
+ const tmpManifest = this.pict.PictSectionRecordSet.manifestDefinitions[tmpManifestHash];
200
+ if (!tmpManifest)
201
+ {
202
+ this.pict.log.error(`RecordSetList: No manifest found for ${pRecordSetConfiguration.RecordSet}. List Render failed.`);
203
+ }
204
+ else
205
+ {
206
+ return this.renderListFromManifest(tmpManifest, pRecordSetConfiguration, pProviderHash, pFilterString, pSerializedFilterExperience, pOffset, pPageSize);
207
+ }
208
+ }
209
+
196
210
  const tmpEncodedFilterExperience = pSerializedFilterExperience && encodeURIComponent(pSerializedFilterExperience);
197
211
  if (tmpEncodedFilterExperience)
198
212
  {
@@ -411,6 +425,257 @@ class viewRecordSetList extends libPictRecordSetRecordView
411
425
  }.bind(this));
412
426
  }
413
427
 
428
+ /**
429
+ * @param {object} pManifest
430
+ * @param {Record<string, any>} pRecordSetConfiguration
431
+ * @param {string} pProviderHash
432
+ * @param {string} pFilterString
433
+ * @param {string} pSerializedFilterExperience
434
+ * @param {number} pOffset
435
+ * @param {number} pPageSize
436
+ *
437
+ * @return {Promise<void>}
438
+ */
439
+ async renderListFromManifest(pManifest, pRecordSetConfiguration, pProviderHash, pFilterString, pSerializedFilterExperience, pOffset, pPageSize)
440
+ {
441
+ if (!pRecordSetConfiguration)
442
+ {
443
+ this.pict.log.error(`RecordSetList: No record set configuration found. List Render failed.`);
444
+ return;
445
+ }
446
+ // Get the records
447
+ if (!(pProviderHash in this.pict.providers))
448
+ {
449
+ this.pict.log.error(`RecordSetList: No provider found for ${pProviderHash} in ${pRecordSetConfiguration.RecordSet}. List Render failed.`);
450
+ return;
451
+ }
452
+
453
+ let tmpTitle = pRecordSetConfiguration.Title || pRecordSetConfiguration.RecordSet;
454
+ if (pManifest && pManifest.TitleTemplate)
455
+ {
456
+ tmpTitle = this.pict.parseTemplate(pManifest.TitleTemplate, pRecordSetConfiguration);
457
+ }
458
+
459
+ const tmpEncodedFilterExperience = pSerializedFilterExperience && encodeURIComponent(pSerializedFilterExperience);
460
+ if (tmpEncodedFilterExperience)
461
+ {
462
+ // shove filter xp into the active filters for this recordset
463
+ const tmpExperienceFromURL = await this.pict.views['PRSP-Filters'].deserializeFilterExperience(pSerializedFilterExperience);
464
+ if (tmpExperienceFromURL)
465
+ {
466
+ this.pict.manifest.setValueByHash(this.pict.Bundle, `_ActiveFilterState[${pRecordSetConfiguration.RecordSet}].FilterClauses`, tmpExperienceFromURL);
467
+ }
468
+ }
469
+
470
+ let tmpRecordListData =
471
+ {
472
+ "Title": tmpTitle,
473
+
474
+ "RecordSet": pRecordSetConfiguration.RecordSet,
475
+ "RecordSetConfiguration": pRecordSetConfiguration,
476
+
477
+ "RenderDestination": this.options.DefaultDestinationAddress,
478
+
479
+ "FilterString": pFilterString ? encodeURIComponent(pFilterString) : undefined,
480
+
481
+ "Records": { "Records": [] },
482
+ "TotalRecordCount": { "Count": -1 },
483
+
484
+ "Offset": pOffset || 0,
485
+ "PageSize": pPageSize || 100,
486
+ };
487
+
488
+ // TODO: There are still problems with the way these have nested data. Discuss how we might move that around
489
+ // Fetch the records
490
+ tmpRecordListData.Records = await this.pict.providers[pProviderHash].getDecoratedRecords(tmpRecordListData);
491
+ // Get the total record count
492
+ tmpRecordListData.TotalRecordCount = await this.pict.providers[pProviderHash].getRecordSetCount(tmpRecordListData);
493
+ // Get the record schema
494
+ tmpRecordListData.RecordSchema = await this.pict.providers[pProviderHash].getRecordSchema();
495
+
496
+ // TODO: This should be coming from the schema but that can come after we discuss how we deal with default routing
497
+ tmpRecordListData.GUIDAddress = `GUID${this.pict.providers[pProviderHash].options.Entity}`;
498
+
499
+ // Get the "page end record number" for the current page (e.g. for messaging like Record 700 to 800 of 75,000)
500
+ const tmpOffset = Number(tmpRecordListData.Offset);
501
+ tmpRecordListData.PageEnd = tmpOffset + tmpRecordListData.Records.Records.length;
502
+
503
+ // Compute the number of pages total
504
+ tmpRecordListData.PageCount = Math.ceil(tmpRecordListData.TotalRecordCount.Count / tmpRecordListData.PageSize);
505
+
506
+ // Generate each page's links.
507
+ // TODO: This is fast and cool; any reason not to?
508
+ // Get "bookmarks" as references to the array of page links.
509
+ tmpRecordListData.PageLinkBookmarks = (
510
+ {
511
+ Current: Math.floor(tmpRecordListData.Offset / tmpRecordListData.PageSize)
512
+ });
513
+ tmpRecordListData.PageLinks = [];
514
+ for (let i = 0; i < tmpRecordListData.PageCount; i++)
515
+ {
516
+ if (tmpRecordListData.FilterString)
517
+ {
518
+ tmpRecordListData.PageLinks.push(
519
+ {
520
+ Page: i + 1,
521
+ RelativeOffset: i - tmpRecordListData.PageLinkBookmarks.Current,
522
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/List/FilteredTo/${tmpRecordListData.FilterString}/${i * tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
523
+ });
524
+ }
525
+ else
526
+ {
527
+ tmpRecordListData.PageLinks.push(
528
+ {
529
+ Page: i + 1,
530
+ RelativeOffset: i - tmpRecordListData.PageLinkBookmarks.Current,
531
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/List/${i * tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
532
+ });
533
+ }
534
+ if (tmpEncodedFilterExperience)
535
+ {
536
+ tmpRecordListData.PageLinks[tmpRecordListData.PageLinks.length - 1].URL += `/FilterExperience/${tmpEncodedFilterExperience}`;
537
+ }
538
+ }
539
+
540
+ //FIXME: short-term workaround to not blow up the tempplate rendering with way too many links
541
+ const linkRangeStart = Math.max(0, tmpRecordListData.PageLinkBookmarks.Current - 10);
542
+ const linkRangeEnd = Math.min(tmpRecordListData.PageLinks.length, tmpRecordListData.PageLinkBookmarks.Current + 10);
543
+ tmpRecordListData.PageLinksLimited = tmpRecordListData.PageLinks.slice(linkRangeStart, linkRangeEnd);
544
+ if (linkRangeStart > 0)
545
+ {
546
+ if (tmpRecordListData.FilterString)
547
+ {
548
+ tmpRecordListData.PageLinksLimited.unshift(
549
+ {
550
+ Page: 1,
551
+ RelativeOffset: -tmpRecordListData.PageLinkBookmarks.Current,
552
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/list/FilteredTo/${tmpRecordListData.FilterString}/${tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
553
+ });
554
+ }
555
+ else
556
+ {
557
+ tmpRecordListData.PageLinksLimited.unshift(
558
+ {
559
+ Page: 1,
560
+ RelativeOffset: -tmpRecordListData.PageLinkBookmarks.Current,
561
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/List/0/${tmpRecordListData.PageSize}`
562
+ });
563
+ }
564
+ if (tmpEncodedFilterExperience)
565
+ {
566
+ tmpRecordListData.PageLinksLimited[tmpRecordListData.PageLinksLimited.length - 1].URL += `/FilterExperience/${tmpEncodedFilterExperience}`;
567
+ }
568
+ }
569
+ if (linkRangeEnd < tmpRecordListData.PageLinks.length)
570
+ {
571
+ if (tmpRecordListData.FilterString)
572
+ {
573
+ tmpRecordListData.PageLinksLimited.push(
574
+ {
575
+ Page: tmpRecordListData.PageCount,
576
+ RelativeOffset: (tmpRecordListData.PageCount - 1) - tmpRecordListData.PageLinkBookmarks.Current,
577
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/List/FilteredTo/${tmpRecordListData.FilterString}/${(tmpRecordListData.PageCount - 1) * tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
578
+ });
579
+ }
580
+ else
581
+ {
582
+ tmpRecordListData.PageLinksLimited.push(
583
+ {
584
+ Page: tmpRecordListData.PageCount,
585
+ RelativeOffset: (tmpRecordListData.PageCount - 1) - tmpRecordListData.PageLinkBookmarks.Current,
586
+ URL: `#/PSRS/${tmpRecordListData.RecordSet}/List/${(tmpRecordListData.PageCount - 1) * tmpRecordListData.PageSize}/${tmpRecordListData.PageSize}`
587
+ });
588
+ }
589
+ if (tmpEncodedFilterExperience)
590
+ {
591
+ tmpRecordListData.PageLinksLimited[tmpRecordListData.PageLinksLimited.length - 1].URL += `/FilterExperience/${tmpEncodedFilterExperience}`;
592
+ }
593
+ }
594
+
595
+ tmpRecordListData.PageLinkBookmarks.Previous = tmpRecordListData.PageLinkBookmarks.Current - 1;
596
+ tmpRecordListData.PageLinkBookmarks.Next = tmpRecordListData.PageLinkBookmarks.Current + 1;
597
+ tmpRecordListData.PageLinkBookmarks.ShowPreviousLink = true;
598
+ tmpRecordListData.PageLinkBookmarks.ShowNextLink = true;
599
+ if (tmpRecordListData.PageLinkBookmarks.Previous < 0)
600
+ {
601
+ tmpRecordListData.PageLinkBookmarks.PreviousLink = false;
602
+ tmpRecordListData.PageLinkBookmarks.ShowPreviousLink = false;
603
+ }
604
+ else
605
+ {
606
+ tmpRecordListData.PageLinkBookmarks.PreviousLink = tmpRecordListData.PageLinks[tmpRecordListData.PageLinkBookmarks.Previous];
607
+ }
608
+ if (tmpRecordListData.PageLinkBookmarks.Next >= tmpRecordListData.PageLinks.length)
609
+ {
610
+ tmpRecordListData.PageLinkBookmarks.NextLink = false;
611
+ tmpRecordListData.PageLinkBookmarks.ShowNextLink = false;
612
+ }
613
+ else
614
+ {
615
+ tmpRecordListData.PageLinkBookmarks.NextLink = tmpRecordListData.PageLinks[tmpRecordListData.PageLinkBookmarks.Next];
616
+ }
617
+
618
+ tmpRecordListData.TableCells = pManifest?.TableCells;
619
+
620
+ if (!tmpRecordListData.TableCells)
621
+ {
622
+ if (tmpRecordListData.RecordSetConfiguration.hasOwnProperty('RecordSetListColumns'))
623
+ {
624
+ tmpRecordListData.TableCells = tmpRecordListData.RecordSetConfiguration.RecordSetListColumns.map((key) =>
625
+ {
626
+ if (typeof key === 'object')
627
+ {
628
+ if (!key.DisplayName)
629
+ {
630
+ key.DisplayName = key.Key; //FIXME: use schema?
631
+ }
632
+ if (!key.ManifestHash)
633
+ {
634
+ key.ManifestHash = 'Default';
635
+ }
636
+ return key;
637
+ }
638
+ return {
639
+ Key: key,
640
+ DisplayName: key, //FIXME: use schema?
641
+ ManifestHash: 'Default',
642
+ PictDashboard:
643
+ {
644
+ ValueTemplate: '{~DVBK:Record.Payload:Record.Data.Key~}',
645
+ },
646
+ };
647
+ });
648
+ }
649
+ else
650
+ {
651
+ this.dynamicallyGenerateColumns(tmpRecordListData);
652
+ }
653
+ }
654
+
655
+ tmpRecordListData = this.onBeforeRenderList(tmpRecordListData);
656
+
657
+ this.pict.providers.DynamicRecordsetSolver.solveDashboard(pManifest, tmpRecordListData.Records.Records);
658
+
659
+ this.renderAsync('PRSP_Renderable_List', tmpRecordListData.RenderDestination, tmpRecordListData,
660
+ function (pError)
661
+ {
662
+ if (pError)
663
+ {
664
+ this.pict.log.error(`RecordSetList: Error rendering list ${pError}`, tmpRecordListData);
665
+ return;
666
+ }
667
+
668
+ if (this.pict.LogNoisiness > 0)
669
+ {
670
+ this.pict.log.info(`RecordSetList: Rendered list ${tmpRecordListData.RecordSet} with ${tmpRecordListData.Records.Records.length} records.`, tmpRecordListData);
671
+ }
672
+ else
673
+ {
674
+ this.pict.log.info(`RecordSetList: Rendered list ${tmpRecordListData.RecordSet} with ${tmpRecordListData.Records.Records.length} records.`);
675
+ }
676
+ }.bind(this));
677
+ }
678
+
414
679
  onInitialize()
415
680
  {
416
681
  this.childViews.headerList = this.pict.addView('PRSP-List-HeaderList', viewHeaderList.default_configuration, viewHeaderList);