@sumaris-net/ngx-components 1.16.0 → 1.16.3

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.
@@ -10935,6 +10935,9 @@
10935
10935
  EntityUtils.isLocalId = function (id) {
10936
10936
  return isNotNil(id) && +id < 0;
10937
10937
  };
10938
+ EntityUtils.isRemoteId = function (id) {
10939
+ return isNotNil(id) && +id >= 0;
10940
+ };
10938
10941
  return EntityUtils;
10939
10942
  }());
10940
10943
 
@@ -20305,53 +20308,59 @@
20305
20308
  .then(function () {
20306
20309
  if (opts === null || opts === void 0 ? void 0 : opts.maxProgression)
20307
20310
  progression.next(opts.maxProgression);
20308
- if (opts === null || opts === void 0 ? void 0 : opts.progression)
20309
- opts.progression.complete();
20311
+ progression.complete();
20310
20312
  })
20311
20313
  .catch(function (err) { return progression.error(err); });
20312
20314
  return progression;
20313
20315
  };
20314
20316
  JobUtils.fetchAllPages = function (loadPageFn, opts) {
20315
- var _a;
20316
20317
  return __awaiter(this, void 0, void 0, function () {
20317
- var maxProgression, total, pageCount, progressionStep, currentPageDataCount, fetchSize, offset, data, res, actualProgression, lastProgressionStep;
20318
- return __generator(this, function (_b) {
20319
- switch (_b.label) {
20318
+ var maxProgression, progression, total, pageCount, progressionStep, currentPageDataCount, fetchSize, offset, data, res;
20319
+ return __generator(this, function (_a) {
20320
+ switch (_a.label) {
20320
20321
  case 0:
20321
- maxProgression = opts && opts.maxProgression || undefined;
20322
- fetchSize = opts && opts.fetchSize || 1000;
20322
+ maxProgression = toNumber(opts === null || opts === void 0 ? void 0 : opts.maxProgression, 100);
20323
+ progression = opts === null || opts === void 0 ? void 0 : opts.progression;
20324
+ fetchSize = toNumber(opts === null || opts === void 0 ? void 0 : opts.fetchSize, 1000);
20325
+ if (fetchSize <= 0)
20326
+ throw new Error('Unable to fetch pages: invalid fetchSize: ' + fetchSize);
20323
20327
  offset = 0;
20324
20328
  data = [];
20325
- _b.label = 1;
20329
+ _a.label = 1;
20326
20330
  case 1:
20327
20331
  if (opts && opts.logPrefix)
20328
20332
  console.debug(opts.logPrefix + " Fetching page #" + offset / fetchSize + "...");
20329
20333
  return [4 /*yield*/, loadPageFn(offset, fetchSize)];
20330
20334
  case 2:
20331
- res = _b.sent();
20335
+ res = _a.sent();
20336
+ // Concat to previous result
20332
20337
  data = data.concat(res.data);
20338
+ // Compute variables, for next loop
20333
20339
  currentPageDataCount = res.data && res.data.length || 0;
20334
20340
  offset += currentPageDataCount;
20335
- // Set total count (only if not already set)
20341
+ // Set total count (only once)
20336
20342
  if (isNil(total) && isNotNil(res.total)) {
20337
20343
  total = res.total;
20338
20344
  // Compute the number of page
20339
20345
  pageCount = Math.round(res.total / fetchSize + 0.5); // Round to HALF_UP integer
20340
- actualProgression = Math.max(0, toNumber(opts && ((_a = opts.progression) === null || _a === void 0 ? void 0 : _a.value), 0));
20341
- progressionStep = maxProgression
20342
- ? (maxProgression - actualProgression) / pageCount
20343
- : undefined /*if 0 reset to undefined*/;
20346
+ // Compute step, by dividing maxProgression by number of page
20347
+ if (progression) {
20348
+ progressionStep = maxProgression / pageCount;
20349
+ // DEBUG
20350
+ if (opts && opts.logPrefix)
20351
+ console.debug(opts.logPrefix + " {pageCount: " + pageCount + ", progression: " + progression.value + ", pageProgressionStep: " + progressionStep + "}");
20352
+ }
20344
20353
  }
20345
20354
  // Increment progression on each iteration (if possible)
20346
- if (opts && opts.progression && isNotNil(progressionStep)) {
20347
- opts.progression.next(opts.progression.value + progressionStep);
20355
+ if (isNotNil(progressionStep)) {
20356
+ progression.next(progression.value + progressionStep);
20348
20357
  }
20349
- if (opts && opts.onPageLoaded)
20358
+ if (opts === null || opts === void 0 ? void 0 : opts.onPageLoaded)
20350
20359
  opts.onPageLoaded(res);
20351
- _b.label = 3;
20360
+ _a.label = 3;
20352
20361
  case 3:
20353
20362
  if (currentPageDataCount > 0 && ((isNil(total) && currentPageDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20354
- _b.label = 4;
20363
+ _a.label = 4;
20355
20364
  case 4:
20356
20365
  // Complete progression to reach progressionStep value (because of round)
20357
20366
  if (isNotNil(progressionStep)) {
@@ -20361,14 +20370,19 @@
20361
20370
  total = data.length;
20362
20371
  pageCount = Math.round(data.length / fetchSize + 0.5);
20363
20372
  }
20364
- lastProgressionStep = opts.maxProgression - (progressionStep * pageCount);
20365
- if (opts && opts.progression && lastProgressionStep > 0) {
20366
- opts.progression.next(opts.progression.value + lastProgressionStep);
20367
- }
20373
+ // Compute final increment, using the real page count
20374
+ progressionStep = Math.max(0, maxProgression - (progressionStep * pageCount));
20375
+ }
20376
+ // Or increment once (e.g. when total is not known, in received LoadResult)
20377
+ else if (progression) {
20378
+ progressionStep = maxProgression;
20368
20379
  }
20369
- // Or increment once
20370
- else if (opts && opts.progression && opts.maxProgression) {
20371
- opts.progression.next(opts.progression.value + opts.maxProgression);
20380
+ // DEBUG
20381
+ if (opts && opts.logPrefix)
20382
+ console.debug(opts.logPrefix + " All pages fetched - {progression: " + progression.value + ", lastProgressionStep: " + progressionStep);
20383
+ // Final increment
20384
+ if (progression && progressionStep > 0) {
20385
+ progression.next(progression.value + progressionStep);
20372
20386
  }
20373
20387
  return [2 /*return*/, {
20374
20388
  data: data,
@@ -29483,7 +29497,7 @@
29483
29497
  fetchPolicy: 'network-only',
29484
29498
  withTotal: (offset === 0),
29485
29499
  toEntity: false
29486
- }); }, Object.assign(Object.assign({}, opts), { maxProgression: maxProgression * 0.9 }))];
29500
+ }); }, { progression: opts === null || opts === void 0 ? void 0 : opts.progression, maxProgression: maxProgression * 0.9 })];
29487
29501
  case 1:
29488
29502
  res = _a.sent();
29489
29503
  // Save result locally