ng-configcat-publicapi-ui 2.12.0 → 2.13.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.
@@ -159,6 +159,66 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
159
159
  type: Input
160
160
  }] } });
161
161
 
162
+ class FormHelper {
163
+ static getErrorMessage(control, hint = '') {
164
+ if (!control || control.valid) {
165
+ return;
166
+ }
167
+ if (control.hasError('required')) {
168
+ return `${hint} The field is required.`;
169
+ }
170
+ if (control.hasError('pattern')) {
171
+ return 'Not a valid e-mail address.';
172
+ }
173
+ if (control.hasError('minlength')) {
174
+ return 'The field must be at least ' + control.getError('minlength').requiredLength + ' characters long';
175
+ }
176
+ if (control.hasError('maxlength')) {
177
+ return 'The field must be at max ' + control.getError('maxlength').requiredLength + ' characters long';
178
+ }
179
+ return;
180
+ }
181
+ static handleErrors(formGroup, error) {
182
+ if (error instanceof HttpErrorResponse) {
183
+ const response = error;
184
+ switch (response.status) {
185
+ case 400:
186
+ let unknownFieldName = false;
187
+ for (const fieldName in error.error) {
188
+ if (error.error.hasOwnProperty(fieldName) && error.error[fieldName] &&
189
+ (error.error[fieldName]?.length > 0 || error.error[fieldName]?.Errors?.length > 0)) {
190
+ let jsonFieldName = fieldName;
191
+ if (jsonFieldName.length > 0) {
192
+ jsonFieldName = jsonFieldName[0].toLowerCase() + jsonFieldName.slice(1);
193
+ }
194
+ const errorMessage = error.error[fieldName]?.Errors?.length > 0 ?
195
+ (error.error[fieldName]?.Errors.map((e) => e.ErrorMessage)).join(', ')
196
+ : error.error[fieldName];
197
+ if (formGroup.controls.hasOwnProperty(jsonFieldName)) {
198
+ formGroup.controls[jsonFieldName].setErrors({ serverSide: errorMessage });
199
+ }
200
+ else {
201
+ unknownFieldName = true;
202
+ }
203
+ }
204
+ }
205
+ if (unknownFieldName) {
206
+ formGroup.setErrors({ serverSide: 'Something went wrong.' });
207
+ }
208
+ break;
209
+ // in these cases we do not show errors on the form, they're handled by the http
210
+ // interceptor in src\app\_interceptors\httpstatuscode.interceptor.ts
211
+ case 402:
212
+ case 429:
213
+ return;
214
+ }
215
+ }
216
+ else {
217
+ formGroup.setErrors({ serverSide: 'Something went wrong on our side. This is not your fault. Please try again.' });
218
+ }
219
+ }
220
+ }
221
+
162
222
  class ReasonDialogComponent {
163
223
  constructor(dialogRef, formBuilder) {
164
224
  this.dialogRef = dialogRef;
@@ -1386,66 +1446,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
1386
1446
  type: Input
1387
1447
  }] } });
1388
1448
 
1389
- class FormHelper {
1390
- static getErrorMessage(control, hint = '') {
1391
- if (!control || control.valid) {
1392
- return;
1393
- }
1394
- if (control.hasError('required')) {
1395
- return `${hint} The field is required.`;
1396
- }
1397
- if (control.hasError('pattern')) {
1398
- return 'Not a valid e-mail address.';
1399
- }
1400
- if (control.hasError('minlength')) {
1401
- return 'The field must be at least ' + control.getError('minlength').requiredLength + ' characters long';
1402
- }
1403
- if (control.hasError('maxlength')) {
1404
- return 'The field must be at max ' + control.getError('maxlength').requiredLength + ' characters long';
1405
- }
1406
- return;
1407
- }
1408
- static handleErrors(formGroup, error) {
1409
- if (error instanceof HttpErrorResponse) {
1410
- const response = error;
1411
- switch (response.status) {
1412
- case 400:
1413
- let unknownFieldName = false;
1414
- for (const fieldName in error.error) {
1415
- if (error.error.hasOwnProperty(fieldName) && error.error[fieldName] &&
1416
- (error.error[fieldName]?.length > 0 || error.error[fieldName]?.Errors?.length > 0)) {
1417
- let jsonFieldName = fieldName;
1418
- if (jsonFieldName.length > 0) {
1419
- jsonFieldName = jsonFieldName[0].toLowerCase() + jsonFieldName.slice(1);
1420
- }
1421
- const errorMessage = error.error[fieldName]?.Errors?.length > 0 ?
1422
- (error.error[fieldName]?.Errors.map((e) => e.ErrorMessage)).join(', ')
1423
- : error.error[fieldName];
1424
- if (formGroup.controls.hasOwnProperty(jsonFieldName)) {
1425
- formGroup.controls[jsonFieldName].setErrors({ serverSide: errorMessage });
1426
- }
1427
- else {
1428
- unknownFieldName = true;
1429
- }
1430
- }
1431
- }
1432
- if (unknownFieldName) {
1433
- formGroup.setErrors({ serverSide: 'Something went wrong.' });
1434
- }
1435
- break;
1436
- // in these cases we do not show errors on the form, they're handled by the http
1437
- // interceptor in src\app\_interceptors\httpstatuscode.interceptor.ts
1438
- case 402:
1439
- case 429:
1440
- return;
1441
- }
1442
- }
1443
- else {
1444
- formGroup.setErrors({ serverSide: 'Something went wrong on our side. This is not your fault. Please try again.' });
1445
- }
1446
- }
1447
- }
1448
-
1449
1449
  class AuthorizationComponent {
1450
1450
  constructor(formBuilder, publicApiService) {
1451
1451
  this.formBuilder = formBuilder;
@@ -1623,5 +1623,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.1", ngImpor
1623
1623
  * Generated bundle index. Do not edit.
1624
1624
  */
1625
1625
 
1626
- export { AuthorizationComponent, ConfigSelectComponent, EnvironmentSelectComponent, NgConfigCatPublicApiUIModule, ProductSelectComponent, PublicApiService, SettingItemComponent, SettingSelectComponent };
1626
+ export { AuthorizationComponent, ConfigSelectComponent, EnvironmentSelectComponent, FormHelper, NgConfigCatPublicApiUIModule, ProductSelectComponent, PublicApiService, SettingItemComponent, SettingSelectComponent };
1627
1627
  //# sourceMappingURL=ng-configcat-publicapi-ui.mjs.map