@lenne.tech/ng-base 14.10.1 → 14.11.0

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.
@@ -7,9 +7,10 @@ import { gql } from 'apollo-angular';
7
7
  import { sha256 } from 'js-sha256';
8
8
  import { map } from 'rxjs/operators';
9
9
  import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
10
+ import * as i2 from '@angular/common';
11
+ import { DOCUMENT } from '@angular/common';
10
12
  import * as i1$1 from '@angular/router';
11
13
  import { NavigationEnd } from '@angular/router';
12
- import * as i2 from '@angular/common';
13
14
  import { createClient } from 'graphql-ws';
14
15
 
15
16
  /**
@@ -1586,15 +1587,65 @@ class LoaderService {
1586
1587
  constructor() {
1587
1588
  this.isLoading = new BehaviorSubject(false);
1588
1589
  }
1590
+ /**
1591
+ * Start loading manually
1592
+ */
1589
1593
  start() {
1590
- this.isLoading.next(true);
1594
+ if (!this.isLoading.value) {
1595
+ this.isLoading.next(true);
1596
+ this.lastStartTime = new Date().getTime();
1597
+ }
1591
1598
  }
1592
- stop() {
1593
- this.isLoading.next(false);
1599
+ /**
1600
+ * Stop loading manually
1601
+ *
1602
+ * @param duration
1603
+ */
1604
+ stop(duration = 1800) {
1605
+ const diffMs = new Date().getTime() - this.lastStartTime;
1606
+ if (diffMs >= duration) {
1607
+ this.isLoading.next(false);
1608
+ return;
1609
+ }
1610
+ setTimeout(() => {
1611
+ this.isLoading.next(false);
1612
+ }, duration - diffMs);
1594
1613
  }
1614
+ /**
1615
+ * Get loader as observable
1616
+ */
1595
1617
  getAsObservable() {
1596
1618
  return this.isLoading.asObservable();
1597
1619
  }
1620
+ /**
1621
+ * Load until observable done
1622
+ *
1623
+ * @param observable
1624
+ * @param duration
1625
+ */
1626
+ loadUntilObservable(observable, duration = 1800) {
1627
+ return new Observable((subscriber) => {
1628
+ const startFrom = new Date().getTime();
1629
+ this.isLoading.next(true);
1630
+ observable.subscribe({
1631
+ next: (value) => {
1632
+ const diffMs = new Date().getTime() - startFrom;
1633
+ if (diffMs >= duration) {
1634
+ subscriber.next(value);
1635
+ subscriber.complete();
1636
+ this.isLoading.next(false);
1637
+ return;
1638
+ }
1639
+ setTimeout(() => {
1640
+ subscriber.next(value);
1641
+ subscriber.complete();
1642
+ this.isLoading.next(false);
1643
+ }, duration - diffMs);
1644
+ },
1645
+ error: (error) => subscriber.error(error),
1646
+ });
1647
+ });
1648
+ }
1598
1649
  }
1599
1650
  LoaderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: LoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1600
1651
  LoaderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: LoaderService, providedIn: 'root' });
@@ -1681,165 +1732,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImpor
1681
1732
  }]
1682
1733
  }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }]; } });
1683
1734
 
1684
- class FormsService {
1685
- validateAllFormFields(formGroup) {
1686
- Object.keys(formGroup.controls).forEach((field) => {
1687
- const control = formGroup.get(field);
1688
- if (control instanceof UntypedFormControl) {
1689
- control.markAsTouched({ onlySelf: true });
1690
- }
1691
- else if (control instanceof UntypedFormGroup) {
1692
- this.validateAllFormFields(control);
1693
- }
1694
- });
1695
- }
1696
- }
1697
- FormsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1698
- FormsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, providedIn: 'root' });
1699
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, decorators: [{
1700
- type: Injectable,
1701
- args: [{
1702
- providedIn: 'root',
1703
- }]
1704
- }] });
1705
-
1706
- class UserService extends GraphQLPlusService {
1707
- constructor(apollo, graphqlMetaService, loaderService, authService) {
1708
- super(apollo, graphqlMetaService, loaderService);
1709
- this.apollo = apollo;
1710
- this.graphqlMetaService = graphqlMetaService;
1711
- this.loaderService = loaderService;
1712
- this.authService = authService;
1713
- }
1714
- /**
1715
- * Login
1716
- *
1717
- * @param input
1718
- */
1719
- login(input) {
1720
- return this.graphQl('signIn', {
1721
- arguments: { input },
1722
- fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
1723
- type: GraphQLRequestType.QUERY,
1724
- loading: true,
1725
- }).pipe(map$1((response) => {
1726
- this.authService.token = response.token;
1727
- this.authService.currentUser = response.user;
1728
- return Auth.map({
1729
- token: response.token,
1730
- user: BasicUser.map(response.user),
1731
- });
1732
- }));
1733
- }
1734
- /**
1735
- * Register
1736
- *
1737
- * @param input
1738
- */
1739
- register(input) {
1740
- return this.graphQl('signUp', {
1741
- arguments: { input },
1742
- fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
1743
- type: GraphQLRequestType.MUTATION,
1744
- loading: true,
1745
- }).pipe(map$1((response) => {
1746
- this.authService.token = response.token;
1747
- this.authService.currentUser = response.user;
1748
- return Auth.map({
1749
- token: response.token,
1750
- user: BasicUser.map(response.user),
1751
- });
1752
- }));
1753
- }
1754
- /**
1755
- * This function will make a GraphQL query to the server, and return the result
1756
- *
1757
- * @param id - The id of the user you want to get
1758
- * @returns A GraphQLRequest object.
1759
- */
1760
- get(id) {
1761
- return this.graphQl('getUser', {
1762
- arguments: { id },
1763
- fields: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'],
1764
- type: GraphQLRequestType.QUERY,
1765
- loading: true,
1766
- });
1767
- }
1768
- /**
1769
- * Request password reset mail
1770
- *
1771
- * @param email
1772
- */
1773
- requestPasswordResetMail(email) {
1774
- return this.graphQl('requestPasswordResetMail', {
1775
- arguments: { email },
1776
- fields: [],
1777
- type: GraphQLRequestType.QUERY,
1778
- loading: true,
1779
- });
1780
- }
1781
- /**
1782
- * Change password of current user
1783
- *
1784
- * @param id
1785
- * @param password
1786
- */
1787
- changePassword(id, password) {
1788
- return this.graphQl('updateUser', {
1789
- arguments: { id, input: { password } },
1790
- fields: ['id'],
1791
- type: GraphQLRequestType.MUTATION,
1792
- loading: true,
1793
- });
1794
- }
1795
- /**
1796
- * Set new password by token
1797
- *
1798
- * @param token
1799
- * @param password
1800
- */
1801
- resetPassword(token, password) {
1802
- return this.graphQl('resetPassword', {
1803
- arguments: { token, password },
1804
- type: GraphQLRequestType.MUTATION,
1805
- loading: true,
1806
- });
1807
- }
1808
- /**
1809
- * Delete user by id
1810
- *
1811
- * @param id
1812
- */
1813
- delete(id) {
1814
- return this.graphQl('deleteUser', {
1815
- arguments: { id },
1816
- fields: ['id'],
1817
- type: GraphQLRequestType.MUTATION,
1818
- loading: true,
1819
- });
1820
- }
1821
- /**
1822
- * Verify user by token
1823
- *
1824
- * @param token
1825
- */
1826
- verifyUser(token) {
1827
- return this.graphQl('verifyUser', {
1828
- arguments: { token },
1829
- type: GraphQLRequestType.MUTATION,
1830
- loading: true,
1831
- });
1832
- }
1833
- }
1834
- UserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, deps: [{ token: i1.Apollo }, { token: GraphQLMetaService }, { token: LoaderService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable });
1835
- UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, providedIn: 'root' });
1836
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, decorators: [{
1837
- type: Injectable,
1838
- args: [{
1839
- providedIn: 'root',
1840
- }]
1841
- }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }, { type: AuthService }]; } });
1842
-
1843
1735
  /**
1844
1736
  * Image service
1845
1737
  */
@@ -2113,6 +2005,186 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImpor
2113
2005
  args: [BASE_MODULE_CONFIG]
2114
2006
  }] }, { type: ImageService }]; } });
2115
2007
 
2008
+ class FormsService {
2009
+ constructor(document, scrollService) {
2010
+ this.document = document;
2011
+ this.scrollService = scrollService;
2012
+ }
2013
+ validateAllFormFields(formGroup) {
2014
+ Object.keys(formGroup.controls).forEach((field) => {
2015
+ const control = formGroup.get(field);
2016
+ if (control instanceof UntypedFormControl) {
2017
+ control.markAsTouched({ onlySelf: true });
2018
+ }
2019
+ else if (control instanceof UntypedFormGroup) {
2020
+ this.validateAllFormFields(control);
2021
+ }
2022
+ });
2023
+ }
2024
+ findInvalidControls(formGroup) {
2025
+ const invalid = [];
2026
+ const controls = formGroup.controls;
2027
+ Object.keys(formGroup.controls).forEach((name) => {
2028
+ if (controls[name].invalid) {
2029
+ invalid.push(name);
2030
+ }
2031
+ });
2032
+ return invalid;
2033
+ }
2034
+ scrollToInvalidControl(form) {
2035
+ const invalidForm = this.findInvalidControls(form)[0];
2036
+ this.scrollService.scrollTo(invalidForm);
2037
+ }
2038
+ }
2039
+ FormsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, deps: [{ token: DOCUMENT }, { token: ScrollService }], target: i0.ɵɵFactoryTarget.Injectable });
2040
+ FormsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, providedIn: 'root' });
2041
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, decorators: [{
2042
+ type: Injectable,
2043
+ args: [{
2044
+ providedIn: 'root',
2045
+ }]
2046
+ }], ctorParameters: function () { return [{ type: Document, decorators: [{
2047
+ type: Inject,
2048
+ args: [DOCUMENT]
2049
+ }] }, { type: ScrollService }]; } });
2050
+
2051
+ class UserService extends GraphQLPlusService {
2052
+ constructor(apollo, graphqlMetaService, loaderService, authService) {
2053
+ super(apollo, graphqlMetaService, loaderService);
2054
+ this.apollo = apollo;
2055
+ this.graphqlMetaService = graphqlMetaService;
2056
+ this.loaderService = loaderService;
2057
+ this.authService = authService;
2058
+ }
2059
+ /**
2060
+ * Login
2061
+ *
2062
+ * @param input
2063
+ */
2064
+ login(input) {
2065
+ return this.graphQl('signIn', {
2066
+ arguments: { input },
2067
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
2068
+ type: GraphQLRequestType.QUERY,
2069
+ loading: true,
2070
+ }).pipe(map$1((response) => {
2071
+ this.authService.token = response.token;
2072
+ this.authService.currentUser = response.user;
2073
+ return Auth.map({
2074
+ token: response.token,
2075
+ user: BasicUser.map(response.user),
2076
+ });
2077
+ }));
2078
+ }
2079
+ /**
2080
+ * Register
2081
+ *
2082
+ * @param input
2083
+ */
2084
+ register(input) {
2085
+ return this.graphQl('signUp', {
2086
+ arguments: { input },
2087
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
2088
+ type: GraphQLRequestType.MUTATION,
2089
+ loading: true,
2090
+ }).pipe(map$1((response) => {
2091
+ this.authService.token = response.token;
2092
+ this.authService.currentUser = response.user;
2093
+ return Auth.map({
2094
+ token: response.token,
2095
+ user: BasicUser.map(response.user),
2096
+ });
2097
+ }));
2098
+ }
2099
+ /**
2100
+ * This function will make a GraphQL query to the server, and return the result
2101
+ *
2102
+ * @param id - The id of the user you want to get
2103
+ * @returns A GraphQLRequest object.
2104
+ */
2105
+ get(id) {
2106
+ return this.graphQl('getUser', {
2107
+ arguments: { id },
2108
+ fields: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'],
2109
+ type: GraphQLRequestType.QUERY,
2110
+ loading: true,
2111
+ });
2112
+ }
2113
+ /**
2114
+ * Request password reset mail
2115
+ *
2116
+ * @param email
2117
+ */
2118
+ requestPasswordResetMail(email) {
2119
+ return this.graphQl('requestPasswordResetMail', {
2120
+ arguments: { email },
2121
+ fields: [],
2122
+ type: GraphQLRequestType.QUERY,
2123
+ loading: true,
2124
+ });
2125
+ }
2126
+ /**
2127
+ * Change password of current user
2128
+ *
2129
+ * @param id
2130
+ * @param password
2131
+ */
2132
+ changePassword(id, password) {
2133
+ return this.graphQl('updateUser', {
2134
+ arguments: { id, input: { password } },
2135
+ fields: ['id'],
2136
+ type: GraphQLRequestType.MUTATION,
2137
+ loading: true,
2138
+ });
2139
+ }
2140
+ /**
2141
+ * Set new password by token
2142
+ *
2143
+ * @param token
2144
+ * @param password
2145
+ */
2146
+ resetPassword(token, password) {
2147
+ return this.graphQl('resetPassword', {
2148
+ arguments: { token, password },
2149
+ type: GraphQLRequestType.MUTATION,
2150
+ loading: true,
2151
+ });
2152
+ }
2153
+ /**
2154
+ * Delete user by id
2155
+ *
2156
+ * @param id
2157
+ */
2158
+ delete(id) {
2159
+ return this.graphQl('deleteUser', {
2160
+ arguments: { id },
2161
+ fields: ['id'],
2162
+ type: GraphQLRequestType.MUTATION,
2163
+ loading: true,
2164
+ });
2165
+ }
2166
+ /**
2167
+ * Verify user by token
2168
+ *
2169
+ * @param token
2170
+ */
2171
+ verifyUser(token) {
2172
+ return this.graphQl('verifyUser', {
2173
+ arguments: { token },
2174
+ type: GraphQLRequestType.MUTATION,
2175
+ loading: true,
2176
+ });
2177
+ }
2178
+ }
2179
+ UserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, deps: [{ token: i1.Apollo }, { token: GraphQLMetaService }, { token: LoaderService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable });
2180
+ UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, providedIn: 'root' });
2181
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, decorators: [{
2182
+ type: Injectable,
2183
+ args: [{
2184
+ providedIn: 'root',
2185
+ }]
2186
+ }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }, { type: AuthService }]; } });
2187
+
2116
2188
  class ToastService {
2117
2189
  constructor() {
2118
2190
  this.toastsObservables = new BehaviorSubject([]);