@onehat/data 1.19.9 → 1.19.11

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.
@@ -583,6 +583,15 @@ describe('Repository Base', function() {
583
583
  expect(this.repository.page).to.be.eq(1);
584
584
  });
585
585
 
586
+ it('setIsPaginated', function() {
587
+
588
+ this.repository.setIsPaginated(true);
589
+ expect(this.repository.isPaginated).to.be.true;
590
+
591
+ this.repository.setIsPaginated(false);
592
+ expect(this.repository.isPaginated).to.be.false;
593
+ });
594
+
586
595
  });
587
596
 
588
597
  describe('creating', function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.19.9",
3
+ "version": "1.19.11",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -362,8 +362,8 @@ class AjaxRepository extends Repository {
362
362
  * Refreshes entities.
363
363
  */
364
364
  _onChangePagination = () => {
365
- this.setBaseParam(this.paramPageNum, this.page);
366
- this.setBaseParam(this.paramPageSize, this.pageSize);
365
+ this.setBaseParam(this.paramPageNum, this.isPaginated ? this.page : null);
366
+ this.setBaseParam(this.paramPageSize, this.isPaginated ? this.pageSize : null);
367
367
 
368
368
  if (this.isLoaded && !this.eventsPaused) {
369
369
  return this.reload();
@@ -399,6 +399,17 @@ class AjaxRepository extends Repository {
399
399
  this.emit('beforeLoad'); // TODO: canceling beforeLoad will cancel the load operation
400
400
  this.markLoading();
401
401
 
402
+ if (params?.showMore) {
403
+ delete params.showMore;
404
+ this.isShowingMore = true;
405
+ } else {
406
+ this.isShowingMore = false;
407
+ }
408
+ if (this.isShowingMore) {
409
+ this.pauseEvents();
410
+ this.setPage(this.page +1);
411
+ this.resumeEvents();
412
+ }
402
413
 
403
414
  if (!_.isNil(params) && _.isObject(params)) {
404
415
  this.setParams(params);
@@ -426,14 +437,23 @@ class AjaxRepository extends Repository {
426
437
  message
427
438
  } = this._processServerResponse(result);
428
439
 
429
- this._destroyEntities();
430
-
431
- // Set the current entities
432
- this.entities = _.map(root, (data) => {
433
- const entity = Repository._createEntity(this.schema, data, repository, true);
434
- this._relayEntityEvents(entity);
435
- return entity;
436
- });
440
+ if (this.isShowingMore) {
441
+ // Add to the current entities
442
+ const newEntities = _.map(root, (data) => {
443
+ const entity = Repository._createEntity(this.schema, data, repository, true);
444
+ this._relayEntityEvents(entity);
445
+ return entity;
446
+ });
447
+ this.entities = this.entities.concat(newEntities);
448
+ } else {
449
+ // Replace the current entities
450
+ this._destroyEntities();
451
+ this.entities = _.map(root, (data) => {
452
+ const entity = Repository._createEntity(this.schema, data, repository, true);
453
+ this._relayEntityEvents(entity);
454
+ return entity;
455
+ });
456
+ }
437
457
 
438
458
  // Set the total records that pass filter
439
459
  this.total = total;
@@ -456,6 +476,11 @@ class AjaxRepository extends Repository {
456
476
  });
457
477
  }
458
478
 
479
+ showMore = (params = {}, callback) => {
480
+ params.showMore = true;
481
+ return this.load(params, callback);
482
+ }
483
+
459
484
  /**
460
485
  * Reload a single entity from storage.
461
486
  * If the entity is in the internal representation, update it.
@@ -102,6 +102,11 @@ export default class Repository extends EventEmitter {
102
102
  */
103
103
  isPaginated: false,
104
104
 
105
+ /**
106
+ * @member {bool} isShowingMore - Whether this repository is in "show more" mode
107
+ */
108
+ isShowingMore: false,
109
+
105
110
  /**
106
111
  * @member {number} pageSize - Max number of entities per page
107
112
  * Example: For "Showing 21-30 of 45" This would be 10
@@ -801,8 +806,25 @@ export default class Repository extends EventEmitter {
801
806
  this.setPage(1);
802
807
  }
803
808
 
809
+ /**
810
+ * Sets isPaginated
811
+ */
812
+ setIsPaginated = (bool) => {
813
+ if (this.isDestroyed) {
814
+ this.throwError('this.setIsPaginated is no longer valid. Repository has been destroyed.');
815
+ return;
816
+ }
817
+ this.isPaginated = bool;
818
+
819
+ if (this._onChangePagination) {
820
+ return this._onChangePagination();
821
+ }
822
+ return true;
823
+ }
824
+
804
825
  /**
805
826
  * Sets the pageSize
827
+ * @fires changePage
806
828
  * @fires changePageSize
807
829
  */
808
830
  setPageSize = (pageSize) => {
@@ -834,6 +856,7 @@ export default class Repository extends EventEmitter {
834
856
  /**
835
857
  * Advances to a specific page of entities
836
858
  * @return {boolean} success
859
+ * @fires changePage
837
860
  */
838
861
  setPage = (page) => {
839
862
  if (this.isDestroyed) {