@senior-agronegocio/angular-components 0.0.51 → 0.0.55
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/senior-agronegocio-angular-components.umd.js +469 -499
- package/bundles/senior-agronegocio-angular-components.umd.js.map +1 -1
- package/bundles/senior-agronegocio-angular-components.umd.min.js +2 -2
- package/bundles/senior-agronegocio-angular-components.umd.min.js.map +1 -1
- package/common/agro-platform-utils.class.d.ts +1 -1
- package/common/agro-string-utils.class.d.ts +7 -0
- package/esm2015/common/agro-platform-utils.class.js +2 -3
- package/esm2015/common/agro-string-utils.class.js +32 -58
- package/esm2015/form-validator/agro-form-validator.js +28 -30
- package/esm5/common/agro-platform-utils.class.js +2 -3
- package/esm5/common/agro-string-utils.class.js +32 -58
- package/esm5/form-validator/agro-form-validator.js +28 -31
- package/fesm2015/senior-agronegocio-angular-components.js +455 -484
- package/fesm2015/senior-agronegocio-angular-components.js.map +1 -1
- package/fesm5/senior-agronegocio-angular-components.js +469 -499
- package/fesm5/senior-agronegocio-angular-components.js.map +1 -1
- package/form-validator/agro-form-validator.d.ts +12 -15
- package/package.json +1 -1
|
@@ -34,149 +34,6 @@ var DateComparisonType;
|
|
|
34
34
|
DateComparisonType["lessThan"] = "lessThan";
|
|
35
35
|
})(DateComparisonType || (DateComparisonType = {}));
|
|
36
36
|
|
|
37
|
-
var AGRO_REGEX = {
|
|
38
|
-
/**
|
|
39
|
-
* Validação de E-mail
|
|
40
|
-
*/
|
|
41
|
-
isEmail: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
42
|
-
/**
|
|
43
|
-
* Validação de Números Inteiros Positivos
|
|
44
|
-
*/
|
|
45
|
-
positiveInteger: /^[1-9]\d*$/,
|
|
46
|
-
/**
|
|
47
|
-
* Validação de Números Decimais Positivos
|
|
48
|
-
*/
|
|
49
|
-
positiveDecimal: /^\d*\.?\d+$/,
|
|
50
|
-
/**
|
|
51
|
-
* Validação de string que consiste apenas em espaços em branco ou está vazia.
|
|
52
|
-
*/
|
|
53
|
-
onlyBlankSpaces: /^\s*$/,
|
|
54
|
-
/**
|
|
55
|
-
* Validação de CEP (Código Postal)
|
|
56
|
-
*/
|
|
57
|
-
zipCode: /^\d{8}$|^\d{5}-\d{3}$/,
|
|
58
|
-
/**
|
|
59
|
-
* Validação de String (qualquer caractere)
|
|
60
|
-
*/
|
|
61
|
-
isString: /^[\s\S]*$/,
|
|
62
|
-
/**
|
|
63
|
-
* Validação de UUID
|
|
64
|
-
*/
|
|
65
|
-
isUUID: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/,
|
|
66
|
-
/**
|
|
67
|
-
* Validação de Número
|
|
68
|
-
*/
|
|
69
|
-
isNumber: /^-?\d+$/,
|
|
70
|
-
/**
|
|
71
|
-
* Validação de Número Decimal
|
|
72
|
-
*/
|
|
73
|
-
isDecimal: /^\d*\.?\d+$/,
|
|
74
|
-
/**
|
|
75
|
-
* Validação de Placa de Veículo
|
|
76
|
-
*/
|
|
77
|
-
isLicensePlate: /^[A-Za-z0-9]{1,7}-?[A-Za-z0-9]{1,7}$/,
|
|
78
|
-
/**
|
|
79
|
-
* Validação de Número de Telefone
|
|
80
|
-
*/
|
|
81
|
-
isPhoneNumber: /^\+?\d{1,4}-?\d{6,11}$/,
|
|
82
|
-
/**
|
|
83
|
-
* Validação de Data (Formato YYYY-MM-DD)
|
|
84
|
-
*/
|
|
85
|
-
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
86
|
-
/**
|
|
87
|
-
* Validação de Hora (Formato HH:mm)
|
|
88
|
-
*/
|
|
89
|
-
isTime: /^(0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
90
|
-
/**
|
|
91
|
-
* Validação de Data e Hora (Formato YYYY-MM-DD HH:mm)
|
|
92
|
-
*/
|
|
93
|
-
isDateTime: /^\d{4}-\d{2}-\d{2} (0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
94
|
-
/**
|
|
95
|
-
* Validação de URL
|
|
96
|
-
*/
|
|
97
|
-
isURL: /^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/,
|
|
98
|
-
/**
|
|
99
|
-
* Validação de Número Hexadecimal
|
|
100
|
-
*/
|
|
101
|
-
isHexNumber: /^[0-9a-fA-F]+$/,
|
|
102
|
-
/**
|
|
103
|
-
* Validação de Base64
|
|
104
|
-
*/
|
|
105
|
-
isBase64: /^[a-zA-Z0-9+/]+={0,2}$/,
|
|
106
|
-
/**
|
|
107
|
-
* Validação de Nome de Usuário (3 a 20 caracteres alfanuméricos)
|
|
108
|
-
*/
|
|
109
|
-
isUsername: /^\w{3,20}$/,
|
|
110
|
-
/**
|
|
111
|
-
* Validação de Alfanumérico
|
|
112
|
-
*/
|
|
113
|
-
isAlphanumeric: /^[a-zA-Z0-9]+$/,
|
|
114
|
-
/**
|
|
115
|
-
* Validação de Slug (letras minúsculas, números e traços)
|
|
116
|
-
*/
|
|
117
|
-
isSlug: /^[a-z0-9-]+$/,
|
|
118
|
-
/**
|
|
119
|
-
* Validação de Número de Cartão de Crédito
|
|
120
|
-
*/
|
|
121
|
-
isCreditCard: /^\d{4}-\d{4}-\d{4}-\d{4}$/,
|
|
122
|
-
/**
|
|
123
|
-
* Validação de Número Hexadecimal
|
|
124
|
-
*/
|
|
125
|
-
isHexadecimal: /^[0-9a-fA-F]+$/,
|
|
126
|
-
/**
|
|
127
|
-
* Validação de Moeda
|
|
128
|
-
*/
|
|
129
|
-
isCurrency: /^\d+(\.\d{1,2})?$/,
|
|
130
|
-
/**
|
|
131
|
-
* Validação de Porcentagem
|
|
132
|
-
*/
|
|
133
|
-
isPercentage: /^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)$/,
|
|
134
|
-
/**
|
|
135
|
-
* Validação de Tag HTML Simples
|
|
136
|
-
*/
|
|
137
|
-
isHTMLTag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/,
|
|
138
|
-
/**
|
|
139
|
-
* Validação de Nome de Usuário com Espaços (3 a 20 caracteres alfanuméricos e espaços)
|
|
140
|
-
*/
|
|
141
|
-
isUsernameWithSpaces: /^[a-zA-Z0-9_ ]{3,20}$/,
|
|
142
|
-
/**
|
|
143
|
-
* Validação de Senha Forte (mínimo 8 caracteres, uma letra minúscula, uma letra maiúscula, um número e um caractere especial)
|
|
144
|
-
*/
|
|
145
|
-
isStrongPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
|
146
|
-
/**
|
|
147
|
-
* Validação de String Alfabética
|
|
148
|
-
*/
|
|
149
|
-
isAlphabetic: /^[a-zA-Z]+$/,
|
|
150
|
-
/**
|
|
151
|
-
* Validação de Hora no Formato de 12 Horas
|
|
152
|
-
*/
|
|
153
|
-
isTime12Hour: /^(0?[1-9]|1[0-2]):\d{2} (AM|PM)$/i,
|
|
154
|
-
/**
|
|
155
|
-
* Validação de Latitude
|
|
156
|
-
*/
|
|
157
|
-
isLatitude: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
|
|
158
|
-
/**
|
|
159
|
-
* Validação de Longitude
|
|
160
|
-
*/
|
|
161
|
-
isLongitude: /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
|
|
162
|
-
/**
|
|
163
|
-
* Validação de Endereço MAC
|
|
164
|
-
*/
|
|
165
|
-
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
166
|
-
/**
|
|
167
|
-
* Validação de Data de Expiração de Cartão de Crédito
|
|
168
|
-
*/
|
|
169
|
-
isCreditCardExpiration: /^(0[1-9]|1[0-2])\/\d{2}$/,
|
|
170
|
-
/**
|
|
171
|
-
* Validação de Número de Seguro Social (SSN)
|
|
172
|
-
*/
|
|
173
|
-
isSSN: /^\d{3}-\d{2}-\d{4}$/,
|
|
174
|
-
/**
|
|
175
|
-
* Validação se todos os dígitos são iguais
|
|
176
|
-
*/
|
|
177
|
-
isAllDigitsEqual: /^(.)\1+$/,
|
|
178
|
-
};
|
|
179
|
-
|
|
180
37
|
var NumberComparisonType;
|
|
181
38
|
(function (NumberComparisonType) {
|
|
182
39
|
NumberComparisonType["EQUALS"] = "EQUALS";
|
|
@@ -1525,298 +1382,64 @@ var AgroObjectUtils = /** @class */ (function () {
|
|
|
1525
1382
|
return AgroObjectUtils;
|
|
1526
1383
|
}());
|
|
1527
1384
|
|
|
1528
|
-
var
|
|
1529
|
-
function
|
|
1385
|
+
var AgroCookieUtils = /** @class */ (function () {
|
|
1386
|
+
function AgroCookieUtils() {
|
|
1387
|
+
}
|
|
1388
|
+
AgroCookieUtils.getCookie = function (name, parseURIValue) {
|
|
1389
|
+
if (parseURIValue === void 0) { parseURIValue = false; }
|
|
1390
|
+
var cookieValue = document.cookie.split(';')
|
|
1391
|
+
.map(function (cookie) { return cookie.trim(); })
|
|
1392
|
+
.find(function (cookie) { return cookie.startsWith(name); });
|
|
1393
|
+
var result = cookieValue === null || cookieValue === void 0 ? void 0 : cookieValue.split('=')[1];
|
|
1394
|
+
if (parseURIValue && result) {
|
|
1395
|
+
result = decodeURIComponent(result);
|
|
1396
|
+
}
|
|
1397
|
+
return result;
|
|
1398
|
+
};
|
|
1399
|
+
AgroCookieUtils.parseCookieToObject = function (cookieString, parseURIString) {
|
|
1400
|
+
if (parseURIString === void 0) { parseURIString = false; }
|
|
1401
|
+
var cookieObject = {};
|
|
1402
|
+
if (parseURIString) {
|
|
1403
|
+
cookieString = decodeURIComponent(cookieString);
|
|
1404
|
+
}
|
|
1405
|
+
cookieString.split(';').forEach(function (cookie) {
|
|
1406
|
+
var _a = __read(cookie.split('=').map(function (c) { return c.trim(); }), 2), key = _a[0], value = _a[1];
|
|
1407
|
+
cookieObject[key] = value;
|
|
1408
|
+
});
|
|
1409
|
+
return cookieObject;
|
|
1410
|
+
};
|
|
1411
|
+
AgroCookieUtils.prototype.setCookie = function (name, value, days) {
|
|
1412
|
+
var date = new Date();
|
|
1413
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
1414
|
+
var expires = 'expires=' + date.toUTCString();
|
|
1415
|
+
document.cookie = name + '=' + value + ';' + expires + ';path=/';
|
|
1416
|
+
};
|
|
1417
|
+
return AgroCookieUtils;
|
|
1418
|
+
}());
|
|
1419
|
+
|
|
1420
|
+
var AgroDateUtils = /** @class */ (function () {
|
|
1421
|
+
function AgroDateUtils() {
|
|
1530
1422
|
}
|
|
1531
1423
|
/**
|
|
1532
|
-
*
|
|
1533
|
-
*
|
|
1534
|
-
* @
|
|
1535
|
-
* this.myForm = this.fb.group({
|
|
1536
|
-
* EMAIL_FIELD: ['', [Validators.required, AgroFormValidator.emailValidator]]
|
|
1537
|
-
* });
|
|
1538
|
-
* @param control
|
|
1539
|
-
* @returns
|
|
1424
|
+
* Verifica se uma data é nula ou indefinida.
|
|
1425
|
+
* @param date - A data a ser verificada.
|
|
1426
|
+
* @returns True se a data for nula ou indefinida, false caso contrário.
|
|
1540
1427
|
*/
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
control.setErrors({ emailValidator: true });
|
|
1544
|
-
return { emailValidator: true };
|
|
1545
|
-
}
|
|
1546
|
-
control.setErrors(null);
|
|
1547
|
-
return null;
|
|
1428
|
+
AgroDateUtils.isNullOrUndefined = function (date) {
|
|
1429
|
+
return date === null || date === undefined;
|
|
1548
1430
|
};
|
|
1549
1431
|
/**
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1553
|
-
* A validação será através do enum DateComparisonType.
|
|
1554
|
-
*
|
|
1555
|
-
* @example
|
|
1556
|
-
* this.myForm = this.fb.group({
|
|
1557
|
-
* NOME_CAMPO: ['', [Validators.required, AgroFormValidator.compareDateWithToday(DateComparisonType.greatherThan)]]
|
|
1558
|
-
* });
|
|
1559
|
-
* @param comparisonType
|
|
1560
|
-
* @returns
|
|
1432
|
+
* Verifica se uma data não é nula e não é indefinida.
|
|
1433
|
+
* @param date - A data a ser verificada.
|
|
1434
|
+
* @returns True se a data não for nula e não for indefinida, false caso contrário.
|
|
1561
1435
|
*/
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
var _a, _b;
|
|
1565
|
-
var methodName = 'dateComparisonToday';
|
|
1566
|
-
var selectedDate = new Date(control.value);
|
|
1567
|
-
var currentDate = new Date();
|
|
1568
|
-
var conditions = (_a = {},
|
|
1569
|
-
_a[DateComparisonType.greatherThan] = selectedDate <= currentDate,
|
|
1570
|
-
_a[DateComparisonType.lessThan] = selectedDate >= currentDate,
|
|
1571
|
-
_a);
|
|
1572
|
-
if (conditions[comparisonType]) {
|
|
1573
|
-
return _b = {}, _b[methodName] = { value: control.value }, _b;
|
|
1574
|
-
}
|
|
1575
|
-
return null;
|
|
1576
|
-
};
|
|
1577
|
-
return compareDate;
|
|
1436
|
+
AgroDateUtils.isNotNullOrUndefined = function (date) {
|
|
1437
|
+
return !AgroDateUtils.isNullOrUndefined(date);
|
|
1578
1438
|
};
|
|
1579
1439
|
/**
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
* Aplique esse campo no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
1584
|
-
* @example
|
|
1585
|
-
* this.myForm = this.fb.group({
|
|
1586
|
-
NOME_CAMPO_dateA: ['', Validators.required],
|
|
1587
|
-
NOME_CAMPO_dateB: ['', Validators.required]
|
|
1588
|
-
}, { validator: AgroFormValidator.dateComparisonValidator('NOME_CAMPO_dateA', 'NOME_CAMPO_dateB') });
|
|
1589
|
-
* @param controlNameA
|
|
1590
|
-
* @param controlNameB
|
|
1591
|
-
* @returns
|
|
1592
|
-
*/
|
|
1593
|
-
AgroFormValidator.compareDateWithOtherDateField = function (controlNameA, controlNameB) {
|
|
1594
|
-
var compareDate = function (control) {
|
|
1595
|
-
var _a, _b;
|
|
1596
|
-
var _c, _d, _e, _f, _g;
|
|
1597
|
-
var formGroup = control;
|
|
1598
|
-
var dateA = (_c = formGroup.get(controlNameA)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1599
|
-
var dateB = (_d = formGroup.get(controlNameB)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1600
|
-
var methodName = 'compareDateWithOtherDateField';
|
|
1601
|
-
if (dateA && dateB) {
|
|
1602
|
-
var dateAObj = new Date(dateA);
|
|
1603
|
-
var dateBObj = new Date(dateB);
|
|
1604
|
-
if (dateAObj < dateBObj) {
|
|
1605
|
-
(_e = formGroup.get(controlNameA)) === null || _e === void 0 ? void 0 : _e.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1606
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1607
|
-
}
|
|
1608
|
-
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1609
|
-
(_g = formGroup.get(controlNameA)) === null || _g === void 0 ? void 0 : _g.setErrors(null);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
return null;
|
|
1613
|
-
};
|
|
1614
|
-
return compareDate;
|
|
1615
|
-
};
|
|
1616
|
-
/**
|
|
1617
|
-
* Validator para checar se o campo é um número de telefone de acordo com uma máscara informada.
|
|
1618
|
-
*
|
|
1619
|
-
* @example
|
|
1620
|
-
* this.myForm = this.fb.group({
|
|
1621
|
-
* TELEFONE_FIELD: ['', [Validators.required, AgroFormValidator.phoneValidator('(99) 9999-9999')]]
|
|
1622
|
-
* });
|
|
1623
|
-
* @param mask
|
|
1624
|
-
* @returns
|
|
1625
|
-
*/
|
|
1626
|
-
AgroFormValidator.phoneValidator = function (mask) {
|
|
1627
|
-
var phoneControlValidation = function (control) {
|
|
1628
|
-
var _a, _b;
|
|
1629
|
-
var methodName = 'phoneValidator';
|
|
1630
|
-
var regex = new RegExp("^" + mask.replace(/9/g, '\\d').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/-/g, '\\-') + "$");
|
|
1631
|
-
if (control.value && !regex.test(control.value)) {
|
|
1632
|
-
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1633
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1634
|
-
}
|
|
1635
|
-
control.setErrors(null);
|
|
1636
|
-
return null;
|
|
1637
|
-
};
|
|
1638
|
-
return phoneControlValidation;
|
|
1639
|
-
};
|
|
1640
|
-
/**
|
|
1641
|
-
* Validator para checar se um campo de números é maior ou menor que outro campo.
|
|
1642
|
-
*
|
|
1643
|
-
* Aplique esse validator no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
1644
|
-
* @example
|
|
1645
|
-
* this.myForm = this.fb.group({
|
|
1646
|
-
* NUMERO_A: ['', Validators.required],
|
|
1647
|
-
* NUMERO_B: ['', Validators.required]
|
|
1648
|
-
* }, { validator: AgroFormValidator.compareNumberFields('NUMERO_A', 'NUMERO_B', NumberComparisonType.EQUALS) });
|
|
1649
|
-
*
|
|
1650
|
-
* Neste caso, a verificação será se o NUMERO_A é igual ao NUMERB_B.
|
|
1651
|
-
* @param controlNameA
|
|
1652
|
-
* @param controlNameB
|
|
1653
|
-
* @returns
|
|
1654
|
-
*/
|
|
1655
|
-
AgroFormValidator.compareNumberFields = function (controlNameA, controlNameB, comparisonMethod) {
|
|
1656
|
-
var compareNumber = function (control) {
|
|
1657
|
-
var _a, _b, _c;
|
|
1658
|
-
var _d, _e, _f;
|
|
1659
|
-
var formGroup = control;
|
|
1660
|
-
var numberA = (_d = formGroup.get(controlNameA)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1661
|
-
var numberB = (_e = formGroup.get(controlNameB)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1662
|
-
var methodName = 'compareNumberFields';
|
|
1663
|
-
if (numberA && numberB) {
|
|
1664
|
-
var errorType = NumberComparisonType[comparisonMethod];
|
|
1665
|
-
var errorCondition = (_a = {},
|
|
1666
|
-
_a[NumberComparisonType.EQUALS] = numberA !== numberB,
|
|
1667
|
-
_a[NumberComparisonType.GREATER_THAN] = numberA <= numberB,
|
|
1668
|
-
_a[NumberComparisonType.LESS_THAN] = numberA >= numberB,
|
|
1669
|
-
_a[NumberComparisonType.GREATER_THAN_OR_EQUAL] = numberA < numberB,
|
|
1670
|
-
_a[NumberComparisonType.LESS_THAN_OR_EQUAL] = numberA > numberB,
|
|
1671
|
-
_a[NumberComparisonType.NOT_EQUALS] = numberA === numberB,
|
|
1672
|
-
_a);
|
|
1673
|
-
if (errorCondition[comparisonMethod]) {
|
|
1674
|
-
var controlA = formGroup.get(controlNameA);
|
|
1675
|
-
if (controlA) {
|
|
1676
|
-
controlA.setErrors((_b = {}, _b[methodName] = comparisonMethod, _b));
|
|
1677
|
-
}
|
|
1678
|
-
return _c = {}, _c[methodName] = errorType, _c;
|
|
1679
|
-
}
|
|
1680
|
-
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1681
|
-
var controlA = formGroup.get(controlNameA);
|
|
1682
|
-
if (controlA) {
|
|
1683
|
-
controlA.setErrors(null);
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
return null;
|
|
1688
|
-
};
|
|
1689
|
-
return compareNumber;
|
|
1690
|
-
};
|
|
1691
|
-
/**
|
|
1692
|
-
* Validator para checar se um valor está entre os demais valores de três formControls.
|
|
1693
|
-
*
|
|
1694
|
-
* Aplique esse validator no FormGroup, passando os nomes dos três formControls que deseja comparar.
|
|
1695
|
-
* @example
|
|
1696
|
-
* this.myForm = this.fb.group({
|
|
1697
|
-
* minorFormControl: ['', Validators.required],
|
|
1698
|
-
* targetFormControl: ['', Validators.required],
|
|
1699
|
-
* majorFormControl: ['', Validators.required]
|
|
1700
|
-
* }, { validator: AgroFormValidator.checkValueBetween('minorFormControl', 'targetFormControl', 'majorFormControl') });
|
|
1701
|
-
*
|
|
1702
|
-
* Neste caso, a verificação será se o targetFormControl está entre o minorFormControl e o majorFormControl.
|
|
1703
|
-
* @param minorFormControl
|
|
1704
|
-
* @param targetFormControl
|
|
1705
|
-
* @param majorFormControl
|
|
1706
|
-
* @returns
|
|
1707
|
-
*/
|
|
1708
|
-
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
1709
|
-
var checkValue = function (control) {
|
|
1710
|
-
var _a, _b;
|
|
1711
|
-
var _c, _d, _e, _f;
|
|
1712
|
-
var formGroup = control;
|
|
1713
|
-
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1714
|
-
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1715
|
-
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1716
|
-
var methodName = 'checkValueBetween';
|
|
1717
|
-
if (valueA && valueB && valueC) {
|
|
1718
|
-
if (valueB < valueA || valueB > valueC) {
|
|
1719
|
-
var targetControl = formGroup.get(targetFormControl);
|
|
1720
|
-
if (targetControl) {
|
|
1721
|
-
targetControl.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1722
|
-
}
|
|
1723
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1724
|
-
}
|
|
1725
|
-
else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1726
|
-
var targetControl = formGroup.get(targetFormControl);
|
|
1727
|
-
if (targetControl) {
|
|
1728
|
-
targetControl.setErrors(null);
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
return null;
|
|
1733
|
-
};
|
|
1734
|
-
return checkValue;
|
|
1735
|
-
};
|
|
1736
|
-
/**
|
|
1737
|
-
* Validator para checar se o campo é um objeto e se possui uma propriedade específica.
|
|
1738
|
-
*
|
|
1739
|
-
* @example
|
|
1740
|
-
* this.myForm = this.fb.group({
|
|
1741
|
-
* OBJETO_FIELD: ['', [Validators.required, AgroFormValidator.objectPropertyValidator('propriedade')]]
|
|
1742
|
-
* });
|
|
1743
|
-
* @param propertyName
|
|
1744
|
-
* @returns
|
|
1745
|
-
*/
|
|
1746
|
-
AgroFormValidator.objectPropertyValidator = function (propertyName) {
|
|
1747
|
-
var objectProperty = function (control) {
|
|
1748
|
-
var _a, _b;
|
|
1749
|
-
var methodName = 'objectProperty';
|
|
1750
|
-
if (AgroObjectUtils.isObject(control.value) && AgroObjectUtils.containsProperty(control.value, propertyName)) {
|
|
1751
|
-
control.setErrors(null);
|
|
1752
|
-
return null;
|
|
1753
|
-
}
|
|
1754
|
-
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1755
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1756
|
-
};
|
|
1757
|
-
return objectProperty;
|
|
1758
|
-
};
|
|
1759
|
-
return AgroFormValidator;
|
|
1760
|
-
}());
|
|
1761
|
-
|
|
1762
|
-
var AgroCookieUtils = /** @class */ (function () {
|
|
1763
|
-
function AgroCookieUtils() {
|
|
1764
|
-
}
|
|
1765
|
-
AgroCookieUtils.getCookie = function (name, parseURIValue) {
|
|
1766
|
-
if (parseURIValue === void 0) { parseURIValue = false; }
|
|
1767
|
-
var cookieValue = document.cookie.split(';')
|
|
1768
|
-
.map(function (cookie) { return cookie.trim(); })
|
|
1769
|
-
.find(function (cookie) { return cookie.startsWith(name); });
|
|
1770
|
-
var result = cookieValue === null || cookieValue === void 0 ? void 0 : cookieValue.split('=')[1];
|
|
1771
|
-
if (parseURIValue && result) {
|
|
1772
|
-
result = decodeURIComponent(result);
|
|
1773
|
-
}
|
|
1774
|
-
return result;
|
|
1775
|
-
};
|
|
1776
|
-
AgroCookieUtils.parseCookieToObject = function (cookieString, parseURIString) {
|
|
1777
|
-
if (parseURIString === void 0) { parseURIString = false; }
|
|
1778
|
-
var cookieObject = {};
|
|
1779
|
-
if (parseURIString) {
|
|
1780
|
-
cookieString = decodeURIComponent(cookieString);
|
|
1781
|
-
}
|
|
1782
|
-
cookieString.split(';').forEach(function (cookie) {
|
|
1783
|
-
var _a = __read(cookie.split('=').map(function (c) { return c.trim(); }), 2), key = _a[0], value = _a[1];
|
|
1784
|
-
cookieObject[key] = value;
|
|
1785
|
-
});
|
|
1786
|
-
return cookieObject;
|
|
1787
|
-
};
|
|
1788
|
-
AgroCookieUtils.prototype.setCookie = function (name, value, days) {
|
|
1789
|
-
var date = new Date();
|
|
1790
|
-
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
1791
|
-
var expires = 'expires=' + date.toUTCString();
|
|
1792
|
-
document.cookie = name + '=' + value + ';' + expires + ';path=/';
|
|
1793
|
-
};
|
|
1794
|
-
return AgroCookieUtils;
|
|
1795
|
-
}());
|
|
1796
|
-
|
|
1797
|
-
var AgroDateUtils = /** @class */ (function () {
|
|
1798
|
-
function AgroDateUtils() {
|
|
1799
|
-
}
|
|
1800
|
-
/**
|
|
1801
|
-
* Verifica se uma data é nula ou indefinida.
|
|
1802
|
-
* @param date - A data a ser verificada.
|
|
1803
|
-
* @returns True se a data for nula ou indefinida, false caso contrário.
|
|
1804
|
-
*/
|
|
1805
|
-
AgroDateUtils.isNullOrUndefined = function (date) {
|
|
1806
|
-
return date === null || date === undefined;
|
|
1807
|
-
};
|
|
1808
|
-
/**
|
|
1809
|
-
* Verifica se uma data não é nula e não é indefinida.
|
|
1810
|
-
* @param date - A data a ser verificada.
|
|
1811
|
-
* @returns True se a data não for nula e não for indefinida, false caso contrário.
|
|
1812
|
-
*/
|
|
1813
|
-
AgroDateUtils.isNotNullOrUndefined = function (date) {
|
|
1814
|
-
return !AgroDateUtils.isNullOrUndefined(date);
|
|
1815
|
-
};
|
|
1816
|
-
/**
|
|
1817
|
-
* Verifica se uma data é válida.
|
|
1818
|
-
* @param date - A data a ser verificada.
|
|
1819
|
-
* @returns True se a data for válida, false caso contrário.
|
|
1440
|
+
* Verifica se uma data é válida.
|
|
1441
|
+
* @param date - A data a ser verificada.
|
|
1442
|
+
* @returns True se a data for válida, false caso contrário.
|
|
1820
1443
|
*/
|
|
1821
1444
|
AgroDateUtils.isValid = function (date) {
|
|
1822
1445
|
return !isNaN(Date.parse(date));
|
|
@@ -1898,21 +1521,164 @@ var AgroDateUtils = /** @class */ (function () {
|
|
|
1898
1521
|
* @param format
|
|
1899
1522
|
* @returns
|
|
1900
1523
|
*/
|
|
1901
|
-
AgroDateUtils.formatDate = function (date, format) {
|
|
1902
|
-
if (format === void 0) { format = 'DD/MM/YYYY'; }
|
|
1903
|
-
var moment$1 = moment;
|
|
1904
|
-
return moment$1(date).utc().format(format);
|
|
1905
|
-
};
|
|
1524
|
+
AgroDateUtils.formatDate = function (date, format) {
|
|
1525
|
+
if (format === void 0) { format = 'DD/MM/YYYY'; }
|
|
1526
|
+
var moment$1 = moment;
|
|
1527
|
+
return moment$1(date).utc().format(format);
|
|
1528
|
+
};
|
|
1529
|
+
/**
|
|
1530
|
+
* Retorna uma string com o número informado adicionando um 0 à esquerda, caso o número seja menor que 10.
|
|
1531
|
+
* @param value
|
|
1532
|
+
* @returns
|
|
1533
|
+
*/
|
|
1534
|
+
AgroDateUtils.padZero = function (value) {
|
|
1535
|
+
return value < AGRO_NUMBERS.TEN ? '0' + value : value.toString();
|
|
1536
|
+
};
|
|
1537
|
+
return AgroDateUtils;
|
|
1538
|
+
}());
|
|
1539
|
+
|
|
1540
|
+
var AGRO_REGEX = {
|
|
1541
|
+
/**
|
|
1542
|
+
* Validação de E-mail
|
|
1543
|
+
*/
|
|
1544
|
+
isEmail: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
1545
|
+
/**
|
|
1546
|
+
* Validação de Números Inteiros Positivos
|
|
1547
|
+
*/
|
|
1548
|
+
positiveInteger: /^[1-9]\d*$/,
|
|
1549
|
+
/**
|
|
1550
|
+
* Validação de Números Decimais Positivos
|
|
1551
|
+
*/
|
|
1552
|
+
positiveDecimal: /^\d*\.?\d+$/,
|
|
1553
|
+
/**
|
|
1554
|
+
* Validação de string que consiste apenas em espaços em branco ou está vazia.
|
|
1555
|
+
*/
|
|
1556
|
+
onlyBlankSpaces: /^\s*$/,
|
|
1557
|
+
/**
|
|
1558
|
+
* Validação de CEP (Código Postal)
|
|
1559
|
+
*/
|
|
1560
|
+
zipCode: /^\d{8}$|^\d{5}-\d{3}$/,
|
|
1561
|
+
/**
|
|
1562
|
+
* Validação de String (qualquer caractere)
|
|
1563
|
+
*/
|
|
1564
|
+
isString: /^[\s\S]*$/,
|
|
1565
|
+
/**
|
|
1566
|
+
* Validação de UUID
|
|
1567
|
+
*/
|
|
1568
|
+
isUUID: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/,
|
|
1569
|
+
/**
|
|
1570
|
+
* Validação de Número
|
|
1571
|
+
*/
|
|
1572
|
+
isNumber: /^-?\d+$/,
|
|
1573
|
+
/**
|
|
1574
|
+
* Validação de Número Decimal
|
|
1575
|
+
*/
|
|
1576
|
+
isDecimal: /^\d*\.?\d+$/,
|
|
1577
|
+
/**
|
|
1578
|
+
* Validação de Placa de Veículo
|
|
1579
|
+
*/
|
|
1580
|
+
isLicensePlate: /^[A-Za-z0-9]{1,7}-?[A-Za-z0-9]{1,7}$/,
|
|
1581
|
+
/**
|
|
1582
|
+
* Validação de Número de Telefone
|
|
1583
|
+
*/
|
|
1584
|
+
isPhoneNumber: /^\+?\d{1,4}-?\d{6,11}$/,
|
|
1585
|
+
/**
|
|
1586
|
+
* Validação de Data (Formato YYYY-MM-DD)
|
|
1587
|
+
*/
|
|
1588
|
+
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
1589
|
+
/**
|
|
1590
|
+
* Validação de Hora (Formato HH:mm)
|
|
1591
|
+
*/
|
|
1592
|
+
isTime: /^(0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
1593
|
+
/**
|
|
1594
|
+
* Validação de Data e Hora (Formato YYYY-MM-DD HH:mm)
|
|
1595
|
+
*/
|
|
1596
|
+
isDateTime: /^\d{4}-\d{2}-\d{2} (0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
1597
|
+
/**
|
|
1598
|
+
* Validação de URL
|
|
1599
|
+
*/
|
|
1600
|
+
isURL: /^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/,
|
|
1601
|
+
/**
|
|
1602
|
+
* Validação de Número Hexadecimal
|
|
1603
|
+
*/
|
|
1604
|
+
isHexNumber: /^[0-9a-fA-F]+$/,
|
|
1605
|
+
/**
|
|
1606
|
+
* Validação de Base64
|
|
1607
|
+
*/
|
|
1608
|
+
isBase64: /^[a-zA-Z0-9+/]+={0,2}$/,
|
|
1609
|
+
/**
|
|
1610
|
+
* Validação de Nome de Usuário (3 a 20 caracteres alfanuméricos)
|
|
1611
|
+
*/
|
|
1612
|
+
isUsername: /^\w{3,20}$/,
|
|
1613
|
+
/**
|
|
1614
|
+
* Validação de Alfanumérico
|
|
1615
|
+
*/
|
|
1616
|
+
isAlphanumeric: /^[a-zA-Z0-9]+$/,
|
|
1617
|
+
/**
|
|
1618
|
+
* Validação de Slug (letras minúsculas, números e traços)
|
|
1619
|
+
*/
|
|
1620
|
+
isSlug: /^[a-z0-9-]+$/,
|
|
1621
|
+
/**
|
|
1622
|
+
* Validação de Número de Cartão de Crédito
|
|
1623
|
+
*/
|
|
1624
|
+
isCreditCard: /^\d{4}-\d{4}-\d{4}-\d{4}$/,
|
|
1625
|
+
/**
|
|
1626
|
+
* Validação de Número Hexadecimal
|
|
1627
|
+
*/
|
|
1628
|
+
isHexadecimal: /^[0-9a-fA-F]+$/,
|
|
1629
|
+
/**
|
|
1630
|
+
* Validação de Moeda
|
|
1631
|
+
*/
|
|
1632
|
+
isCurrency: /^\d+(\.\d{1,2})?$/,
|
|
1633
|
+
/**
|
|
1634
|
+
* Validação de Porcentagem
|
|
1635
|
+
*/
|
|
1636
|
+
isPercentage: /^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)$/,
|
|
1637
|
+
/**
|
|
1638
|
+
* Validação de Tag HTML Simples
|
|
1639
|
+
*/
|
|
1640
|
+
isHTMLTag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/,
|
|
1641
|
+
/**
|
|
1642
|
+
* Validação de Nome de Usuário com Espaços (3 a 20 caracteres alfanuméricos e espaços)
|
|
1643
|
+
*/
|
|
1644
|
+
isUsernameWithSpaces: /^[a-zA-Z0-9_ ]{3,20}$/,
|
|
1645
|
+
/**
|
|
1646
|
+
* Validação de Senha Forte (mínimo 8 caracteres, uma letra minúscula, uma letra maiúscula, um número e um caractere especial)
|
|
1647
|
+
*/
|
|
1648
|
+
isStrongPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
|
1649
|
+
/**
|
|
1650
|
+
* Validação de String Alfabética
|
|
1651
|
+
*/
|
|
1652
|
+
isAlphabetic: /^[a-zA-Z]+$/,
|
|
1653
|
+
/**
|
|
1654
|
+
* Validação de Hora no Formato de 12 Horas
|
|
1655
|
+
*/
|
|
1656
|
+
isTime12Hour: /^(0?[1-9]|1[0-2]):\d{2} (AM|PM)$/i,
|
|
1657
|
+
/**
|
|
1658
|
+
* Validação de Latitude
|
|
1659
|
+
*/
|
|
1660
|
+
isLatitude: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
|
|
1661
|
+
/**
|
|
1662
|
+
* Validação de Longitude
|
|
1663
|
+
*/
|
|
1664
|
+
isLongitude: /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
|
|
1665
|
+
/**
|
|
1666
|
+
* Validação de Endereço MAC
|
|
1667
|
+
*/
|
|
1668
|
+
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
1669
|
+
/**
|
|
1670
|
+
* Validação de Data de Expiração de Cartão de Crédito
|
|
1671
|
+
*/
|
|
1672
|
+
isCreditCardExpiration: /^(0[1-9]|1[0-2])\/\d{2}$/,
|
|
1673
|
+
/**
|
|
1674
|
+
* Validação de Número de Seguro Social (SSN)
|
|
1675
|
+
*/
|
|
1676
|
+
isSSN: /^\d{3}-\d{2}-\d{4}$/,
|
|
1906
1677
|
/**
|
|
1907
|
-
*
|
|
1908
|
-
* @param value
|
|
1909
|
-
* @returns
|
|
1678
|
+
* Validação se todos os dígitos são iguais
|
|
1910
1679
|
*/
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
};
|
|
1914
|
-
return AgroDateUtils;
|
|
1915
|
-
}());
|
|
1680
|
+
isAllDigitsEqual: /^(.)\1+$/,
|
|
1681
|
+
};
|
|
1916
1682
|
|
|
1917
1683
|
/**
|
|
1918
1684
|
* Classe utilitária para operações de string.
|
|
@@ -2166,70 +1932,35 @@ var AgroStringUtils = /** @class */ (function () {
|
|
|
2166
1932
|
return matches ? matches.length : AGRO_NUMBERS.ZERO;
|
|
2167
1933
|
};
|
|
2168
1934
|
AgroStringUtils.validateCPF = function (cpf) {
|
|
2169
|
-
// Remover caracteres não numéricos
|
|
2170
1935
|
cpf = cpf.replace(/\D/g, "");
|
|
2171
|
-
|
|
2172
|
-
if (cpf.length !== AGRO_NUMBERS.ELEVEN) {
|
|
2173
|
-
return false;
|
|
2174
|
-
}
|
|
2175
|
-
// Verificar se todos os dígitos são iguais (caso contrário, é um sinal de CPF inválido)
|
|
2176
|
-
if (/^(\d)\1{10}$/.test(cpf)) {
|
|
2177
|
-
return false;
|
|
2178
|
-
}
|
|
2179
|
-
// Calcular o primeiro dígito verificador
|
|
2180
|
-
var sum = AGRO_NUMBERS.ZERO;
|
|
2181
|
-
var remainder;
|
|
2182
|
-
for (var i = AGRO_NUMBERS.ONE; i <= AGRO_NUMBERS.NINE; i++) {
|
|
2183
|
-
sum += parseInt(cpf[i - AGRO_NUMBERS.ONE]) * (AGRO_NUMBERS.ELEVEN - i);
|
|
2184
|
-
}
|
|
2185
|
-
remainder = sum % AGRO_NUMBERS.ELEVEN;
|
|
2186
|
-
if (remainder === AGRO_NUMBERS.TEN || remainder === AGRO_NUMBERS.ELEVEN) {
|
|
2187
|
-
remainder = AGRO_NUMBERS.ZERO;
|
|
2188
|
-
}
|
|
2189
|
-
if (remainder !== parseInt(cpf[AGRO_NUMBERS.NINE])) {
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
|
-
// Calcular o segundo dígito verificador
|
|
2193
|
-
sum = AGRO_NUMBERS.ZERO;
|
|
2194
|
-
for (var i = AGRO_NUMBERS.ONE; i <= AGRO_NUMBERS.TEN; i++) {
|
|
2195
|
-
sum += parseInt(cpf[i - AGRO_NUMBERS.ONE]) * (AGRO_NUMBERS.TWELVE - i);
|
|
2196
|
-
}
|
|
2197
|
-
remainder = sum % AGRO_NUMBERS.ELEVEN;
|
|
2198
|
-
if (remainder === AGRO_NUMBERS.TEN || remainder === AGRO_NUMBERS.ELEVEN) {
|
|
2199
|
-
remainder = AGRO_NUMBERS.ZERO;
|
|
2200
|
-
}
|
|
2201
|
-
if (remainder !== parseInt(cpf[AGRO_NUMBERS.TEN])) {
|
|
1936
|
+
if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) {
|
|
2202
1937
|
return false;
|
|
2203
1938
|
}
|
|
2204
|
-
|
|
1939
|
+
var calcCheckDigit = function (length) {
|
|
1940
|
+
var sum = 0;
|
|
1941
|
+
for (var i = 0; i < length; i++) {
|
|
1942
|
+
sum += Number(cpf[i]) * (length + 1 - i);
|
|
1943
|
+
}
|
|
1944
|
+
var remainder = sum % 11;
|
|
1945
|
+
return remainder < 2 ? 0 : 11 - remainder;
|
|
1946
|
+
};
|
|
1947
|
+
return (calcCheckDigit(9) === Number(cpf[9]) &&
|
|
1948
|
+
calcCheckDigit(10) === Number(cpf[10]));
|
|
2205
1949
|
};
|
|
2206
1950
|
AgroStringUtils.validateCNPJ = function (cnpj) {
|
|
2207
|
-
// Remove todos os caracteres não numéricos
|
|
2208
1951
|
cnpj = cnpj.replace(/\D/g, "");
|
|
2209
|
-
|
|
2210
|
-
if (cnpj.length !== 14)
|
|
1952
|
+
if (cnpj.length !== 14 || /^(\d)\1{13}$/.test(cnpj))
|
|
2211
1953
|
return false;
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
var digito1 = resto < 2 ? 0 : 11 - resto;
|
|
2223
|
-
// Cálculo do segundo dígito verificador
|
|
2224
|
-
soma = 0;
|
|
2225
|
-
var pesos2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
2226
|
-
for (var i = 0; i < 13; i++) {
|
|
2227
|
-
soma += parseInt(cnpj.charAt(i)) * pesos2[i];
|
|
2228
|
-
}
|
|
2229
|
-
resto = soma % 11;
|
|
2230
|
-
var digito2 = resto < 2 ? 0 : 11 - resto;
|
|
2231
|
-
// Verifica se os dígitos verificadores são válidos
|
|
2232
|
-
return parseInt(cnpj.charAt(12)) === digito1 && parseInt(cnpj.charAt(13)) === digito2;
|
|
1954
|
+
var calcularDigito = function (length) {
|
|
1955
|
+
var pesos = length === 12
|
|
1956
|
+
? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
1957
|
+
: [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
1958
|
+
var soma = pesos.reduce(function (acc, peso, i) { return acc + Number(cnpj[i]) * peso; }, 0);
|
|
1959
|
+
var resto = soma % 11;
|
|
1960
|
+
return resto < 2 ? 0 : 11 - resto;
|
|
1961
|
+
};
|
|
1962
|
+
return (calcularDigito(12) === Number(cnpj[12]) &&
|
|
1963
|
+
calcularDigito(13) === Number(cnpj[13]));
|
|
2233
1964
|
};
|
|
2234
1965
|
/**
|
|
2235
1966
|
* Método para aplicar uma máscara em uma string. Considere a máscara com valores 9 para aplicação
|
|
@@ -2289,6 +2020,15 @@ var AgroStringUtils = /** @class */ (function () {
|
|
|
2289
2020
|
AgroStringUtils.isInvalid = function (str) {
|
|
2290
2021
|
return !AgroStringUtils.isValid(str);
|
|
2291
2022
|
};
|
|
2023
|
+
/**
|
|
2024
|
+
* Valida se uma string é um e-mail válido ou não
|
|
2025
|
+
* Retorna um booleano para indicar se é um e-mail válido ou não
|
|
2026
|
+
* @param email - A string a ser verificada
|
|
2027
|
+
* @returns True se a string for um e-mail válido, false caso contrário
|
|
2028
|
+
*/
|
|
2029
|
+
AgroStringUtils.isValidEmail = function (email) {
|
|
2030
|
+
return AGRO_REGEX.isEmail.test(email);
|
|
2031
|
+
};
|
|
2292
2032
|
return AgroStringUtils;
|
|
2293
2033
|
}());
|
|
2294
2034
|
|
|
@@ -2330,7 +2070,7 @@ var AgroPlatformUtils = /** @class */ (function () {
|
|
|
2330
2070
|
/**
|
|
2331
2071
|
* Retorna o usuário logado
|
|
2332
2072
|
* Caso contrário, retorna uma instância de Error
|
|
2333
|
-
* @returns string ||
|
|
2073
|
+
* @returns string || null
|
|
2334
2074
|
*/
|
|
2335
2075
|
AgroPlatformUtils.getCurrentUserName = function () {
|
|
2336
2076
|
var _a;
|
|
@@ -2341,7 +2081,6 @@ var AgroPlatformUtils = /** @class */ (function () {
|
|
|
2341
2081
|
return str;
|
|
2342
2082
|
}
|
|
2343
2083
|
}
|
|
2344
|
-
console.error('Cookie: "com.senior.token" não encontrado.');
|
|
2345
2084
|
return null;
|
|
2346
2085
|
};
|
|
2347
2086
|
/**
|
|
@@ -2723,6 +2462,237 @@ var AgroArrayUtils = /** @class */ (function () {
|
|
|
2723
2462
|
return AgroArrayUtils;
|
|
2724
2463
|
}());
|
|
2725
2464
|
|
|
2465
|
+
var AgroFormValidator = /** @class */ (function () {
|
|
2466
|
+
function AgroFormValidator() {
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Validator para checar se o campo é um e-mail
|
|
2470
|
+
*
|
|
2471
|
+
* @example
|
|
2472
|
+
* this.myForm = this.fb.group({
|
|
2473
|
+
* EMAIL_FIELD: ['', [Validators.required, AgroFormValidator.emailValidator]]
|
|
2474
|
+
* });
|
|
2475
|
+
* @param control
|
|
2476
|
+
* @returns
|
|
2477
|
+
*/
|
|
2478
|
+
AgroFormValidator.emailValidator = function (control) {
|
|
2479
|
+
var email = control.value;
|
|
2480
|
+
if (!email) {
|
|
2481
|
+
return null;
|
|
2482
|
+
}
|
|
2483
|
+
return AgroStringUtils.isValidEmail(email) ? null : { emailValidator: true };
|
|
2484
|
+
};
|
|
2485
|
+
/**
|
|
2486
|
+
* Aplique esse validador em um campo do tipo Date, para verificar se a data selecionada é maior ou menor que a data atual.
|
|
2487
|
+
*
|
|
2488
|
+
* Utilize o parâmetro comparisonType para definir se a data selecionada deve ser maior ou menor que a data atual.
|
|
2489
|
+
* A validação será através do enum DateComparisonType.
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* this.myForm = this.fb.group({
|
|
2493
|
+
* NOME_CAMPO: ['', [Validators.required, AgroFormValidator.compareDateWithToday(DateComparisonType.greatherThan)]]
|
|
2494
|
+
* });
|
|
2495
|
+
* @param comparisonType
|
|
2496
|
+
* @returns
|
|
2497
|
+
*/
|
|
2498
|
+
AgroFormValidator.compareDateWithToday = function (comparisonType) {
|
|
2499
|
+
var compareDate = function (control) {
|
|
2500
|
+
var _a, _b;
|
|
2501
|
+
var methodName = 'dateComparisonToday';
|
|
2502
|
+
var selectedDate = new Date(control.value);
|
|
2503
|
+
var currentDate = new Date();
|
|
2504
|
+
var conditions = (_a = {},
|
|
2505
|
+
_a[DateComparisonType.greatherThan] = selectedDate <= currentDate,
|
|
2506
|
+
_a[DateComparisonType.lessThan] = selectedDate >= currentDate,
|
|
2507
|
+
_a);
|
|
2508
|
+
if (conditions[comparisonType]) {
|
|
2509
|
+
return _b = {}, _b[methodName] = { value: control.value }, _b;
|
|
2510
|
+
}
|
|
2511
|
+
return null;
|
|
2512
|
+
};
|
|
2513
|
+
return compareDate;
|
|
2514
|
+
};
|
|
2515
|
+
/**
|
|
2516
|
+
* Compara dois campos do tipo Date, verificando se o campo A é maior que o campo B. Se A for maior que B, então
|
|
2517
|
+
* o campo A é invalidado. Caso contrário, o campo A é validado.
|
|
2518
|
+
*
|
|
2519
|
+
* Aplique esse campo no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2520
|
+
* @example
|
|
2521
|
+
* this.myForm = this.fb.group({
|
|
2522
|
+
NOME_CAMPO_dateA: ['', Validators.required],
|
|
2523
|
+
NOME_CAMPO_dateB: ['', Validators.required]
|
|
2524
|
+
}, { validator: AgroFormValidator.dateComparisonValidator('NOME_CAMPO_dateA', 'NOME_CAMPO_dateB') });
|
|
2525
|
+
* @param controlNameA
|
|
2526
|
+
* @param controlNameB
|
|
2527
|
+
* @returns
|
|
2528
|
+
*/
|
|
2529
|
+
AgroFormValidator.compareDateWithOtherDateField = function (controlNameA, controlNameB) {
|
|
2530
|
+
var compareDate = function (control) {
|
|
2531
|
+
var _a, _b;
|
|
2532
|
+
var _c, _d, _e, _f, _g;
|
|
2533
|
+
var formGroup = control;
|
|
2534
|
+
var dateA = (_c = formGroup.get(controlNameA)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2535
|
+
var dateB = (_d = formGroup.get(controlNameB)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2536
|
+
var methodName = 'compareDateWithOtherDateField';
|
|
2537
|
+
if (dateA && dateB) {
|
|
2538
|
+
var dateAObj = new Date(dateA);
|
|
2539
|
+
var dateBObj = new Date(dateB);
|
|
2540
|
+
if (dateAObj < dateBObj) {
|
|
2541
|
+
(_e = formGroup.get(controlNameA)) === null || _e === void 0 ? void 0 : _e.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2542
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2543
|
+
}
|
|
2544
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2545
|
+
(_g = formGroup.get(controlNameA)) === null || _g === void 0 ? void 0 : _g.setErrors(null);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
return null;
|
|
2549
|
+
};
|
|
2550
|
+
return compareDate;
|
|
2551
|
+
};
|
|
2552
|
+
/**
|
|
2553
|
+
* Validator para checar se um campo de números é maior ou menor que outro campo.
|
|
2554
|
+
*
|
|
2555
|
+
* Aplique esse validator no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2556
|
+
* @example
|
|
2557
|
+
* this.myForm = this.fb.group({
|
|
2558
|
+
* NUMERO_A: ['', Validators.required],
|
|
2559
|
+
* NUMERO_B: ['', Validators.required]
|
|
2560
|
+
* }, { validator: AgroFormValidator.compareNumberFields('NUMERO_A', 'NUMERO_B', NumberComparisonType.EQUALS) });
|
|
2561
|
+
*
|
|
2562
|
+
* Neste caso, a verificação será se o NUMERO_A é igual ao NUMERB_B.
|
|
2563
|
+
* @param controlNameA
|
|
2564
|
+
* @param controlNameB
|
|
2565
|
+
* @returns
|
|
2566
|
+
*/
|
|
2567
|
+
AgroFormValidator.compareNumberFields = function (controlNameA, controlNameB, comparisonMethod) {
|
|
2568
|
+
var compareNumber = function (control) {
|
|
2569
|
+
var _a, _b, _c;
|
|
2570
|
+
var _d, _e, _f;
|
|
2571
|
+
var formGroup = control;
|
|
2572
|
+
var numberA = (_d = formGroup.get(controlNameA)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2573
|
+
var numberB = (_e = formGroup.get(controlNameB)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2574
|
+
var methodName = 'compareNumberFields';
|
|
2575
|
+
if (numberA && numberB) {
|
|
2576
|
+
var errorType = NumberComparisonType[comparisonMethod];
|
|
2577
|
+
var errorCondition = (_a = {},
|
|
2578
|
+
_a[NumberComparisonType.EQUALS] = numberA !== numberB,
|
|
2579
|
+
_a[NumberComparisonType.GREATER_THAN] = numberA <= numberB,
|
|
2580
|
+
_a[NumberComparisonType.LESS_THAN] = numberA >= numberB,
|
|
2581
|
+
_a[NumberComparisonType.GREATER_THAN_OR_EQUAL] = numberA < numberB,
|
|
2582
|
+
_a[NumberComparisonType.LESS_THAN_OR_EQUAL] = numberA > numberB,
|
|
2583
|
+
_a[NumberComparisonType.NOT_EQUALS] = numberA === numberB,
|
|
2584
|
+
_a);
|
|
2585
|
+
if (errorCondition[comparisonMethod]) {
|
|
2586
|
+
var controlA = formGroup.get(controlNameA);
|
|
2587
|
+
if (controlA) {
|
|
2588
|
+
controlA.setErrors((_b = {}, _b[methodName] = comparisonMethod, _b));
|
|
2589
|
+
}
|
|
2590
|
+
return _c = {}, _c[methodName] = errorType, _c;
|
|
2591
|
+
}
|
|
2592
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2593
|
+
var controlA = formGroup.get(controlNameA);
|
|
2594
|
+
if (controlA) {
|
|
2595
|
+
controlA.setErrors(null);
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
return null;
|
|
2600
|
+
};
|
|
2601
|
+
return compareNumber;
|
|
2602
|
+
};
|
|
2603
|
+
/**
|
|
2604
|
+
* Validator para checar se um valor está entre os demais valores de três formControls.
|
|
2605
|
+
*
|
|
2606
|
+
* Aplique esse validator no FormGroup, passando os nomes dos três formControls que deseja comparar.
|
|
2607
|
+
* @example
|
|
2608
|
+
* this.myForm = this.fb.group({
|
|
2609
|
+
* minorFormControl: ['', Validators.required],
|
|
2610
|
+
* targetFormControl: ['', Validators.required],
|
|
2611
|
+
* majorFormControl: ['', Validators.required]
|
|
2612
|
+
* }, { validator: AgroFormValidator.checkValueBetween('minorFormControl', 'targetFormControl', 'majorFormControl') });
|
|
2613
|
+
*
|
|
2614
|
+
* Neste caso, a verificação será se o targetFormControl está entre o minorFormControl e o majorFormControl.
|
|
2615
|
+
* @param minorFormControl
|
|
2616
|
+
* @param targetFormControl
|
|
2617
|
+
* @param majorFormControl
|
|
2618
|
+
* @returns
|
|
2619
|
+
*/
|
|
2620
|
+
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
2621
|
+
var checkValue = function (control) {
|
|
2622
|
+
var _a, _b;
|
|
2623
|
+
var _c, _d, _e, _f;
|
|
2624
|
+
var formGroup = control;
|
|
2625
|
+
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2626
|
+
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2627
|
+
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2628
|
+
var methodName = 'checkValueBetween';
|
|
2629
|
+
if (valueA && valueB && valueC) {
|
|
2630
|
+
if (valueB < valueA || valueB > valueC) {
|
|
2631
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2632
|
+
if (targetControl) {
|
|
2633
|
+
targetControl.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2634
|
+
}
|
|
2635
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2636
|
+
}
|
|
2637
|
+
else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2638
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2639
|
+
if (targetControl) {
|
|
2640
|
+
targetControl.setErrors(null);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
return null;
|
|
2645
|
+
};
|
|
2646
|
+
return checkValue;
|
|
2647
|
+
};
|
|
2648
|
+
/**
|
|
2649
|
+
* Validator para checar se o campo é um objeto e se possui uma propriedade específica.
|
|
2650
|
+
*
|
|
2651
|
+
* @example
|
|
2652
|
+
* this.myForm = this.fb.group({
|
|
2653
|
+
* OBJETO_FIELD: ['', [Validators.required, AgroFormValidator.objectPropertyValidator('propriedade')]]
|
|
2654
|
+
* });
|
|
2655
|
+
* @param propertyName
|
|
2656
|
+
* @returns
|
|
2657
|
+
*/
|
|
2658
|
+
AgroFormValidator.objectPropertyValidator = function (propertyName) {
|
|
2659
|
+
var objectProperty = function (control) {
|
|
2660
|
+
var _a, _b;
|
|
2661
|
+
var methodName = 'objectProperty';
|
|
2662
|
+
if (AgroObjectUtils.isObject(control.value) && AgroObjectUtils.containsProperty(control.value, propertyName)) {
|
|
2663
|
+
control.setErrors(null);
|
|
2664
|
+
return null;
|
|
2665
|
+
}
|
|
2666
|
+
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2667
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2668
|
+
};
|
|
2669
|
+
return objectProperty;
|
|
2670
|
+
};
|
|
2671
|
+
/**
|
|
2672
|
+
* Verifica se a string informada é um CPF válido.
|
|
2673
|
+
* Se a validação for false, retorna um objeto com a chave cpfValidator.
|
|
2674
|
+
*/
|
|
2675
|
+
AgroFormValidator.CPFValidator = function (control) {
|
|
2676
|
+
var cpf = control.value;
|
|
2677
|
+
if (!cpf) {
|
|
2678
|
+
return null;
|
|
2679
|
+
}
|
|
2680
|
+
return AgroStringUtils.validateCPF(cpf) ? null : { cpfValidator: true };
|
|
2681
|
+
};
|
|
2682
|
+
/**
|
|
2683
|
+
* Verifica se a string informada é um CNPJ válido.
|
|
2684
|
+
* Se a validação for false, retorna um objeto com a chave cnpjValidator.
|
|
2685
|
+
*/
|
|
2686
|
+
AgroFormValidator.CNPJValidator = function (control) {
|
|
2687
|
+
var cnpj = control.value;
|
|
2688
|
+
if (!cnpj) {
|
|
2689
|
+
return null;
|
|
2690
|
+
}
|
|
2691
|
+
return AgroStringUtils.validateCNPJ(cnpj) ? null : { cnpjValidator: true };
|
|
2692
|
+
};
|
|
2693
|
+
return AgroFormValidator;
|
|
2694
|
+
}());
|
|
2695
|
+
|
|
2726
2696
|
var AsyncLock = /** @class */ (function () {
|
|
2727
2697
|
function AsyncLock() {
|
|
2728
2698
|
this.queue = [];
|