@sumaris-net/ngx-components 1.15.14 → 1.16.2

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