@osovitny/anatoly 2.1.8 → 2.1.10

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.
@@ -45,9 +45,6 @@
45
45
  Created:
46
46
  26 Jun 2020
47
47
 
48
- Version:
49
- 1.0
50
-
51
48
  Copyright (c) 2016-2021 Osovitny Inc. All rights reserved.
52
49
  </file>
53
50
  */
@@ -65,9 +62,6 @@
65
62
  Created:
66
63
  5 May 2020
67
64
 
68
- Version:
69
- 1.0
70
-
71
65
  Copyright (c) 2020 Deloitte Tax. All rights reserved.
72
66
  </file>
73
67
  */
@@ -1592,58 +1586,155 @@
1592
1586
  { type: i1.HttpClient }
1593
1587
  ]; };
1594
1588
 
1589
+ var WebStorageService = /** @class */ (function () {
1590
+ function WebStorageService(storage) {
1591
+ this.storage =
1592
+ storage === 'local' || storage === 'localStorage'
1593
+ ? localStorage
1594
+ : sessionStorage;
1595
+ }
1596
+ WebStorageService.prototype.setItem = function (key, value) {
1597
+ this.storage.setItem(key, value);
1598
+ };
1599
+ WebStorageService.prototype.setObject = function (key, value) {
1600
+ this.storage.setItem(key, JSON.stringify(value));
1601
+ };
1602
+ WebStorageService.prototype.getItem = function (key) {
1603
+ return this.storage.getItem(key);
1604
+ };
1605
+ WebStorageService.prototype.getObject = function (key) {
1606
+ var value = this.storage.getItem(key);
1607
+ if (!value) {
1608
+ return null;
1609
+ }
1610
+ return JSON.parse(value);
1611
+ };
1612
+ WebStorageService.prototype.remove = function (key) {
1613
+ this.storage.removeItem(key);
1614
+ };
1615
+ return WebStorageService;
1616
+ }());
1617
+ var LocalStorageService = /** @class */ (function (_super) {
1618
+ __extends(LocalStorageService, _super);
1619
+ function LocalStorageService() {
1620
+ return _super.call(this, 'localStorage') || this;
1621
+ }
1622
+ return LocalStorageService;
1623
+ }(WebStorageService));
1624
+ LocalStorageService.decorators = [
1625
+ { type: i0.Injectable }
1626
+ ];
1627
+ LocalStorageService.ctorParameters = function () { return []; };
1628
+ var SessionStorageService = /** @class */ (function (_super) {
1629
+ __extends(SessionStorageService, _super);
1630
+ function SessionStorageService() {
1631
+ return _super.call(this, 'sessionStorage') || this;
1632
+ }
1633
+ return SessionStorageService;
1634
+ }(WebStorageService));
1635
+ SessionStorageService.decorators = [
1636
+ { type: i0.Injectable }
1637
+ ];
1638
+ SessionStorageService.ctorParameters = function () { return []; };
1639
+
1595
1640
  var AppContextService = /** @class */ (function (_super) {
1596
1641
  __extends(AppContextService, _super);
1597
- function AppContextService(http) {
1642
+ function AppContextService(http, sessionStorage) {
1598
1643
  var _this = _super.call(this, http) || this;
1599
1644
  _this.http = http;
1600
- _this.current = null;
1601
- _this.successes = [];
1645
+ _this.sessionStorage = sessionStorage;
1646
+ //Consts
1647
+ _this.storageKeyName = 'appContext';
1602
1648
  _this.subscription = null;
1649
+ _this.successes = [];
1603
1650
  _this.baseUrl = '/api/appContext';
1604
1651
  return _this;
1605
1652
  }
1606
- AppContextService.prototype.getCurrent = function (success) {
1607
- var _this = this;
1608
- if (typeof success == 'undefined') {
1653
+ AppContextService.prototype.updateContextIfExpired = function () {
1654
+ var context = this.sessionStorage.getObject(this.storageKeyName);
1655
+ if (!context) {
1609
1656
  return;
1610
1657
  }
1611
- if (this.current != null) {
1612
- success(this.current);
1613
- return;
1614
- }
1615
- this.successes.push(success);
1616
- if (this.subscription != null) {
1617
- return;
1658
+ var lu = context.lastRequested;
1659
+ if (lu) {
1660
+ var now = new Date();
1661
+ var lastRequested = new Date(context.lastRequested);
1662
+ var in2Mins = new Date(lastRequested.getFullYear(), lastRequested.getMonth(), lastRequested.getDate(), lastRequested.getHours(), lastRequested.getMinutes() + 2, 0, 0);
1663
+ if (in2Mins.getTime() < now.getTime()) {
1664
+ this.updateCurrentContext();
1665
+ }
1618
1666
  }
1619
- this.subscription = this.get('GetCurrentContext', null).subscribe(function (data) {
1620
- _this.dataReceived(data);
1621
- }, function (e) { });
1622
1667
  };
1623
1668
  AppContextService.prototype.dataReceived = function (data) {
1624
1669
  this.current = data;
1625
1670
  for (var i = 0; i < this.successes.length; i++) {
1626
1671
  var success = this.successes[i];
1627
- success(data);
1672
+ if (success) {
1673
+ success(data);
1674
+ }
1628
1675
  }
1629
1676
  this.successes = [];
1630
1677
  this.subscription.unsubscribe();
1631
1678
  this.subscription = null;
1632
1679
  this.current = null;
1633
1680
  };
1681
+ AppContextService.prototype.getCurrent = function (success, getCachedIfExist) {
1682
+ var _this = this;
1683
+ if (success === void 0) { success = null; }
1684
+ if (getCachedIfExist === void 0) { getCachedIfExist = true; }
1685
+ var current = this.current;
1686
+ if (getCachedIfExist && current != null) {
1687
+ if (success) {
1688
+ success(current);
1689
+ }
1690
+ return;
1691
+ }
1692
+ if (success) {
1693
+ this.successes.push(success);
1694
+ }
1695
+ if (this.subscription != null) {
1696
+ return;
1697
+ }
1698
+ var now = new Date();
1699
+ console.log('Requesting a new AppContext at ' + now);
1700
+ this.subscription = this.get('getCurrentContext', null).subscribe(function (data) {
1701
+ _this.dataReceived(data);
1702
+ }, function (e) {
1703
+ });
1704
+ };
1705
+ AppContextService.prototype.updateCurrentContext = function (success) {
1706
+ if (success === void 0) { success = null; }
1707
+ this.getCurrent(success, false);
1708
+ };
1709
+ AppContextService.prototype.clearCurrentContex = function () {
1710
+ this.sessionStorage.remove(this.storageKeyName);
1711
+ };
1634
1712
  AppContextService.prototype.isUserSignedIn = function () {
1635
1713
  return ContextInitState.isUserSignedIn;
1636
1714
  };
1637
1715
  AppContextService.prototype.isUserAdmin = function () {
1638
1716
  return ContextInitState.isUserAdmin;
1639
1717
  };
1718
+ Object.defineProperty(AppContextService.prototype, "current", {
1719
+ //current
1720
+ get: function () {
1721
+ this.updateContextIfExpired();
1722
+ return this.sessionStorage.getObject(this.storageKeyName);
1723
+ },
1724
+ set: function (value) {
1725
+ this.sessionStorage.setObject(this.storageKeyName, value);
1726
+ },
1727
+ enumerable: false,
1728
+ configurable: true
1729
+ });
1640
1730
  return AppContextService;
1641
1731
  }(BaseApiService));
1642
1732
  AppContextService.decorators = [
1643
1733
  { type: i0.Injectable }
1644
1734
  ];
1645
1735
  AppContextService.ctorParameters = function () { return [
1646
- { type: i1.HttpClient }
1736
+ { type: i1.HttpClient },
1737
+ { type: SessionStorageService }
1647
1738
  ]; };
1648
1739
 
1649
1740
  /*
@@ -1718,57 +1809,6 @@
1718
1809
  },] }
1719
1810
  ];
1720
1811
 
1721
- var WebStorageService = /** @class */ (function () {
1722
- function WebStorageService(storage) {
1723
- this.storage =
1724
- storage === 'local' || storage === 'localStorage'
1725
- ? localStorage
1726
- : sessionStorage;
1727
- }
1728
- WebStorageService.prototype.setItem = function (key, value) {
1729
- this.storage.setItem(key, value);
1730
- };
1731
- WebStorageService.prototype.setObject = function (key, value) {
1732
- this.storage.setItem(key, JSON.stringify(value));
1733
- };
1734
- WebStorageService.prototype.getItem = function (key) {
1735
- return this.storage.getItem(key);
1736
- };
1737
- WebStorageService.prototype.getObject = function (key) {
1738
- var value = this.storage.getItem(key);
1739
- if (!value) {
1740
- return null;
1741
- }
1742
- return JSON.parse(value);
1743
- };
1744
- WebStorageService.prototype.remove = function (key) {
1745
- this.storage.removeItem(key);
1746
- };
1747
- return WebStorageService;
1748
- }());
1749
- var LocalStorageService = /** @class */ (function (_super) {
1750
- __extends(LocalStorageService, _super);
1751
- function LocalStorageService() {
1752
- return _super.call(this, 'localStorage') || this;
1753
- }
1754
- return LocalStorageService;
1755
- }(WebStorageService));
1756
- LocalStorageService.decorators = [
1757
- { type: i0.Injectable }
1758
- ];
1759
- LocalStorageService.ctorParameters = function () { return []; };
1760
- var SessionStorageService = /** @class */ (function (_super) {
1761
- __extends(SessionStorageService, _super);
1762
- function SessionStorageService() {
1763
- return _super.call(this, 'sessionStorage') || this;
1764
- }
1765
- return SessionStorageService;
1766
- }(WebStorageService));
1767
- SessionStorageService.decorators = [
1768
- { type: i0.Injectable }
1769
- ];
1770
- SessionStorageService.ctorParameters = function () { return []; };
1771
-
1772
1812
  /*
1773
1813
  <file>
1774
1814
  Project:
@@ -2021,6 +2061,33 @@
2021
2061
  Utils.downloadFile(fileName, downloadURL);
2022
2062
  }
2023
2063
  };
2064
+ /*
2065
+ Author:
2066
+ https://medium.com/@mhagemann/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1
2067
+ */
2068
+ Utils.slugify = function (text, prefix, postfix) {
2069
+ if (prefix === void 0) { prefix = ''; }
2070
+ if (postfix === void 0) { postfix = ''; }
2071
+ var a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;';
2072
+ var b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------';
2073
+ var p = new RegExp(a.split('').join('|'), 'g');
2074
+ /*
2075
+ https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
2076
+ https://stackoverflow.com/questions/822452/strip-html-from-text-javascript
2077
+ */
2078
+ text = text.replace(/(<([^>]+)>)/gi, '');
2079
+ var result = text
2080
+ .toString()
2081
+ .toLowerCase()
2082
+ .replace(/\s+/g, '-') // Replace spaces with -
2083
+ .replace(p, function (c) { return b.charAt(a.indexOf(c)); }) // Replace special characters
2084
+ .replace(/&/g, '-and-') // Replace & with 'and'
2085
+ .replace(/[^\w\-]+/g, '') // Remove all non-word characters
2086
+ .replace(/\-\-+/g, '-') // Replace multiple - with single -
2087
+ .replace(/^-+/, '') // Trim - from start of text
2088
+ .replace(/-+$/, ''); // Trim - from end of text
2089
+ return prefix + result + postfix;
2090
+ };
2024
2091
  return Utils;
2025
2092
  }());
2026
2093
 
@@ -2471,9 +2538,6 @@
2471
2538
  Created:
2472
2539
  14 Aug 2018
2473
2540
 
2474
- Version:
2475
- 1.0
2476
-
2477
2541
  Copyright (c) 2016-2021 Osovitny Inc. All rights reserved.
2478
2542
  </file>
2479
2543
  */