@sumaris-net/ngx-components 0.25.19 → 0.26.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.
Files changed (29) hide show
  1. package/bundles/sumaris-net.ngx-components.umd.js +73 -53
  2. package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
  3. package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
  4. package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
  5. package/doc/changelog.md +6 -0
  6. package/esm2015/src/app/core/account/account.js +5 -7
  7. package/esm2015/src/app/core/auth/form/form-auth.js +6 -7
  8. package/esm2015/src/app/core/form/entity-editor.class.js +25 -16
  9. package/esm2015/src/app/core/form/form.class.js +29 -12
  10. package/esm2015/src/app/core/form/list.form.js +2 -2
  11. package/esm2015/src/app/core/form/properties.form.js +2 -3
  12. package/esm2015/src/app/core/settings/settings.page.js +5 -7
  13. package/esm2015/src/app/core/table/table.class.js +4 -4
  14. package/esm2015/src/app/shared/pipes/form.pipes.js +1 -1
  15. package/esm2015/src/app/shared/validator/form-error-adapter.class.js +3 -3
  16. package/esm2015/src/app/shared/validator/validators.js +8 -9
  17. package/fesm2015/sumaris-net.ngx-components.js +72 -53
  18. package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/app/core/account/account.d.ts +2 -5
  21. package/src/app/core/auth/form/form-auth.d.ts +2 -4
  22. package/src/app/core/form/entity-editor.class.d.ts +13 -2
  23. package/src/app/core/form/form.class.d.ts +15 -12
  24. package/src/app/core/form/properties.form.d.ts +0 -1
  25. package/src/app/core/settings/settings.page.d.ts +2 -5
  26. package/src/app/core/table/table.class.d.ts +4 -7
  27. package/src/app/shared/pipes/form.pipes.d.ts +2 -2
  28. package/src/app/shared/validator/form-error-adapter.class.d.ts +6 -6
  29. package/sumaris-net.ngx-components.metadata.json +1 -1
@@ -3128,23 +3128,22 @@
3128
3128
  };
3129
3129
  };
3130
3130
  SharedFormGroupValidators.dateMaxDuration = function (startDateField, endDateField, maxDuration, durationUnit) {
3131
+ var maxDurationError = { dateMaxDuration: true };
3131
3132
  return function (group) {
3132
- var endField = group.get(endDateField);
3133
3133
  var startDate = fromDateISOString(group.get(startDateField).value);
3134
+ var endField = group.get(endDateField);
3134
3135
  var endDate = fromDateISOString(endField.value);
3135
3136
  if (isNotNil(startDate) && isNotNil(endDate) && Math.abs(startDate.diff(endDate, durationUnit)) > maxDuration) {
3137
+ console.log('TODO error !');
3136
3138
  // Update end field
3137
- var endFieldErrors = endField.errors || {};
3138
- endFieldErrors['dateMaxDuration'] = true;
3139
- endField.setErrors(endFieldErrors);
3140
3139
  endField.markAsTouched({ onlySelf: true });
3140
+ endField.markAsPending();
3141
+ endField.setErrors(Object.assign(Object.assign({}, endField.errors), maxDurationError));
3141
3142
  // Return the error (should be apply to the parent form)
3142
- return { dateMaxDuration: true };
3143
+ return maxDurationError;
3143
3144
  }
3144
3145
  // OK: remove the existing on the end field
3145
- else {
3146
- SharedValidators.clearError(endField, 'dateMaxDuration');
3147
- }
3146
+ SharedValidators.clearError(endField, 'dateMaxDuration');
3148
3147
  return null;
3149
3148
  };
3150
3149
  };
@@ -4019,8 +4018,8 @@
4019
4018
  }, "");
4020
4019
  };
4021
4020
  FormErrorAdapter.prototype.translateControlPath = function (path, opts) {
4022
- if (opts === null || opts === void 0 ? void 0 : opts.pathTranslateService) {
4023
- return opts === null || opts === void 0 ? void 0 : opts.pathTranslateService.translateControlPath(path);
4021
+ if (opts === null || opts === void 0 ? void 0 : opts.controlPathTranslator) {
4022
+ return opts === null || opts === void 0 ? void 0 : opts.controlPathTranslator.translateControlPath(path);
4024
4023
  }
4025
4024
  var i18nKey = (opts && opts.i18nPrefix || '') + changeCaseToUnderscore(path).toUpperCase();
4026
4025
  return this.translate.instant(i18nKey);
@@ -18909,20 +18908,22 @@
18909
18908
 
18910
18909
  // eslint-disable-next-line @angular-eslint/directive-class-suffix
18911
18910
  var AppForm = /** @class */ (function () {
18912
- function AppForm(dateAdapter, form, settings) {
18913
- this.dateAdapter = dateAdapter;
18914
- this.settings = settings;
18915
- this._subscription = new rxjs.Subscription();
18911
+ function AppForm(injector, form) {
18912
+ var _this = this;
18913
+ this.error = null;
18916
18914
  this._enable = false;
18917
18915
  this._loading = true;
18918
- this.error = null;
18916
+ this.i18nFieldPrefix = null;
18917
+ this._subscription = new rxjs.Subscription();
18919
18918
  this.debug = false;
18920
18919
  this.onCancel = new i0.EventEmitter();
18921
18920
  this.onSubmit = new i0.EventEmitter();
18922
18921
  if (form)
18923
18922
  this.setForm(form);
18924
- this.autocompleteHelper = new MatAutocompleteConfigHolder(settings && {
18925
- getUserAttributes: function (a, b) { return settings.getFieldDisplayAttributes(a, b); }
18923
+ this.settings = injector.get(LocalSettingsService);
18924
+ this.errorTranslator = injector.get(FormErrorAdapter);
18925
+ this.autocompleteHelper = new MatAutocompleteConfigHolder(this.settings && {
18926
+ getUserAttributes: function (a, b) { return _this.settings.getFieldDisplayAttributes(a, b); }
18926
18927
  });
18927
18928
  this.autocompleteFields = this.autocompleteHelper.fields;
18928
18929
  }
@@ -19022,6 +19023,9 @@
19022
19023
  });
19023
19024
  AppForm.prototype.ngOnInit = function () {
19024
19025
  this._enable ? this.enable() : this.disable();
19026
+ this.errorTranslatorOptions = this.errorTranslatorOptions || {
19027
+ controlPathTranslator: this
19028
+ };
19025
19029
  };
19026
19030
  AppForm.prototype.ngOnDestroy = function () {
19027
19031
  this._subscription.unsubscribe();
@@ -19131,7 +19135,18 @@
19131
19135
  if (!opts || opts.emitEvent !== false)
19132
19136
  this.markForCheck();
19133
19137
  };
19138
+ AppForm.prototype.translateControlPath = function (path) {
19139
+ return this.getFieldName(path);
19140
+ };
19134
19141
  /* -- protected methods -- */
19142
+ AppForm.prototype.getFormError = function (form, opts) {
19143
+ if (!form || !this.errorTranslator)
19144
+ return undefined;
19145
+ return this.errorTranslator.translateErrors(this.form, Object.assign({ controlPathTranslator: this }, opts));
19146
+ };
19147
+ AppForm.prototype.getFieldName = function (path) {
19148
+ return (this.i18nFieldPrefix || '') + changeCaseToUnderscore(path).toUpperCase();
19149
+ };
19135
19150
  AppForm.prototype.registerSubscription = function (sub) {
19136
19151
  return this._subscription.add(sub);
19137
19152
  };
@@ -19148,13 +19163,13 @@
19148
19163
  { type: i0.Directive }
19149
19164
  ];
19150
19165
  AppForm.ctorParameters = function () { return [
19151
- { type: undefined },
19152
- { type: i1.FormGroup },
19153
- { type: LocalSettingsService }
19166
+ { type: i0.Injector },
19167
+ { type: i1.FormGroup }
19154
19168
  ]; };
19155
19169
  AppForm.propDecorators = {
19156
19170
  debug: [{ type: i0.Input }],
19157
19171
  tabindex: [{ type: i0.Input }],
19172
+ errorTranslatorOptions: [{ type: i0.Input }],
19158
19173
  form: [{ type: i0.Input }],
19159
19174
  onCancel: [{ type: i0.Output }],
19160
19175
  onSubmit: [{ type: i0.Output }]
@@ -19162,12 +19177,12 @@
19162
19177
 
19163
19178
  var AuthForm = /** @class */ (function (_super) {
19164
19179
  __extends(AuthForm, _super);
19165
- function AuthForm(platform, dateAdapter, formBuilder, settings, configService, modalCtrl, network, cd, environment) {
19166
- var _this = _super.call(this, dateAdapter, formBuilder.group({
19180
+ function AuthForm(injector, platform, formBuilder, settings, configService, modalCtrl, network, cd, environment) {
19181
+ var _this = _super.call(this, injector, formBuilder.group({
19167
19182
  username: [null, i1.Validators.required],
19168
19183
  password: [null, i1.Validators.required],
19169
19184
  offline: [network.offline]
19170
- }), settings) || this;
19185
+ })) || this;
19171
19186
  _this.configService = configService;
19172
19187
  _this.modalCtrl = modalCtrl;
19173
19188
  _this.network = network;
@@ -19271,8 +19286,8 @@
19271
19286
  },] }
19272
19287
  ];
19273
19288
  AuthForm.ctorParameters = function () { return [
19289
+ { type: i0.Injector },
19274
19290
  { type: PlatformService },
19275
- { type: i1$3.DateAdapter },
19276
19291
  { type: i1.FormBuilder },
19277
19292
  { type: LocalSettingsService },
19278
19293
  { type: ConfigService },
@@ -19975,9 +19990,8 @@
19975
19990
 
19976
19991
  var AccountPage = /** @class */ (function (_super) {
19977
19992
  __extends(AccountPage, _super);
19978
- function AccountPage(dateAdapter, router, formBuilder, accountService, validatorService, settingsValidatorService, translate, settings, cd, locales) {
19979
- var _this = _super.call(this, dateAdapter, validatorService.getFormGroup(accountService.account), settings) || this;
19980
- _this.dateAdapter = dateAdapter;
19993
+ function AccountPage(injector, router, formBuilder, accountService, validatorService, settingsValidatorService, translate, settings, cd, locales) {
19994
+ var _this = _super.call(this, injector, validatorService.getFormGroup(accountService.account)) || this;
19981
19995
  _this.router = router;
19982
19996
  _this.formBuilder = formBuilder;
19983
19997
  _this.accountService = accountService;
@@ -20173,7 +20187,7 @@
20173
20187
  },] }
20174
20188
  ];
20175
20189
  AccountPage.ctorParameters = function () { return [
20176
- { type: i1$3.DateAdapter },
20190
+ { type: i0.Injector },
20177
20191
  { type: i3.Router },
20178
20192
  { type: i1.FormBuilder },
20179
20193
  { type: AccountService },
@@ -20572,9 +20586,8 @@
20572
20586
 
20573
20587
  var SettingsPage = /** @class */ (function (_super_1) {
20574
20588
  __extends(SettingsPage, _super_1);
20575
- function SettingsPage(dateAdapter, platform, router, validatorService, alertCtrl, translate, formBuilder, accountService, settings, cd, network, locales) {
20576
- var _this = _super_1.call(this, dateAdapter, validatorService.getFormGroup(), settings) || this;
20577
- _this.dateAdapter = dateAdapter;
20589
+ function SettingsPage(injector, platform, router, validatorService, alertCtrl, translate, formBuilder, accountService, settings, cd, network, locales) {
20590
+ var _this = _super_1.call(this, injector, validatorService.getFormGroup()) || this;
20578
20591
  _this.platform = platform;
20579
20592
  _this.router = router;
20580
20593
  _this.validatorService = validatorService;
@@ -20928,7 +20941,7 @@
20928
20941
  },] }
20929
20942
  ];
20930
20943
  SettingsPage.ctorParameters = function () { return [
20931
- { type: i1$3.DateAdapter },
20944
+ { type: i0.Injector },
20932
20945
  { type: PlatformService },
20933
20946
  { type: i3.Router },
20934
20947
  { type: LocalSettingsValidatorService },
@@ -20945,8 +20958,7 @@
20945
20958
  var AppPropertiesForm = /** @class */ (function (_super) {
20946
20959
  __extends(AppPropertiesForm, _super);
20947
20960
  function AppPropertiesForm(injector, formBuilder, dateAdapter, settings, cd, formGroupDir) {
20948
- var _this = _super.call(this, dateAdapter, null, settings) || this;
20949
- _this.injector = injector;
20961
+ var _this = _super.call(this, injector, null) || this;
20950
20962
  _this.formBuilder = formBuilder;
20951
20963
  _this.dateAdapter = dateAdapter;
20952
20964
  _this.settings = settings;
@@ -21070,7 +21082,7 @@
21070
21082
  var AppListForm = /** @class */ (function (_super) {
21071
21083
  __extends(AppListForm, _super);
21072
21084
  function AppListForm(injector, formBuilder, dateAdapter, settings, cd, formGroupDir) {
21073
- var _this = _super.call(this, dateAdapter, null, settings) || this;
21085
+ var _this = _super.call(this, injector, null) || this;
21074
21086
  _this.injector = injector;
21075
21087
  _this.formBuilder = formBuilder;
21076
21088
  _this.dateAdapter = dateAdapter;
@@ -23715,7 +23727,7 @@
23715
23727
  this.saveBeforeSort = toBoolean(this.saveBeforeSort, !this.readOnly); // force to false when readonly
23716
23728
  this.saveBeforeFilter = toBoolean(this.saveBeforeFilter, !this.readOnly); // force to false when readonly
23717
23729
  this.keepEditedRowOnSave = toBoolean(this.keepEditedRowOnSave, this.inlineEdition);
23718
- this.translateErrorOptions = this.translateErrorOptions || { separator: ', ', pathTranslateService: this }; // Can be override in subclasses constructors
23730
+ this.errorTranslatorOptions = this.errorTranslatorOptions || { separator: ', ', controlPathTranslator: this }; // Can be override in subclasses constructors
23719
23731
  // Check ask user confirmation is possible
23720
23732
  if (this.confirmBeforeDelete && !this.alertCtrl)
23721
23733
  throw Error('Missing \'alertCtrl\' or \'injector\' in component\'s constructor.');
@@ -24792,7 +24804,7 @@
24792
24804
  return this._autocompleteConfigHolder.add(fieldName, options);
24793
24805
  };
24794
24806
  AppTable.prototype.getI18nColumnName = function (columnName) {
24795
- return this.i18nColumnPrefix + changeCaseToUnderscore(columnName).toUpperCase();
24807
+ return (this.i18nColumnPrefix || '') + changeCaseToUnderscore(columnName).toUpperCase();
24796
24808
  };
24797
24809
  AppTable.prototype.generateTableId = function () {
24798
24810
  return this.location.path(true).replace(/[?].*$/g, '').replace(/\/[\d]+/g, '_id') + '_' + this.constructor.name;
@@ -24911,7 +24923,7 @@
24911
24923
  row = row || this.editedRow;
24912
24924
  if (!row || !this.formErrorAdapter)
24913
24925
  return undefined;
24914
- return this.formErrorAdapter.translateErrors(row.validator, Object.assign(Object.assign({}, this.translateErrorOptions), opts));
24926
+ return this.formErrorAdapter.translateErrors(row.validator, Object.assign(Object.assign({}, this.errorTranslatorOptions), opts));
24915
24927
  };
24916
24928
  AppTable.prototype.setError = function (value, opts) {
24917
24929
  if (this.errorSubject.value !== value) {
@@ -25756,6 +25768,7 @@
25756
25768
  enableListenChanges: (injector.get(ENVIRONMENT).listenRemoteChanges === true), pathIdAttribute: 'id', autoLoad: true, autoUpdateRoute: true, i18nPrefix: ''
25757
25769
  }, options);
25758
25770
  _this.settings = injector.get(LocalSettingsService);
25771
+ _this.formErrorAdapter = injector.get(FormErrorAdapter);
25759
25772
  _this.cd = injector.get(i0.ChangeDetectorRef);
25760
25773
  _this.dateFormat = injector.get(DateFormatPipe);
25761
25774
  _this.toastController = injector.get(i1$5.ToastController);
@@ -25857,7 +25870,6 @@
25857
25870
  /**
25858
25871
  * Load data from the snapshot route
25859
25872
  *
25860
- * @param route
25861
25873
  * @protected
25862
25874
  */
25863
25875
  AppEntityEditor.prototype.loadFromRoute = function () {
@@ -25966,7 +25978,7 @@
25966
25978
  idChanged = isNotNil(data.id)
25967
25979
  && this.previousDataId !== undefined // Ignore if first loading (=undefined)
25968
25980
  && this.previousDataId !== data.id;
25969
- opts = Object.assign({ updateRoute: this._autoUpdateRoute && idChanged && !this.loading, openTabIndex: this._autoOpenNextTab && idChanged && this.computeNextTabIndex() }, opts);
25981
+ opts = Object.assign({ updateRoute: this._autoUpdateRoute && idChanged && !this.loading, openTabIndex: this._autoOpenNextTab && idChanged && isNil(this.previousDataId) && this.computeNextTabIndex() }, opts);
25970
25982
  this.data = data;
25971
25983
  this.previousDataId = data.id || null;
25972
25984
  promiseOrVoid = this.setValue(data);
@@ -25987,7 +25999,7 @@
25987
25999
  .then(function () { return _this.updateTitle(data); });
25988
26000
  }
25989
26001
  else {
25990
- // Update the tag group index
26002
+ // Update the next tab
25991
26003
  this.updateTabIndex(opts.openTabIndex);
25992
26004
  // Update the title.
25993
26005
  this.updateTitle(data);
@@ -26022,7 +26034,7 @@
26022
26034
  switch (_b.label) {
26023
26035
  case 0:
26024
26036
  this.queryParams = this.queryParams || {};
26025
- // Open the tab group
26037
+ // Open the next tab
26026
26038
  this.updateTabIndex(opts && opts.openTabIndex);
26027
26039
  // Save the opened tab into the queryParams
26028
26040
  this.queryParams.tab = this.selectedTabIndex;
@@ -26055,12 +26067,9 @@
26055
26067
  * Update the route location, and open the next tab
26056
26068
  */
26057
26069
  AppEntityEditor.prototype.updateTabIndex = function (tabIndex) {
26058
- // Open the second tab
26059
- if (isNotNil(tabIndex)) {
26060
- if (this.selectedTabIndex !== tabIndex) {
26061
- this.selectedTabIndex = tabIndex;
26062
- this.markForCheck();
26063
- }
26070
+ if (isNotNil(tabIndex) && tabIndex > this.selectedTabIndex) {
26071
+ this.selectedTabIndex = tabIndex;
26072
+ this.markForCheck();
26064
26073
  }
26065
26074
  };
26066
26075
  AppEntityEditor.prototype.saveAndClose = function (event, options) {
@@ -26094,7 +26103,13 @@
26094
26103
  });
26095
26104
  });
26096
26105
  };
26097
- AppEntityEditor.prototype.save = function (event, options) {
26106
+ /**
26107
+ * Save the editor, by calling the dataService.save().
26108
+ * Ensure that editor if valid. If not, display an error
26109
+ * @param event
26110
+ * @param opts
26111
+ */
26112
+ AppEntityEditor.prototype.save = function (event, opts) {
26098
26113
  return __awaiter(this, void 0, void 0, function () {
26099
26114
  var data, updatedData, err_2;
26100
26115
  return __generator(this, function (_b) {
@@ -26132,14 +26147,14 @@
26132
26147
  case 3:
26133
26148
  data = _b.sent();
26134
26149
  this.disable();
26135
- return [4 /*yield*/, this.dataService.save(data, options)];
26150
+ return [4 /*yield*/, this.dataService.save(data, opts)];
26136
26151
  case 4:
26137
26152
  updatedData = _b.sent();
26138
26153
  return [4 /*yield*/, this.onEntitySaved(updatedData)];
26139
26154
  case 5:
26140
26155
  _b.sent();
26141
26156
  // Update the view (e.g metadata)
26142
- return [4 /*yield*/, this.updateView(updatedData, options)];
26157
+ return [4 /*yield*/, this.updateView(updatedData, opts)];
26143
26158
  case 6:
26144
26159
  // Update the view (e.g metadata)
26145
26160
  _b.sent();
@@ -26297,7 +26312,7 @@
26297
26312
  });
26298
26313
  };
26299
26314
  AppEntityEditor.prototype.setError = function (err) {
26300
- console.error('[data-editor] ' + err && err.message || err, err);
26315
+ console.error('[entity-editor] Error: ' + err && err.message || '', err);
26301
26316
  var userMessage = err && err.message && this.translate.instant(err.message) || err;
26302
26317
  // Add details error (if any) under the main message
26303
26318
  var detailMessage = err && err.details && (err.details.message || err.details) || undefined;
@@ -26309,8 +26324,13 @@
26309
26324
  this.error = userMessage;
26310
26325
  };
26311
26326
  /* -- protected methods -- */
26327
+ /**
26328
+ * Return undefined to keep same tab
26329
+ * @protected
26330
+ */
26312
26331
  AppEntityEditor.prototype.computeNextTabIndex = function () {
26313
- return this.selectedTabIndex + 1 < this.tabCount ? this.selectedTabIndex + 1 : undefined;
26332
+ var nextTabIndex = this.selectedTabIndex + 1;
26333
+ return nextTabIndex < this.tabCount ? nextTabIndex : undefined;
26314
26334
  };
26315
26335
  AppEntityEditor.prototype.unload = function () {
26316
26336
  return __awaiter(this, void 0, void 0, function () {