@sumaris-net/ngx-components 1.15.14 → 1.16.0

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.
@@ -20301,51 +20301,57 @@
20301
20301
  };
20302
20302
  JobUtils.run = function (runnable, opts) {
20303
20303
  var progression = new rxjs.BehaviorSubject(0);
20304
- runnable(progression, opts)
20304
+ runnable(Object.assign(Object.assign({}, opts), { progression: progression }))
20305
20305
  .then(function () {
20306
- if (opts && opts.maxProgression)
20306
+ if (opts === null || opts === void 0 ? void 0 : opts.maxProgression)
20307
20307
  progression.next(opts.maxProgression);
20308
- progression.complete();
20308
+ if (opts === null || opts === void 0 ? void 0 : opts.progression)
20309
+ opts.progression.complete();
20309
20310
  })
20310
20311
  .catch(function (err) { return progression.error(err); });
20311
20312
  return progression;
20312
20313
  };
20313
- JobUtils.fetchAllPages = function (loadPageFn, progression, opts) {
20314
+ JobUtils.fetchAllPages = function (loadPageFn, opts) {
20315
+ var _a;
20314
20316
  return __awaiter(this, void 0, void 0, function () {
20315
- var maxProgression, total, loopCount, progressionStep, loopDataCount, fetchSize, offset, data, res, lastProgressionStep;
20316
- return __generator(this, function (_a) {
20317
- switch (_a.label) {
20317
+ var maxProgression, total, pageCount, progressionStep, currentPageDataCount, fetchSize, offset, data, res, actualProgression, lastProgressionStep;
20318
+ return __generator(this, function (_b) {
20319
+ switch (_b.label) {
20318
20320
  case 0:
20319
20321
  maxProgression = opts && opts.maxProgression || undefined;
20320
20322
  fetchSize = opts && opts.fetchSize || 1000;
20321
20323
  offset = 0;
20322
20324
  data = [];
20323
- _a.label = 1;
20325
+ _b.label = 1;
20324
20326
  case 1:
20325
20327
  if (opts && opts.logPrefix)
20326
20328
  console.debug(opts.logPrefix + " Fetching page #" + offset / fetchSize + "...");
20327
20329
  return [4 /*yield*/, loadPageFn(offset, fetchSize)];
20328
20330
  case 2:
20329
- res = _a.sent();
20331
+ res = _b.sent();
20330
20332
  data = data.concat(res.data);
20331
- loopDataCount = res.data && res.data.length || 0;
20332
- offset += loopDataCount;
20333
+ currentPageDataCount = res.data && res.data.length || 0;
20334
+ offset += currentPageDataCount;
20333
20335
  // Set total count (only if not already set)
20334
20336
  if (isNil(total) && isNotNil(res.total)) {
20335
20337
  total = res.total;
20336
- loopCount = Math.round(res.total / fetchSize + 0.5); // Round to next integer
20337
- progressionStep = maxProgression ? maxProgression / loopCount : undefined /*if 0 reset to undefined*/;
20338
+ // Compute the number of page
20339
+ 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*/;
20338
20344
  }
20339
20345
  // Increment progression on each iteration (if possible)
20340
- if (isNotNil(progressionStep)) {
20341
- progression.next(progression.getValue() + progressionStep);
20346
+ if (opts && opts.progression && isNotNil(progressionStep)) {
20347
+ opts.progression.next(opts.progression.value + progressionStep);
20342
20348
  }
20343
20349
  if (opts && opts.onPageLoaded)
20344
20350
  opts.onPageLoaded(res);
20345
- _a.label = 3;
20351
+ _b.label = 3;
20346
20352
  case 3:
20347
- if (loopDataCount > 0 && ((isNil(total) && loopDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20348
- _a.label = 4;
20353
+ if (currentPageDataCount > 0 && ((isNil(total) && currentPageDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20354
+ _b.label = 4;
20349
20355
  case 4:
20350
20356
  // Complete progression to reach progressionStep value (because of round)
20351
20357
  if (isNotNil(progressionStep)) {
@@ -20353,16 +20359,16 @@
20353
20359
  if (isNotNil(total) && data.length < total) {
20354
20360
  console.warn("A function loadAll() returned a bad total (less than all page's data)! Expected " + total + " but fetch " + data.length);
20355
20361
  total = data.length;
20356
- loopCount = Math.round(data.length / fetchSize + 0.5);
20362
+ pageCount = Math.round(data.length / fetchSize + 0.5);
20357
20363
  }
20358
- lastProgressionStep = opts.maxProgression - (progressionStep * loopCount);
20359
- if (lastProgressionStep > 0) {
20360
- progression.next(progression.getValue() + lastProgressionStep);
20364
+ lastProgressionStep = opts.maxProgression - (progressionStep * pageCount);
20365
+ if (opts && opts.progression && lastProgressionStep > 0) {
20366
+ opts.progression.next(opts.progression.value + lastProgressionStep);
20361
20367
  }
20362
20368
  }
20363
20369
  // Or increment once
20364
- else if (opts.maxProgression) {
20365
- progression.next(progression.getValue() + opts.maxProgression);
20370
+ else if (opts && opts.progression && opts.maxProgression) {
20371
+ opts.progression.next(opts.progression.value + opts.maxProgression);
20366
20372
  }
20367
20373
  return [2 /*return*/, {
20368
20374
  data: data,
@@ -29459,28 +29465,25 @@
29459
29465
  });
29460
29466
  });
29461
29467
  };
29462
- PersonService.prototype.executeImport = function (progression, opts) {
29468
+ PersonService.prototype.executeImport = function (filter, opts) {
29463
29469
  var _super = Object.create(null, {
29464
29470
  loadAll: { get: function () { return _super_1.prototype.loadAll; } }
29465
29471
  });
29466
29472
  return __awaiter(this, void 0, void 0, function () {
29467
- var maxProgression, filter, res;
29473
+ var maxProgression, res;
29468
29474
  var _this = this;
29469
29475
  return __generator(this, function (_a) {
29470
29476
  switch (_a.label) {
29471
29477
  case 0:
29472
29478
  maxProgression = opts && opts.maxProgression || 100;
29473
- filter = {
29474
- statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY],
29475
- userProfiles: ['SUPERVISOR', 'USER', 'GUEST']
29476
- };
29479
+ filter = Object.assign(Object.assign({}, filter), { statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY], userProfiles: ['SUPERVISOR', 'USER', 'GUEST'] });
29477
29480
  console.info('[person-service] Importing persons...');
29478
29481
  return [4 /*yield*/, JobUtils.fetchAllPages(function (offset, size) { return _super.loadAll.call(_this, offset, size, 'id', null, filter, {
29479
29482
  debug: false,
29480
29483
  fetchPolicy: 'network-only',
29481
29484
  withTotal: (offset === 0),
29482
29485
  toEntity: false
29483
- }); }, progression, { maxProgression: maxProgression * 0.9 })];
29486
+ }); }, Object.assign(Object.assign({}, opts), { maxProgression: maxProgression * 0.9 }))];
29484
29487
  case 1:
29485
29488
  res = _a.sent();
29486
29489
  // Save result locally
@@ -29498,7 +29501,7 @@
29498
29501
  if (!source)
29499
29502
  return undefined;
29500
29503
  console.debug('TODO check isInstanceOf');
29501
- if (!isInstanceOf(source, exports.Person)) {
29504
+ if (!(source instanceof exports.Person)) {
29502
29505
  source = exports.Person.fromObject(source);
29503
29506
  }
29504
29507
  var target = source.asObject();