@senior-agronegocio/angular-components 0.0.52 → 0.0.56
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 +477 -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 +13 -0
- package/esm2015/common/agro-string-utils.class.js +23 -8
- package/esm2015/form-validator/agro-form-validator.js +39 -30
- package/esm5/common/agro-string-utils.class.js +23 -8
- package/esm5/form-validator/agro-form-validator.js +39 -31
- package/fesm2015/senior-agronegocio-angular-components.js +463 -439
- package/fesm2015/senior-agronegocio-angular-components.js.map +1 -1
- package/fesm5/senior-agronegocio-angular-components.js +477 -454
- package/fesm5/senior-agronegocio-angular-components.js.map +1 -1
- package/form-validator/agro-form-validator.d.ts +17 -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));
|
|
@@ -2065,30 +1688,173 @@
|
|
|
2065
1688
|
* @param otherDate - A outra data a ser comparada.
|
|
2066
1689
|
* @returns True se a data for maior que outra data, false caso contrário.
|
|
2067
1690
|
*/
|
|
2068
|
-
AgroDateUtils.isGreater = function (date, otherDate) {
|
|
2069
|
-
return date > otherDate;
|
|
2070
|
-
};
|
|
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})$/,
|
|
1845
|
+
/**
|
|
1846
|
+
* Validação de Data de Expiração de Cartão de Crédito
|
|
1847
|
+
*/
|
|
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.
|
|
@@ -2354,23 +2120,19 @@
|
|
|
2354
2120
|
var remainder = sum % 11;
|
|
2355
2121
|
return remainder < 2 ? 0 : 11 - remainder;
|
|
2356
2122
|
};
|
|
2357
|
-
return
|
|
2358
|
-
calcCheckDigit(10) === Number(cpf[10]));
|
|
2123
|
+
return calcCheckDigit(9) === Number(cpf[9]) && calcCheckDigit(10) === Number(cpf[10]);
|
|
2359
2124
|
};
|
|
2360
2125
|
AgroStringUtils.validateCNPJ = function (cnpj) {
|
|
2361
2126
|
cnpj = cnpj.replace(/\D/g, "");
|
|
2362
2127
|
if (cnpj.length !== 14 || /^(\d)\1{13}$/.test(cnpj))
|
|
2363
2128
|
return false;
|
|
2364
2129
|
var calcularDigito = function (length) {
|
|
2365
|
-
var pesos = length === 12
|
|
2366
|
-
? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
2367
|
-
: [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
2130
|
+
var pesos = length === 12 ? [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] : [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
2368
2131
|
var soma = pesos.reduce(function (acc, peso, i) { return acc + Number(cnpj[i]) * peso; }, 0);
|
|
2369
2132
|
var resto = soma % 11;
|
|
2370
2133
|
return resto < 2 ? 0 : 11 - resto;
|
|
2371
2134
|
};
|
|
2372
|
-
return
|
|
2373
|
-
calcularDigito(13) === Number(cnpj[13]));
|
|
2135
|
+
return calcularDigito(12) === Number(cnpj[12]) && calcularDigito(13) === Number(cnpj[13]);
|
|
2374
2136
|
};
|
|
2375
2137
|
/**
|
|
2376
2138
|
* Método para aplicar uma máscara em uma string. Considere a máscara com valores 9 para aplicação
|
|
@@ -2430,6 +2192,25 @@
|
|
|
2430
2192
|
AgroStringUtils.isInvalid = function (str) {
|
|
2431
2193
|
return !AgroStringUtils.isValid(str);
|
|
2432
2194
|
};
|
|
2195
|
+
/**
|
|
2196
|
+
* Valida se uma string é um e-mail válido ou não
|
|
2197
|
+
* Retorna um booleano para indicar se é um e-mail válido ou não
|
|
2198
|
+
* @param email - A string a ser verificada
|
|
2199
|
+
* @returns True se a string for um e-mail válido, false caso contrário
|
|
2200
|
+
*/
|
|
2201
|
+
AgroStringUtils.isValidEmail = function (email) {
|
|
2202
|
+
return AGRO_REGEX.isEmail.test(email);
|
|
2203
|
+
};
|
|
2204
|
+
/**
|
|
2205
|
+
* Valida se uma string é uma placa de veículo BR válida ou não.
|
|
2206
|
+
* Retorna um booleano para indicar se é uma placa válida ou não.
|
|
2207
|
+
* @param plate - A string a ser verificada
|
|
2208
|
+
*/
|
|
2209
|
+
AgroStringUtils.isValidLicensePlate = function (plate) {
|
|
2210
|
+
var oldFormat = /^[A-Z]{3}-?\d{4}$/;
|
|
2211
|
+
var mercosulFormat = /^[A-Z]{3}\d[A-Z]\d{2}$/;
|
|
2212
|
+
return oldFormat.test(plate) || mercosulFormat.test(plate);
|
|
2213
|
+
};
|
|
2433
2214
|
return AgroStringUtils;
|
|
2434
2215
|
}());
|
|
2435
2216
|
|
|
@@ -2863,6 +2644,248 @@
|
|
|
2863
2644
|
return AgroArrayUtils;
|
|
2864
2645
|
}());
|
|
2865
2646
|
|
|
2647
|
+
var AgroFormValidator = /** @class */ (function () {
|
|
2648
|
+
function AgroFormValidator() {
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* Validator para checar se o campo é um e-mail
|
|
2652
|
+
*
|
|
2653
|
+
* @example
|
|
2654
|
+
* this.myForm = this.fb.group({
|
|
2655
|
+
* EMAIL_FIELD: ['', [Validators.required, AgroFormValidator.emailValidator]]
|
|
2656
|
+
* });
|
|
2657
|
+
* @param control
|
|
2658
|
+
* @returns
|
|
2659
|
+
*/
|
|
2660
|
+
AgroFormValidator.emailValidator = function (control) {
|
|
2661
|
+
var email = control.value;
|
|
2662
|
+
if (!email) {
|
|
2663
|
+
return null;
|
|
2664
|
+
}
|
|
2665
|
+
return AgroStringUtils.isValidEmail(email) ? null : { emailValidator: true };
|
|
2666
|
+
};
|
|
2667
|
+
/**
|
|
2668
|
+
* Aplique esse validador em um campo do tipo Date, para verificar se a data selecionada é maior ou menor que a data atual.
|
|
2669
|
+
*
|
|
2670
|
+
* Utilize o parâmetro comparisonType para definir se a data selecionada deve ser maior ou menor que a data atual.
|
|
2671
|
+
* A validação será através do enum DateComparisonType.
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* this.myForm = this.fb.group({
|
|
2675
|
+
* NOME_CAMPO: ['', [Validators.required, AgroFormValidator.compareDateWithToday(DateComparisonType.greatherThan)]]
|
|
2676
|
+
* });
|
|
2677
|
+
* @param comparisonType
|
|
2678
|
+
* @returns
|
|
2679
|
+
*/
|
|
2680
|
+
AgroFormValidator.compareDateWithToday = function (comparisonType) {
|
|
2681
|
+
var compareDate = function (control) {
|
|
2682
|
+
var _a, _b;
|
|
2683
|
+
var methodName = 'dateComparisonToday';
|
|
2684
|
+
var selectedDate = new Date(control.value);
|
|
2685
|
+
var currentDate = new Date();
|
|
2686
|
+
var conditions = (_a = {},
|
|
2687
|
+
_a[exports.DateComparisonType.greatherThan] = selectedDate <= currentDate,
|
|
2688
|
+
_a[exports.DateComparisonType.lessThan] = selectedDate >= currentDate,
|
|
2689
|
+
_a);
|
|
2690
|
+
if (conditions[comparisonType]) {
|
|
2691
|
+
return _b = {}, _b[methodName] = { value: control.value }, _b;
|
|
2692
|
+
}
|
|
2693
|
+
return null;
|
|
2694
|
+
};
|
|
2695
|
+
return compareDate;
|
|
2696
|
+
};
|
|
2697
|
+
/**
|
|
2698
|
+
* Compara dois campos do tipo Date, verificando se o campo A é maior que o campo B. Se A for maior que B, então
|
|
2699
|
+
* o campo A é invalidado. Caso contrário, o campo A é validado.
|
|
2700
|
+
*
|
|
2701
|
+
* Aplique esse campo no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2702
|
+
* @example
|
|
2703
|
+
* this.myForm = this.fb.group({
|
|
2704
|
+
NOME_CAMPO_dateA: ['', Validators.required],
|
|
2705
|
+
NOME_CAMPO_dateB: ['', Validators.required]
|
|
2706
|
+
}, { validator: AgroFormValidator.dateComparisonValidator('NOME_CAMPO_dateA', 'NOME_CAMPO_dateB') });
|
|
2707
|
+
* @param controlNameA
|
|
2708
|
+
* @param controlNameB
|
|
2709
|
+
* @returns
|
|
2710
|
+
*/
|
|
2711
|
+
AgroFormValidator.compareDateWithOtherDateField = function (controlNameA, controlNameB) {
|
|
2712
|
+
var compareDate = function (control) {
|
|
2713
|
+
var _a, _b;
|
|
2714
|
+
var _c, _d, _e, _f, _g;
|
|
2715
|
+
var formGroup = control;
|
|
2716
|
+
var dateA = (_c = formGroup.get(controlNameA)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2717
|
+
var dateB = (_d = formGroup.get(controlNameB)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2718
|
+
var methodName = 'compareDateWithOtherDateField';
|
|
2719
|
+
if (dateA && dateB) {
|
|
2720
|
+
var dateAObj = new Date(dateA);
|
|
2721
|
+
var dateBObj = new Date(dateB);
|
|
2722
|
+
if (dateAObj < dateBObj) {
|
|
2723
|
+
(_e = formGroup.get(controlNameA)) === null || _e === void 0 ? void 0 : _e.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2724
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2725
|
+
}
|
|
2726
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2727
|
+
(_g = formGroup.get(controlNameA)) === null || _g === void 0 ? void 0 : _g.setErrors(null);
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
return null;
|
|
2731
|
+
};
|
|
2732
|
+
return compareDate;
|
|
2733
|
+
};
|
|
2734
|
+
/**
|
|
2735
|
+
* Validator para checar se um campo de números é maior ou menor que outro campo.
|
|
2736
|
+
*
|
|
2737
|
+
* Aplique esse validator no FormGroup, passando os nomes dos campos que deseja comparar.
|
|
2738
|
+
* @example
|
|
2739
|
+
* this.myForm = this.fb.group({
|
|
2740
|
+
* NUMERO_A: ['', Validators.required],
|
|
2741
|
+
* NUMERO_B: ['', Validators.required]
|
|
2742
|
+
* }, { validator: AgroFormValidator.compareNumberFields('NUMERO_A', 'NUMERO_B', NumberComparisonType.EQUALS) });
|
|
2743
|
+
*
|
|
2744
|
+
* Neste caso, a verificação será se o NUMERO_A é igual ao NUMERB_B.
|
|
2745
|
+
* @param controlNameA
|
|
2746
|
+
* @param controlNameB
|
|
2747
|
+
* @returns
|
|
2748
|
+
*/
|
|
2749
|
+
AgroFormValidator.compareNumberFields = function (controlNameA, controlNameB, comparisonMethod) {
|
|
2750
|
+
var compareNumber = function (control) {
|
|
2751
|
+
var _a, _b, _c;
|
|
2752
|
+
var _d, _e, _f;
|
|
2753
|
+
var formGroup = control;
|
|
2754
|
+
var numberA = (_d = formGroup.get(controlNameA)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2755
|
+
var numberB = (_e = formGroup.get(controlNameB)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2756
|
+
var methodName = 'compareNumberFields';
|
|
2757
|
+
if (numberA && numberB) {
|
|
2758
|
+
var errorType = exports.NumberComparisonType[comparisonMethod];
|
|
2759
|
+
var errorCondition = (_a = {},
|
|
2760
|
+
_a[exports.NumberComparisonType.EQUALS] = numberA !== numberB,
|
|
2761
|
+
_a[exports.NumberComparisonType.GREATER_THAN] = numberA <= numberB,
|
|
2762
|
+
_a[exports.NumberComparisonType.LESS_THAN] = numberA >= numberB,
|
|
2763
|
+
_a[exports.NumberComparisonType.GREATER_THAN_OR_EQUAL] = numberA < numberB,
|
|
2764
|
+
_a[exports.NumberComparisonType.LESS_THAN_OR_EQUAL] = numberA > numberB,
|
|
2765
|
+
_a[exports.NumberComparisonType.NOT_EQUALS] = numberA === numberB,
|
|
2766
|
+
_a);
|
|
2767
|
+
if (errorCondition[comparisonMethod]) {
|
|
2768
|
+
var controlA = formGroup.get(controlNameA);
|
|
2769
|
+
if (controlA) {
|
|
2770
|
+
controlA.setErrors((_b = {}, _b[methodName] = comparisonMethod, _b));
|
|
2771
|
+
}
|
|
2772
|
+
return _c = {}, _c[methodName] = errorType, _c;
|
|
2773
|
+
}
|
|
2774
|
+
else if ((_f = formGroup.get(controlNameA)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2775
|
+
var controlA = formGroup.get(controlNameA);
|
|
2776
|
+
if (controlA) {
|
|
2777
|
+
controlA.setErrors(null);
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
return null;
|
|
2782
|
+
};
|
|
2783
|
+
return compareNumber;
|
|
2784
|
+
};
|
|
2785
|
+
/**
|
|
2786
|
+
* Validator para checar se um valor está entre os demais valores de três formControls.
|
|
2787
|
+
*
|
|
2788
|
+
* Aplique esse validator no FormGroup, passando os nomes dos três formControls que deseja comparar.
|
|
2789
|
+
* @example
|
|
2790
|
+
* this.myForm = this.fb.group({
|
|
2791
|
+
* minorFormControl: ['', Validators.required],
|
|
2792
|
+
* targetFormControl: ['', Validators.required],
|
|
2793
|
+
* majorFormControl: ['', Validators.required]
|
|
2794
|
+
* }, { validator: AgroFormValidator.checkValueBetween('minorFormControl', 'targetFormControl', 'majorFormControl') });
|
|
2795
|
+
*
|
|
2796
|
+
* Neste caso, a verificação será se o targetFormControl está entre o minorFormControl e o majorFormControl.
|
|
2797
|
+
* @param minorFormControl
|
|
2798
|
+
* @param targetFormControl
|
|
2799
|
+
* @param majorFormControl
|
|
2800
|
+
* @returns
|
|
2801
|
+
*/
|
|
2802
|
+
AgroFormValidator.checkValueBetween = function (minorFormControl, targetFormControl, majorFormControl) {
|
|
2803
|
+
var checkValue = function (control) {
|
|
2804
|
+
var _a, _b;
|
|
2805
|
+
var _c, _d, _e, _f;
|
|
2806
|
+
var formGroup = control;
|
|
2807
|
+
var valueA = (_c = formGroup.get(minorFormControl)) === null || _c === void 0 ? void 0 : _c.value;
|
|
2808
|
+
var valueB = (_d = formGroup.get(targetFormControl)) === null || _d === void 0 ? void 0 : _d.value;
|
|
2809
|
+
var valueC = (_e = formGroup.get(majorFormControl)) === null || _e === void 0 ? void 0 : _e.value;
|
|
2810
|
+
var methodName = 'checkValueBetween';
|
|
2811
|
+
if (valueA && valueB && valueC) {
|
|
2812
|
+
if (valueB < valueA || valueB > valueC) {
|
|
2813
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2814
|
+
if (targetControl) {
|
|
2815
|
+
targetControl.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2816
|
+
}
|
|
2817
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2818
|
+
}
|
|
2819
|
+
else if ((_f = formGroup.get(targetFormControl)) === null || _f === void 0 ? void 0 : _f.hasError(methodName)) {
|
|
2820
|
+
var targetControl = formGroup.get(targetFormControl);
|
|
2821
|
+
if (targetControl) {
|
|
2822
|
+
targetControl.setErrors(null);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
return null;
|
|
2827
|
+
};
|
|
2828
|
+
return checkValue;
|
|
2829
|
+
};
|
|
2830
|
+
/**
|
|
2831
|
+
* Validator para checar se o campo é um objeto e se possui uma propriedade específica.
|
|
2832
|
+
*
|
|
2833
|
+
* @example
|
|
2834
|
+
* this.myForm = this.fb.group({
|
|
2835
|
+
* OBJETO_FIELD: ['', [Validators.required, AgroFormValidator.objectPropertyValidator('propriedade')]]
|
|
2836
|
+
* });
|
|
2837
|
+
* @param propertyName
|
|
2838
|
+
* @returns
|
|
2839
|
+
*/
|
|
2840
|
+
AgroFormValidator.objectPropertyValidator = function (propertyName) {
|
|
2841
|
+
var objectProperty = function (control) {
|
|
2842
|
+
var _a, _b;
|
|
2843
|
+
var methodName = 'objectProperty';
|
|
2844
|
+
if (AgroObjectUtils.isObject(control.value) && AgroObjectUtils.containsProperty(control.value, propertyName)) {
|
|
2845
|
+
control.setErrors(null);
|
|
2846
|
+
return null;
|
|
2847
|
+
}
|
|
2848
|
+
control.setErrors((_a = {}, _a[methodName] = true, _a));
|
|
2849
|
+
return _b = {}, _b[methodName] = true, _b;
|
|
2850
|
+
};
|
|
2851
|
+
return objectProperty;
|
|
2852
|
+
};
|
|
2853
|
+
/**
|
|
2854
|
+
* Verifica se a string informada é um CPF válido.
|
|
2855
|
+
* Se a validação for false, retorna um objeto com a chave cpfValidator.
|
|
2856
|
+
*/
|
|
2857
|
+
AgroFormValidator.CPFValidator = function (control) {
|
|
2858
|
+
var cpf = control.value;
|
|
2859
|
+
if (!cpf) {
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
return AgroStringUtils.validateCPF(cpf) ? null : { cpfValidator: true };
|
|
2863
|
+
};
|
|
2864
|
+
/**
|
|
2865
|
+
* Verifica se a string informada é um CNPJ válido.
|
|
2866
|
+
* Se a validação for false, retorna um objeto com a chave cnpjValidator.
|
|
2867
|
+
*/
|
|
2868
|
+
AgroFormValidator.CNPJValidator = function (control) {
|
|
2869
|
+
var cnpj = control.value;
|
|
2870
|
+
if (!cnpj) {
|
|
2871
|
+
return null;
|
|
2872
|
+
}
|
|
2873
|
+
return AgroStringUtils.validateCNPJ(cnpj) ? null : { cnpjValidator: true };
|
|
2874
|
+
};
|
|
2875
|
+
/**
|
|
2876
|
+
* Verifica se a string informada é uma placa de veículo válido.
|
|
2877
|
+
* Se a validação for false, retorna um objeto com a chave licensePlate.
|
|
2878
|
+
*/
|
|
2879
|
+
AgroFormValidator.licensePlateValidator = function (control) {
|
|
2880
|
+
var plate = control.value;
|
|
2881
|
+
if (!plate) {
|
|
2882
|
+
return null;
|
|
2883
|
+
}
|
|
2884
|
+
return AgroStringUtils.isValidLicensePlate(plate) ? null : { licensePlate: true };
|
|
2885
|
+
};
|
|
2886
|
+
return AgroFormValidator;
|
|
2887
|
+
}());
|
|
2888
|
+
|
|
2866
2889
|
var AsyncLock = /** @class */ (function () {
|
|
2867
2890
|
function AsyncLock() {
|
|
2868
2891
|
this.queue = [];
|