@senior-agronegocio/angular-components 0.0.52 → 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 +460 -454
- 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-string-utils.class.d.ts +7 -0
- package/esm2015/common/agro-string-utils.class.js +10 -1
- package/esm2015/form-validator/agro-form-validator.js +28 -30
- package/esm5/common/agro-string-utils.class.js +10 -1
- package/esm5/form-validator/agro-form-validator.js +28 -31
- package/fesm2015/senior-agronegocio-angular-components.js +446 -439
- package/fesm2015/senior-agronegocio-angular-components.js.map +1 -1
- package/fesm5/senior-agronegocio-angular-components.js +460 -454
- 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
|
@@ -210,149 +210,6 @@
|
|
|
210
210
|
DateComparisonType["lessThan"] = "lessThan";
|
|
211
211
|
})(exports.DateComparisonType || (exports.DateComparisonType = {}));
|
|
212
212
|
|
|
213
|
-
var AGRO_REGEX = {
|
|
214
|
-
/**
|
|
215
|
-
* Validação de E-mail
|
|
216
|
-
*/
|
|
217
|
-
isEmail: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
218
|
-
/**
|
|
219
|
-
* Validação de Números Inteiros Positivos
|
|
220
|
-
*/
|
|
221
|
-
positiveInteger: /^[1-9]\d*$/,
|
|
222
|
-
/**
|
|
223
|
-
* Validação de Números Decimais Positivos
|
|
224
|
-
*/
|
|
225
|
-
positiveDecimal: /^\d*\.?\d+$/,
|
|
226
|
-
/**
|
|
227
|
-
* Validação de string que consiste apenas em espaços em branco ou está vazia.
|
|
228
|
-
*/
|
|
229
|
-
onlyBlankSpaces: /^\s*$/,
|
|
230
|
-
/**
|
|
231
|
-
* Validação de CEP (Código Postal)
|
|
232
|
-
*/
|
|
233
|
-
zipCode: /^\d{8}$|^\d{5}-\d{3}$/,
|
|
234
|
-
/**
|
|
235
|
-
* Validação de String (qualquer caractere)
|
|
236
|
-
*/
|
|
237
|
-
isString: /^[\s\S]*$/,
|
|
238
|
-
/**
|
|
239
|
-
* Validação de UUID
|
|
240
|
-
*/
|
|
241
|
-
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}$/,
|
|
242
|
-
/**
|
|
243
|
-
* Validação de Número
|
|
244
|
-
*/
|
|
245
|
-
isNumber: /^-?\d+$/,
|
|
246
|
-
/**
|
|
247
|
-
* Validação de Número Decimal
|
|
248
|
-
*/
|
|
249
|
-
isDecimal: /^\d*\.?\d+$/,
|
|
250
|
-
/**
|
|
251
|
-
* Validação de Placa de Veículo
|
|
252
|
-
*/
|
|
253
|
-
isLicensePlate: /^[A-Za-z0-9]{1,7}-?[A-Za-z0-9]{1,7}$/,
|
|
254
|
-
/**
|
|
255
|
-
* Validação de Número de Telefone
|
|
256
|
-
*/
|
|
257
|
-
isPhoneNumber: /^\+?\d{1,4}-?\d{6,11}$/,
|
|
258
|
-
/**
|
|
259
|
-
* Validação de Data (Formato YYYY-MM-DD)
|
|
260
|
-
*/
|
|
261
|
-
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
262
|
-
/**
|
|
263
|
-
* Validação de Hora (Formato HH:mm)
|
|
264
|
-
*/
|
|
265
|
-
isTime: /^(0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
266
|
-
/**
|
|
267
|
-
* Validação de Data e Hora (Formato YYYY-MM-DD HH:mm)
|
|
268
|
-
*/
|
|
269
|
-
isDateTime: /^\d{4}-\d{2}-\d{2} (0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
270
|
-
/**
|
|
271
|
-
* Validação de URL
|
|
272
|
-
*/
|
|
273
|
-
isURL: /^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/,
|
|
274
|
-
/**
|
|
275
|
-
* Validação de Número Hexadecimal
|
|
276
|
-
*/
|
|
277
|
-
isHexNumber: /^[0-9a-fA-F]+$/,
|
|
278
|
-
/**
|
|
279
|
-
* Validação de Base64
|
|
280
|
-
*/
|
|
281
|
-
isBase64: /^[a-zA-Z0-9+/]+={0,2}$/,
|
|
282
|
-
/**
|
|
283
|
-
* Validação de Nome de Usuário (3 a 20 caracteres alfanuméricos)
|
|
284
|
-
*/
|
|
285
|
-
isUsername: /^\w{3,20}$/,
|
|
286
|
-
/**
|
|
287
|
-
* Validação de Alfanumérico
|
|
288
|
-
*/
|
|
289
|
-
isAlphanumeric: /^[a-zA-Z0-9]+$/,
|
|
290
|
-
/**
|
|
291
|
-
* Validação de Slug (letras minúsculas, números e traços)
|
|
292
|
-
*/
|
|
293
|
-
isSlug: /^[a-z0-9-]+$/,
|
|
294
|
-
/**
|
|
295
|
-
* Validação de Número de Cartão de Crédito
|
|
296
|
-
*/
|
|
297
|
-
isCreditCard: /^\d{4}-\d{4}-\d{4}-\d{4}$/,
|
|
298
|
-
/**
|
|
299
|
-
* Validação de Número Hexadecimal
|
|
300
|
-
*/
|
|
301
|
-
isHexadecimal: /^[0-9a-fA-F]+$/,
|
|
302
|
-
/**
|
|
303
|
-
* Validação de Moeda
|
|
304
|
-
*/
|
|
305
|
-
isCurrency: /^\d+(\.\d{1,2})?$/,
|
|
306
|
-
/**
|
|
307
|
-
* Validação de Porcentagem
|
|
308
|
-
*/
|
|
309
|
-
isPercentage: /^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)$/,
|
|
310
|
-
/**
|
|
311
|
-
* Validação de Tag HTML Simples
|
|
312
|
-
*/
|
|
313
|
-
isHTMLTag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/,
|
|
314
|
-
/**
|
|
315
|
-
* Validação de Nome de Usuário com Espaços (3 a 20 caracteres alfanuméricos e espaços)
|
|
316
|
-
*/
|
|
317
|
-
isUsernameWithSpaces: /^[a-zA-Z0-9_ ]{3,20}$/,
|
|
318
|
-
/**
|
|
319
|
-
* Validação de Senha Forte (mínimo 8 caracteres, uma letra minúscula, uma letra maiúscula, um número e um caractere especial)
|
|
320
|
-
*/
|
|
321
|
-
isStrongPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
|
322
|
-
/**
|
|
323
|
-
* Validação de String Alfabética
|
|
324
|
-
*/
|
|
325
|
-
isAlphabetic: /^[a-zA-Z]+$/,
|
|
326
|
-
/**
|
|
327
|
-
* Validação de Hora no Formato de 12 Horas
|
|
328
|
-
*/
|
|
329
|
-
isTime12Hour: /^(0?[1-9]|1[0-2]):\d{2} (AM|PM)$/i,
|
|
330
|
-
/**
|
|
331
|
-
* Validação de Latitude
|
|
332
|
-
*/
|
|
333
|
-
isLatitude: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
|
|
334
|
-
/**
|
|
335
|
-
* Validação de Longitude
|
|
336
|
-
*/
|
|
337
|
-
isLongitude: /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
|
|
338
|
-
/**
|
|
339
|
-
* Validação de Endereço MAC
|
|
340
|
-
*/
|
|
341
|
-
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
342
|
-
/**
|
|
343
|
-
* Validação de Data de Expiração de Cartão de Crédito
|
|
344
|
-
*/
|
|
345
|
-
isCreditCardExpiration: /^(0[1-9]|1[0-2])\/\d{2}$/,
|
|
346
|
-
/**
|
|
347
|
-
* Validação de Número de Seguro Social (SSN)
|
|
348
|
-
*/
|
|
349
|
-
isSSN: /^\d{3}-\d{2}-\d{4}$/,
|
|
350
|
-
/**
|
|
351
|
-
* Validação se todos os dígitos são iguais
|
|
352
|
-
*/
|
|
353
|
-
isAllDigitsEqual: /^(.)\1+$/,
|
|
354
|
-
};
|
|
355
|
-
|
|
356
213
|
|
|
357
214
|
(function (NumberComparisonType) {
|
|
358
215
|
NumberComparisonType["EQUALS"] = "EQUALS";
|
|
@@ -1701,298 +1558,64 @@
|
|
|
1701
1558
|
return AgroObjectUtils;
|
|
1702
1559
|
}());
|
|
1703
1560
|
|
|
1704
|
-
var
|
|
1705
|
-
function
|
|
1561
|
+
var AgroCookieUtils = /** @class */ (function () {
|
|
1562
|
+
function AgroCookieUtils() {
|
|
1563
|
+
}
|
|
1564
|
+
AgroCookieUtils.getCookie = function (name, parseURIValue) {
|
|
1565
|
+
if (parseURIValue === void 0) { parseURIValue = false; }
|
|
1566
|
+
var cookieValue = document.cookie.split(';')
|
|
1567
|
+
.map(function (cookie) { return cookie.trim(); })
|
|
1568
|
+
.find(function (cookie) { return cookie.startsWith(name); });
|
|
1569
|
+
var result = cookieValue === null || cookieValue === void 0 ? void 0 : cookieValue.split('=')[1];
|
|
1570
|
+
if (parseURIValue && result) {
|
|
1571
|
+
result = decodeURIComponent(result);
|
|
1572
|
+
}
|
|
1573
|
+
return result;
|
|
1574
|
+
};
|
|
1575
|
+
AgroCookieUtils.parseCookieToObject = function (cookieString, parseURIString) {
|
|
1576
|
+
if (parseURIString === void 0) { parseURIString = false; }
|
|
1577
|
+
var cookieObject = {};
|
|
1578
|
+
if (parseURIString) {
|
|
1579
|
+
cookieString = decodeURIComponent(cookieString);
|
|
1580
|
+
}
|
|
1581
|
+
cookieString.split(';').forEach(function (cookie) {
|
|
1582
|
+
var _a = __read(cookie.split('=').map(function (c) { return c.trim(); }), 2), key = _a[0], value = _a[1];
|
|
1583
|
+
cookieObject[key] = value;
|
|
1584
|
+
});
|
|
1585
|
+
return cookieObject;
|
|
1586
|
+
};
|
|
1587
|
+
AgroCookieUtils.prototype.setCookie = function (name, value, days) {
|
|
1588
|
+
var date = new Date();
|
|
1589
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
1590
|
+
var expires = 'expires=' + date.toUTCString();
|
|
1591
|
+
document.cookie = name + '=' + value + ';' + expires + ';path=/';
|
|
1592
|
+
};
|
|
1593
|
+
return AgroCookieUtils;
|
|
1594
|
+
}());
|
|
1595
|
+
|
|
1596
|
+
var AgroDateUtils = /** @class */ (function () {
|
|
1597
|
+
function AgroDateUtils() {
|
|
1706
1598
|
}
|
|
1707
1599
|
/**
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
* @
|
|
1711
|
-
* this.myForm = this.fb.group({
|
|
1712
|
-
* EMAIL_FIELD: ['', [Validators.required, AgroFormValidator.emailValidator]]
|
|
1713
|
-
* });
|
|
1714
|
-
* @param control
|
|
1715
|
-
* @returns
|
|
1600
|
+
* Verifica se uma data é nula ou indefinida.
|
|
1601
|
+
* @param date - A data a ser verificada.
|
|
1602
|
+
* @returns True se a data for nula ou indefinida, false caso contrário.
|
|
1716
1603
|
*/
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
control.setErrors({ emailValidator: true });
|
|
1720
|
-
return { emailValidator: true };
|
|
1721
|
-
}
|
|
1722
|
-
control.setErrors(null);
|
|
1723
|
-
return null;
|
|
1604
|
+
AgroDateUtils.isNullOrUndefined = function (date) {
|
|
1605
|
+
return date === null || date === undefined;
|
|
1724
1606
|
};
|
|
1725
1607
|
/**
|
|
1726
|
-
*
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1729
|
-
* A validação será através do enum DateComparisonType.
|
|
1730
|
-
*
|
|
1731
|
-
* @example
|
|
1732
|
-
* this.myForm = this.fb.group({
|
|
1733
|
-
* NOME_CAMPO: ['', [Validators.required, AgroFormValidator.compareDateWithToday(DateComparisonType.greatherThan)]]
|
|
1734
|
-
* });
|
|
1735
|
-
* @param comparisonType
|
|
1736
|
-
* @returns
|
|
1608
|
+
* Verifica se uma data não é nula e não é indefinida.
|
|
1609
|
+
* @param date - A data a ser verificada.
|
|
1610
|
+
* @returns True se a data não for nula e não for indefinida, false caso contrário.
|
|
1737
1611
|
*/
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
var _a, _b;
|
|
1741
|
-
var methodName = 'dateComparisonToday';
|
|
1742
|
-
var selectedDate = new Date(control.value);
|
|
1743
|
-
var currentDate = new Date();
|
|
1744
|
-
var conditions = (_a = {},
|
|
1745
|
-
_a[exports.DateComparisonType.greatherThan] = selectedDate <= currentDate,
|
|
1746
|
-
_a[exports.DateComparisonType.lessThan] = selectedDate >= currentDate,
|
|
1747
|
-
_a);
|
|
1748
|
-
if (conditions[comparisonType]) {
|
|
1749
|
-
return _b = {}, _b[methodName] = { value: control.value }, _b;
|
|
1750
|
-
}
|
|
1751
|
-
return null;
|
|
1752
|
-
};
|
|
1753
|
-
return compareDate;
|
|
1612
|
+
AgroDateUtils.isNotNullOrUndefined = function (date) {
|
|
1613
|
+
return !AgroDateUtils.isNullOrUndefined(date);
|
|
1754
1614
|
};
|
|
1755
1615
|
/**
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1759
|
-
* Aplique esse campo no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
1760
|
-
* @example
|
|
1761
|
-
* this.myForm = this.fb.group({
|
|
1762
|
-
NOME_CAMPO_dateA: ['', Validators.required],
|
|
1763
|
-
NOME_CAMPO_dateB: ['', Validators.required]
|
|
1764
|
-
}, { validator: AgroFormValidator.dateComparisonValidator('NOME_CAMPO_dateA', 'NOME_CAMPO_dateB') });
|
|
1765
|
-
* @param controlNameA
|
|
1766
|
-
* @param controlNameB
|
|
1767
|
-
* @returns
|
|
1768
|
-
*/
|
|
1769
|
-
AgroFormValidator.compareDateWithOtherDateField = function (controlNameA, controlNameB) {
|
|
1770
|
-
var compareDate = function (control) {
|
|
1771
|
-
var _a, _b;
|
|
1772
|
-
var _c, _d, _e, _f, _g;
|
|
1773
|
-
var formGroup = control;
|
|
1774
|
-
var dateA = (_c = formGroup.get(controlNameA)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1775
|
-
var dateB = (_d = formGroup.get(controlNameB)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1776
|
-
var methodName = 'compareDateWithOtherDateField';
|
|
1777
|
-
if (dateA && dateB) {
|
|
1778
|
-
var dateAObj = new Date(dateA);
|
|
1779
|
-
var dateBObj = new Date(dateB);
|
|
1780
|
-
if (dateAObj < dateBObj) {
|
|
1781
|
-
(_e = formGroup.get(controlNameA)) === null || _e === void 0 ? void 0 : _e.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1782
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1783
|
-
}
|
|
1784
|
-
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1785
|
-
(_g = formGroup.get(controlNameA)) === null || _g === void 0 ? void 0 : _g.setErrors(null);
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
return null;
|
|
1789
|
-
};
|
|
1790
|
-
return compareDate;
|
|
1791
|
-
};
|
|
1792
|
-
/**
|
|
1793
|
-
* Validator para checar se o campo é um número de telefone de acordo com uma máscara informada.
|
|
1794
|
-
*
|
|
1795
|
-
* @example
|
|
1796
|
-
* this.myForm = this.fb.group({
|
|
1797
|
-
* TELEFONE_FIELD: ['', [Validators.required, AgroFormValidator.phoneValidator('(99) 9999-9999')]]
|
|
1798
|
-
* });
|
|
1799
|
-
* @param mask
|
|
1800
|
-
* @returns
|
|
1801
|
-
*/
|
|
1802
|
-
AgroFormValidator.phoneValidator = function (mask) {
|
|
1803
|
-
var phoneControlValidation = function (control) {
|
|
1804
|
-
var _a, _b;
|
|
1805
|
-
var methodName = 'phoneValidator';
|
|
1806
|
-
var regex = new RegExp("^" + mask.replace(/9/g, '\\d').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/-/g, '\\-') + "$");
|
|
1807
|
-
if (control.value && !regex.test(control.value)) {
|
|
1808
|
-
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1809
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1810
|
-
}
|
|
1811
|
-
control.setErrors(null);
|
|
1812
|
-
return null;
|
|
1813
|
-
};
|
|
1814
|
-
return phoneControlValidation;
|
|
1815
|
-
};
|
|
1816
|
-
/**
|
|
1817
|
-
* Validator para checar se um campo de números é maior ou menor que outro campo.
|
|
1818
|
-
*
|
|
1819
|
-
* Aplique esse validator no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
1820
|
-
* @example
|
|
1821
|
-
* this.myForm = this.fb.group({
|
|
1822
|
-
* NUMERO_A: ['', Validators.required],
|
|
1823
|
-
* NUMERO_B: ['', Validators.required]
|
|
1824
|
-
* }, { validator: AgroFormValidator.compareNumberFields('NUMERO_A', 'NUMERO_B', NumberComparisonType.EQUALS) });
|
|
1825
|
-
*
|
|
1826
|
-
* Neste caso, a verificação será se o NUMERO_A é igual ao NUMERB_B.
|
|
1827
|
-
* @param controlNameA
|
|
1828
|
-
* @param controlNameB
|
|
1829
|
-
* @returns
|
|
1830
|
-
*/
|
|
1831
|
-
AgroFormValidator.compareNumberFields = function (controlNameA, controlNameB, comparisonMethod) {
|
|
1832
|
-
var compareNumber = function (control) {
|
|
1833
|
-
var _a, _b, _c;
|
|
1834
|
-
var _d, _e, _f;
|
|
1835
|
-
var formGroup = control;
|
|
1836
|
-
var numberA = (_d = formGroup.get(controlNameA)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1837
|
-
var numberB = (_e = formGroup.get(controlNameB)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1838
|
-
var methodName = 'compareNumberFields';
|
|
1839
|
-
if (numberA && numberB) {
|
|
1840
|
-
var errorType = exports.NumberComparisonType[comparisonMethod];
|
|
1841
|
-
var errorCondition = (_a = {},
|
|
1842
|
-
_a[exports.NumberComparisonType.EQUALS] = numberA !== numberB,
|
|
1843
|
-
_a[exports.NumberComparisonType.GREATER_THAN] = numberA <= numberB,
|
|
1844
|
-
_a[exports.NumberComparisonType.LESS_THAN] = numberA >= numberB,
|
|
1845
|
-
_a[exports.NumberComparisonType.GREATER_THAN_OR_EQUAL] = numberA < numberB,
|
|
1846
|
-
_a[exports.NumberComparisonType.LESS_THAN_OR_EQUAL] = numberA > numberB,
|
|
1847
|
-
_a[exports.NumberComparisonType.NOT_EQUALS] = numberA === numberB,
|
|
1848
|
-
_a);
|
|
1849
|
-
if (errorCondition[comparisonMethod]) {
|
|
1850
|
-
var controlA = formGroup.get(controlNameA);
|
|
1851
|
-
if (controlA) {
|
|
1852
|
-
controlA.setErrors((_b = {}, _b[methodName] = comparisonMethod, _b));
|
|
1853
|
-
}
|
|
1854
|
-
return _c = {}, _c[methodName] = errorType, _c;
|
|
1855
|
-
}
|
|
1856
|
-
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1857
|
-
var controlA = formGroup.get(controlNameA);
|
|
1858
|
-
if (controlA) {
|
|
1859
|
-
controlA.setErrors(null);
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
return null;
|
|
1864
|
-
};
|
|
1865
|
-
return compareNumber;
|
|
1866
|
-
};
|
|
1867
|
-
/**
|
|
1868
|
-
* Validator para checar se um valor está entre os demais valores de três formControls.
|
|
1869
|
-
*
|
|
1870
|
-
* Aplique esse validator no FormGroup, passando os nomes dos três formControls que deseja comparar.
|
|
1871
|
-
* @example
|
|
1872
|
-
* this.myForm = this.fb.group({
|
|
1873
|
-
* minorFormControl: ['', Validators.required],
|
|
1874
|
-
* targetFormControl: ['', Validators.required],
|
|
1875
|
-
* majorFormControl: ['', Validators.required]
|
|
1876
|
-
* }, { validator: AgroFormValidator.checkValueBetween('minorFormControl', 'targetFormControl', 'majorFormControl') });
|
|
1877
|
-
*
|
|
1878
|
-
* Neste caso, a verificação será se o targetFormControl está entre o minorFormControl e o majorFormControl.
|
|
1879
|
-
* @param minorFormControl
|
|
1880
|
-
* @param targetFormControl
|
|
1881
|
-
* @param majorFormControl
|
|
1882
|
-
* @returns
|
|
1883
|
-
*/
|
|
1884
|
-
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
1885
|
-
var checkValue = function (control) {
|
|
1886
|
-
var _a, _b;
|
|
1887
|
-
var _c, _d, _e, _f;
|
|
1888
|
-
var formGroup = control;
|
|
1889
|
-
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
1890
|
-
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
1891
|
-
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
1892
|
-
var methodName = 'checkValueBetween';
|
|
1893
|
-
if (valueA && valueB && valueC) {
|
|
1894
|
-
if (valueB < valueA || valueB > valueC) {
|
|
1895
|
-
var targetControl = formGroup.get(targetFormControl);
|
|
1896
|
-
if (targetControl) {
|
|
1897
|
-
targetControl.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1898
|
-
}
|
|
1899
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1900
|
-
}
|
|
1901
|
-
else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
1902
|
-
var targetControl = formGroup.get(targetFormControl);
|
|
1903
|
-
if (targetControl) {
|
|
1904
|
-
targetControl.setErrors(null);
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
return null;
|
|
1909
|
-
};
|
|
1910
|
-
return checkValue;
|
|
1911
|
-
};
|
|
1912
|
-
/**
|
|
1913
|
-
* Validator para checar se o campo é um objeto e se possui uma propriedade específica.
|
|
1914
|
-
*
|
|
1915
|
-
* @example
|
|
1916
|
-
* this.myForm = this.fb.group({
|
|
1917
|
-
* OBJETO_FIELD: ['', [Validators.required, AgroFormValidator.objectPropertyValidator('propriedade')]]
|
|
1918
|
-
* });
|
|
1919
|
-
* @param propertyName
|
|
1920
|
-
* @returns
|
|
1921
|
-
*/
|
|
1922
|
-
AgroFormValidator.objectPropertyValidator = function (propertyName) {
|
|
1923
|
-
var objectProperty = function (control) {
|
|
1924
|
-
var _a, _b;
|
|
1925
|
-
var methodName = 'objectProperty';
|
|
1926
|
-
if (AgroObjectUtils.isObject(control.value) && AgroObjectUtils.containsProperty(control.value, propertyName)) {
|
|
1927
|
-
control.setErrors(null);
|
|
1928
|
-
return null;
|
|
1929
|
-
}
|
|
1930
|
-
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
1931
|
-
return _b = {}, _b[methodName] = true, _b;
|
|
1932
|
-
};
|
|
1933
|
-
return objectProperty;
|
|
1934
|
-
};
|
|
1935
|
-
return AgroFormValidator;
|
|
1936
|
-
}());
|
|
1937
|
-
|
|
1938
|
-
var AgroCookieUtils = /** @class */ (function () {
|
|
1939
|
-
function AgroCookieUtils() {
|
|
1940
|
-
}
|
|
1941
|
-
AgroCookieUtils.getCookie = function (name, parseURIValue) {
|
|
1942
|
-
if (parseURIValue === void 0) { parseURIValue = false; }
|
|
1943
|
-
var cookieValue = document.cookie.split(';')
|
|
1944
|
-
.map(function (cookie) { return cookie.trim(); })
|
|
1945
|
-
.find(function (cookie) { return cookie.startsWith(name); });
|
|
1946
|
-
var result = cookieValue === null || cookieValue === void 0 ? void 0 : cookieValue.split('=')[1];
|
|
1947
|
-
if (parseURIValue && result) {
|
|
1948
|
-
result = decodeURIComponent(result);
|
|
1949
|
-
}
|
|
1950
|
-
return result;
|
|
1951
|
-
};
|
|
1952
|
-
AgroCookieUtils.parseCookieToObject = function (cookieString, parseURIString) {
|
|
1953
|
-
if (parseURIString === void 0) { parseURIString = false; }
|
|
1954
|
-
var cookieObject = {};
|
|
1955
|
-
if (parseURIString) {
|
|
1956
|
-
cookieString = decodeURIComponent(cookieString);
|
|
1957
|
-
}
|
|
1958
|
-
cookieString.split(';').forEach(function (cookie) {
|
|
1959
|
-
var _a = __read(cookie.split('=').map(function (c) { return c.trim(); }), 2), key = _a[0], value = _a[1];
|
|
1960
|
-
cookieObject[key] = value;
|
|
1961
|
-
});
|
|
1962
|
-
return cookieObject;
|
|
1963
|
-
};
|
|
1964
|
-
AgroCookieUtils.prototype.setCookie = function (name, value, days) {
|
|
1965
|
-
var date = new Date();
|
|
1966
|
-
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
1967
|
-
var expires = 'expires=' + date.toUTCString();
|
|
1968
|
-
document.cookie = name + '=' + value + ';' + expires + ';path=/';
|
|
1969
|
-
};
|
|
1970
|
-
return AgroCookieUtils;
|
|
1971
|
-
}());
|
|
1972
|
-
|
|
1973
|
-
var AgroDateUtils = /** @class */ (function () {
|
|
1974
|
-
function AgroDateUtils() {
|
|
1975
|
-
}
|
|
1976
|
-
/**
|
|
1977
|
-
* Verifica se uma data é nula ou indefinida.
|
|
1978
|
-
* @param date - A data a ser verificada.
|
|
1979
|
-
* @returns True se a data for nula ou indefinida, false caso contrário.
|
|
1980
|
-
*/
|
|
1981
|
-
AgroDateUtils.isNullOrUndefined = function (date) {
|
|
1982
|
-
return date === null || date === undefined;
|
|
1983
|
-
};
|
|
1984
|
-
/**
|
|
1985
|
-
* Verifica se uma data não é nula e não é indefinida.
|
|
1986
|
-
* @param date - A data a ser verificada.
|
|
1987
|
-
* @returns True se a data não for nula e não for indefinida, false caso contrário.
|
|
1988
|
-
*/
|
|
1989
|
-
AgroDateUtils.isNotNullOrUndefined = function (date) {
|
|
1990
|
-
return !AgroDateUtils.isNullOrUndefined(date);
|
|
1991
|
-
};
|
|
1992
|
-
/**
|
|
1993
|
-
* Verifica se uma data é válida.
|
|
1994
|
-
* @param date - A data a ser verificada.
|
|
1995
|
-
* @returns True se a data for válida, false caso contrário.
|
|
1616
|
+
* Verifica se uma data é válida.
|
|
1617
|
+
* @param date - A data a ser verificada.
|
|
1618
|
+
* @returns True se a data for válida, false caso contrário.
|
|
1996
1619
|
*/
|
|
1997
1620
|
AgroDateUtils.isValid = function (date) {
|
|
1998
1621
|
return !isNaN(Date.parse(date));
|
|
@@ -2056,39 +1679,182 @@
|
|
|
2056
1679
|
* @param otherDate - A outra data a ser comparada.
|
|
2057
1680
|
* @returns True se a data for menor que outra data, false caso contrário.
|
|
2058
1681
|
*/
|
|
2059
|
-
AgroDateUtils.isLess = function (date, otherDate) {
|
|
2060
|
-
return date < otherDate;
|
|
2061
|
-
};
|
|
1682
|
+
AgroDateUtils.isLess = function (date, otherDate) {
|
|
1683
|
+
return date < otherDate;
|
|
1684
|
+
};
|
|
1685
|
+
/**
|
|
1686
|
+
* Verifica se uma data é maior que outra data.
|
|
1687
|
+
* @param date - A data a ser verificada.
|
|
1688
|
+
* @param otherDate - A outra data a ser comparada.
|
|
1689
|
+
* @returns True se a data for maior que outra data, false caso contrário.
|
|
1690
|
+
*/
|
|
1691
|
+
AgroDateUtils.isGreater = function (date, otherDate) {
|
|
1692
|
+
return date > otherDate;
|
|
1693
|
+
};
|
|
1694
|
+
/**
|
|
1695
|
+
* Retorna a data formatada conforme o formato especificado.
|
|
1696
|
+
* @param date
|
|
1697
|
+
* @param format
|
|
1698
|
+
* @returns
|
|
1699
|
+
*/
|
|
1700
|
+
AgroDateUtils.formatDate = function (date, format) {
|
|
1701
|
+
if (format === void 0) { format = 'DD/MM/YYYY'; }
|
|
1702
|
+
var moment$1 = moment;
|
|
1703
|
+
return moment$1(date).utc().format(format);
|
|
1704
|
+
};
|
|
1705
|
+
/**
|
|
1706
|
+
* Retorna uma string com o número informado adicionando um 0 à esquerda, caso o número seja menor que 10.
|
|
1707
|
+
* @param value
|
|
1708
|
+
* @returns
|
|
1709
|
+
*/
|
|
1710
|
+
AgroDateUtils.padZero = function (value) {
|
|
1711
|
+
return value < exports.AGRO_NUMBERS.TEN ? '0' + value : value.toString();
|
|
1712
|
+
};
|
|
1713
|
+
return AgroDateUtils;
|
|
1714
|
+
}());
|
|
1715
|
+
|
|
1716
|
+
var AGRO_REGEX = {
|
|
1717
|
+
/**
|
|
1718
|
+
* Validação de E-mail
|
|
1719
|
+
*/
|
|
1720
|
+
isEmail: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
1721
|
+
/**
|
|
1722
|
+
* Validação de Números Inteiros Positivos
|
|
1723
|
+
*/
|
|
1724
|
+
positiveInteger: /^[1-9]\d*$/,
|
|
1725
|
+
/**
|
|
1726
|
+
* Validação de Números Decimais Positivos
|
|
1727
|
+
*/
|
|
1728
|
+
positiveDecimal: /^\d*\.?\d+$/,
|
|
1729
|
+
/**
|
|
1730
|
+
* Validação de string que consiste apenas em espaços em branco ou está vazia.
|
|
1731
|
+
*/
|
|
1732
|
+
onlyBlankSpaces: /^\s*$/,
|
|
1733
|
+
/**
|
|
1734
|
+
* Validação de CEP (Código Postal)
|
|
1735
|
+
*/
|
|
1736
|
+
zipCode: /^\d{8}$|^\d{5}-\d{3}$/,
|
|
1737
|
+
/**
|
|
1738
|
+
* Validação de String (qualquer caractere)
|
|
1739
|
+
*/
|
|
1740
|
+
isString: /^[\s\S]*$/,
|
|
1741
|
+
/**
|
|
1742
|
+
* Validação de UUID
|
|
1743
|
+
*/
|
|
1744
|
+
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}$/,
|
|
1745
|
+
/**
|
|
1746
|
+
* Validação de Número
|
|
1747
|
+
*/
|
|
1748
|
+
isNumber: /^-?\d+$/,
|
|
1749
|
+
/**
|
|
1750
|
+
* Validação de Número Decimal
|
|
1751
|
+
*/
|
|
1752
|
+
isDecimal: /^\d*\.?\d+$/,
|
|
1753
|
+
/**
|
|
1754
|
+
* Validação de Placa de Veículo
|
|
1755
|
+
*/
|
|
1756
|
+
isLicensePlate: /^[A-Za-z0-9]{1,7}-?[A-Za-z0-9]{1,7}$/,
|
|
1757
|
+
/**
|
|
1758
|
+
* Validação de Número de Telefone
|
|
1759
|
+
*/
|
|
1760
|
+
isPhoneNumber: /^\+?\d{1,4}-?\d{6,11}$/,
|
|
1761
|
+
/**
|
|
1762
|
+
* Validação de Data (Formato YYYY-MM-DD)
|
|
1763
|
+
*/
|
|
1764
|
+
isDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
1765
|
+
/**
|
|
1766
|
+
* Validação de Hora (Formato HH:mm)
|
|
1767
|
+
*/
|
|
1768
|
+
isTime: /^(0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
1769
|
+
/**
|
|
1770
|
+
* Validação de Data e Hora (Formato YYYY-MM-DD HH:mm)
|
|
1771
|
+
*/
|
|
1772
|
+
isDateTime: /^\d{4}-\d{2}-\d{2} (0\d|1\d|2[0-3]):[0-5]\d$/,
|
|
1773
|
+
/**
|
|
1774
|
+
* Validação de URL
|
|
1775
|
+
*/
|
|
1776
|
+
isURL: /^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?$/,
|
|
1777
|
+
/**
|
|
1778
|
+
* Validação de Número Hexadecimal
|
|
1779
|
+
*/
|
|
1780
|
+
isHexNumber: /^[0-9a-fA-F]+$/,
|
|
1781
|
+
/**
|
|
1782
|
+
* Validação de Base64
|
|
1783
|
+
*/
|
|
1784
|
+
isBase64: /^[a-zA-Z0-9+/]+={0,2}$/,
|
|
1785
|
+
/**
|
|
1786
|
+
* Validação de Nome de Usuário (3 a 20 caracteres alfanuméricos)
|
|
1787
|
+
*/
|
|
1788
|
+
isUsername: /^\w{3,20}$/,
|
|
1789
|
+
/**
|
|
1790
|
+
* Validação de Alfanumérico
|
|
1791
|
+
*/
|
|
1792
|
+
isAlphanumeric: /^[a-zA-Z0-9]+$/,
|
|
1793
|
+
/**
|
|
1794
|
+
* Validação de Slug (letras minúsculas, números e traços)
|
|
1795
|
+
*/
|
|
1796
|
+
isSlug: /^[a-z0-9-]+$/,
|
|
1797
|
+
/**
|
|
1798
|
+
* Validação de Número de Cartão de Crédito
|
|
1799
|
+
*/
|
|
1800
|
+
isCreditCard: /^\d{4}-\d{4}-\d{4}-\d{4}$/,
|
|
1801
|
+
/**
|
|
1802
|
+
* Validação de Número Hexadecimal
|
|
1803
|
+
*/
|
|
1804
|
+
isHexadecimal: /^[0-9a-fA-F]+$/,
|
|
1805
|
+
/**
|
|
1806
|
+
* Validação de Moeda
|
|
1807
|
+
*/
|
|
1808
|
+
isCurrency: /^\d+(\.\d{1,2})?$/,
|
|
1809
|
+
/**
|
|
1810
|
+
* Validação de Porcentagem
|
|
1811
|
+
*/
|
|
1812
|
+
isPercentage: /^(100(\.0{1,2})?|[1-9]?\d(\.\d{1,2})?)$/,
|
|
1813
|
+
/**
|
|
1814
|
+
* Validação de Tag HTML Simples
|
|
1815
|
+
*/
|
|
1816
|
+
isHTMLTag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/,
|
|
1817
|
+
/**
|
|
1818
|
+
* Validação de Nome de Usuário com Espaços (3 a 20 caracteres alfanuméricos e espaços)
|
|
1819
|
+
*/
|
|
1820
|
+
isUsernameWithSpaces: /^[a-zA-Z0-9_ ]{3,20}$/,
|
|
1821
|
+
/**
|
|
1822
|
+
* Validação de Senha Forte (mínimo 8 caracteres, uma letra minúscula, uma letra maiúscula, um número e um caractere especial)
|
|
1823
|
+
*/
|
|
1824
|
+
isStrongPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
|
1825
|
+
/**
|
|
1826
|
+
* Validação de String Alfabética
|
|
1827
|
+
*/
|
|
1828
|
+
isAlphabetic: /^[a-zA-Z]+$/,
|
|
1829
|
+
/**
|
|
1830
|
+
* Validação de Hora no Formato de 12 Horas
|
|
1831
|
+
*/
|
|
1832
|
+
isTime12Hour: /^(0?[1-9]|1[0-2]):\d{2} (AM|PM)$/i,
|
|
1833
|
+
/**
|
|
1834
|
+
* Validação de Latitude
|
|
1835
|
+
*/
|
|
1836
|
+
isLatitude: /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
|
|
1837
|
+
/**
|
|
1838
|
+
* Validação de Longitude
|
|
1839
|
+
*/
|
|
1840
|
+
isLongitude: /^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,
|
|
1841
|
+
/**
|
|
1842
|
+
* Validação de Endereço MAC
|
|
1843
|
+
*/
|
|
1844
|
+
isMACAddress: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
|
|
2062
1845
|
/**
|
|
2063
|
-
*
|
|
2064
|
-
* @param date - A data a ser verificada.
|
|
2065
|
-
* @param otherDate - A outra data a ser comparada.
|
|
2066
|
-
* @returns True se a data for maior que outra data, false caso contrário.
|
|
1846
|
+
* Validação de Data de Expiração de Cartão de Crédito
|
|
2067
1847
|
*/
|
|
2068
|
-
|
|
2069
|
-
return date > otherDate;
|
|
2070
|
-
};
|
|
1848
|
+
isCreditCardExpiration: /^(0[1-9]|1[0-2])\/\d{2}$/,
|
|
2071
1849
|
/**
|
|
2072
|
-
*
|
|
2073
|
-
* @param date
|
|
2074
|
-
* @param format
|
|
2075
|
-
* @returns
|
|
1850
|
+
* Validação de Número de Seguro Social (SSN)
|
|
2076
1851
|
*/
|
|
2077
|
-
|
|
2078
|
-
if (format === void 0) { format = 'DD/MM/YYYY'; }
|
|
2079
|
-
var moment$1 = moment;
|
|
2080
|
-
return moment$1(date).utc().format(format);
|
|
2081
|
-
};
|
|
1852
|
+
isSSN: /^\d{3}-\d{2}-\d{4}$/,
|
|
2082
1853
|
/**
|
|
2083
|
-
*
|
|
2084
|
-
* @param value
|
|
2085
|
-
* @returns
|
|
1854
|
+
* Validação se todos os dígitos são iguais
|
|
2086
1855
|
*/
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
};
|
|
2090
|
-
return AgroDateUtils;
|
|
2091
|
-
}());
|
|
1856
|
+
isAllDigitsEqual: /^(.)\1+$/,
|
|
1857
|
+
};
|
|
2092
1858
|
|
|
2093
1859
|
/**
|
|
2094
1860
|
* Classe utilitária para operações de string.
|
|
@@ -2430,6 +2196,15 @@
|
|
|
2430
2196
|
AgroStringUtils.isInvalid = function (str) {
|
|
2431
2197
|
return !AgroStringUtils.isValid(str);
|
|
2432
2198
|
};
|
|
2199
|
+
/**
|
|
2200
|
+
* Valida se uma string é um e-mail válido ou não
|
|
2201
|
+
* Retorna um booleano para indicar se é um e-mail válido ou não
|
|
2202
|
+
* @param email - A string a ser verificada
|
|
2203
|
+
* @returns True se a string for um e-mail válido, false caso contrário
|
|
2204
|
+
*/
|
|
2205
|
+
AgroStringUtils.isValidEmail = function (email) {
|
|
2206
|
+
return AGRO_REGEX.isEmail.test(email);
|
|
2207
|
+
};
|
|
2433
2208
|
return AgroStringUtils;
|
|
2434
2209
|
}());
|
|
2435
2210
|
|
|
@@ -2863,6 +2638,237 @@
|
|
|
2863
2638
|
return AgroArrayUtils;
|
|
2864
2639
|
}());
|
|
2865
2640
|
|
|
2641
|
+
var AgroFormValidator = /** @class */ (function () {
|
|
2642
|
+
function AgroFormValidator() {
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* Validator para checar se o campo é um e-mail
|
|
2646
|
+
*
|
|
2647
|
+
* @example
|
|
2648
|
+
* this.myForm = this.fb.group({
|
|
2649
|
+
* EMAIL_FIELD: ['', [Validators.required, AgroFormValidator.emailValidator]]
|
|
2650
|
+
* });
|
|
2651
|
+
* @param control
|
|
2652
|
+
* @returns
|
|
2653
|
+
*/
|
|
2654
|
+
AgroFormValidator.emailValidator = function (control) {
|
|
2655
|
+
var email = control.value;
|
|
2656
|
+
if (!email) {
|
|
2657
|
+
return null;
|
|
2658
|
+
}
|
|
2659
|
+
return AgroStringUtils.isValidEmail(email) ? null : { emailValidator: true };
|
|
2660
|
+
};
|
|
2661
|
+
/**
|
|
2662
|
+
* Aplique esse validador em um campo do tipo Date, para verificar se a data selecionada é maior ou menor que a data atual.
|
|
2663
|
+
*
|
|
2664
|
+
* Utilize o parâmetro comparisonType para definir se a data selecionada deve ser maior ou menor que a data atual.
|
|
2665
|
+
* A validação será através do enum DateComparisonType.
|
|
2666
|
+
*
|
|
2667
|
+
* @example
|
|
2668
|
+
* this.myForm = this.fb.group({
|
|
2669
|
+
* NOME_CAMPO: ['', [Validators.required, AgroFormValidator.compareDateWithToday(DateComparisonType.greatherThan)]]
|
|
2670
|
+
* });
|
|
2671
|
+
* @param comparisonType
|
|
2672
|
+
* @returns
|
|
2673
|
+
*/
|
|
2674
|
+
AgroFormValidator.compareDateWithToday = function (comparisonType) {
|
|
2675
|
+
var compareDate = function (control) {
|
|
2676
|
+
var _a, _b;
|
|
2677
|
+
var methodName = 'dateComparisonToday';
|
|
2678
|
+
var selectedDate = new Date(control.value);
|
|
2679
|
+
var currentDate = new Date();
|
|
2680
|
+
var conditions = (_a = {},
|
|
2681
|
+
_a[exports.DateComparisonType.greatherThan] = selectedDate <= currentDate,
|
|
2682
|
+
_a[exports.DateComparisonType.lessThan] = selectedDate >= currentDate,
|
|
2683
|
+
_a);
|
|
2684
|
+
if (conditions[comparisonType]) {
|
|
2685
|
+
return _b = {}, _b[methodName] = { value: control.value }, _b;
|
|
2686
|
+
}
|
|
2687
|
+
return null;
|
|
2688
|
+
};
|
|
2689
|
+
return compareDate;
|
|
2690
|
+
};
|
|
2691
|
+
/**
|
|
2692
|
+
* Compara dois campos do tipo Date, verificando se o campo A é maior que o campo B. Se A for maior que B, então
|
|
2693
|
+
* o campo A é invalidado. Caso contrário, o campo A é validado.
|
|
2694
|
+
*
|
|
2695
|
+
* Aplique esse campo no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2696
|
+
* @example
|
|
2697
|
+
* this.myForm = this.fb.group({
|
|
2698
|
+
NOME_CAMPO_dateA: ['', Validators.required],
|
|
2699
|
+
NOME_CAMPO_dateB: ['', Validators.required]
|
|
2700
|
+
}, { validator: AgroFormValidator.dateComparisonValidator('NOME_CAMPO_dateA', 'NOME_CAMPO_dateB') });
|
|
2701
|
+
* @param controlNameA
|
|
2702
|
+
* @param controlNameB
|
|
2703
|
+
* @returns
|
|
2704
|
+
*/
|
|
2705
|
+
AgroFormValidator.compareDateWithOtherDateField = function (controlNameA, controlNameB) {
|
|
2706
|
+
var compareDate = function (control) {
|
|
2707
|
+
var _a, _b;
|
|
2708
|
+
var _c, _d, _e, _f, _g;
|
|
2709
|
+
var formGroup = control;
|
|
2710
|
+
var dateA = (_c = formGroup.get(controlNameA)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2711
|
+
var dateB = (_d = formGroup.get(controlNameB)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2712
|
+
var methodName = 'compareDateWithOtherDateField';
|
|
2713
|
+
if (dateA && dateB) {
|
|
2714
|
+
var dateAObj = new Date(dateA);
|
|
2715
|
+
var dateBObj = new Date(dateB);
|
|
2716
|
+
if (dateAObj < dateBObj) {
|
|
2717
|
+
(_e = formGroup.get(controlNameA)) === null || _e === void 0 ? void 0 : _e.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2718
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2719
|
+
}
|
|
2720
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2721
|
+
(_g = formGroup.get(controlNameA)) === null || _g === void 0 ? void 0 : _g.setErrors(null);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
return null;
|
|
2725
|
+
};
|
|
2726
|
+
return compareDate;
|
|
2727
|
+
};
|
|
2728
|
+
/**
|
|
2729
|
+
* Validator para checar se um campo de números é maior ou menor que outro campo.
|
|
2730
|
+
*
|
|
2731
|
+
* Aplique esse validator no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2732
|
+
* @example
|
|
2733
|
+
* this.myForm = this.fb.group({
|
|
2734
|
+
* NUMERO_A: ['', Validators.required],
|
|
2735
|
+
* NUMERO_B: ['', Validators.required]
|
|
2736
|
+
* }, { validator: AgroFormValidator.compareNumberFields('NUMERO_A', 'NUMERO_B', NumberComparisonType.EQUALS) });
|
|
2737
|
+
*
|
|
2738
|
+
* Neste caso, a verificação será se o NUMERO_A é igual ao NUMERB_B.
|
|
2739
|
+
* @param controlNameA
|
|
2740
|
+
* @param controlNameB
|
|
2741
|
+
* @returns
|
|
2742
|
+
*/
|
|
2743
|
+
AgroFormValidator.compareNumberFields = function (controlNameA, controlNameB, comparisonMethod) {
|
|
2744
|
+
var compareNumber = function (control) {
|
|
2745
|
+
var _a, _b, _c;
|
|
2746
|
+
var _d, _e, _f;
|
|
2747
|
+
var formGroup = control;
|
|
2748
|
+
var numberA = (_d = formGroup.get(controlNameA)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2749
|
+
var numberB = (_e = formGroup.get(controlNameB)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2750
|
+
var methodName = 'compareNumberFields';
|
|
2751
|
+
if (numberA && numberB) {
|
|
2752
|
+
var errorType = exports.NumberComparisonType[comparisonMethod];
|
|
2753
|
+
var errorCondition = (_a = {},
|
|
2754
|
+
_a[exports.NumberComparisonType.EQUALS] = numberA !== numberB,
|
|
2755
|
+
_a[exports.NumberComparisonType.GREATER_THAN] = numberA <= numberB,
|
|
2756
|
+
_a[exports.NumberComparisonType.LESS_THAN] = numberA >= numberB,
|
|
2757
|
+
_a[exports.NumberComparisonType.GREATER_THAN_OR_EQUAL] = numberA < numberB,
|
|
2758
|
+
_a[exports.NumberComparisonType.LESS_THAN_OR_EQUAL] = numberA > numberB,
|
|
2759
|
+
_a[exports.NumberComparisonType.NOT_EQUALS] = numberA === numberB,
|
|
2760
|
+
_a);
|
|
2761
|
+
if (errorCondition[comparisonMethod]) {
|
|
2762
|
+
var controlA = formGroup.get(controlNameA);
|
|
2763
|
+
if (controlA) {
|
|
2764
|
+
controlA.setErrors((_b = {}, _b[methodName] = comparisonMethod, _b));
|
|
2765
|
+
}
|
|
2766
|
+
return _c = {}, _c[methodName] = errorType, _c;
|
|
2767
|
+
}
|
|
2768
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2769
|
+
var controlA = formGroup.get(controlNameA);
|
|
2770
|
+
if (controlA) {
|
|
2771
|
+
controlA.setErrors(null);
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
return null;
|
|
2776
|
+
};
|
|
2777
|
+
return compareNumber;
|
|
2778
|
+
};
|
|
2779
|
+
/**
|
|
2780
|
+
* Validator para checar se um valor está entre os demais valores de três formControls.
|
|
2781
|
+
*
|
|
2782
|
+
* Aplique esse validator no FormGroup, passando os nomes dos três formControls que deseja comparar.
|
|
2783
|
+
* @example
|
|
2784
|
+
* this.myForm = this.fb.group({
|
|
2785
|
+
* minorFormControl: ['', Validators.required],
|
|
2786
|
+
* targetFormControl: ['', Validators.required],
|
|
2787
|
+
* majorFormControl: ['', Validators.required]
|
|
2788
|
+
* }, { validator: AgroFormValidator.checkValueBetween('minorFormControl', 'targetFormControl', 'majorFormControl') });
|
|
2789
|
+
*
|
|
2790
|
+
* Neste caso, a verificação será se o targetFormControl está entre o minorFormControl e o majorFormControl.
|
|
2791
|
+
* @param minorFormControl
|
|
2792
|
+
* @param targetFormControl
|
|
2793
|
+
* @param majorFormControl
|
|
2794
|
+
* @returns
|
|
2795
|
+
*/
|
|
2796
|
+
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
2797
|
+
var checkValue = function (control) {
|
|
2798
|
+
var _a, _b;
|
|
2799
|
+
var _c, _d, _e, _f;
|
|
2800
|
+
var formGroup = control;
|
|
2801
|
+
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2802
|
+
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2803
|
+
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2804
|
+
var methodName = 'checkValueBetween';
|
|
2805
|
+
if (valueA && valueB && valueC) {
|
|
2806
|
+
if (valueB < valueA || valueB > valueC) {
|
|
2807
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2808
|
+
if (targetControl) {
|
|
2809
|
+
targetControl.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2810
|
+
}
|
|
2811
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2812
|
+
}
|
|
2813
|
+
else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2814
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2815
|
+
if (targetControl) {
|
|
2816
|
+
targetControl.setErrors(null);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
return null;
|
|
2821
|
+
};
|
|
2822
|
+
return checkValue;
|
|
2823
|
+
};
|
|
2824
|
+
/**
|
|
2825
|
+
* Validator para checar se o campo é um objeto e se possui uma propriedade específica.
|
|
2826
|
+
*
|
|
2827
|
+
* @example
|
|
2828
|
+
* this.myForm = this.fb.group({
|
|
2829
|
+
* OBJETO_FIELD: ['', [Validators.required, AgroFormValidator.objectPropertyValidator('propriedade')]]
|
|
2830
|
+
* });
|
|
2831
|
+
* @param propertyName
|
|
2832
|
+
* @returns
|
|
2833
|
+
*/
|
|
2834
|
+
AgroFormValidator.objectPropertyValidator = function (propertyName) {
|
|
2835
|
+
var objectProperty = function (control) {
|
|
2836
|
+
var _a, _b;
|
|
2837
|
+
var methodName = 'objectProperty';
|
|
2838
|
+
if (AgroObjectUtils.isObject(control.value) && AgroObjectUtils.containsProperty(control.value, propertyName)) {
|
|
2839
|
+
control.setErrors(null);
|
|
2840
|
+
return null;
|
|
2841
|
+
}
|
|
2842
|
+
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2843
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2844
|
+
};
|
|
2845
|
+
return objectProperty;
|
|
2846
|
+
};
|
|
2847
|
+
/**
|
|
2848
|
+
* Verifica se a string informada é um CPF válido.
|
|
2849
|
+
* Se a validação for false, retorna um objeto com a chave cpfValidator.
|
|
2850
|
+
*/
|
|
2851
|
+
AgroFormValidator.CPFValidator = function (control) {
|
|
2852
|
+
var cpf = control.value;
|
|
2853
|
+
if (!cpf) {
|
|
2854
|
+
return null;
|
|
2855
|
+
}
|
|
2856
|
+
return AgroStringUtils.validateCPF(cpf) ? null : { cpfValidator: true };
|
|
2857
|
+
};
|
|
2858
|
+
/**
|
|
2859
|
+
* Verifica se a string informada é um CNPJ válido.
|
|
2860
|
+
* Se a validação for false, retorna um objeto com a chave cnpjValidator.
|
|
2861
|
+
*/
|
|
2862
|
+
AgroFormValidator.CNPJValidator = function (control) {
|
|
2863
|
+
var cnpj = control.value;
|
|
2864
|
+
if (!cnpj) {
|
|
2865
|
+
return null;
|
|
2866
|
+
}
|
|
2867
|
+
return AgroStringUtils.validateCNPJ(cnpj) ? null : { cnpjValidator: true };
|
|
2868
|
+
};
|
|
2869
|
+
return AgroFormValidator;
|
|
2870
|
+
}());
|
|
2871
|
+
|
|
2866
2872
|
var AsyncLock = /** @class */ (function () {
|
|
2867
2873
|
function AsyncLock() {
|
|
2868
2874
|
this.queue = [];
|