@sumaris-net/ngx-components 1.15.13 → 1.16.1

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.
@@ -11314,18 +11314,14 @@
11314
11314
  var HttpUtils = /** @class */ (function () {
11315
11315
  function HttpUtils() {
11316
11316
  }
11317
- HttpUtils.getResource = function (http, uri, opts) {
11317
+ HttpUtils.getText = function (http, uri, opts) {
11318
11318
  return __awaiter(this, void 0, void 0, function () {
11319
11319
  var err_1;
11320
11320
  return __generator(this, function (_a) {
11321
11321
  switch (_a.label) {
11322
11322
  case 0:
11323
11323
  // Add headers
11324
- opts = Object.assign({}, opts
11325
- //headers: new HttpHeaders(),
11326
- //.append('X-App-Name', environment.name)
11327
- //.append('X-App-Version', environment.version),
11328
- );
11324
+ opts = opts || { responseType: 'text' };
11329
11325
  // Force no cache
11330
11326
  if (opts.nocache === true) {
11331
11327
  opts.headers = (opts.headers instanceof i2$1.HttpHeaders ? opts.headers : new i2$1.HttpHeaders(opts.headers));
@@ -11336,10 +11332,8 @@
11336
11332
  _a.label = 1;
11337
11333
  case 1:
11338
11334
  _a.trys.push([1, 3, , 4]);
11339
- return [4 /*yield*/, http.get(uri, opts).toPromise()];
11340
- case 2:
11341
- // Using web http client
11342
- return [2 /*return*/, (_a.sent())];
11335
+ return [4 /*yield*/, http.get(uri, Object.assign(Object.assign({}, opts), { responseType: 'text' })).toPromise()];
11336
+ case 2: return [2 /*return*/, (_a.sent())];
11343
11337
  case 3:
11344
11338
  err_1 = _a.sent();
11345
11339
  if (err_1 && err_1.message) {
@@ -11354,6 +11348,40 @@
11354
11348
  });
11355
11349
  });
11356
11350
  };
11351
+ HttpUtils.getJson = function (http, uri, opts) {
11352
+ return __awaiter(this, void 0, void 0, function () {
11353
+ var err_2;
11354
+ return __generator(this, function (_a) {
11355
+ switch (_a.label) {
11356
+ case 0:
11357
+ // Add headers
11358
+ opts = opts || {};
11359
+ // Force no cache
11360
+ if (opts.nocache === true) {
11361
+ opts.headers = (opts.headers instanceof i2$1.HttpHeaders ? opts.headers : new i2$1.HttpHeaders(opts.headers));
11362
+ opts.headers
11363
+ .append('Cache-Control', 'no-cache')
11364
+ .append('Pragma', 'no-cache');
11365
+ }
11366
+ _a.label = 1;
11367
+ case 1:
11368
+ _a.trys.push([1, 3, , 4]);
11369
+ return [4 /*yield*/, http.get(uri, Object.assign(Object.assign({}, opts), { responseType: 'json' })).toPromise()];
11370
+ case 2: return [2 /*return*/, (_a.sent())];
11371
+ case 3:
11372
+ err_2 = _a.sent();
11373
+ if (err_2 && err_2.message) {
11374
+ console.error("[network] Error on get request " + uri + ": " + err_2.message, err_2);
11375
+ }
11376
+ else {
11377
+ console.error("[network] Error on get request " + uri + ": " + (err_2 && err_2.statusText) + " - " + JSON.stringify(err_2));
11378
+ }
11379
+ throw { code: err_2.status, message: 'ERROR.UNKNOWN_NETWORK_ERROR' };
11380
+ case 4: return [2 /*return*/];
11381
+ }
11382
+ });
11383
+ });
11384
+ };
11357
11385
  return HttpUtils;
11358
11386
  }());
11359
11387
 
@@ -11374,7 +11402,7 @@
11374
11402
  if (peerUrl.endsWith('/')) {
11375
11403
  peerUrl = peerUrl.substr(0, peerUrl.length - 1);
11376
11404
  }
11377
- return [2 /*return*/, HttpUtils.getResource(http, peerUrl + '/api/node/info', opts)];
11405
+ return [2 /*return*/, HttpUtils.getJson(http, peerUrl + '/api/node/info', opts)];
11378
11406
  });
11379
11407
  });
11380
11408
  }
@@ -12639,7 +12667,7 @@
12639
12667
  if (opts === null || opts === void 0 ? void 0 : opts.nocache) {
12640
12668
  path += '?t=' + Date.now();
12641
12669
  }
12642
- return [4 /*yield*/, this.get(path, opts)];
12670
+ return [4 /*yield*/, this.getText(path, opts)];
12643
12671
  case 1:
12644
12672
  appVersion = _b.sent();
12645
12673
  if (isNotNilOrBlank(appVersion))
@@ -12906,31 +12934,43 @@
12906
12934
  });
12907
12935
  this._timerSubscription.add(function () { return console.debug('[network] Refresh timer stopped'); });
12908
12936
  };
12937
+ NetworkService.prototype.getText = function (path, opts) {
12938
+ return __awaiter(this, void 0, void 0, function () {
12939
+ var uri;
12940
+ return __generator(this, function (_b) {
12941
+ uri = this.getUri(path);
12942
+ return [2 /*return*/, HttpUtils.getText(this.http, uri, opts)];
12943
+ });
12944
+ });
12945
+ };
12909
12946
  NetworkService.prototype.get = function (path, opts) {
12910
12947
  return __awaiter(this, void 0, void 0, function () {
12911
- var uri, peerUrl;
12948
+ var uri;
12912
12949
  return __generator(this, function (_b) {
12913
- uri = path;
12914
- // If path is not an URI: prepend with peer URL
12915
- if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
12916
- peerUrl = (this.peer && this.peer.url);
12917
- // Remove trailing slash
12918
- if (peerUrl.endsWith('/')) {
12919
- peerUrl = peerUrl.substr(0, peerUrl.length - 1);
12920
- }
12921
- // Add first path
12922
- if (!path.startsWith('/')) {
12923
- path = '/' + path;
12924
- }
12925
- // Create the URI: concat peer URL and path
12926
- uri = peerUrl + path;
12927
- }
12928
- // Execute the request
12929
- return [2 /*return*/, HttpUtils.getResource(this.http, uri, opts)];
12950
+ uri = this.getUri(path);
12951
+ return [2 /*return*/, HttpUtils.getJson(this.http, uri, opts)];
12930
12952
  });
12931
12953
  });
12932
12954
  };
12933
12955
  /* -- Protected methods -- */
12956
+ NetworkService.prototype.getUri = function (path) {
12957
+ var uri = path;
12958
+ // If path is not an URI: prepend with peer URL
12959
+ if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
12960
+ var peerUrl = (this.peer && this.peer.url);
12961
+ // Remove trailing slash
12962
+ if (peerUrl.endsWith('/')) {
12963
+ peerUrl = peerUrl.substr(0, peerUrl.length - 1);
12964
+ }
12965
+ // Add first path
12966
+ if (!path.startsWith('/')) {
12967
+ path = '/' + path;
12968
+ }
12969
+ // Create the URI: concat peer URL and path
12970
+ uri = peerUrl + path;
12971
+ }
12972
+ return uri;
12973
+ };
12934
12974
  NetworkService.prototype.onDeviceConnectionChanged = function (connectionType) {
12935
12975
  connectionType = (connectionType || 'unknown').toLowerCase();
12936
12976
  if (connectionType.startsWith('cell'))
@@ -20261,51 +20301,57 @@
20261
20301
  };
20262
20302
  JobUtils.run = function (runnable, opts) {
20263
20303
  var progression = new rxjs.BehaviorSubject(0);
20264
- runnable(progression, opts)
20304
+ runnable(Object.assign(Object.assign({}, opts), { progression: progression }))
20265
20305
  .then(function () {
20266
- if (opts && opts.maxProgression)
20306
+ if (opts === null || opts === void 0 ? void 0 : opts.maxProgression)
20267
20307
  progression.next(opts.maxProgression);
20268
- progression.complete();
20308
+ if (opts === null || opts === void 0 ? void 0 : opts.progression)
20309
+ opts.progression.complete();
20269
20310
  })
20270
20311
  .catch(function (err) { return progression.error(err); });
20271
20312
  return progression;
20272
20313
  };
20273
- JobUtils.fetchAllPages = function (loadPageFn, progression, opts) {
20314
+ JobUtils.fetchAllPages = function (loadPageFn, opts) {
20315
+ var _a;
20274
20316
  return __awaiter(this, void 0, void 0, function () {
20275
- var maxProgression, total, loopCount, progressionStep, loopDataCount, fetchSize, offset, data, res, lastProgressionStep;
20276
- return __generator(this, function (_a) {
20277
- 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) {
20278
20320
  case 0:
20279
20321
  maxProgression = opts && opts.maxProgression || undefined;
20280
20322
  fetchSize = opts && opts.fetchSize || 1000;
20281
20323
  offset = 0;
20282
20324
  data = [];
20283
- _a.label = 1;
20325
+ _b.label = 1;
20284
20326
  case 1:
20285
20327
  if (opts && opts.logPrefix)
20286
20328
  console.debug(opts.logPrefix + " Fetching page #" + offset / fetchSize + "...");
20287
20329
  return [4 /*yield*/, loadPageFn(offset, fetchSize)];
20288
20330
  case 2:
20289
- res = _a.sent();
20331
+ res = _b.sent();
20290
20332
  data = data.concat(res.data);
20291
- loopDataCount = res.data && res.data.length || 0;
20292
- offset += loopDataCount;
20333
+ currentPageDataCount = res.data && res.data.length || 0;
20334
+ offset += currentPageDataCount;
20293
20335
  // Set total count (only if not already set)
20294
20336
  if (isNil(total) && isNotNil(res.total)) {
20295
20337
  total = res.total;
20296
- loopCount = Math.round(res.total / fetchSize + 0.5); // Round to next integer
20297
- 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*/;
20298
20344
  }
20299
20345
  // Increment progression on each iteration (if possible)
20300
- if (isNotNil(progressionStep)) {
20301
- progression.next(progression.getValue() + progressionStep);
20346
+ if (opts && opts.progression && isNotNil(progressionStep)) {
20347
+ opts.progression.next(opts.progression.value + progressionStep);
20302
20348
  }
20303
20349
  if (opts && opts.onPageLoaded)
20304
20350
  opts.onPageLoaded(res);
20305
- _a.label = 3;
20351
+ _b.label = 3;
20306
20352
  case 3:
20307
- if (loopDataCount > 0 && ((isNil(total) && loopDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20308
- _a.label = 4;
20353
+ if (currentPageDataCount > 0 && ((isNil(total) && currentPageDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20354
+ _b.label = 4;
20309
20355
  case 4:
20310
20356
  // Complete progression to reach progressionStep value (because of round)
20311
20357
  if (isNotNil(progressionStep)) {
@@ -20313,16 +20359,16 @@
20313
20359
  if (isNotNil(total) && data.length < total) {
20314
20360
  console.warn("A function loadAll() returned a bad total (less than all page's data)! Expected " + total + " but fetch " + data.length);
20315
20361
  total = data.length;
20316
- loopCount = Math.round(data.length / fetchSize + 0.5);
20362
+ pageCount = Math.round(data.length / fetchSize + 0.5);
20317
20363
  }
20318
- lastProgressionStep = opts.maxProgression - (progressionStep * loopCount);
20319
- if (lastProgressionStep > 0) {
20320
- 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);
20321
20367
  }
20322
20368
  }
20323
20369
  // Or increment once
20324
- else if (opts.maxProgression) {
20325
- progression.next(progression.getValue() + opts.maxProgression);
20370
+ else if (opts && opts.progression && opts.maxProgression) {
20371
+ opts.progression.next(opts.maxProgression);
20326
20372
  }
20327
20373
  return [2 /*return*/, {
20328
20374
  data: data,
@@ -29419,28 +29465,25 @@
29419
29465
  });
29420
29466
  });
29421
29467
  };
29422
- PersonService.prototype.executeImport = function (progression, opts) {
29468
+ PersonService.prototype.executeImport = function (filter, opts) {
29423
29469
  var _super = Object.create(null, {
29424
29470
  loadAll: { get: function () { return _super_1.prototype.loadAll; } }
29425
29471
  });
29426
29472
  return __awaiter(this, void 0, void 0, function () {
29427
- var maxProgression, filter, res;
29473
+ var maxProgression, res;
29428
29474
  var _this = this;
29429
29475
  return __generator(this, function (_a) {
29430
29476
  switch (_a.label) {
29431
29477
  case 0:
29432
29478
  maxProgression = opts && opts.maxProgression || 100;
29433
- filter = {
29434
- statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY],
29435
- userProfiles: ['SUPERVISOR', 'USER', 'GUEST']
29436
- };
29479
+ filter = Object.assign(Object.assign({}, filter), { statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY], userProfiles: ['SUPERVISOR', 'USER', 'GUEST'] });
29437
29480
  console.info('[person-service] Importing persons...');
29438
29481
  return [4 /*yield*/, JobUtils.fetchAllPages(function (offset, size) { return _super.loadAll.call(_this, offset, size, 'id', null, filter, {
29439
29482
  debug: false,
29440
29483
  fetchPolicy: 'network-only',
29441
29484
  withTotal: (offset === 0),
29442
29485
  toEntity: false
29443
- }); }, progression, { maxProgression: maxProgression * 0.9 })];
29486
+ }); }, Object.assign(Object.assign({}, opts), { maxProgression: maxProgression * 0.9 }))];
29444
29487
  case 1:
29445
29488
  res = _a.sent();
29446
29489
  // Save result locally
@@ -29458,7 +29501,7 @@
29458
29501
  if (!source)
29459
29502
  return undefined;
29460
29503
  console.debug('TODO check isInstanceOf');
29461
- if (!isInstanceOf(source, exports.Person)) {
29504
+ if (!(source instanceof exports.Person)) {
29462
29505
  source = exports.Person.fromObject(source);
29463
29506
  }
29464
29507
  var target = source.asObject();