@sumaris-net/ngx-components 1.15.12 → 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.
@@ -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'))
@@ -18426,11 +18466,11 @@
18426
18466
  return FileResponse;
18427
18467
  }());
18428
18468
  function isProgressEvent(event) {
18429
- return event.type === i2$1.HttpEventType.UploadProgress
18430
- || event.type === i2$1.HttpEventType.DownloadProgress;
18469
+ return event && (event.type === i2$1.HttpEventType.UploadProgress
18470
+ || event.type === i2$1.HttpEventType.DownloadProgress);
18431
18471
  }
18432
18472
  function isResponseEvent(event) {
18433
- return event.type === i2$1.HttpEventType.Response;
18473
+ return event && event.type === i2$1.HttpEventType.Response;
18434
18474
  }
18435
18475
 
18436
18476
  var UploadFileComponent = /** @class */ (function () {
@@ -18573,7 +18613,7 @@
18573
18613
  });
18574
18614
  jobs = files
18575
18615
  .map(function (f) { return f; })
18576
- .filter(function (file) { return isNil(file.progress) && !file.error; }) // Skip if already started or in error
18616
+ .filter(function (file) { return file && isNil(file.progress) && !file.error; }) // Skip if already started or in error
18577
18617
  .map(function (file, i) {
18578
18618
  // Wait if need
18579
18619
  if (isNotNil(_this.maxParallelUpload)) {
@@ -18591,12 +18631,12 @@
18591
18631
  file.progress = 0;
18592
18632
  return rxjs.of(file);
18593
18633
  })
18594
- .map(function (file$) { return file$.pipe(
18634
+ .map(function (file$) { return file$.pipe(operators.filter(isNotNil),
18595
18635
  // Log
18596
18636
  operators.tap(function (file) { return console.debug("[upload-file] " + file.name + ": uploading..."); }),
18597
18637
  // Start uploading
18598
18638
  operators.switchMap(function (file) { return _this.uploadFn(file)
18599
- .pipe(operators.map(function (event) {
18639
+ .pipe(operators.filter(isNotNil), operators.map(function (event) {
18600
18640
  // Progress event
18601
18641
  if (isProgressEvent(event)) {
18602
18642
  if (isNotNil(event.loaded) && event.loaded >= 0) {
@@ -18606,10 +18646,6 @@
18606
18646
  file.progress = -1; // Indeterminate progression
18607
18647
  }
18608
18648
  }
18609
- // User event
18610
- else if (event.type === i2$1.HttpEventType.User) {
18611
- file.progress = -1; // Indeterminate progression
18612
- }
18613
18649
  // Response event
18614
18650
  else if (isResponseEvent(event)) {
18615
18651
  file.progress = 1;
@@ -20265,51 +20301,57 @@
20265
20301
  };
20266
20302
  JobUtils.run = function (runnable, opts) {
20267
20303
  var progression = new rxjs.BehaviorSubject(0);
20268
- runnable(progression, opts)
20304
+ runnable(Object.assign(Object.assign({}, opts), { progression: progression }))
20269
20305
  .then(function () {
20270
- if (opts && opts.maxProgression)
20306
+ if (opts === null || opts === void 0 ? void 0 : opts.maxProgression)
20271
20307
  progression.next(opts.maxProgression);
20272
- progression.complete();
20308
+ if (opts === null || opts === void 0 ? void 0 : opts.progression)
20309
+ opts.progression.complete();
20273
20310
  })
20274
20311
  .catch(function (err) { return progression.error(err); });
20275
20312
  return progression;
20276
20313
  };
20277
- JobUtils.fetchAllPages = function (loadPageFn, progression, opts) {
20314
+ JobUtils.fetchAllPages = function (loadPageFn, opts) {
20315
+ var _a;
20278
20316
  return __awaiter(this, void 0, void 0, function () {
20279
- var maxProgression, total, loopCount, progressionStep, loopDataCount, fetchSize, offset, data, res, lastProgressionStep;
20280
- return __generator(this, function (_a) {
20281
- 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) {
20282
20320
  case 0:
20283
20321
  maxProgression = opts && opts.maxProgression || undefined;
20284
20322
  fetchSize = opts && opts.fetchSize || 1000;
20285
20323
  offset = 0;
20286
20324
  data = [];
20287
- _a.label = 1;
20325
+ _b.label = 1;
20288
20326
  case 1:
20289
20327
  if (opts && opts.logPrefix)
20290
20328
  console.debug(opts.logPrefix + " Fetching page #" + offset / fetchSize + "...");
20291
20329
  return [4 /*yield*/, loadPageFn(offset, fetchSize)];
20292
20330
  case 2:
20293
- res = _a.sent();
20331
+ res = _b.sent();
20294
20332
  data = data.concat(res.data);
20295
- loopDataCount = res.data && res.data.length || 0;
20296
- offset += loopDataCount;
20333
+ currentPageDataCount = res.data && res.data.length || 0;
20334
+ offset += currentPageDataCount;
20297
20335
  // Set total count (only if not already set)
20298
20336
  if (isNil(total) && isNotNil(res.total)) {
20299
20337
  total = res.total;
20300
- loopCount = Math.round(res.total / fetchSize + 0.5); // Round to next integer
20301
- 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*/;
20302
20344
  }
20303
20345
  // Increment progression on each iteration (if possible)
20304
- if (isNotNil(progressionStep)) {
20305
- progression.next(progression.getValue() + progressionStep);
20346
+ if (opts && opts.progression && isNotNil(progressionStep)) {
20347
+ opts.progression.next(opts.progression.value + progressionStep);
20306
20348
  }
20307
20349
  if (opts && opts.onPageLoaded)
20308
20350
  opts.onPageLoaded(res);
20309
- _a.label = 3;
20351
+ _b.label = 3;
20310
20352
  case 3:
20311
- if (loopDataCount > 0 && ((isNil(total) && loopDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20312
- _a.label = 4;
20353
+ if (currentPageDataCount > 0 && ((isNil(total) && currentPageDataCount === fetchSize) || (isNotNil(total) && (offset < total)))) return [3 /*break*/, 1];
20354
+ _b.label = 4;
20313
20355
  case 4:
20314
20356
  // Complete progression to reach progressionStep value (because of round)
20315
20357
  if (isNotNil(progressionStep)) {
@@ -20317,16 +20359,16 @@
20317
20359
  if (isNotNil(total) && data.length < total) {
20318
20360
  console.warn("A function loadAll() returned a bad total (less than all page's data)! Expected " + total + " but fetch " + data.length);
20319
20361
  total = data.length;
20320
- loopCount = Math.round(data.length / fetchSize + 0.5);
20362
+ pageCount = Math.round(data.length / fetchSize + 0.5);
20321
20363
  }
20322
- lastProgressionStep = opts.maxProgression - (progressionStep * loopCount);
20323
- if (lastProgressionStep > 0) {
20324
- 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);
20325
20367
  }
20326
20368
  }
20327
20369
  // Or increment once
20328
- else if (opts.maxProgression) {
20329
- progression.next(progression.getValue() + opts.maxProgression);
20370
+ else if (opts && opts.progression && opts.maxProgression) {
20371
+ opts.progression.next(opts.progression.value + opts.maxProgression);
20330
20372
  }
20331
20373
  return [2 /*return*/, {
20332
20374
  data: data,
@@ -29423,28 +29465,25 @@
29423
29465
  });
29424
29466
  });
29425
29467
  };
29426
- PersonService.prototype.executeImport = function (progression, opts) {
29468
+ PersonService.prototype.executeImport = function (filter, opts) {
29427
29469
  var _super = Object.create(null, {
29428
29470
  loadAll: { get: function () { return _super_1.prototype.loadAll; } }
29429
29471
  });
29430
29472
  return __awaiter(this, void 0, void 0, function () {
29431
- var maxProgression, filter, res;
29473
+ var maxProgression, res;
29432
29474
  var _this = this;
29433
29475
  return __generator(this, function (_a) {
29434
29476
  switch (_a.label) {
29435
29477
  case 0:
29436
29478
  maxProgression = opts && opts.maxProgression || 100;
29437
- filter = {
29438
- statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY],
29439
- userProfiles: ['SUPERVISOR', 'USER', 'GUEST']
29440
- };
29479
+ filter = Object.assign(Object.assign({}, filter), { statusIds: [StatusIds.ENABLE, StatusIds.TEMPORARY], userProfiles: ['SUPERVISOR', 'USER', 'GUEST'] });
29441
29480
  console.info('[person-service] Importing persons...');
29442
29481
  return [4 /*yield*/, JobUtils.fetchAllPages(function (offset, size) { return _super.loadAll.call(_this, offset, size, 'id', null, filter, {
29443
29482
  debug: false,
29444
29483
  fetchPolicy: 'network-only',
29445
29484
  withTotal: (offset === 0),
29446
29485
  toEntity: false
29447
- }); }, progression, { maxProgression: maxProgression * 0.9 })];
29486
+ }); }, Object.assign(Object.assign({}, opts), { maxProgression: maxProgression * 0.9 }))];
29448
29487
  case 1:
29449
29488
  res = _a.sent();
29450
29489
  // Save result locally
@@ -29462,7 +29501,7 @@
29462
29501
  if (!source)
29463
29502
  return undefined;
29464
29503
  console.debug('TODO check isInstanceOf');
29465
- if (!isInstanceOf(source, exports.Person)) {
29504
+ if (!(source instanceof exports.Person)) {
29466
29505
  source = exports.Person.fromObject(source);
29467
29506
  }
29468
29507
  var target = source.asObject();