@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,10 +7,11 @@ 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 { __awaiter } from 'tslib';
11
13
  import * as i1$1 from '@angular/router';
12
14
  import { NavigationEnd } from '@angular/router';
13
- import * as i2 from '@angular/common';
14
15
  import { createClient } from 'graphql-ws';
15
16
 
16
17
  /**
@@ -1544,15 +1545,65 @@ class LoaderService {
1544
1545
  constructor() {
1545
1546
  this.isLoading = new BehaviorSubject(false);
1546
1547
  }
1548
+ /**
1549
+ * Start loading manually
1550
+ */
1547
1551
  start() {
1548
- this.isLoading.next(true);
1552
+ if (!this.isLoading.value) {
1553
+ this.isLoading.next(true);
1554
+ this.lastStartTime = new Date().getTime();
1555
+ }
1549
1556
  }
1550
- stop() {
1551
- this.isLoading.next(false);
1557
+ /**
1558
+ * Stop loading manually
1559
+ *
1560
+ * @param duration
1561
+ */
1562
+ stop(duration = 1800) {
1563
+ const diffMs = new Date().getTime() - this.lastStartTime;
1564
+ if (diffMs >= duration) {
1565
+ this.isLoading.next(false);
1566
+ return;
1567
+ }
1568
+ setTimeout(() => {
1569
+ this.isLoading.next(false);
1570
+ }, duration - diffMs);
1552
1571
  }
1572
+ /**
1573
+ * Get loader as observable
1574
+ */
1553
1575
  getAsObservable() {
1554
1576
  return this.isLoading.asObservable();
1555
1577
  }
1578
+ /**
1579
+ * Load until observable done
1580
+ *
1581
+ * @param observable
1582
+ * @param duration
1583
+ */
1584
+ loadUntilObservable(observable, duration = 1800) {
1585
+ return new Observable((subscriber) => {
1586
+ const startFrom = new Date().getTime();
1587
+ this.isLoading.next(true);
1588
+ observable.subscribe({
1589
+ next: (value) => {
1590
+ const diffMs = new Date().getTime() - startFrom;
1591
+ if (diffMs >= duration) {
1592
+ subscriber.next(value);
1593
+ subscriber.complete();
1594
+ this.isLoading.next(false);
1595
+ return;
1596
+ }
1597
+ setTimeout(() => {
1598
+ subscriber.next(value);
1599
+ subscriber.complete();
1600
+ this.isLoading.next(false);
1601
+ }, duration - diffMs);
1602
+ },
1603
+ error: (error) => subscriber.error(error),
1604
+ });
1605
+ });
1606
+ }
1556
1607
  }
1557
1608
  LoaderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: LoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1558
1609
  LoaderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: LoaderService, providedIn: 'root' });
@@ -1639,165 +1690,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImpor
1639
1690
  }]
1640
1691
  }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }]; } });
1641
1692
 
1642
- class FormsService {
1643
- validateAllFormFields(formGroup) {
1644
- Object.keys(formGroup.controls).forEach((field) => {
1645
- const control = formGroup.get(field);
1646
- if (control instanceof UntypedFormControl) {
1647
- control.markAsTouched({ onlySelf: true });
1648
- }
1649
- else if (control instanceof UntypedFormGroup) {
1650
- this.validateAllFormFields(control);
1651
- }
1652
- });
1653
- }
1654
- }
1655
- FormsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1656
- FormsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, providedIn: 'root' });
1657
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, decorators: [{
1658
- type: Injectable,
1659
- args: [{
1660
- providedIn: 'root',
1661
- }]
1662
- }] });
1663
-
1664
- class UserService extends GraphQLPlusService {
1665
- constructor(apollo, graphqlMetaService, loaderService, authService) {
1666
- super(apollo, graphqlMetaService, loaderService);
1667
- this.apollo = apollo;
1668
- this.graphqlMetaService = graphqlMetaService;
1669
- this.loaderService = loaderService;
1670
- this.authService = authService;
1671
- }
1672
- /**
1673
- * Login
1674
- *
1675
- * @param input
1676
- */
1677
- login(input) {
1678
- return this.graphQl('signIn', {
1679
- arguments: { input },
1680
- fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
1681
- type: GraphQLRequestType.QUERY,
1682
- loading: true,
1683
- }).pipe(map$1((response) => {
1684
- this.authService.token = response.token;
1685
- this.authService.currentUser = response.user;
1686
- return Auth.map({
1687
- token: response.token,
1688
- user: BasicUser.map(response.user),
1689
- });
1690
- }));
1691
- }
1692
- /**
1693
- * Register
1694
- *
1695
- * @param input
1696
- */
1697
- register(input) {
1698
- return this.graphQl('signUp', {
1699
- arguments: { input },
1700
- fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
1701
- type: GraphQLRequestType.MUTATION,
1702
- loading: true,
1703
- }).pipe(map$1((response) => {
1704
- this.authService.token = response.token;
1705
- this.authService.currentUser = response.user;
1706
- return Auth.map({
1707
- token: response.token,
1708
- user: BasicUser.map(response.user),
1709
- });
1710
- }));
1711
- }
1712
- /**
1713
- * This function will make a GraphQL query to the server, and return the result
1714
- *
1715
- * @param id - The id of the user you want to get
1716
- * @returns A GraphQLRequest object.
1717
- */
1718
- get(id) {
1719
- return this.graphQl('getUser', {
1720
- arguments: { id },
1721
- fields: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'],
1722
- type: GraphQLRequestType.QUERY,
1723
- loading: true,
1724
- });
1725
- }
1726
- /**
1727
- * Request password reset mail
1728
- *
1729
- * @param email
1730
- */
1731
- requestPasswordResetMail(email) {
1732
- return this.graphQl('requestPasswordResetMail', {
1733
- arguments: { email },
1734
- fields: [],
1735
- type: GraphQLRequestType.QUERY,
1736
- loading: true,
1737
- });
1738
- }
1739
- /**
1740
- * Change password of current user
1741
- *
1742
- * @param id
1743
- * @param password
1744
- */
1745
- changePassword(id, password) {
1746
- return this.graphQl('updateUser', {
1747
- arguments: { id, input: { password } },
1748
- fields: ['id'],
1749
- type: GraphQLRequestType.MUTATION,
1750
- loading: true,
1751
- });
1752
- }
1753
- /**
1754
- * Set new password by token
1755
- *
1756
- * @param token
1757
- * @param password
1758
- */
1759
- resetPassword(token, password) {
1760
- return this.graphQl('resetPassword', {
1761
- arguments: { token, password },
1762
- type: GraphQLRequestType.MUTATION,
1763
- loading: true,
1764
- });
1765
- }
1766
- /**
1767
- * Delete user by id
1768
- *
1769
- * @param id
1770
- */
1771
- delete(id) {
1772
- return this.graphQl('deleteUser', {
1773
- arguments: { id },
1774
- fields: ['id'],
1775
- type: GraphQLRequestType.MUTATION,
1776
- loading: true,
1777
- });
1778
- }
1779
- /**
1780
- * Verify user by token
1781
- *
1782
- * @param token
1783
- */
1784
- verifyUser(token) {
1785
- return this.graphQl('verifyUser', {
1786
- arguments: { token },
1787
- type: GraphQLRequestType.MUTATION,
1788
- loading: true,
1789
- });
1790
- }
1791
- }
1792
- 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 });
1793
- UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, providedIn: 'root' });
1794
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, decorators: [{
1795
- type: Injectable,
1796
- args: [{
1797
- providedIn: 'root',
1798
- }]
1799
- }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }, { type: AuthService }]; } });
1800
-
1801
1693
  /**
1802
1694
  * Image service
1803
1695
  */
@@ -2060,6 +1952,188 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImpor
2060
1952
  }] }, { type: ImageService }];
2061
1953
  } });
2062
1954
 
1955
+ class FormsService {
1956
+ constructor(document, scrollService) {
1957
+ this.document = document;
1958
+ this.scrollService = scrollService;
1959
+ }
1960
+ validateAllFormFields(formGroup) {
1961
+ Object.keys(formGroup.controls).forEach((field) => {
1962
+ const control = formGroup.get(field);
1963
+ if (control instanceof UntypedFormControl) {
1964
+ control.markAsTouched({ onlySelf: true });
1965
+ }
1966
+ else if (control instanceof UntypedFormGroup) {
1967
+ this.validateAllFormFields(control);
1968
+ }
1969
+ });
1970
+ }
1971
+ findInvalidControls(formGroup) {
1972
+ const invalid = [];
1973
+ const controls = formGroup.controls;
1974
+ Object.keys(formGroup.controls).forEach((name) => {
1975
+ if (controls[name].invalid) {
1976
+ invalid.push(name);
1977
+ }
1978
+ });
1979
+ return invalid;
1980
+ }
1981
+ scrollToInvalidControl(form) {
1982
+ const invalidForm = this.findInvalidControls(form)[0];
1983
+ this.scrollService.scrollTo(invalidForm);
1984
+ }
1985
+ }
1986
+ 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 });
1987
+ FormsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, providedIn: 'root' });
1988
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: FormsService, decorators: [{
1989
+ type: Injectable,
1990
+ args: [{
1991
+ providedIn: 'root',
1992
+ }]
1993
+ }], ctorParameters: function () {
1994
+ return [{ type: Document, decorators: [{
1995
+ type: Inject,
1996
+ args: [DOCUMENT]
1997
+ }] }, { type: ScrollService }];
1998
+ } });
1999
+
2000
+ class UserService extends GraphQLPlusService {
2001
+ constructor(apollo, graphqlMetaService, loaderService, authService) {
2002
+ super(apollo, graphqlMetaService, loaderService);
2003
+ this.apollo = apollo;
2004
+ this.graphqlMetaService = graphqlMetaService;
2005
+ this.loaderService = loaderService;
2006
+ this.authService = authService;
2007
+ }
2008
+ /**
2009
+ * Login
2010
+ *
2011
+ * @param input
2012
+ */
2013
+ login(input) {
2014
+ return this.graphQl('signIn', {
2015
+ arguments: { input },
2016
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
2017
+ type: GraphQLRequestType.QUERY,
2018
+ loading: true,
2019
+ }).pipe(map$1((response) => {
2020
+ this.authService.token = response.token;
2021
+ this.authService.currentUser = response.user;
2022
+ return Auth.map({
2023
+ token: response.token,
2024
+ user: BasicUser.map(response.user),
2025
+ });
2026
+ }));
2027
+ }
2028
+ /**
2029
+ * Register
2030
+ *
2031
+ * @param input
2032
+ */
2033
+ register(input) {
2034
+ return this.graphQl('signUp', {
2035
+ arguments: { input },
2036
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
2037
+ type: GraphQLRequestType.MUTATION,
2038
+ loading: true,
2039
+ }).pipe(map$1((response) => {
2040
+ this.authService.token = response.token;
2041
+ this.authService.currentUser = response.user;
2042
+ return Auth.map({
2043
+ token: response.token,
2044
+ user: BasicUser.map(response.user),
2045
+ });
2046
+ }));
2047
+ }
2048
+ /**
2049
+ * This function will make a GraphQL query to the server, and return the result
2050
+ *
2051
+ * @param id - The id of the user you want to get
2052
+ * @returns A GraphQLRequest object.
2053
+ */
2054
+ get(id) {
2055
+ return this.graphQl('getUser', {
2056
+ arguments: { id },
2057
+ fields: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'],
2058
+ type: GraphQLRequestType.QUERY,
2059
+ loading: true,
2060
+ });
2061
+ }
2062
+ /**
2063
+ * Request password reset mail
2064
+ *
2065
+ * @param email
2066
+ */
2067
+ requestPasswordResetMail(email) {
2068
+ return this.graphQl('requestPasswordResetMail', {
2069
+ arguments: { email },
2070
+ fields: [],
2071
+ type: GraphQLRequestType.QUERY,
2072
+ loading: true,
2073
+ });
2074
+ }
2075
+ /**
2076
+ * Change password of current user
2077
+ *
2078
+ * @param id
2079
+ * @param password
2080
+ */
2081
+ changePassword(id, password) {
2082
+ return this.graphQl('updateUser', {
2083
+ arguments: { id, input: { password } },
2084
+ fields: ['id'],
2085
+ type: GraphQLRequestType.MUTATION,
2086
+ loading: true,
2087
+ });
2088
+ }
2089
+ /**
2090
+ * Set new password by token
2091
+ *
2092
+ * @param token
2093
+ * @param password
2094
+ */
2095
+ resetPassword(token, password) {
2096
+ return this.graphQl('resetPassword', {
2097
+ arguments: { token, password },
2098
+ type: GraphQLRequestType.MUTATION,
2099
+ loading: true,
2100
+ });
2101
+ }
2102
+ /**
2103
+ * Delete user by id
2104
+ *
2105
+ * @param id
2106
+ */
2107
+ delete(id) {
2108
+ return this.graphQl('deleteUser', {
2109
+ arguments: { id },
2110
+ fields: ['id'],
2111
+ type: GraphQLRequestType.MUTATION,
2112
+ loading: true,
2113
+ });
2114
+ }
2115
+ /**
2116
+ * Verify user by token
2117
+ *
2118
+ * @param token
2119
+ */
2120
+ verifyUser(token) {
2121
+ return this.graphQl('verifyUser', {
2122
+ arguments: { token },
2123
+ type: GraphQLRequestType.MUTATION,
2124
+ loading: true,
2125
+ });
2126
+ }
2127
+ }
2128
+ 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 });
2129
+ UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, providedIn: 'root' });
2130
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: UserService, decorators: [{
2131
+ type: Injectable,
2132
+ args: [{
2133
+ providedIn: 'root',
2134
+ }]
2135
+ }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }, { type: AuthService }]; } });
2136
+
2063
2137
  class ToastService {
2064
2138
  constructor() {
2065
2139
  this.toastsObservables = new BehaviorSubject([]);