@sumaris-net/ngx-components 0.27.23 → 0.28.3

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.
@@ -46,7 +46,6 @@ import * as momentImported from 'moment';
46
46
  import { isMoment } from 'moment';
47
47
  import * as i1 from '@angular/material-moment-adapter';
48
48
  import { MomentDateAdapter, MatMomentDateModule } from '@angular/material-moment-adapter';
49
- import { isDefined } from '@ngx-translate/core/lib/util';
50
49
  import { Keyboard } from '@ionic-native/keyboard/ngx';
51
50
  import { TextMaskModule } from 'angular2-text-mask';
52
51
  import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
@@ -2113,7 +2112,7 @@ class DateUtils {
2113
2112
  return date1 && date2 && date1.isSameOrBefore(date2) ? date1 : date2;
2114
2113
  }
2115
2114
  static max(date1, date2) {
2116
- return date1 && date2 && date1.isSameOrAfter(date2) ? date1 : date2;
2115
+ return !date1 ? date2 : (!date2 || date1.isSameOrAfter(date2) ? date1 : date2);
2117
2116
  }
2118
2117
  }
2119
2118
  function toDateISOString(value) {
@@ -2432,7 +2431,7 @@ class TranslateContextService {
2432
2431
  }
2433
2432
  get(key, context, interpolateParams) {
2434
2433
  // No context: do a normal translate
2435
- if (!isDefined(context))
2434
+ if (!isNil(context))
2436
2435
  return this.translate.get(key, interpolateParams);
2437
2436
  // Compute a contextual i18n key, using the context as suffix
2438
2437
  const contextKey = this.contextualKey(key, context);
@@ -2509,12 +2508,11 @@ class TranslateContextPipe {
2509
2508
  return this.value;
2510
2509
  }
2511
2510
  }
2512
- TranslateContextPipe.ɵprov = i0.ɵɵdefineInjectable({ factory: function TranslateContextPipe_Factory() { return new TranslateContextPipe(i0.ɵɵinject(TranslateContextService), i0.ɵɵinject(i0.ChangeDetectorRef)); }, token: TranslateContextPipe, providedIn: "root" });
2513
2511
  TranslateContextPipe.decorators = [
2512
+ { type: Injectable },
2514
2513
  { type: Pipe, args: [{
2515
2514
  name: 'translateContext'
2516
- },] },
2517
- { type: Injectable, args: [{ providedIn: 'root' },] }
2515
+ },] }
2518
2516
  ];
2519
2517
  TranslateContextPipe.ctorParameters = () => [
2520
2518
  { type: TranslateContextService },
@@ -2527,12 +2525,11 @@ class TranslatablePipe {
2527
2525
  return (_a = changeCaseToUnderscore(value)) === null || _a === void 0 ? void 0 : _a.toUpperCase();
2528
2526
  }
2529
2527
  }
2530
- TranslatablePipe.ɵprov = i0.ɵɵdefineInjectable({ factory: function TranslatablePipe_Factory() { return new TranslatablePipe(); }, token: TranslatablePipe, providedIn: "root" });
2531
2528
  TranslatablePipe.decorators = [
2532
2529
  { type: Pipe, args: [{
2533
2530
  name: 'translatable'
2534
2531
  },] },
2535
- { type: Injectable, args: [{ providedIn: 'root' },] }
2532
+ { type: Injectable }
2536
2533
  ];
2537
2534
 
2538
2535
  class PropertyGetPipe {
@@ -16660,7 +16657,7 @@ class AppForm {
16660
16657
  this.error = null;
16661
16658
  this._enable = false;
16662
16659
  this._$ready = new BehaviorSubject(false);
16663
- this._loading = true;
16660
+ this._$loading = new BehaviorSubject(true);
16664
16661
  this.i18nFieldPrefix = null;
16665
16662
  this._subscription = new Subscription();
16666
16663
  this.debug = false;
@@ -16676,8 +16673,20 @@ class AppForm {
16676
16673
  });
16677
16674
  this.autocompleteFields = this.autocompleteHelper.fields;
16678
16675
  }
16679
- get _ready() {
16680
- return this._$ready.value == true;
16676
+ /**
16677
+ * @deprecated
16678
+ */
16679
+ set _loading(value) {
16680
+ this._$loading.next(value);
16681
+ }
16682
+ /**
16683
+ * @deprecated
16684
+ */
16685
+ get _loading() {
16686
+ return this._$loading.value;
16687
+ }
16688
+ get loading() {
16689
+ return this._$loading.value;
16681
16690
  }
16682
16691
  get value() {
16683
16692
  return this.form.value;
@@ -16771,9 +16780,11 @@ class AppForm {
16771
16780
  if (this.debug)
16772
16781
  console.debug('[form] Updating form (using entity)', data);
16773
16782
  // Convert object to json, then apply it to form (e.g. convert 'undefined' into 'null')
16774
- AppFormUtils.copyEntity2Form(data, this.form, Object.assign({ emitEvent: false, onlySelf: true }, opts));
16775
- if (!opts || opts.emitEvent !== true)
16783
+ AppFormUtils.copyEntity2Form(data, this.form, opts);
16784
+ if (!opts || opts.emitEvent !== false) {
16785
+ this.markAsLoaded({ emitEvent: false });
16776
16786
  this.markForCheck();
16787
+ }
16777
16788
  }
16778
16789
  reset(data, opts) {
16779
16790
  if (data) {
@@ -16822,15 +16833,15 @@ class AppForm {
16822
16833
  this.markForCheck();
16823
16834
  }
16824
16835
  markAsLoading(opts) {
16825
- if (!this._loading) {
16826
- this._loading = true;
16836
+ if (this._$loading.value !== true) {
16837
+ this._$loading.next(true);
16827
16838
  if (!opts || opts.emitEvent !== false)
16828
16839
  this.markForCheck();
16829
16840
  }
16830
16841
  }
16831
16842
  markAsLoaded(opts) {
16832
- if (this._loading) {
16833
- this._loading = false;
16843
+ if (this._$loading.value !== false) {
16844
+ this._$loading.next(false);
16834
16845
  if (!opts || opts.emitEvent !== false)
16835
16846
  this.markForCheck();
16836
16847
  }
@@ -16920,7 +16931,6 @@ class AuthForm extends AppForm {
16920
16931
  this.network = network;
16921
16932
  this.cd = cd;
16922
16933
  this.environment = environment;
16923
- this.loading = false;
16924
16934
  this.canWorkOffline = false;
16925
16935
  this.showPwd = false;
16926
16936
  this.onCancel = new EventEmitter();
@@ -16968,13 +16978,13 @@ class AuthForm extends AppForm {
16968
16978
  }
16969
16979
  if (this.form.invalid || this.loading)
16970
16980
  return;
16971
- this.loading = true;
16981
+ this.markAsLoading();
16972
16982
  const data = this.form.value;
16973
16983
  this.showPwd = false; // Hide password
16974
16984
  this.error = null; // Reset error
16975
16985
  this.registerSubscription(this.onSubmit
16976
16986
  .pipe(debounceTime(500))
16977
- .subscribe(res => this.loading = false));
16987
+ .subscribe(res => this.markAsLoaded()));
16978
16988
  setTimeout(() => this.onSubmit.emit({
16979
16989
  username: data.username,
16980
16990
  password: data.password,
@@ -17613,7 +17623,6 @@ class AccountPage extends AppForm {
17613
17623
  this.translate = translate;
17614
17624
  this.settings = settings;
17615
17625
  this.cd = cd;
17616
- this.loading = true;
17617
17626
  this.email = {
17618
17627
  confirmed: false,
17619
17628
  notConfirmed: false,
@@ -17643,7 +17652,7 @@ class AccountPage extends AppForm {
17643
17652
  this.onLogin(this.accountService.account);
17644
17653
  }
17645
17654
  else {
17646
- this.loading = false;
17655
+ this.markAsLoaded();
17647
17656
  }
17648
17657
  }));
17649
17658
  }
@@ -17660,7 +17669,7 @@ class AccountPage extends AppForm {
17660
17669
  this.enable();
17661
17670
  this.markAsPristine();
17662
17671
  this.startListenChanges();
17663
- this.loading = false;
17672
+ this.markAsLoaded();
17664
17673
  }
17665
17674
  onLogout() {
17666
17675
  this.isLogin = false;
@@ -17677,7 +17686,7 @@ class AccountPage extends AppForm {
17677
17686
  refresh(event) {
17678
17687
  return __awaiter(this, void 0, void 0, function* () {
17679
17688
  this.disable();
17680
- this.loading = true;
17689
+ this.markAsLoading();
17681
17690
  return this.accountService.refresh();
17682
17691
  });
17683
17692
  }
@@ -18150,7 +18159,6 @@ class SettingsPage extends AppForm {
18150
18159
  this.cd = cd;
18151
18160
  this.network = network;
18152
18161
  this.locales = locales;
18153
- this.loading = true;
18154
18162
  this.saving = false;
18155
18163
  this.usageModes = ['FIELD', 'DESK'];
18156
18164
  this.propertyDefinitionsByKey = {};
@@ -18210,7 +18218,7 @@ class SettingsPage extends AppForm {
18210
18218
  }
18211
18219
  load() {
18212
18220
  return __awaiter(this, void 0, void 0, function* () {
18213
- this.loading = true;
18221
+ this.markAsLoading();
18214
18222
  console.debug('[settings] Loading settings...');
18215
18223
  const data = this.settings.settings;
18216
18224
  // Set defaults
@@ -18241,7 +18249,7 @@ class SettingsPage extends AppForm {
18241
18249
  this.enable({ emitEvent: false });
18242
18250
  // Apply inheritance
18243
18251
  this.setAccountInheritance(data.accountInheritance, { emitEvent: false });
18244
- this.loading = false;
18252
+ this.markAsLoaded();
18245
18253
  this.error = null;
18246
18254
  this.markForCheck();
18247
18255
  }
@@ -18426,7 +18434,6 @@ class AppPropertiesForm extends AppForm {
18426
18434
  this.settings = settings;
18427
18435
  this.cd = cd;
18428
18436
  this.formGroupDir = formGroupDir;
18429
- this.loading = true;
18430
18437
  this.definitionsMapByKey = {};
18431
18438
  this.definitionsByIndex = {};
18432
18439
  //this.debug = !environment.production;
@@ -18495,7 +18502,7 @@ class AppPropertiesForm extends AppForm {
18495
18502
  this.helper.resize(values.length);
18496
18503
  this.helper.formArray.patchValue(values, { emitEvent: false });
18497
18504
  this.markAsPristine();
18498
- this.loading = false;
18505
+ this.markAsLoaded();
18499
18506
  }
18500
18507
  /* -- protected methods -- */
18501
18508
  getPropertyFormGroup(data) {
@@ -18539,7 +18546,6 @@ class AppListForm extends AppForm {
18539
18546
  this.settings = settings;
18540
18547
  this.cd = cd;
18541
18548
  this.formGroupDir = formGroupDir;
18542
- this.loading = true;
18543
18549
  this.selection = new SelectionModel(true, []);
18544
18550
  this.displayWithFn = referentialToString;
18545
18551
  this.onNewItem = new EventEmitter();
@@ -18623,7 +18629,7 @@ class AppListForm extends AppForm {
18623
18629
  }
18624
18630
  this.selection.clear();
18625
18631
  this.markAsPristine();
18626
- this.loading = false;
18632
+ this.markAsLoaded();
18627
18633
  }
18628
18634
  /** Whether the number of selected elements matches the total number of rows. */
18629
18635
  isAllSelected() {
@@ -22018,6 +22024,9 @@ class AppEditor {
22018
22024
  get tables() {
22019
22025
  return this._children && this._children.filter(c => c instanceof AppTable);
22020
22026
  }
22027
+ get forms() {
22028
+ return this._children && this._children.filter(c => c instanceof AppForm);
22029
+ }
22021
22030
  get dirty() {
22022
22031
  var _a;
22023
22032
  return this._dirty || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(c => c.enabled && c.dirty)) !== -1) || false;
@@ -22138,10 +22147,15 @@ class AppEditor {
22138
22147
  }
22139
22148
  }
22140
22149
  markAsLoaded(opts) {
22150
+ var _a;
22141
22151
  if (this._loading) {
22142
22152
  this._loading = false;
22143
- if (!opts || opts.emitEvent !== false)
22153
+ if (!opts || opts.emitEvent !== false) {
22154
+ // Emit to children forms
22155
+ // Tables should be changed by parent
22156
+ (_a = this.forms) === null || _a === void 0 ? void 0 : _a.forEach(c => c.markAsLoaded(opts));
22144
22157
  this.markForCheck();
22158
+ }
22145
22159
  }
22146
22160
  }
22147
22161
  markAsReady(opts) {
@@ -22659,12 +22673,20 @@ class AppEntityEditor extends AppTabEditor {
22659
22673
  this.error = null;
22660
22674
  // New data
22661
22675
  if (isNil(id)) {
22662
- // Create using default values
22663
- const data = new this.dataType();
22664
- this._usageMode = this.computeUsageMode(data);
22665
- yield this.onNewEntity(data, opts);
22666
- yield this.updateView(data, Object.assign({ openTabIndex: 0 }, opts));
22667
- this.markAsLoaded();
22676
+ try {
22677
+ // Create using default values
22678
+ const data = new this.dataType();
22679
+ this._usageMode = this.computeUsageMode(data);
22680
+ yield this.onNewEntity(data, opts);
22681
+ yield this.updateView(data, Object.assign({ openTabIndex: 0 }, opts));
22682
+ }
22683
+ catch (err) {
22684
+ this.setError(err);
22685
+ this.selectedTabIndex = 0;
22686
+ }
22687
+ finally {
22688
+ this.markAsLoaded();
22689
+ }
22668
22690
  }
22669
22691
  // Load existing data
22670
22692
  else {