@sumaris-net/ngx-components 0.25.10 → 0.25.11
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.
- package/bundles/sumaris-net.ngx-components.umd.js +74 -0
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/public_api.js +3 -1
- package/esm2015/src/app/core/core.module.js +4 -1
- package/esm2015/src/app/core/form/form-error-translate.pipe.js +19 -0
- package/esm2015/src/app/core/form/form-error.adapter.js +56 -0
- package/fesm2015/sumaris-net.ngx-components.js +69 -1
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +2 -0
- package/src/app/core/form/form-error-translate.pipe.d.ts +8 -0
- package/src/app/core/form/form-error.adapter.d.ts +16 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -22219,6 +22219,76 @@
|
|
|
22219
22219
|
forward: [{ type: i0.Output }]
|
|
22220
22220
|
};
|
|
22221
22221
|
|
|
22222
|
+
var FormErrorAdapter = /** @class */ (function () {
|
|
22223
|
+
function FormErrorAdapter(translate) {
|
|
22224
|
+
this.translate = translate;
|
|
22225
|
+
}
|
|
22226
|
+
FormErrorAdapter.prototype.formatError = function (form, opts) {
|
|
22227
|
+
var _this = this;
|
|
22228
|
+
if (!form || !form.invalid)
|
|
22229
|
+
return '';
|
|
22230
|
+
var separator = opts && opts.separator || ', ';
|
|
22231
|
+
var recursive = !opts || opts.recursive !== false;
|
|
22232
|
+
var errors = AppFormUtils.getFormErrors(form, { recursive: recursive });
|
|
22233
|
+
var i18nErrors = errors && Object.keys(errors).reduce(function (res, key) {
|
|
22234
|
+
var control = form.get(key);
|
|
22235
|
+
// Should be a control map of errors
|
|
22236
|
+
if (control) {
|
|
22237
|
+
// Try to convert from a map, for one column control
|
|
22238
|
+
var i18nFieldNameKey = _this.getI18nFieldName(key, opts);
|
|
22239
|
+
var i18nFieldName = _this.translate.instant(i18nFieldNameKey);
|
|
22240
|
+
// OK, we have a field name: use it
|
|
22241
|
+
var columnErrors = Object.keys(control.errors).map(function (errorKey) { return _this.getI18nError(errorKey, control.errors[errorKey]); });
|
|
22242
|
+
if (isEmptyArray(columnErrors))
|
|
22243
|
+
return res;
|
|
22244
|
+
// Add separator
|
|
22245
|
+
if (res.length)
|
|
22246
|
+
res += separator;
|
|
22247
|
+
return res + i18nFieldName + ": " + columnErrors.join(separator);
|
|
22248
|
+
}
|
|
22249
|
+
// Or try as global form error
|
|
22250
|
+
var formError = _this.getI18nError(key, errors[key]);
|
|
22251
|
+
if (isNil(formError))
|
|
22252
|
+
return res;
|
|
22253
|
+
return res + (res.length ? separator : '') + formError;
|
|
22254
|
+
}, "");
|
|
22255
|
+
return i18nErrors;
|
|
22256
|
+
};
|
|
22257
|
+
FormErrorAdapter.prototype.getI18nFieldName = function (fieldName, opts) {
|
|
22258
|
+
return (opts && opts.i18nPrefix || '') + changeCaseToUnderscore(fieldName).toUpperCase();
|
|
22259
|
+
};
|
|
22260
|
+
FormErrorAdapter.prototype.getI18nError = function (errorKey, errorContent) {
|
|
22261
|
+
var _this = this;
|
|
22262
|
+
return SharedValidators.translateError(function (a, b) { return _this.translate.instant(a, b); }, errorKey, errorContent);
|
|
22263
|
+
};
|
|
22264
|
+
return FormErrorAdapter;
|
|
22265
|
+
}());
|
|
22266
|
+
FormErrorAdapter.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function FormErrorAdapter_Factory() { return new FormErrorAdapter(i0__namespace.ɵɵinject(i1__namespace$1.TranslateService)); }, token: FormErrorAdapter, providedIn: "root" });
|
|
22267
|
+
FormErrorAdapter.decorators = [
|
|
22268
|
+
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
22269
|
+
];
|
|
22270
|
+
FormErrorAdapter.ctorParameters = function () { return [
|
|
22271
|
+
{ type: i1$2.TranslateService }
|
|
22272
|
+
]; };
|
|
22273
|
+
|
|
22274
|
+
var FormErrorTranslatePipe = /** @class */ (function () {
|
|
22275
|
+
function FormErrorTranslatePipe(adapter) {
|
|
22276
|
+
this.adapter = adapter;
|
|
22277
|
+
}
|
|
22278
|
+
FormErrorTranslatePipe.prototype.transform = function (form, opts) {
|
|
22279
|
+
return this.adapter.formatError(form, opts);
|
|
22280
|
+
};
|
|
22281
|
+
return FormErrorTranslatePipe;
|
|
22282
|
+
}());
|
|
22283
|
+
FormErrorTranslatePipe.decorators = [
|
|
22284
|
+
{ type: i0.Pipe, args: [{
|
|
22285
|
+
name: 'translateFormError',
|
|
22286
|
+
},] }
|
|
22287
|
+
];
|
|
22288
|
+
FormErrorTranslatePipe.ctorParameters = function () { return [
|
|
22289
|
+
{ type: FormErrorAdapter }
|
|
22290
|
+
]; };
|
|
22291
|
+
|
|
22222
22292
|
var CoreModule = /** @class */ (function () {
|
|
22223
22293
|
function CoreModule() {
|
|
22224
22294
|
}
|
|
@@ -22251,6 +22321,7 @@
|
|
|
22251
22321
|
IsLoginAccountPipe,
|
|
22252
22322
|
AccountToStringPipe,
|
|
22253
22323
|
DepartmentToStringPipe,
|
|
22324
|
+
FormErrorTranslatePipe,
|
|
22254
22325
|
// Home and menu
|
|
22255
22326
|
HomePage,
|
|
22256
22327
|
AboutModal,
|
|
@@ -22284,6 +22355,7 @@
|
|
|
22284
22355
|
PersonToStringPipe,
|
|
22285
22356
|
IsLoginAccountPipe,
|
|
22286
22357
|
AccountToStringPipe,
|
|
22358
|
+
FormErrorTranslatePipe,
|
|
22287
22359
|
// Components
|
|
22288
22360
|
HomePage,
|
|
22289
22361
|
AuthForm,
|
|
@@ -27707,6 +27779,8 @@
|
|
|
27707
27779
|
exports.FormArrayHelper = FormArrayHelper;
|
|
27708
27780
|
exports.FormButtonsBarComponent = FormButtonsBarComponent;
|
|
27709
27781
|
exports.FormButtonsBarToken = FormButtonsBarToken;
|
|
27782
|
+
exports.FormErrorAdapter = FormErrorAdapter;
|
|
27783
|
+
exports.FormErrorTranslatePipe = FormErrorTranslatePipe;
|
|
27710
27784
|
exports.FormFieldValuesHolder = FormFieldValuesHolder;
|
|
27711
27785
|
exports.Fragments = Fragments;
|
|
27712
27786
|
exports.GraphqlService = GraphqlService;
|