ice-utilities
Version:
Utilities for manage arrays, breadcrumb, dom elements, dates, injectors, local storage, login, objects, router animations, router, session storage, strings and translate utilities, encryption, for angular 6+ with ECMAScript 6 - ECMAScript 2015
1,856 lines (1,840 loc) • 171 kB
JavaScript
import SimpleCrypto from 'simple-crypto-js/src/SimpleCrypto';
import notify from 'devextreme/ui/notify';
import { PRIMARY_OUTLET } from '@angular/router';
import { Injector } from '@angular/core';
import { animate, state, style, transition, trigger } from '@angular/animations';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class ObjectUtils {
/**
* @param {?} obj
* @return {?}
*/
static isObject(obj) {
return (typeof obj === 'object');
}
/**
* @param {?} obj
* @return {?}
*/
static isEmpty(obj) {
return (this.isObject(obj) && (JSON.stringify(obj) === JSON.stringify({})));
}
/**
* @param {?} obj
* @return {?}
*/
static isEmptyCircular(obj) {
/** @type {?} */
let isEmpty = true;
Object.keys(obj).forEach(key => {
isEmpty = false;
});
return isEmpty;
}
/**
* @param {?} myObject
* @return {?}
*/
static copyNestedObject(myObject) {
return Object.assign({}, myObject); // JSON.parse(JSON.stringify(myObject));
}
/**
* @param {?} myObject
* @return {?}
*/
static copyObject(myObject) {
return this.copyNestedObject(myObject);
}
/**
* @param {?} obj
* @return {?}
*/
static objectToNum(obj) {
/** @type {?} */
const newObj = {};
Object.keys(obj).forEach(prop => {
newObj[prop] = +obj[prop];
});
}
/**
* @param {?=} obj1
* @param {?=} obj2
* @return {?}
*/
static merge(obj1 = {}, obj2 = {}) {
return Object.assign({}, obj1, obj2);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class EncryptUtils {
/**
* @param {?} key
* @return {?}
*/
static setKey(key) {
if (key && key !== null && key.length > 0) {
this._key = key;
this._SimpleCrypto = new SimpleCrypto(this._key);
}
}
/**
* @return {?}
*/
static hasEncryption() {
return (this._key && this._key.length > 0 && this._SimpleCrypto);
}
/**
* @param {?} data
* @return {?}
*/
static encrypt(data) {
if (this.hasEncryption() && data && data !== null) {
return this._SimpleCrypto.encrypt(data);
}
else {
return '';
}
}
/**
* @param {?} ciphered
* @return {?}
*/
static decrypt(ciphered) {
if (this.hasEncryption() && ciphered && ciphered !== null && ciphered.length > 0) {
/** @type {?} */
let val = this._SimpleCrypto.decrypt(ciphered);
try {
val = JSON.parse(val);
}
catch (e) { }
return val;
}
else {
return null;
}
}
/**
* @return {?}
*/
static generateKey() {
return SimpleCrypto.generateRandom();
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class SessionUtils {
/**
* @private
* @param {?} key
* @return {?}
*/
static codeKey(key) {
return btoa(key.toUpperCase());
}
/**
* @param {?} key
* @param {?} value
* @return {?}
*/
static setSession(key, value) {
if (EncryptUtils.hasEncryption()) {
sessionStorage.setItem(this.codeKey(key), EncryptUtils.encrypt(value));
}
else {
/** @type {?} */
let val;
if (ObjectUtils.isObject(value)) {
val = JSON.stringify(value);
}
else {
val = value;
}
sessionStorage.setItem(key, val);
}
}
/**
* @param {?} key
* @return {?}
*/
static deleteSession(key) {
if (EncryptUtils.hasEncryption()) {
sessionStorage.removeItem(this.codeKey(key));
}
else {
sessionStorage.removeItem(key);
}
}
/**
* @param {?} key
* @return {?}
*/
static getSession(key) {
if (EncryptUtils.hasEncryption()) {
return EncryptUtils.decrypt(sessionStorage.getItem(this.codeKey(key)));
}
else {
/** @type {?} */
let val = sessionStorage.getItem(key);
try {
val = JSON.parse(val);
}
catch (e) { }
return val;
}
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Created by ICEMANven on 22/08/2018.
*/
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
class Base64 {
constructor() {
this._keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
}
// public method for encoding
/**
* @param {?} input
* @return {?}
*/
encode(input) {
/** @type {?} */
let output = '';
/** @type {?} */
let chr1;
/** @type {?} */
let chr2;
/** @type {?} */
let chr3;
/** @type {?} */
let enc1;
/** @type {?} */
let enc2;
/** @type {?} */
let enc3;
/** @type {?} */
let enc4;
/** @type {?} */
let i = 0;
input = this._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
}
else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
}
// public method for decoding
/**
* @param {?} input
* @return {?}
*/
decode(input) {
/** @type {?} */
let output = '';
/** @type {?} */
let chr1;
/** @type {?} */
let chr2;
/** @type {?} */
let chr3;
/** @type {?} */
let enc1;
/** @type {?} */
let enc2;
/** @type {?} */
let enc3;
/** @type {?} */
let enc4;
/** @type {?} */
let i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 !== 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 !== 64) {
output = output + String.fromCharCode(chr3);
}
}
output = this._utf8_decode(output);
// output = this._utf8_encode(output);
return output;
}
// private method for UTF-8 encoding
/**
* @param {?} string
* @return {?}
*/
_utf8_encode(string) {
string = string.replace(/\r\n/g, '\n');
/** @type {?} */
let utftext = '';
for (let n = 0; n < string.length; n++) {
/** @type {?} */
const c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
// private method for UTF-8 decoding
/**
* @param {?} utftext
* @return {?}
*/
_utf8_decode(utftext) {
/** @type {?} */
let string = '';
/** @type {?} */
let i = 0;
/** @type {?} */
let c1;
/** @type {?} */
let c2;
/** @type {?} */
let c3;
/** @type {?} */
let c = c1 = c2 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// Taken from https://github.com/killmenot/webtoolkit.md5
/** @type {?} */
let md5 = (string) => {
/**
* @param {?} lValue
* @param {?} iShiftBits
* @return {?}
*/
function RotateLeft(lValue, iShiftBits) {
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
}
/**
* @param {?} lX
* @param {?} lY
* @return {?}
*/
function AddUnsigned(lX, lY) {
/** @type {?} */
var lX4;
/** @type {?} */
var lY4;
/** @type {?} */
var lX8;
/** @type {?} */
var lY8;
/** @type {?} */
var lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
lX4 = (lX & 0x40000000);
lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if (lX4 & lY4) {
return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
}
if (lX4 | lY4) {
if (lResult & 0x40000000) {
return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
}
else {
return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
}
}
else {
return (lResult ^ lX8 ^ lY8);
}
}
/**
* @param {?} x
* @param {?} y
* @param {?} z
* @return {?}
*/
function F(x, y, z) {
return (x & y) | ((~x) & z);
}
/**
* @param {?} x
* @param {?} y
* @param {?} z
* @return {?}
*/
function G(x, y, z) {
return (x & z) | (y & (~z));
}
/**
* @param {?} x
* @param {?} y
* @param {?} z
* @return {?}
*/
function H(x, y, z) {
return (x ^ y ^ z);
}
/**
* @param {?} x
* @param {?} y
* @param {?} z
* @return {?}
*/
function I(x, y, z) {
return (y ^ (x | (~z)));
}
/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} x
* @param {?} s
* @param {?} ac
* @return {?}
*/
function FF(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} x
* @param {?} s
* @param {?} ac
* @return {?}
*/
function GG(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} x
* @param {?} s
* @param {?} ac
* @return {?}
*/
function HH(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
/**
* @param {?} a
* @param {?} b
* @param {?} c
* @param {?} d
* @param {?} x
* @param {?} s
* @param {?} ac
* @return {?}
*/
function II(a, b, c, d, x, s, ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
}
/**
* @param {?} string
* @return {?}
*/
function ConvertToWordArray(string) {
/** @type {?} */
var lWordCount;
/** @type {?} */
var lMessageLength = string.length;
/** @type {?} */
var lNumberOfWords_temp1 = lMessageLength + 8;
/** @type {?} */
var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
/** @type {?} */
var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
/** @type {?} */
var lWordArray = Array(lNumberOfWords - 1);
/** @type {?} */
var lBytePosition = 0;
/** @type {?} */
var lByteCount = 0;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
return lWordArray;
}
/**
* @param {?} lValue
* @return {?}
*/
function WordToHex(lValue) {
/** @type {?} */
var WordToHexValue = "";
/** @type {?} */
var WordToHexValue_temp = "";
/** @type {?} */
var lByte;
/** @type {?} */
var lCount;
for (lCount = 0; lCount <= 3; lCount++) {
lByte = (lValue >>> (lCount * 8)) & 255;
WordToHexValue_temp = "0" + lByte.toString(16);
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
}
return WordToHexValue;
}
/**
* @param {?} string
* @return {?}
*/
function Utf8Encode(string) {
string = string.replace(/\r\n/g, "\n");
/** @type {?} */
var utftext = "";
for (var n = 0; n < string.length; n++) {
/** @type {?} */
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
/** @type {?} */
var x = Array();
/** @type {?} */
var k;
/** @type {?} */
var AA;
/** @type {?} */
var BB;
/** @type {?} */
var CC;
/** @type {?} */
var DD;
/** @type {?} */
var a;
/** @type {?} */
var b;
/** @type {?} */
var c;
/** @type {?} */
var d;
/** @type {?} */
var S11 = 7;
/** @type {?} */
var S12 = 12;
/** @type {?} */
var S13 = 17;
/** @type {?} */
var S14 = 22;
/** @type {?} */
var S21 = 5;
/** @type {?} */
var S22 = 9;
/** @type {?} */
var S23 = 14;
/** @type {?} */
var S24 = 20;
/** @type {?} */
var S31 = 4;
/** @type {?} */
var S32 = 11;
/** @type {?} */
var S33 = 16;
/** @type {?} */
var S34 = 23;
/** @type {?} */
var S41 = 6;
/** @type {?} */
var S42 = 10;
/** @type {?} */
var S43 = 15;
/** @type {?} */
var S44 = 21;
string = Utf8Encode(string);
x = ConvertToWordArray(string);
a = 0x67452301;
b = 0xEFCDAB89;
c = 0x98BADCFE;
d = 0x10325476;
for (k = 0; k < x.length; k += 16) {
AA = a;
BB = b;
CC = c;
DD = d;
a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
a = AddUnsigned(a, AA);
b = AddUnsigned(b, BB);
c = AddUnsigned(c, CC);
d = AddUnsigned(d, DD);
}
/** @type {?} */
var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
return temp.toLowerCase();
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class StringUtils {
/**
* @param {?} sanitizer
* @return {?}
*/
static setSanitizerInstance(sanitizer) {
if (!this.sanitizer && sanitizer) {
this.sanitizer = sanitizer;
}
}
/**
* @param {?} str
* @param {?} find
* @return {?}
*/
static includes(str, find) {
return str.includes(find);
}
/**
* @param {?} str
* @param {?} find
* @return {?}
*/
static startsWith(str, find) {
return str.startsWith(find);
}
/**
* @param {?} str
* @param {?} find
* @return {?}
*/
static endsWith(str, find) {
return str.endsWith(find);
}
/**
* @param {?} val
* @return {?}
*/
static isString(val) {
return (typeof val === 'string' || val instanceof String);
}
/**
* @param {?} text
* @return {?}
*/
static removeAccents(text) {
return text ? text.normalize('NFD').replace(/[\u0300-\u036f]/g, '') : '';
}
/**
* @param {?} st
* @return {?}
*/
static StringToNumber(st) {
return parseInt(st, 10);
}
/**
* @param {?} st
* @return {?}
*/
static Utf8Encode(st) {
// return this.b64._utf8_encode(st);
// const sst = this.utf8.utf8decode(st);
return st;
}
/**
* @param {?} st
* @return {?}
*/
static Utf8Decode(st) {
// return this.b64._utf8_decode(st);
// const sst = this.utf8.utf8decode(st);
return st;
}
/**
* @param {?} bb
* @return {?}
*/
static base64Decode(bb) {
/** @type {?} */
const b64 = new Base64();
return b64.decode(bb);
}
/**
* @param {?} text
* @return {?}
*/
static isEmpty(text) {
return (text === '');
}
/**
* @param {?} text
* @return {?}
*/
static bypassSecurityTrustUrl(text) {
return this.sanitizer.bypassSecurityTrustUrl(text);
}
/**
* @param {?} text
* @return {?}
*/
static toMd5(text) {
return md5(text);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class TranslateUtils {
/**
* @param {?} translateService
* @return {?}
*/
static setTranlateInstance(translateService) {
if (!this.translateService && translateService) {
this.translateService = translateService;
}
}
/**
* @param {?} text
* @return {?}
*/
static Translate(text) {
if (this.translateService) {
/** @type {?} */
let translation = '';
this.translateService.get(text).subscribe(trans => {
translation = trans;
});
return translation;
}
else {
return text;
}
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class GlobalUtils {
/**
* @param {?} responsiveWidth
* @return {?}
*/
static setResponsiveWidth(responsiveWidth) {
if (!this.responsiveWidth && responsiveWidth) {
this.responsiveWidth = responsiveWidth;
}
}
/**
* @param {?} timeshow
* @return {?}
*/
static setTimeShow(timeshow) {
if (!this.timeshow && timeshow) {
this.timeshow = timeshow;
}
}
/**
* @param {?} obj1
* @param {?} obj2
* @return {?}
*/
static areEquals(obj1, obj2) {
return JSON.stringify(obj1) === JSON.stringify(obj2);
}
/**
* @param {?} data
* @return {?}
*/
static isEmptyData(data) {
return (this.areEquals(data, '') || this.areEquals(data, 0) || data === null || this.areEquals(data, {}) || this.areEquals(data, []));
}
/**
* @param {?} data
* @return {?}
*/
static isUndefined(data) {
return typeof data === 'undefined';
}
/**
* @param {?} name
* @return {?}
*/
static setSysname(name) {
SessionUtils.setSession('sysname', name);
}
/**
* @return {?}
*/
static getSysname() {
return SessionUtils.getSession('sysname');
}
/**
* @param {?} width
* @param {?} actstt
* @return {?}
*/
static autoFixSidebarState(width, actstt) {
if (width <= this.responsiveWidth) {
return 'inres';
}
else {
if (actstt === 'inres') {
return 'out';
}
else {
return actstt;
}
}
}
/**
* @param {?} stt
* @param {?} width
* @param {?} actstt
* @param {?} responsiveWidth
* @return {?}
*/
static fixsidebarState(stt, width, actstt, responsiveWidth) {
if (width <= responsiveWidth) {
if (actstt === 'inres') {
return 'in';
}
else {
return 'inres';
}
}
else {
return stt;
}
}
/**
* @param {?} stt
* @param {?} width
* @param {?} responsiveWidth
* @return {?}
*/
static fixContainerState(stt, width, responsiveWidth) {
if (width <= responsiveWidth) {
return 'inres';
}
else {
return stt;
}
}
/**
* @param {?} men
* @param {?} data
* @return {?}
*/
static successNotify(men, data) {
notify(TranslateUtils.Translate(men) + ' '
+ JSON.stringify(data), 'success', this.timeshow);
}
/**
* @param {?} error
* @param {?} men
* @param {?=} type
* @return {?}
*/
static cathNotify(error, men, type = 'warning') {
/** @type {?} */
const tmen = TranslateUtils.Translate(men);
this.notifyError(tmen, error, type);
}
/**
* @private
* @param {?} tmen
* @param {?} error
* @param {?} type
* @return {?}
*/
static notifyError(tmen, error, type) {
notify(`${tmen} :${this.errorCath(error)}`, type, this.timeshow);
if (type === 'error') {
throw new Error(tmen);
}
}
/**
* @param {?} error
* @param {?} men
* @param {?} extraMen
* @param {?=} type
* @return {?}
*/
static cathNotifyExtraMen(error, men, extraMen, type = 'warning') {
/** @type {?} */
const tmen = `${TranslateUtils.Translate(men)} ${extraMen}`;
this.notifyError(tmen, error, type);
}
/**
* @param {?} error
* @return {?}
*/
static errorCath(error) {
/** @type {?} */
let errorMen = '';
if (StringUtils.isString(error)) {
errorMen = error;
}
else if (ObjectUtils.isObject(error)) {
if (error.error) {
if (StringUtils.isString(error.error)) {
errorMen = error.error;
}
else if (ObjectUtils.isObject(error.error) && error.error.ResponseStatus) {
if (error.error.ResponseStatus.Message) {
errorMen = error.error.ResponseStatus.Message;
}
else if (error.error.ResponseStatus.ErrorCode) {
errorMen = error.error.ResponseStatus.ErrorCode;
}
}
else if (StringUtils.isString(error.message)) {
errorMen = error.message;
}
}
else {
if (error.message) {
errorMen = error.message;
}
else if (error.statusText) {
errorMen = error.statusText;
}
}
}
return TranslateUtils.Translate(errorMen);
}
/**
* @return {?}
*/
static getNativeWindow() {
return window;
}
/**
* @param {?} url
* @param {?=} config
* @return {?}
*/
static openWindow(url, config) {
return window.open(url, '', 'location=no,width=1800,height=900,scrollbars=yes,top=100,left=700,resizable = no');
}
/**
* @param {?=} whm
* @return {?}
*/
static setWithHeight(whm) {
if (whm && whm.fullScreen) {
return {
fullscreen: 1,
};
}
/** @type {?} */
let mm = 1.5;
if (whm && whm.Media) {
mm = whm.Media;
}
/** @type {?} */
const val = {
width: window.innerWidth / mm,
height: window.innerHeight / mm
};
if (whm && whm.hasOwnProperty('width')) {
val.width = whm.width;
}
if (whm && whm.hasOwnProperty('height')) {
val.height = whm.height;
}
return val;
}
}
GlobalUtils.responsiveWidth = 960;
GlobalUtils.timeshow = 8000;
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class ArrayUtils {
/**
* @param {?} array
* @param {?} find
* @return {?}
*/
static inArray(array, find) {
return array.includes(find);
}
/**
* @param {?} array
* @param {?} find
* @return {?}
*/
static notInArray(array, find) {
return (!this.inArray(array, find));
}
/**
* @param {?} arr
* @param {?} obj
* @return {?}
*/
static objectInArray(arr, obj) {
return (arr.find(oo => GlobalUtils.areEquals(oo, obj)));
}
/**
* @param {?} arr
* @param {?} obj
* @return {?}
*/
static objectNotInArray(arr, obj) {
return !this.objectInArray(arr, obj);
}
/**
* @param {?} arr
* @param {?} prop
* @param {?} value
* @return {?}
*/
static objectPropInArray(arr, prop, value) {
return (arr.find(oo => GlobalUtils.areEquals(oo[prop], value)));
}
/**
* @param {?} arr
* @param {?} prop
* @param {?} value
* @return {?}
*/
static objectNotPropInArray(arr, prop, value) {
return (!this.objectPropInArray(arr, prop, value));
}
/**
* @param {?} arr
* @return {?}
*/
static cloneArray(arr) {
return [...arr];
}
/**
* @param {?} arr
* @param {?} ind
* @return {?}
*/
static removeFromArray(arr, ind) {
arr.splice(ind, 1);
return arr;
}
/**
* @param {?} arr1
* @param {?} arr2
* @return {?}
*/
static arrayMerge(arr1, arr2) {
return [...arr1, ...arr2];
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class FechasUtils {
/**
* @param {?} DateOri
* @param {?=} RemoveHour
* @return {?}
*/
static toDate(DateOri, RemoveHour) {
/** @type {?} */
let DateObj = DateOri;
if (DateOri) {
try {
/** @type {?} */
const isDate = (typeof DateObj.getMonth === 'function');
if (!isDate) {
/** @type {?} */
const part = DateObj.split('.');
DateObj = Date.parse(part[0]);
}
if (RemoveHour) {
DateObj.setHours(0, 0, 0, 0);
}
return DateObj;
}
catch (e) {
}
}
return null;
}
/**
* @param {?} time
* @return {?}
*/
static unsetTimeZero(time) {
return time ? time.replace(/0001-01-01T00:00:00\.0000000/, '') : '';
}
/**
* @param {?} set
* @return {?}
*/
static unsetAnytimeZero(set) {
Object.keys(set).forEach(prop => {
if (set[prop] === '0001-01-01T00:00:00.0000000') {
set[prop] = this.unsetTimeZero(set[prop]);
}
});
return set;
}
/**
* @param {?} set
* @return {?}
*/
static unsetArrayTimeZero(set) {
/** @type {?} */
const final = [];
for (let s of set) {
s = this.unsetAnytimeZero(s);
final.push(s);
}
return final;
}
/**
* @param {?} date
* @return {?}
*/
static isWeekend(date) {
/** @type {?} */
const day = date.getDay();
return day === 0 || day === 6;
}
/**
* @param {?} date
* @return {?}
*/
static isToday(date) {
/** @type {?} */
const today = new Date;
return (date === today);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class LocalStorageUtils {
/**
* @private
* @param {?} key
* @return {?}
*/
static codeKey(key) {
return btoa(key.toUpperCase());
}
/**
* @param {?} key
* @param {?} value
* @return {?}
*/
static setStorage(key, value) {
if (EncryptUtils.hasEncryption()) {
localStorage.setItem(this.codeKey(key), EncryptUtils.encrypt(value));
}
else {
/** @type {?} */
let val;
if (ObjectUtils.isObject(value)) {
val = JSON.stringify(value);
}
else {
val = value;
}
localStorage.setItem(key, val);
}
}
/**
* @param {?} key
* @return {?}
*/
static deleteStorage(key) {
if (EncryptUtils.hasEncryption()) {
localStorage.removeItem(this.codeKey(key));
}
else {
localStorage.removeItem(key);
}
}
/**
* @param {?} key
* @return {?}
*/
static getstorage(key) {
if (EncryptUtils.hasEncryption()) {
return EncryptUtils.decrypt(localStorage.getItem(this.codeKey(key)));
}
else {
/** @type {?} */
let val = localStorage.getItem(key);
try {
val = JSON.parse(val);
}
catch (e) { }
return val;
}
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class LoginUtils {
/**
* @private
* @return {?}
*/
static LoginKey() {
if (EncryptUtils.hasEncryption()) {
return btoa(EncryptUtils.encrypt(this.getCurrentUser()));
}
else {
return btoa(JSON.stringify(this.getCurrentUser()));
}
}
/**
* @return {?}
*/
static isLoggedin() {
/** @type {?} */
let key;
if (EncryptUtils.hasEncryption()) {
key = EncryptUtils.decrypt(atob(SessionUtils.getSession('isLoggedin')));
return GlobalUtils.areEquals(key, this.getCurrentUser());
}
else {
/** @type {?} */
const log = SessionUtils.getSession('isLoggedin');
if (log === null) {
return false;
}
key = atob(log);
return GlobalUtils.areEquals(JSON.parse(key), this.getCurrentUser());
}
}
/**
* @return {?}
*/
static setLoggedin() {
SessionUtils.setSession('isLoggedin', this.LoginKey());
}
/**
* @return {?}
*/
static logOff() {
sessionStorage.clear();
}
/**
* @param {?} err
* @return {?}
*/
static logFail(err) {
this.logOff();
/** @type {?} */
const men = TranslateUtils.Translate(err.statusText);
notify(men, 'error', 5000);
}
/**
* @param {?} value
* @return {?}
*/
static setCurrentUser(value) {
SessionUtils.setSession('currentUser', value);
}
/**
* @return {?}
*/
static getCurrentUser() {
return SessionUtils.getSession('currentUser');
}
/**
* @param {?} empresas
* @return {?}
*/
static setEmpresasUser(empresas) {
SessionUtils.setSession('empresasUser', empresas);
}
/**
* @return {?}
*/
static getEmpresasUser() {
return SessionUtils.getSession('empresasUser');
}
/**
* @return {?}
*/
static getEmresaIdProd() {
const { IDEmpresaProd } = this.getCurrentUser();
return IDEmpresaProd;
}
/**
* @param {?} id
* @param {?=} nombre
* @return {?}
*/
static setEmpresaCode(id, nombre) {
/** @type {?} */
const crr = this.getCurrentUser();
crr.CompanyCode = id;
if (nombre) {
crr.CompanyName = nombre;
}
this.setCurrentUser(crr);
}
/**
* @return {?}
*/
static getEmpresaCode() {
const { CompanyCode } = this.getCurrentUser();
return CompanyCode;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class RouterUtils {
/**
* @param {?=} router
* @return {?}
*/
static setRouterInstance(router) {
if (!this.router && router) {
this.router = router;
}
}
/**
* @param {?} dir
* @return {?}
*/
static setStaticDir(dir) {
if (!this.staticDir && dir) {
this.staticDir = `/${dir}/`;
this.staticDirR = `/${dir}R/`;
}
}
/**
* @param {?} dir
* @return {?}
*/
static setDynamicDir(dir) {
if (!this.dynamicDir && dir) {
this.dynamicDir = `/${dir}/`;
this.dynamicDirR = `/${dir}R/`;
}
}
/**
* @param {?} dir
* @return {?}
*/
static setNotAllowedDir(dir) {
if (!this.notAllowed && dir) {
this.notAllowed = dir;
}
}
/**
* @param {?} dir
* @return {?}
*/
static setListDir(dir) {
if (!this.listDir && dir) {
this.listDir = dir;
}
}
/**
* @param {?} modulo
* @param {?} tipo
* @param {?=} end
* @return {?}
*/
static getRerouteUrl(modulo, tipo, end) {
if (this.router) {
/** @type {?} */
let url;
/** @type {?} */
const mod = modulo.toUpperCase();
/** @type {?} */
const tt = tipo.toUpperCase();
/** @type {?} */
const urlroute = this.router.url;
if (StringUtils.includes(urlroute, `/${mod}/`)) {
url = `/${mod}R/${tt}/`;
}
else if (StringUtils.includes(urlroute, `/${mod}R/`)) {
url = `/${mod}/${tt}/`;
}
if (end) {
url += end.toString();
}
return url;
}
else {
return '/';
}
}
/**
* @param {?} mod
* @param {?} id
* @return {?}
*/
static setDinamicDirUrl(mod, id) {
return `${this.dynamicDir}${mod.toUpperCase()}/${id.toString()}`;
}
/**
* @param {?} sys
* @param {?} mod
* @return {?}
*/
static setCustomDirUrl(sys, mod) {
return `${this.staticDir}${sys}/${mod}`;
}
/**
* @param {?=} extra
* @return {?}
*/
static evalPerm(extra) {
if (this.router) {
/** @type {?} */
let url = this.router.url;
/** @type {?} */
const sinDrouter = url.split('(');
url = sinDrouter[0];
if (StringUtils.includes(url, ';')) {
/** @type {?} */
const surl = url.split(';');
url = surl[0];
}
if (extra) {
url = url.replace(extra, '');
}
if (StringUtils.includes(url, this.dynamicDirR)) {
url = url.replace(this.dynamicDirR, this.dynamicDir);
}
else if (StringUtils.includes(url, this.staticDirR)) {
url = url.replace(this.staticDirR, this.staticDir);
}
if ((StringUtils.includes(url, this.dynamicDir)
|| StringUtils.includes(url, this.staticDirR)
|| StringUtils.includes(url, this.staticDir)
|| StringUtils.includes(url, this.staticDirR))
&&
this.urlNotAllowed(url)) {
this.router.navigate([this.notAllowed]);
}
}
else {
this.router.navigate([this.notAllowed]);
}
}
/**
* @param {?} route
* @param {?=} params
* @param {?=} lista
* @return {?}
*/
static getSegmentsRoute(route, params = {}, lista = false) {
/** @type {?} */
const tree = this.router.parseUrl(route);
/** @type {?} */
const g = tree.root.children[PRIMARY_OUTLET];
/** @type {?} */
const s = g.segments;
/** @type {?} */
const final = s.map(p => {
return p.path;
});
if (lista) {
return [...final, ...[this.listDir], ...[params]];
}
else {
return [...final, ...[params]];
}
}
/**
* @param {?} route
* @param {?} id
* @param {?=} params
* @param {?=} lista
* @return {?}
*/
static getSegmentsRouteId(route, id, params = {}, lista = false) {
/** @type {?} */
const tree = this.router.parseUrl(route);
/** @type {?} */
const g = tree.root.children[PRIMARY_OUTLET];
/** @type {?} */
const s = g.segments;
/** @type {?} */
const final = s.map(p => {
return p.path;
});
if (lista) {
return [...final, ...[id.toString()], ...['Lista'], ...[params]];
}
else {
return [...final, ...[id.toString()], ...[params]];
}
}
/**
* @param {?} men
* @return {?}
*/
static setNotAllowMen(men) {
SessionUtils.setSession('notallowedmen', men);
}
/**
* @param {?} menset
* @return {?}
*/
static getNotAllowMen(menset) {
/** @type {?} */
let men = SessionUtils.getSession('notallowedmen');
if (men !== null) {
SessionUtils.deleteSession('notallowedmen');
}
else {
men = menset;
}
return TranslateUtils.Translate(men);
}
/**
* @param {?} url
* @return {?}
*/
static setAllowedUrl(url) {
SessionUtils.setSession('allowedurl', url);
}
/**
* @param {?} url
* @return {?}
*/
static urlNotAllowed(url) {
/** @type {?} */
const urlsAllowed = SessionUtils.getSession('allowedurl');
/** @type {?} */
let notA = true;
if (urlsAllowed !== null) {
notA = ArrayUtils.notInArray(urlsAllowed, url);
}
return notA;
}
}
RouterUtils.dynamicDir = '';
RouterUtils.staticDir = '';
RouterUtils.dynamicDirR = '';
RouterUtils.staticDirR = '';
RouterUtils.notAllowed = '/';
RouterUtils.listDir = 'list';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class BreadCrumbUtils {
/**
* @return {?}
*/
static getBreadCrumb() {
return SessionUtils.getSession('breadcrumb');
}
/**
* @param {?} value
* @param {?=} isDinamic
* @return {?}
*/
static setBreadCrumb(value, isDinamic) {
if (!isDinamic) {
value = GlobalUtils.getSysname() + value;
}
SessionUtils.setSession('breadcrumb', value);
}
/**
* @param {?} value
* @return {?}
*/
static getPrinModFromBreadCrumb(value) {
/** @type {?} */
const search = value.split(/\//);
return search[1];
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// @dynamic
/**
* @abstract
*/
class DomElementUtils {
/**
* @param {?} element
* @return {?}
*/
static getContainerElement(element) {
return new Promise(function (resolve, reject) {
DomElementUtils.waitForContainerElement(element, resolve);
});
}
/**
* @param {?} className
* @return {?}
*/
static getContainerClassElement(className) {
return new Promise(function (resolve, reject) {
DomElementUtils.waitForContainerClassElement(className, resolve);
});
}
/**
* @private
* @param {?} id
* @param {?} resolve
* @return {?}
*/
static waitForContainerElement(id, resolve) {
/** @type {?} */
const $configElement = document.getElementById(id);
if (!$configElement || $configElement === null) {
setTimeout(DomElementUtils.waitForContainerElement.bind(this, id, resolve), 30);
}
else {
resolve($configElement);
}
}
/**
* @private
* @param {?} className
* @param {?} resolve
* @return {?}
*/
static waitForContainerClassElement(className, resolve) {
/** @type {?} */
const $configElement = document.getElementsByClassName(className);
if (!$configElement || $configElement === null) {
setTimeout(DomElementUtils.waitForContainerClassElement.bind(this, className, resolve), 30);
}
else {
resolve($configElement);
}
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
*/
class IceUtilities {
/**
* @param {?} data
* @return {?}
*/
static iniIceUtilities(data) {
this.globals.setResponsiveWidth(data.responsiveWidth);
this.globals.setTimeShow(data.timeshow);
this.router.setRouterInstance(data.router);
this.router.setDynamicDir(data.dynamicDir);
this.router.setStaticDir(data.staticDir);
this.router.setNotAll