@eqproject/eqp-dynamic-module 0.0.5 → 0.0.7
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/karma.conf.js +32 -0
- package/ng-package.json +18 -0
- package/package.json +31 -41
- package/src/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.html +10 -0
- package/src/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.scss +3 -0
- package/src/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.ts +228 -0
- package/src/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.html +212 -0
- package/src/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.scss +30 -0
- package/src/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.ts +692 -0
- package/src/lib/components/private/add-form-field/add-form-field.component.html +417 -0
- package/src/lib/components/private/add-form-field/add-form-field.component.scss +38 -0
- package/src/lib/components/private/add-form-field/add-form-field.component.ts +599 -0
- package/src/lib/components/private/dynamic-module-field/dynamic-module-field.component.html +42 -0
- package/src/lib/components/private/dynamic-module-field/dynamic-module-field.component.scss +0 -0
- package/src/lib/components/private/dynamic-module-field/dynamic-module-field.component.ts +125 -0
- package/src/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.html +25 -0
- package/src/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.ts +172 -0
- package/src/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.html +32 -0
- package/src/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.ts +53 -0
- package/src/lib/components/private/field-templates/date-field-template/date-field-template.component.html +6 -0
- package/src/lib/components/private/field-templates/date-field-template/date-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/date-field-template/date-field-template.component.ts +70 -0
- package/src/lib/components/private/field-templates/image-field-template/image-field-template.component.html +57 -0
- package/src/lib/components/private/field-templates/image-field-template/image-field-template.component.scss +4 -0
- package/src/lib/components/private/field-templates/image-field-template/image-field-template.component.ts +203 -0
- package/src/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.html +46 -0
- package/src/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.scss +13 -0
- package/src/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.ts +114 -0
- package/src/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.html +6 -0
- package/src/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.ts +70 -0
- package/src/lib/components/private/field-templates/text-field-template/text-field-template.component.html +5 -0
- package/src/lib/components/private/field-templates/text-field-template/text-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/text-field-template/text-field-template.component.ts +65 -0
- package/src/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.html +5 -0
- package/src/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.scss +0 -0
- package/src/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.ts +48 -0
- package/src/lib/components/private/form-records/add-form-record/add-form-record.component.html +74 -0
- package/src/lib/components/private/form-records/add-form-record/add-form-record.component.scss +0 -0
- package/src/lib/components/private/form-records/add-form-record/add-form-record.component.ts +117 -0
- package/src/lib/components/private/form-records/list-form-record/list-form-record.component.html +14 -0
- package/src/lib/components/private/form-records/list-form-record/list-form-record.component.scss +7 -0
- package/src/lib/components/private/form-records/list-form-record/list-form-record.component.ts +213 -0
- package/src/lib/components/private/spinner/spinner.component.html +3 -0
- package/src/lib/components/private/spinner/spinner.component.scss +100 -0
- package/src/lib/components/private/spinner/spinner.component.ts +19 -0
- package/src/lib/eqp-dynamic-module.module.ts +65 -0
- package/{lib/interfaces/iBaseFieldComponent.interface.d.ts → src/lib/interfaces/iBaseFieldComponent.interface.ts} +1 -1
- package/{lib/interfaces/iRootObject.interface.d.ts → src/lib/interfaces/iRootObject.interface.ts} +1 -1
- package/{lib/models/baseField.model.d.ts → src/lib/models/baseField.model.ts} +14 -5
- package/{lib/models/baseObj.model.d.ts → src/lib/models/baseObj.model.ts} +3 -3
- package/src/lib/models/context.model.ts +10 -0
- package/{lib/models/endPointConfiguration.model.d.ts → src/lib/models/endPointConfiguration.model.ts} +16 -12
- package/{lib/models/entity.model.d.ts → src/lib/models/entity.model.ts} +2 -1
- package/src/lib/models/fields/attachmentField.model.ts +32 -0
- package/{lib/models/fields/booleanField.model.d.ts → src/lib/models/fields/booleanField.model.ts} +8 -4
- package/{lib/models/fields/dateField.model.d.ts → src/lib/models/fields/dateField.model.ts} +5 -3
- package/{lib/models/fields/imageField.model.d.ts → src/lib/models/fields/imageField.model.ts} +8 -3
- package/{lib/models/fields/listValueField.model.d.ts → src/lib/models/fields/listValueField.model.ts} +13 -8
- package/{lib/models/fields/lookupField.model.d.ts → src/lib/models/fields/lookupField.model.ts} +5 -2
- package/{lib/models/fields/numericField.model.d.ts → src/lib/models/fields/numericField.model.ts} +3 -2
- package/{lib/models/fields/testareaField.model.d.ts → src/lib/models/fields/testareaField.model.ts} +3 -2
- package/src/lib/models/fields/textField.model.ts +18 -0
- package/{lib/models/form.model.d.ts → src/lib/models/form.model.ts} +25 -12
- package/{lib/models/record.model.d.ts → src/lib/models/record.model.ts} +4 -5
- package/src/lib/modules/material.module.ts +104 -0
- package/src/lib/services/custom-form-validators.service.ts +21 -0
- package/src/lib/services/eqp-dynamic-module-dialog.service.ts +114 -0
- package/src/lib/services/spinner.service.ts +40 -0
- package/src/lib/services/utilityHelper.services.ts +413 -0
- package/{public-api.d.ts → src/public-api.ts} +3 -0
- package/src/test.ts +26 -0
- package/tsconfig.lib.json +23 -0
- package/tsconfig.lib.prod.json +6 -0
- package/tsconfig.spec.json +17 -0
- package/tslint.json +17 -0
- package/bundles/eqproject-eqp-dynamic-module.umd.js +0 -3992
- package/bundles/eqproject-eqp-dynamic-module.umd.js.map +0 -1
- package/bundles/eqproject-eqp-dynamic-module.umd.min.js +0 -17
- package/bundles/eqproject-eqp-dynamic-module.umd.min.js.map +0 -1
- package/eqproject-eqp-dynamic-module.d.ts +0 -6
- package/eqproject-eqp-dynamic-module.metadata.json +0 -1
- package/esm2015/eqproject-eqp-dynamic-module.js +0 -7
- package/esm2015/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.js +0 -262
- package/esm2015/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.js +0 -649
- package/esm2015/lib/components/private/add-form-field/add-form-field.component.js +0 -577
- package/esm2015/lib/components/private/dynamic-module-field/dynamic-module-field.component.js +0 -127
- package/esm2015/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.js +0 -170
- package/esm2015/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.js +0 -56
- package/esm2015/lib/components/private/field-templates/date-field-template/date-field-template.component.js +0 -71
- package/esm2015/lib/components/private/field-templates/image-field-template/image-field-template.component.js +0 -196
- package/esm2015/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.js +0 -115
- package/esm2015/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.js +0 -71
- package/esm2015/lib/components/private/field-templates/text-field-template/text-field-template.component.js +0 -67
- package/esm2015/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.js +0 -51
- package/esm2015/lib/components/private/form-records/add-form-record/add-form-record.component.js +0 -130
- package/esm2015/lib/components/private/form-records/list-form-record/list-form-record.component.js +0 -216
- package/esm2015/lib/components/private/spinner/spinner.component.js +0 -23
- package/esm2015/lib/eqp-dynamic-module.module.js +0 -71
- package/esm2015/lib/interfaces/iBaseFieldComponent.interface.js +0 -1
- package/esm2015/lib/interfaces/iRootObject.interface.js +0 -1
- package/esm2015/lib/models/baseField.model.js +0 -36
- package/esm2015/lib/models/baseObj.model.js +0 -9
- package/esm2015/lib/models/context.model.js +0 -8
- package/esm2015/lib/models/endPointConfiguration.model.js +0 -23
- package/esm2015/lib/models/entity.model.js +0 -7
- package/esm2015/lib/models/fields/attachmentField.model.js +0 -22
- package/esm2015/lib/models/fields/booleanField.model.js +0 -12
- package/esm2015/lib/models/fields/dateField.model.js +0 -11
- package/esm2015/lib/models/fields/imageField.model.js +0 -8
- package/esm2015/lib/models/fields/listValueField.model.js +0 -14
- package/esm2015/lib/models/fields/lookupField.model.js +0 -5
- package/esm2015/lib/models/fields/numericField.model.js +0 -5
- package/esm2015/lib/models/fields/testareaField.model.js +0 -4
- package/esm2015/lib/models/fields/textField.model.js +0 -14
- package/esm2015/lib/models/form.model.js +0 -24
- package/esm2015/lib/models/record.model.js +0 -8
- package/esm2015/lib/modules/material.module.js +0 -108
- package/esm2015/lib/services/custom-form-validators.service.js +0 -19
- package/esm2015/lib/services/eqp-dynamic-module-dialog.service.js +0 -113
- package/esm2015/lib/services/spinner.service.js +0 -43
- package/esm2015/lib/services/utilityHelper.services.js +0 -387
- package/esm2015/public-api.js +0 -39
- package/esm5/eqproject-eqp-dynamic-module.js +0 -7
- package/esm5/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.js +0 -269
- package/esm5/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.js +0 -664
- package/esm5/lib/components/private/add-form-field/add-form-field.component.js +0 -588
- package/esm5/lib/components/private/dynamic-module-field/dynamic-module-field.component.js +0 -128
- package/esm5/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.js +0 -173
- package/esm5/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.js +0 -57
- package/esm5/lib/components/private/field-templates/date-field-template/date-field-template.component.js +0 -72
- package/esm5/lib/components/private/field-templates/image-field-template/image-field-template.component.js +0 -206
- package/esm5/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.js +0 -119
- package/esm5/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.js +0 -72
- package/esm5/lib/components/private/field-templates/text-field-template/text-field-template.component.js +0 -68
- package/esm5/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.js +0 -52
- package/esm5/lib/components/private/form-records/add-form-record/add-form-record.component.js +0 -133
- package/esm5/lib/components/private/form-records/list-form-record/list-form-record.component.js +0 -220
- package/esm5/lib/components/private/spinner/spinner.component.js +0 -24
- package/esm5/lib/eqp-dynamic-module.module.js +0 -74
- package/esm5/lib/interfaces/iBaseFieldComponent.interface.js +0 -1
- package/esm5/lib/interfaces/iRootObject.interface.js +0 -1
- package/esm5/lib/models/baseField.model.js +0 -43
- package/esm5/lib/models/baseObj.model.js +0 -13
- package/esm5/lib/models/context.model.js +0 -14
- package/esm5/lib/models/endPointConfiguration.model.js +0 -33
- package/esm5/lib/models/entity.model.js +0 -14
- package/esm5/lib/models/fields/attachmentField.model.js +0 -29
- package/esm5/lib/models/fields/booleanField.model.js +0 -19
- package/esm5/lib/models/fields/dateField.model.js +0 -18
- package/esm5/lib/models/fields/imageField.model.js +0 -19
- package/esm5/lib/models/fields/listValueField.model.js +0 -25
- package/esm5/lib/models/fields/lookupField.model.js +0 -12
- package/esm5/lib/models/fields/numericField.model.js +0 -12
- package/esm5/lib/models/fields/testareaField.model.js +0 -11
- package/esm5/lib/models/fields/textField.model.js +0 -21
- package/esm5/lib/models/form.model.js +0 -39
- package/esm5/lib/models/record.model.js +0 -14
- package/esm5/lib/modules/material.module.js +0 -111
- package/esm5/lib/services/custom-form-validators.service.js +0 -23
- package/esm5/lib/services/eqp-dynamic-module-dialog.service.js +0 -123
- package/esm5/lib/services/spinner.service.js +0 -46
- package/esm5/lib/services/utilityHelper.services.js +0 -396
- package/esm5/public-api.js +0 -39
- package/fesm2015/eqproject-eqp-dynamic-module.js +0 -3582
- package/fesm2015/eqproject-eqp-dynamic-module.js.map +0 -1
- package/fesm5/eqproject-eqp-dynamic-module.js +0 -3768
- package/fesm5/eqproject-eqp-dynamic-module.js.map +0 -1
- package/lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component.d.ts +0 -101
- package/lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component.d.ts +0 -235
- package/lib/components/private/add-form-field/add-form-field.component.d.ts +0 -199
- package/lib/components/private/dynamic-module-field/dynamic-module-field.component.d.ts +0 -55
- package/lib/components/private/field-templates/attachment-field-template/attachment-field-template.component.d.ts +0 -68
- package/lib/components/private/field-templates/boolean-field-template/boolean-field-template.component.d.ts +0 -21
- package/lib/components/private/field-templates/date-field-template/date-field-template.component.d.ts +0 -27
- package/lib/components/private/field-templates/image-field-template/image-field-template.component.d.ts +0 -65
- package/lib/components/private/field-templates/list-value-field-template/list-value-field-template.component.d.ts +0 -51
- package/lib/components/private/field-templates/numeric-field-template/numeric-field-template.component.d.ts +0 -26
- package/lib/components/private/field-templates/text-field-template/text-field-template.component.d.ts +0 -22
- package/lib/components/private/field-templates/textarea-field-template/textarea-field-template.component.d.ts +0 -20
- package/lib/components/private/form-records/add-form-record/add-form-record.component.d.ts +0 -52
- package/lib/components/private/form-records/list-form-record/list-form-record.component.d.ts +0 -64
- package/lib/components/private/spinner/spinner.component.d.ts +0 -9
- package/lib/eqp-dynamic-module.module.d.ts +0 -2
- package/lib/models/context.model.d.ts +0 -9
- package/lib/models/fields/attachmentField.model.d.ts +0 -17
- package/lib/models/fields/textField.model.d.ts +0 -15
- package/lib/modules/material.module.d.ts +0 -2
- package/lib/services/custom-form-validators.service.d.ts +0 -5
- package/lib/services/eqp-dynamic-module-dialog.service.d.ts +0 -34
- package/lib/services/spinner.service.d.ts +0 -15
- package/lib/services/utilityHelper.services.d.ts +0 -77
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { HttpClient } from "@angular/common/http";
|
|
2
|
+
import { Injectable } from "@angular/core";
|
|
3
|
+
import { AbstractControl, FormBuilder, FormControl, FormGroup, ValidatorFn, Validators } from "@angular/forms";
|
|
4
|
+
import { BaseField, ColSpanSizesEnum, FieldTypeEnum } from "../models/baseField.model";
|
|
5
|
+
import { Context } from "../models/context.model";
|
|
6
|
+
import { EndPointConfiguration, EndPointData, EndPointDataParams, ParamTypeEnum, RequestMethodEnum } from "../models/endPointConfiguration.model";
|
|
7
|
+
import { AttachmentField } from "../models/fields/attachmentField.model";
|
|
8
|
+
import { ImageField } from "../models/fields/imageField.model";
|
|
9
|
+
import { ListValueField } from "../models/fields/listValueField.model";
|
|
10
|
+
import { TextareaField } from "../models/fields/testareaField.model";
|
|
11
|
+
import { TextMaskEnum, TextField, UrlRegex, TelRegex } from "../models/fields/textField.model";
|
|
12
|
+
import { Form } from "../models/form.model";
|
|
13
|
+
import { Record } from "../models/record.model";
|
|
14
|
+
import { ArrayValidators } from "./custom-form-validators.service";
|
|
15
|
+
import { EqpDynamicModuleDialogService } from "./eqp-dynamic-module-dialog.service";
|
|
16
|
+
import { SpinnerService } from "./spinner.service";
|
|
17
|
+
|
|
18
|
+
@Injectable({
|
|
19
|
+
providedIn: 'root'
|
|
20
|
+
})
|
|
21
|
+
export class UtilityHelperService {
|
|
22
|
+
|
|
23
|
+
public static context: Context = new Context();
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private formBuilder: FormBuilder,
|
|
27
|
+
private http: HttpClient,
|
|
28
|
+
private spinnerService: SpinnerService
|
|
29
|
+
) {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static EvaluateFieldFormula(formula: string, rec: Record, ctx: any): any {
|
|
33
|
+
const evaluatedValue = eval(formula);
|
|
34
|
+
return (evaluatedValue ? evaluatedValue : null);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static SetContext(ctx: Context) {
|
|
38
|
+
this.context = ctx;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static GetFieldType(field: BaseField){
|
|
42
|
+
switch (field.FieldType) {
|
|
43
|
+
case FieldTypeEnum["Campo di testo"]: {
|
|
44
|
+
const t: TextField = Object.assign(new TextField,field);
|
|
45
|
+
return t;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
default: {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Metodo per impostare i valori da suggerire nell'autocomplete per i campi in cui l'utente deve scrivere comandi javascript.
|
|
56
|
+
* In base all'ultimo carattere digitato viene impostato un elenco di oggetti o proprietà che l'utente ha a disposizione in quel momento.
|
|
57
|
+
* @param fields Array di BaseField aggiunti alla Form
|
|
58
|
+
* @param typedFormula Stringa digitata dall'utente
|
|
59
|
+
* @summary Il metodo imposta i suggerimenti basandosi su 3 casi:
|
|
60
|
+
* 1) l'utente non ha digitato nulla o la stringa digitata dall'utente finisce con uno spazio vuoto
|
|
61
|
+
* 2) la stringa digitata dall'utente finisce con un "."
|
|
62
|
+
* 3) la stringa digitata dall'utente non coincide con nessun altro caso sopra (finisce con un carattere qualunque)
|
|
63
|
+
*/
|
|
64
|
+
public static GetAutocompleteOptions(fields: Array<BaseField>, typedFormula: string): Array<{ label: string, value: string }> {
|
|
65
|
+
|
|
66
|
+
let autocompleteOptions: Array<{ label: string, value: string }> = [];
|
|
67
|
+
|
|
68
|
+
// Recupero i nomi di tutti i campi creati fino ad ora nella form.
|
|
69
|
+
const availableRecProperties: Array<string> = fields.map(f => f.Label.split(' ').join('_'));
|
|
70
|
+
|
|
71
|
+
// Nel casi in cui l'utente non ha inserito nulla oppure la stringa finisce con uno spazio vuoto o un simbolo diverso da "."
|
|
72
|
+
// (un carattere non alfanumerico) imposto come suggerimenti solo "rec" e "ctx", ovvero gli unici due oggetti a cui l'utente ha accesso.
|
|
73
|
+
if (
|
|
74
|
+
!typedFormula ||
|
|
75
|
+
(
|
|
76
|
+
!typedFormula.endsWith(".")
|
|
77
|
+
&& new RegExp("[^0-9a-zA-Z_]").test(typedFormula.substring(typedFormula.length - 1, typedFormula.length))
|
|
78
|
+
)
|
|
79
|
+
) {
|
|
80
|
+
autocompleteOptions = [
|
|
81
|
+
{ label: "rec", value: (typedFormula ? typedFormula : '') + "rec" },
|
|
82
|
+
{ label: "ctx", value: (typedFormula ? typedFormula : '') + "ctx" }
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
// Se la stringa finisce con un "." vuol dire che l'utente sta cercando di accedere ad una proprietà di un oggetto
|
|
86
|
+
// a sua disposizione. Recupero il nome dell'ultimo oggetto digitato dall'utente e se l'oggetto scelto è "rec" o "ctx"
|
|
87
|
+
// allora suggerisco le proprietà che esistono all'interno di questi oggetti altrimenti non mostro nulla.
|
|
88
|
+
else if (typedFormula.endsWith(".")) {
|
|
89
|
+
const formulaPieces: Array<string> = typedFormula.split(" ")[typedFormula.split(" ").length - 1].split('.');
|
|
90
|
+
if (formulaPieces[formulaPieces.length - 2] === "rec") {
|
|
91
|
+
autocompleteOptions = availableRecProperties.map(f => { return { label: f, value: typedFormula + f }; });
|
|
92
|
+
} else if (formulaPieces[formulaPieces.length - 2] === "ctx") {
|
|
93
|
+
autocompleteOptions = Object.keys(UtilityHelperService.context).map(f => { return { label: f, value: typedFormula + f }; });
|
|
94
|
+
} else if (formulaPieces.length > 2 && formulaPieces[formulaPieces.length - 3] === "ctx" && formulaPieces[formulaPieces.length - 2] === "User") {
|
|
95
|
+
autocompleteOptions = Object.keys(UtilityHelperService.context.User).map(f => { return { label: f, value: typedFormula + f }; });
|
|
96
|
+
} else {
|
|
97
|
+
autocompleteOptions = [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// In tutti gli altri casi, ovvero quando la stringa digitata finisce con un carattere diverso da quelli
|
|
101
|
+
// controllati finora, vuol dire che l'utente sta digitanto il nome di un oggetto, una proprietà o una
|
|
102
|
+
// funzione javascript. Controllo la parola che l'utente sta digitando e se fa parte di uno degli oggetti a disposizione
|
|
103
|
+
// o una proprietà di essi allora suggerisco i possibili match.
|
|
104
|
+
else {
|
|
105
|
+
const availableOptions: Array<{ label: string, value: string }> = [];
|
|
106
|
+
|
|
107
|
+
// Prendo tutti i blocchi di caratteri digitati dall'utente
|
|
108
|
+
const allFormulaWords: Array<string> = typedFormula.split(" ");
|
|
109
|
+
// Prendo l'ultimo blocco di caratteri digitato dall'utente
|
|
110
|
+
const lastTypedString: string = allFormulaWords[allFormulaWords.length - 1];
|
|
111
|
+
|
|
112
|
+
// Se la l'ultima stringa digitata non contiene caratteri speciali allora splitto la stringa
|
|
113
|
+
// sui "." e imposto i suggerimenti in base al path della prorpietà che si sta digitando.
|
|
114
|
+
if (!new RegExp("[^0-9a-zA-Z_.]").test(lastTypedString)) {
|
|
115
|
+
const propertyPath = lastTypedString.split(".");
|
|
116
|
+
const lastTypedWork = propertyPath[propertyPath.length - 1];
|
|
117
|
+
|
|
118
|
+
let propertiesToCheck: Array<string> = [];
|
|
119
|
+
|
|
120
|
+
if (propertyPath.length == 1) {
|
|
121
|
+
propertiesToCheck = ["rec", "ctx"];
|
|
122
|
+
} else if (propertyPath.length > 1 && propertyPath[propertyPath.length - 2] === "ctx") {
|
|
123
|
+
propertiesToCheck = Object.keys(UtilityHelperService.context);
|
|
124
|
+
} else if (propertyPath.length > 2 && propertyPath[propertyPath.length - 3] === "ctx" && propertyPath[propertyPath.length - 2] === "User") {
|
|
125
|
+
propertiesToCheck = Object.keys(UtilityHelperService.context.User);
|
|
126
|
+
} else if (propertyPath.length > 1 && propertyPath[propertyPath.length - 2] === "rec") {
|
|
127
|
+
propertiesToCheck = availableRecProperties;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Eseguo il controllo sulle proprietà recuperate, aggiungo ai suggerimenti tutti i nomi che iniziano con
|
|
131
|
+
// quello che sta digitando l'utente.
|
|
132
|
+
propertiesToCheck.forEach(prop => {
|
|
133
|
+
if (prop.startsWith(lastTypedWork)) {
|
|
134
|
+
availableOptions.push({ label: prop, value: typedFormula + prop.substring(lastTypedWork.length, prop.length) })
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
autocompleteOptions = availableOptions;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return autocompleteOptions;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Metodo invocato dall'html per impostare le classi css per visualizzare il campo all'interno della form.
|
|
147
|
+
* Se per il field sono state specificate delle classi allora vengono applcate quelle, altrimenti vengono usate
|
|
148
|
+
* delle classi di default.
|
|
149
|
+
* @param field BaseField da visualizzare.
|
|
150
|
+
* @returns Restituisce una stringa contenente le classi css da applicare.
|
|
151
|
+
*/
|
|
152
|
+
getFieldSyleClass(field: BaseField): string {
|
|
153
|
+
if (field.ColSpanSizes && field.ColSpanSizes.length > 0)
|
|
154
|
+
return field.ColSpanSizes.map(size => ColSpanSizesEnum[size].toString()).join(" ");
|
|
155
|
+
|
|
156
|
+
switch (field.FieldType) {
|
|
157
|
+
case FieldTypeEnum["Campo di testo"]:
|
|
158
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
159
|
+
case FieldTypeEnum["Area di testo"]:
|
|
160
|
+
return "col-sm-12 col-md-12 col-lg-12";
|
|
161
|
+
case FieldTypeEnum["Booleano"]:
|
|
162
|
+
return "col-sm-12 col-md-4 col-lg-4 d-flex align-items-center";
|
|
163
|
+
case FieldTypeEnum["Data e/o ora"]:
|
|
164
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
165
|
+
case FieldTypeEnum["Campo numerico"]:
|
|
166
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
167
|
+
case FieldTypeEnum["Allegato"]:
|
|
168
|
+
if (
|
|
169
|
+
(field as AttachmentField).IsMultiAttach ||
|
|
170
|
+
((field as AttachmentField).MetadataFields && (field as AttachmentField).MetadataFields.length > 0)
|
|
171
|
+
) {
|
|
172
|
+
return "col-sm-12 col-md-12 col-lg-12";
|
|
173
|
+
} else {
|
|
174
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
175
|
+
}
|
|
176
|
+
case FieldTypeEnum["Immagine"]:
|
|
177
|
+
if (
|
|
178
|
+
(field as ImageField).AttachDefinition.IsMultiAttach ||
|
|
179
|
+
((field as ImageField).AttachDefinition.MetadataFields && (field as ImageField).AttachDefinition.MetadataFields.length > 0)
|
|
180
|
+
) {
|
|
181
|
+
return "col-sm-12 col-md-12 col-lg-12";
|
|
182
|
+
} else {
|
|
183
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
184
|
+
}
|
|
185
|
+
case FieldTypeEnum["Elenco generico"]:
|
|
186
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
187
|
+
case FieldTypeEnum["Lookup"]:
|
|
188
|
+
return "col-sm-12 col-md-4 col-lg-4";
|
|
189
|
+
case FieldTypeEnum['Form di dettaglio']:
|
|
190
|
+
return "col-sm-12 col-md-12 col-lg-12";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Metodo per creare il FormGroup che rappresenta una Form a partire dai suoi BaseField.
|
|
196
|
+
* @param formFields Lista dei BaseField che compongono la form.
|
|
197
|
+
* @param record Oggetto di tipo Record che contiene i valori dei campi.
|
|
198
|
+
* @param onlyView Se TRUE disabilita la form per renderla in sola lettura.
|
|
199
|
+
* @param includeCurrentFormInField Se TRUE popola la proprietà FormFormGroup all'interno di ogni BaseField con il FormGroup corrente.
|
|
200
|
+
* @returns Restituisce un FormGroup rappresentate la Form a cui appartengono i BaseField ricevuti in input.
|
|
201
|
+
*/
|
|
202
|
+
public CreateFormFormGroup(formFields: Array<BaseField>,
|
|
203
|
+
record: Record,
|
|
204
|
+
onlyView = false,
|
|
205
|
+
includeCurrentFormInField = true): FormGroup {
|
|
206
|
+
const formForm: FormGroup = this.formBuilder.group([]);
|
|
207
|
+
formFields.forEach(field => {
|
|
208
|
+
formForm.addControl(field.Name, this.createFieldFormControl(field, record));
|
|
209
|
+
if (includeCurrentFormInField) {
|
|
210
|
+
field.FormFormGroup = formForm;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
if (onlyView) {
|
|
214
|
+
formForm.disable();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return formForm;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Funzione per creare e aggiungere al FormGroup rappresentante la form un nuovo FormControl a partire da un Field.
|
|
222
|
+
* In nuovo FormControl avrà il nome del campo passato e verranno impostati i Validators in base al tipo del campo stesso.
|
|
223
|
+
* @param field BaseField per cui creare il FormControl da inserire nel FormGroup dela form.
|
|
224
|
+
*/
|
|
225
|
+
private createFieldFormControl(field: BaseField, record: Record): AbstractControl {
|
|
226
|
+
const validators: Array<ValidatorFn> = [];
|
|
227
|
+
|
|
228
|
+
if (field.Required)
|
|
229
|
+
validators.push(Validators.required);
|
|
230
|
+
|
|
231
|
+
switch (field.FieldType) {
|
|
232
|
+
case FieldTypeEnum["Campo di testo"]:
|
|
233
|
+
if ((field as TextField).MaxLenght) { validators.push(Validators.maxLength((field as TextField).MaxLenght)); }
|
|
234
|
+
if ((field as TextField).MinLenght) { validators.push(Validators.minLength((field as TextField).MinLenght)); }
|
|
235
|
+
switch ((field as TextField).TextMask) {
|
|
236
|
+
case TextMaskEnum.Url:
|
|
237
|
+
validators.push(Validators.pattern(UrlRegex));
|
|
238
|
+
break;
|
|
239
|
+
case TextMaskEnum.Email:
|
|
240
|
+
validators.push(Validators.email);
|
|
241
|
+
break;
|
|
242
|
+
case TextMaskEnum.Telefono:
|
|
243
|
+
validators.push(Validators.pattern(TelRegex));
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case FieldTypeEnum["Area di testo"]:
|
|
248
|
+
if ((field as TextareaField).MaxLenght) { validators.push(Validators.maxLength((field as TextareaField).MaxLenght)); }
|
|
249
|
+
if ((field as TextareaField).MinLenght) { validators.push(Validators.minLength((field as TextareaField).MinLenght)); }
|
|
250
|
+
break;
|
|
251
|
+
case FieldTypeEnum.Allegato:
|
|
252
|
+
case FieldTypeEnum.Immagine:
|
|
253
|
+
if (field.Required)
|
|
254
|
+
validators.push(ArrayValidators.minLenght(1));
|
|
255
|
+
break;
|
|
256
|
+
case FieldTypeEnum['Elenco generico']:
|
|
257
|
+
if ((field as ListValueField).IsMultiChoiche)
|
|
258
|
+
if (field.Required)
|
|
259
|
+
validators.push(ArrayValidators.minLenght(1));
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return new FormControl(record[field.Name], validators);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Metodo per configurare gli endpoint da usare di default a partire dall'url base del server
|
|
268
|
+
* a cui si deve connettere e al token da passare per autenticarsi.
|
|
269
|
+
* @param baseServerUrl Stringa dell'url base del server (es: "http://localhost:5000").
|
|
270
|
+
* @param userToken Token dell'utente loggato da usare per autenticarsi se necessario.
|
|
271
|
+
* @returns Resituisce la configurazione completa degli endPoint da usare di default.
|
|
272
|
+
*/
|
|
273
|
+
public ConfigureDefaultEndPoints(baseServerUrl: string, userToken: string): EndPointConfiguration {
|
|
274
|
+
let endPointConfiguration: EndPointConfiguration = new EndPointConfiguration();
|
|
275
|
+
endPointConfiguration = new EndPointConfiguration();
|
|
276
|
+
endPointConfiguration.Records = {
|
|
277
|
+
GetByFormIDEndPoint: {
|
|
278
|
+
Url: baseServerUrl + "/api/v1/getall",
|
|
279
|
+
Token: userToken,
|
|
280
|
+
RequestMethod: RequestMethodEnum.GET,
|
|
281
|
+
},
|
|
282
|
+
GetByIDEndPoint: {
|
|
283
|
+
Url: baseServerUrl + "/api/v1/getByID",
|
|
284
|
+
Token: userToken,
|
|
285
|
+
RequestMethod: RequestMethodEnum.GET,
|
|
286
|
+
},
|
|
287
|
+
SaveEndPoint: {
|
|
288
|
+
Url: baseServerUrl + "/api/v1/save",
|
|
289
|
+
Token: userToken,
|
|
290
|
+
RequestMethod: RequestMethodEnum.POST,
|
|
291
|
+
},
|
|
292
|
+
DuplicateEndPoint: {
|
|
293
|
+
Url: baseServerUrl + "/api/v1/duplicate",
|
|
294
|
+
Token: userToken,
|
|
295
|
+
RequestMethod: RequestMethodEnum.POST,
|
|
296
|
+
},
|
|
297
|
+
DeleteEndPoint: {
|
|
298
|
+
Url: baseServerUrl + "/api/v1/delete",
|
|
299
|
+
Token: userToken,
|
|
300
|
+
RequestMethod: RequestMethodEnum.DELETE,
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
endPointConfiguration.Forms = {
|
|
304
|
+
GetByIDEndPoint: {
|
|
305
|
+
Url: baseServerUrl + "/api/conf/form",
|
|
306
|
+
Token: userToken,
|
|
307
|
+
RequestMethod: RequestMethodEnum.GET,
|
|
308
|
+
},
|
|
309
|
+
SaveEndPoint: {
|
|
310
|
+
Url: baseServerUrl + "/api/conf/form",
|
|
311
|
+
Token: userToken,
|
|
312
|
+
RequestMethod: RequestMethodEnum.POST,
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return endPointConfiguration;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Metodo che data la configurazione di un endpoint costruisce l'url da chiamare, gli eventuali parametri
|
|
320
|
+
* da passare (nel body o nella rotta) ed effettua la chiamata. Al termine della chiamata esegue le eventuali
|
|
321
|
+
* funzioni di callback (sia in caso di successo che in caso di errore) passate in input.
|
|
322
|
+
* @param endPointData Cofigurazione dell'endpoint da chiamare.
|
|
323
|
+
* @param dynamicModuleParams Array dei parametri aggiunti dal modulo dinamico a quelli già configurati
|
|
324
|
+
* (ad esempio il record o la form da salvare oppure l'ID per recuperare una particolare entità).
|
|
325
|
+
* @param callback Metodo da eseguire in caso di successo dopo la chiamata http.
|
|
326
|
+
* NOTA: in input viene passata la risposta della chiamata stessa.
|
|
327
|
+
* @param errorCallBack Metodo da eseguire in caso di errore dopo la chiamata http.
|
|
328
|
+
* NOTA: in input viene passato l'errore generato della chiamata stessa.
|
|
329
|
+
*/
|
|
330
|
+
public RunEndPointCall(
|
|
331
|
+
endPointData: EndPointData,
|
|
332
|
+
dynamicModuleParams: Array<EndPointDataParams> = null,
|
|
333
|
+
callback: (e: Form | Record | Array<Record> ) => void = null,
|
|
334
|
+
errorCallBack: (err: unknown) => void = null
|
|
335
|
+
): void {
|
|
336
|
+
this.spinnerService.addRequestCounter();
|
|
337
|
+
|
|
338
|
+
let url = `${endPointData.Url}`;
|
|
339
|
+
let queryParams: string = null;
|
|
340
|
+
const bodyParams = {
|
|
341
|
+
AdditionalParams: {}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// Se nella configurazione sono stati definiti parametri da aggiungere alla chiamata questi vengono ciclati
|
|
345
|
+
// e aggiunti nel punto in cui devono essere usati.
|
|
346
|
+
if (endPointData.Params) {
|
|
347
|
+
endPointData.Params.forEach(p => {
|
|
348
|
+
switch (p.ParamType) {
|
|
349
|
+
case ParamTypeEnum['Query param']: {
|
|
350
|
+
const stringParam: string = p.ParamName + "=" + p.ParamValue;
|
|
351
|
+
queryParams = (queryParams == null ? "" : queryParams + "&") + stringParam;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case ParamTypeEnum['In route']: {
|
|
355
|
+
url = url + (url.endsWith("/") ? "" : "/") + p.ParamValue;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case ParamTypeEnum['In Body']: {
|
|
359
|
+
bodyParams.AdditionalParams[p.ParamName] = p.ParamValue;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Se sono stati passati parametri da aggiungere alla chiamata definiti all'interno del modulo dinamico
|
|
367
|
+
// vengono ciclati e aggiunti nel punto in cui devono essere usati dopo quelli definiti nella configurazione.
|
|
368
|
+
if (dynamicModuleParams) {
|
|
369
|
+
dynamicModuleParams.forEach(p => {
|
|
370
|
+
switch (p.ParamType) {
|
|
371
|
+
case ParamTypeEnum['Query param']: {
|
|
372
|
+
const stringParam: string = p.ParamName + "=" + p.ParamValue;
|
|
373
|
+
queryParams = (queryParams == null ? "" : queryParams + "&") + stringParam;
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case ParamTypeEnum['In route']: {
|
|
377
|
+
url = url + (url.endsWith("/") ? "" : "/") + p.ParamValue;
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case ParamTypeEnum['In Body']: {
|
|
381
|
+
bodyParams[p.ParamName] = p.ParamValue;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (queryParams != null) {
|
|
389
|
+
url = (url.endsWith("/") ? url.substring(0, url.length - 1) : url) + "?" + queryParams;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
this.http.request(endPointData.RequestMethod, url, {
|
|
393
|
+
headers: endPointData.Token ? { Authorization: endPointData.Token } : null,
|
|
394
|
+
body: ![RequestMethodEnum.DELETE, RequestMethodEnum.GET].includes(endPointData.RequestMethod) ? bodyParams : null
|
|
395
|
+
})
|
|
396
|
+
.subscribe(
|
|
397
|
+
(res: Form | Record | Array<Record> ) => {
|
|
398
|
+
this.spinnerService.removeRequestCounter();
|
|
399
|
+
if (callback) {
|
|
400
|
+
callback(res);
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
(error) => {
|
|
404
|
+
this.spinnerService.removeRequestCounter();
|
|
405
|
+
if (errorCallBack) {
|
|
406
|
+
errorCallBack(error);
|
|
407
|
+
}
|
|
408
|
+
EqpDynamicModuleDialogService.Error(error.message);
|
|
409
|
+
throw new Error(error.message);
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Public API Surface of eqp-dynamic-module
|
|
3
|
+
*/
|
|
1
4
|
export * from './lib/eqp-dynamic-module.module';
|
|
2
5
|
export * from './lib/components/exported/eqp-dynamic-module/eqp-dynamic-module.component';
|
|
3
6
|
export * from './lib/components/exported/eqp-dynamic-module-configurator/eqp-dynamic-module-configurator.component';
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js/dist/zone';
|
|
4
|
+
import 'zone.js/dist/zone-testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
declare const require: {
|
|
12
|
+
context(path: string, deep?: boolean, filter?: RegExp): {
|
|
13
|
+
keys(): string[];
|
|
14
|
+
<T>(id: string): T;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// First, initialize the Angular testing environment.
|
|
19
|
+
getTestBed().initTestEnvironment(
|
|
20
|
+
BrowserDynamicTestingModule,
|
|
21
|
+
platformBrowserDynamicTesting()
|
|
22
|
+
);
|
|
23
|
+
// Then we find all the tests.
|
|
24
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
25
|
+
// And load the modules.
|
|
26
|
+
context.keys().map(context);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../out-tsc/lib",
|
|
5
|
+
"target": "es2015",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"inlineSources": true,
|
|
8
|
+
"types": [],
|
|
9
|
+
"lib": [
|
|
10
|
+
"dom",
|
|
11
|
+
"es2018"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"angularCompilerOptions": {
|
|
15
|
+
"skipTemplateCodegen": true,
|
|
16
|
+
"strictMetadataEmit": true,
|
|
17
|
+
"enableResourceInlining": true
|
|
18
|
+
},
|
|
19
|
+
"exclude": [
|
|
20
|
+
"src/test.ts",
|
|
21
|
+
"**/*.spec.ts"
|
|
22
|
+
]
|
|
23
|
+
}
|