@sumaris-net/ngx-components 0.28.1 → 0.28.5

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.
@@ -2854,23 +2854,42 @@
2854
2854
  TranslateContextService.prototype.get = function (key, context, interpolateParams) {
2855
2855
  var _this = this;
2856
2856
  // No context: do a normal translate
2857
- if (!isNil(context))
2857
+ if (!key || !isNil(context))
2858
2858
  return this.translate.get(key, interpolateParams);
2859
2859
  // Compute a contextual i18n key, using the context as suffix
2860
- var contextKey = this.contextualKey(key, context);
2860
+ var contextualKeys = this.contextualKeys(key, context);
2861
2861
  // Return the contextual translation, or default of not exists
2862
- return this.translate.get(contextKey, interpolateParams)
2863
- .pipe(operators.mergeMap(function (translation) { return (translation !== contextKey) ? rxjs.of(translation) : _this.translate.get(key); }));
2862
+ return this.translate.get(contextualKeys, interpolateParams)
2863
+ .pipe(operators.map(function (translations) { return _this.findFirstValid(contextualKeys, translations); }));
2864
2864
  };
2865
2865
  TranslateContextService.prototype.instant = function (key, context, interpolateParams) {
2866
2866
  // No context: do a normal translate
2867
- if (isNilOrBlank(context))
2867
+ if (!key || isNilOrBlank(context))
2868
2868
  return this.translate.instant(key, interpolateParams);
2869
2869
  // Compute a contextual i18n key, using the context as suffix
2870
- var contextualKey = this.contextualKey(key, context);
2871
- // Return the contextual translation, or default of not exists
2872
- var translation = this.translate.instant(contextualKey, interpolateParams);
2873
- return (translation !== contextualKey) ? translation : this.translate.instant(key, interpolateParams);
2870
+ var contextualKeys = this.contextualKeys(key, context);
2871
+ var translations = this.translate.instant(contextualKeys, interpolateParams);
2872
+ return this.findFirstValid(contextualKeys, translations);
2873
+ };
2874
+ /**
2875
+ * Compute contextual i18n keys, using the context as suffix.<br>
2876
+ * Suffix can be simple name (like 'aaa' - will return ['<key>.aaa']) or complexe (like 'aaa.bbb' - will return ['<key>.aaa.bbb', '<key>.aaa']
2877
+ *
2878
+ * @param key
2879
+ * @param context
2880
+ * @private
2881
+ */
2882
+ TranslateContextService.prototype.contextualKeys = function (key, context) {
2883
+ var _this = this;
2884
+ return context.split('.')
2885
+ .filter(isNotNilOrBlank)
2886
+ .reduce(function (res, item) {
2887
+ var inheritedContext = res.length > 0 ? (res[res.length - 1] + '.') : '';
2888
+ return res.concat(inheritedContext + item);
2889
+ }, [])
2890
+ .reverse() // Start with children, ends with parent key
2891
+ .map(function (contextItem) { return _this.contextualKey(key, contextItem); })
2892
+ .concat(key);
2874
2893
  };
2875
2894
  /**
2876
2895
  * Compute a contextual i18n key, using the context as suffix
@@ -2890,6 +2909,25 @@
2890
2909
  ? "" + context + key
2891
2910
  : parts.slice(0, parts.length - 1).concat(context + parts[parts.length - 1]).join('.');
2892
2911
  };
2912
+ TranslateContextService.prototype.findFirstValid = function (keys, translations) {
2913
+ var e_1, _a;
2914
+ try {
2915
+ // For eac contextual key: try to find translation, then use the first valid
2916
+ for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
2917
+ var key = keys_1_1.value;
2918
+ if (translations[key] !== key)
2919
+ return translations[key];
2920
+ }
2921
+ }
2922
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2923
+ finally {
2924
+ try {
2925
+ if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
2926
+ }
2927
+ finally { if (e_1) throw e_1.error; }
2928
+ }
2929
+ return translations[keys[keys.length - 1]]; // Return the last keys translation
2930
+ };
2893
2931
  return TranslateContextService;
2894
2932
  }());
2895
2933
  TranslateContextService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function TranslateContextService_Factory() { return new TranslateContextService(i0__namespace.ɵɵinject(i1__namespace$1.TranslateService)); }, token: TranslateContextService, providedIn: "root" });
@@ -19139,7 +19177,7 @@
19139
19177
  this.error = null;
19140
19178
  this._enable = false;
19141
19179
  this._$ready = new rxjs.BehaviorSubject(false);
19142
- this._loading = true;
19180
+ this._$loading = new rxjs.BehaviorSubject(true);
19143
19181
  this.i18nFieldPrefix = null;
19144
19182
  this._subscription = new rxjs.Subscription();
19145
19183
  this.debug = false;
@@ -19155,9 +19193,25 @@
19155
19193
  });
19156
19194
  this.autocompleteFields = this.autocompleteHelper.fields;
19157
19195
  }
19158
- Object.defineProperty(AppForm.prototype, "_ready", {
19196
+ Object.defineProperty(AppForm.prototype, "_loading", {
19197
+ /**
19198
+ * @deprecated
19199
+ */
19159
19200
  get: function () {
19160
- return this._$ready.value == true;
19201
+ return this._$loading.value;
19202
+ },
19203
+ /**
19204
+ * @deprecated
19205
+ */
19206
+ set: function (value) {
19207
+ this._$loading.next(value);
19208
+ },
19209
+ enumerable: false,
19210
+ configurable: true
19211
+ });
19212
+ Object.defineProperty(AppForm.prototype, "loading", {
19213
+ get: function () {
19214
+ return this._$loading.value;
19161
19215
  },
19162
19216
  enumerable: false,
19163
19217
  configurable: true
@@ -19295,9 +19349,11 @@
19295
19349
  if (this.debug)
19296
19350
  console.debug('[form] Updating form (using entity)', data);
19297
19351
  // Convert object to json, then apply it to form (e.g. convert 'undefined' into 'null')
19298
- AppFormUtils.copyEntity2Form(data, this.form, Object.assign({ emitEvent: false, onlySelf: true }, opts));
19299
- if (!opts || opts.emitEvent !== true)
19352
+ AppFormUtils.copyEntity2Form(data, this.form, opts);
19353
+ if (!opts || opts.emitEvent !== false) {
19354
+ this.markAsLoaded({ emitEvent: false });
19300
19355
  this.markForCheck();
19356
+ }
19301
19357
  };
19302
19358
  AppForm.prototype.reset = function (data, opts) {
19303
19359
  if (data) {
@@ -19346,15 +19402,15 @@
19346
19402
  this.markForCheck();
19347
19403
  };
19348
19404
  AppForm.prototype.markAsLoading = function (opts) {
19349
- if (!this._loading) {
19350
- this._loading = true;
19405
+ if (this._$loading.value !== true) {
19406
+ this._$loading.next(true);
19351
19407
  if (!opts || opts.emitEvent !== false)
19352
19408
  this.markForCheck();
19353
19409
  }
19354
19410
  };
19355
19411
  AppForm.prototype.markAsLoaded = function (opts) {
19356
- if (this._loading) {
19357
- this._loading = false;
19412
+ if (this._$loading.value !== false) {
19413
+ this._$loading.next(false);
19358
19414
  if (!opts || opts.emitEvent !== false)
19359
19415
  this.markForCheck();
19360
19416
  }
@@ -19455,7 +19511,6 @@
19455
19511
  _this.network = network;
19456
19512
  _this.cd = cd;
19457
19513
  _this.environment = environment;
19458
- _this.loading = false;
19459
19514
  _this.canWorkOffline = false;
19460
19515
  _this.showPwd = false;
19461
19516
  _this.onCancel = new i0.EventEmitter();
@@ -19506,13 +19561,13 @@
19506
19561
  }
19507
19562
  if (this.form.invalid || this.loading)
19508
19563
  return;
19509
- this.loading = true;
19564
+ this.markAsLoading();
19510
19565
  var data = this.form.value;
19511
19566
  this.showPwd = false; // Hide password
19512
19567
  this.error = null; // Reset error
19513
19568
  this.registerSubscription(this.onSubmit
19514
19569
  .pipe(operators.debounceTime(500))
19515
- .subscribe(function (res) { return _this.loading = false; }));
19570
+ .subscribe(function (res) { return _this.markAsLoaded(); }));
19516
19571
  setTimeout(function () { return _this.onSubmit.emit({
19517
19572
  username: data.username,
19518
19573
  password: data.password,
@@ -20267,7 +20322,6 @@
20267
20322
  _this.translate = translate;
20268
20323
  _this.settings = settings;
20269
20324
  _this.cd = cd;
20270
- _this.loading = true;
20271
20325
  _this.email = {
20272
20326
  confirmed: false,
20273
20327
  notConfirmed: false,
@@ -20297,7 +20351,7 @@
20297
20351
  _this.onLogin(_this.accountService.account);
20298
20352
  }
20299
20353
  else {
20300
- _this.loading = false;
20354
+ _this.markAsLoaded();
20301
20355
  }
20302
20356
  }));
20303
20357
  return _this;
@@ -20315,7 +20369,7 @@
20315
20369
  this.enable();
20316
20370
  this.markAsPristine();
20317
20371
  this.startListenChanges();
20318
- this.loading = false;
20372
+ this.markAsLoaded();
20319
20373
  };
20320
20374
  AccountPage.prototype.onLogout = function () {
20321
20375
  this.isLogin = false;
@@ -20333,7 +20387,7 @@
20333
20387
  return __awaiter(this, void 0, void 0, function () {
20334
20388
  return __generator(this, function (_a) {
20335
20389
  this.disable();
20336
- this.loading = true;
20390
+ this.markAsLoading();
20337
20391
  return [2 /*return*/, this.accountService.refresh()];
20338
20392
  });
20339
20393
  });
@@ -20867,7 +20921,6 @@
20867
20921
  _this.cd = cd;
20868
20922
  _this.network = network;
20869
20923
  _this.locales = locales;
20870
- _this.loading = true;
20871
20924
  _this.saving = false;
20872
20925
  _this.usageModes = ['FIELD', 'DESK'];
20873
20926
  _this.propertyDefinitionsByKey = {};
@@ -20957,7 +21010,7 @@
20957
21010
  return __generator(this, function (_a) {
20958
21011
  switch (_a.label) {
20959
21012
  case 0:
20960
- this.loading = true;
21013
+ this.markAsLoading();
20961
21014
  console.debug('[settings] Loading settings...');
20962
21015
  data = this.settings.settings;
20963
21016
  // Set defaults
@@ -20993,7 +21046,7 @@
20993
21046
  this.enable({ emitEvent: false });
20994
21047
  // Apply inheritance
20995
21048
  this.setAccountInheritance(data.accountInheritance, { emitEvent: false });
20996
- this.loading = false;
21049
+ this.markAsLoaded();
20997
21050
  this.error = null;
20998
21051
  this.markForCheck();
20999
21052
  };
@@ -21232,7 +21285,6 @@
21232
21285
  _this.settings = settings;
21233
21286
  _this.cd = cd;
21234
21287
  _this.formGroupDir = formGroupDir;
21235
- _this.loading = true;
21236
21288
  _this.definitionsMapByKey = {};
21237
21289
  _this.definitionsByIndex = {};
21238
21290
  return _this;
@@ -21311,7 +21363,7 @@
21311
21363
  this.helper.resize(values.length);
21312
21364
  this.helper.formArray.patchValue(values, { emitEvent: false });
21313
21365
  this.markAsPristine();
21314
- this.loading = false;
21366
+ this.markAsLoaded();
21315
21367
  };
21316
21368
  /* -- protected methods -- */
21317
21369
  AppPropertiesForm.prototype.getPropertyFormGroup = function (data) {
@@ -21357,7 +21409,6 @@
21357
21409
  _this.settings = settings;
21358
21410
  _this.cd = cd;
21359
21411
  _this.formGroupDir = formGroupDir;
21360
- _this.loading = true;
21361
21412
  _this.selection = new collections.SelectionModel(true, []);
21362
21413
  _this.displayWithFn = referentialToString;
21363
21414
  _this.onNewItem = new i0.EventEmitter();
@@ -21483,7 +21534,7 @@
21483
21534
  }
21484
21535
  this.selection.clear();
21485
21536
  this.markAsPristine();
21486
- this.loading = false;
21537
+ this.markAsLoaded();
21487
21538
  };
21488
21539
  /** Whether the number of selected elements matches the total number of rows. */
21489
21540
  AppListForm.prototype.isAllSelected = function () {
@@ -25516,6 +25567,13 @@
25516
25567
  enumerable: false,
25517
25568
  configurable: true
25518
25569
  });
25570
+ Object.defineProperty(AppEditor.prototype, "forms", {
25571
+ get: function () {
25572
+ return this._children && this._children.filter(function (c) { return c instanceof AppForm; });
25573
+ },
25574
+ enumerable: false,
25575
+ configurable: true
25576
+ });
25519
25577
  Object.defineProperty(AppEditor.prototype, "dirty", {
25520
25578
  get: function () {
25521
25579
  var _a;
@@ -25674,10 +25732,15 @@
25674
25732
  }
25675
25733
  };
25676
25734
  AppEditor.prototype.markAsLoaded = function (opts) {
25735
+ var _a;
25677
25736
  if (this._loading) {
25678
25737
  this._loading = false;
25679
- if (!opts || opts.emitEvent !== false)
25738
+ if (!opts || opts.emitEvent !== false) {
25739
+ // Emit to children forms
25740
+ // Tables should be changed by parent
25741
+ (_a = this.forms) === null || _a === void 0 ? void 0 : _a.forEach(function (c) { return c.markAsLoaded(opts); });
25680
25742
  this.markForCheck();
25743
+ }
25681
25744
  }
25682
25745
  };
25683
25746
  AppEditor.prototype.markAsReady = function (opts) {
@@ -26298,49 +26361,60 @@
26298
26361
  */
26299
26362
  AppEntityEditor.prototype.load = function (id, opts) {
26300
26363
  return __awaiter(this, void 0, void 0, function () {
26301
- var data, data, err_1;
26364
+ var data, err_1, data, err_2;
26302
26365
  return __generator(this, function (_b) {
26303
26366
  switch (_b.label) {
26304
26367
  case 0:
26305
26368
  if (!this.dataService)
26306
26369
  throw new Error('Cannot load data: missing \'dataService\'!');
26307
26370
  this.error = null;
26308
- if (!isNil(id)) return [3 /*break*/, 3];
26371
+ if (!isNil(id)) return [3 /*break*/, 7];
26372
+ _b.label = 1;
26373
+ case 1:
26374
+ _b.trys.push([1, 4, 5, 6]);
26309
26375
  data = new this.dataType();
26310
26376
  this._usageMode = this.computeUsageMode(data);
26311
26377
  return [4 /*yield*/, this.onNewEntity(data, opts)];
26312
- case 1:
26378
+ case 2:
26313
26379
  _b.sent();
26314
26380
  return [4 /*yield*/, this.updateView(data, Object.assign({ openTabIndex: 0 }, opts))];
26315
- case 2:
26381
+ case 3:
26316
26382
  _b.sent();
26383
+ return [3 /*break*/, 6];
26384
+ case 4:
26385
+ err_1 = _b.sent();
26386
+ this.setError(err_1);
26387
+ this.selectedTabIndex = 0;
26388
+ return [3 /*break*/, 6];
26389
+ case 5:
26317
26390
  this.markAsLoaded();
26318
- return [3 /*break*/, 9];
26319
- case 3:
26320
- _b.trys.push([3, 7, 8, 9]);
26391
+ return [7 /*endfinally*/];
26392
+ case 6: return [3 /*break*/, 13];
26393
+ case 7:
26394
+ _b.trys.push([7, 11, 12, 13]);
26321
26395
  return [4 /*yield*/, this.dataService.load(id, opts)];
26322
- case 4:
26396
+ case 8:
26323
26397
  data = _b.sent();
26324
26398
  if (!data)
26325
26399
  throw { code: ErrorCodes$2.DATA_NOT_FOUND_ERROR, message: 'ERROR.DATA_NO_FOUND' };
26326
26400
  this._usageMode = this.computeUsageMode(data);
26327
26401
  return [4 /*yield*/, this.onEntityLoaded(data, opts)];
26328
- case 5:
26402
+ case 9:
26329
26403
  _b.sent();
26330
26404
  return [4 /*yield*/, this.updateView(data, opts)];
26331
- case 6:
26405
+ case 10:
26332
26406
  _b.sent();
26333
26407
  this.startListenRemoteChanges();
26334
- return [3 /*break*/, 9];
26335
- case 7:
26336
- err_1 = _b.sent();
26337
- this.setError(err_1);
26408
+ return [3 /*break*/, 13];
26409
+ case 11:
26410
+ err_2 = _b.sent();
26411
+ this.setError(err_2);
26338
26412
  this.selectedTabIndex = 0;
26339
- return [3 /*break*/, 9];
26340
- case 8:
26413
+ return [3 /*break*/, 13];
26414
+ case 12:
26341
26415
  this.markAsLoaded();
26342
26416
  return [7 /*endfinally*/];
26343
- case 9: return [2 /*return*/];
26417
+ case 13: return [2 /*return*/];
26344
26418
  }
26345
26419
  });
26346
26420
  });
@@ -26515,7 +26589,7 @@
26515
26589
  */
26516
26590
  AppEntityEditor.prototype.save = function (event, opts) {
26517
26591
  return __awaiter(this, void 0, void 0, function () {
26518
- var data, updatedData, err_2;
26592
+ var data, updatedData, err_3;
26519
26593
  return __generator(this, function (_b) {
26520
26594
  switch (_b.label) {
26521
26595
  case 0:
@@ -26568,15 +26642,15 @@
26568
26642
  this.submitted = false;
26569
26643
  return [2 /*return*/, true];
26570
26644
  case 7:
26571
- err_2 = _b.sent();
26645
+ err_3 = _b.sent();
26572
26646
  this.submitted = true;
26573
- this.setError(err_2);
26647
+ this.setError(err_3);
26574
26648
  this.selectedTabIndex = 0;
26575
26649
  this.scrollToTop(); // Scroll to top (to show error)
26576
26650
  this.markAsDirty();
26577
26651
  this.enable();
26578
26652
  // Concurrent change on pod
26579
- if (err_2.code === ServerErrorCodes.BAD_UPDATE_DATE && isNotNil(this.data.id)) {
26653
+ if (err_3.code === ServerErrorCodes.BAD_UPDATE_DATE && isNotNil(this.data.id)) {
26580
26654
  // Call a data reload (in background), to update the GraphQL cache, and allow to cancel changes
26581
26655
  this.dataService.load(this.data.id, { fetchPolicy: 'network-only' }).then(function () {
26582
26656
  console.debug('[data-editor] Data cache reloaded. User can reload page');
@@ -26629,7 +26703,7 @@
26629
26703
  };
26630
26704
  AppEntityEditor.prototype.delete = function (event) {
26631
26705
  return __awaiter(this, void 0, void 0, function () {
26632
- var confirmation, data, isNew, err_3;
26706
+ var confirmation, data, isNew, err_4;
26633
26707
  var _this = this;
26634
26708
  return __generator(this, function (_b) {
26635
26709
  switch (_b.label) {
@@ -26664,9 +26738,9 @@
26664
26738
  this.removePageHistory();
26665
26739
  return [3 /*break*/, 8];
26666
26740
  case 7:
26667
- err_3 = _b.sent();
26741
+ err_4 = _b.sent();
26668
26742
  this.submitted = true;
26669
- this.setError(err_3);
26743
+ this.setError(err_4);
26670
26744
  this.selectedTabIndex = 0;
26671
26745
  this.markAsSaved();
26672
26746
  this.enable();