ngrx-entity-crud 12.0.6-beta.2

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.
Files changed (184) hide show
  1. package/README.md +259 -0
  2. package/bundles/ngrx-entity-crud.umd.js +1829 -0
  3. package/bundles/ngrx-entity-crud.umd.js.map +1 -0
  4. package/esm2015/lib/actions.js +88 -0
  5. package/esm2015/lib/base-crud-gql.service.js +71 -0
  6. package/esm2015/lib/base-crud.service.js +136 -0
  7. package/esm2015/lib/create_adapter.js +14 -0
  8. package/esm2015/lib/effect.js +467 -0
  9. package/esm2015/lib/entity_state.js +23 -0
  10. package/esm2015/lib/ibase-crud-service.js +2 -0
  11. package/esm2015/lib/j-ngrx-filter.js +133 -0
  12. package/esm2015/lib/models.js +17 -0
  13. package/esm2015/lib/reducer.js +353 -0
  14. package/esm2015/lib/state_selectors.js +56 -0
  15. package/esm2015/lib/utils.js +19 -0
  16. package/esm2015/ngrx-entity-crud.js +5 -0
  17. package/esm2015/public-api.js +7 -0
  18. package/fesm2015/ngrx-entity-crud.js +1367 -0
  19. package/fesm2015/ngrx-entity-crud.js.map +1 -0
  20. package/lib/actions.d.ts +5 -0
  21. package/lib/actions.d.ts.map +1 -0
  22. package/lib/base-crud-gql.service.d.ts +19 -0
  23. package/lib/base-crud-gql.service.d.ts.map +1 -0
  24. package/lib/base-crud.service.d.ts +34 -0
  25. package/lib/base-crud.service.d.ts.map +1 -0
  26. package/lib/create_adapter.d.ts +6 -0
  27. package/lib/create_adapter.d.ts.map +1 -0
  28. package/lib/effect.d.ts +132 -0
  29. package/lib/effect.d.ts.map +1 -0
  30. package/lib/entity_state.d.ts +9 -0
  31. package/lib/entity_state.d.ts.map +1 -0
  32. package/lib/ibase-crud-service.d.ts +13 -0
  33. package/lib/ibase-crud-service.d.ts.map +1 -0
  34. package/lib/j-ngrx-filter.d.ts +14 -0
  35. package/lib/j-ngrx-filter.d.ts.map +1 -0
  36. package/lib/models.d.ts +494 -0
  37. package/lib/models.d.ts.map +1 -0
  38. package/lib/reducer.d.ts +11 -0
  39. package/lib/reducer.d.ts.map +1 -0
  40. package/lib/state_selectors.d.ts +5 -0
  41. package/lib/state_selectors.d.ts.map +1 -0
  42. package/lib/utils.d.ts +8 -0
  43. package/lib/utils.d.ts.map +1 -0
  44. package/ngrx-entity-crud.d.ts +5 -0
  45. package/ngrx-entity-crud.d.ts.map +1 -0
  46. package/ngrx-entity-crud.metadata.json +1 -0
  47. package/package.json +41 -0
  48. package/public-api.d.ts +7 -0
  49. package/public-api.d.ts.map +1 -0
  50. package/schematics/auth/files/model/auth.ts +17 -0
  51. package/schematics/auth/files/store/auth-store/actions.ts +30 -0
  52. package/schematics/auth/files/store/auth-store/auth-mock.service.ts +95 -0
  53. package/schematics/auth/files/store/auth-store/auth-store.module.ts +34 -0
  54. package/schematics/auth/files/store/auth-store/auth.guard.ts +44 -0
  55. package/schematics/auth/files/store/auth-store/auth.service.ts +28 -0
  56. package/schematics/auth/files/store/auth-store/conf.ts +2 -0
  57. package/schematics/auth/files/store/auth-store/effects.ts +53 -0
  58. package/schematics/auth/files/store/auth-store/index.d.ts +13 -0
  59. package/schematics/auth/files/store/auth-store/index.ts +13 -0
  60. package/schematics/auth/files/store/auth-store/names.ts +3 -0
  61. package/schematics/auth/files/store/auth-store/reducer.ts +16 -0
  62. package/schematics/auth/files/store/auth-store/selectors.ts +51 -0
  63. package/schematics/auth/files/store/auth-store/state.ts +16 -0
  64. package/schematics/auth/files/views/login/components/logout-button/logout-button.component.ts +49 -0
  65. package/schematics/auth/files/views/login/login-main/login-main.component.html +25 -0
  66. package/schematics/auth/files/views/login/login-main/login-main.component.ts +57 -0
  67. package/schematics/auth/files/views/login/login-routing.module.ts +30 -0
  68. package/schematics/auth/files/views/login/login.module.ts +30 -0
  69. package/schematics/auth/index.d.ts +2 -0
  70. package/schematics/auth/index.js +77 -0
  71. package/schematics/auth/index.js.map +1 -0
  72. package/schematics/auth/schema.json +21 -0
  73. package/schematics/auth0/files/store/auth-store/actions.ts +21 -0
  74. package/schematics/auth0/files/store/auth-store/auth-store.module.ts +32 -0
  75. package/schematics/auth0/files/store/auth-store/auth.guard.ts +44 -0
  76. package/schematics/auth0/files/store/auth-store/authentication.service.ts +32 -0
  77. package/schematics/auth0/files/store/auth-store/conf.ts +2 -0
  78. package/schematics/auth0/files/store/auth-store/effects.ts +59 -0
  79. package/schematics/auth0/files/store/auth-store/index.d.ts +13 -0
  80. package/schematics/auth0/files/store/auth-store/index.ts +13 -0
  81. package/schematics/auth0/files/store/auth-store/login.component.ts +75 -0
  82. package/schematics/auth0/files/store/auth-store/names.ts +3 -0
  83. package/schematics/auth0/files/store/auth-store/profile.ts +12 -0
  84. package/schematics/auth0/files/store/auth-store/reducer.ts +23 -0
  85. package/schematics/auth0/files/store/auth-store/selectors.ts +24 -0
  86. package/schematics/auth0/files/store/auth-store/state.ts +11 -0
  87. package/schematics/auth0/index.d.ts +2 -0
  88. package/schematics/auth0/index.js +67 -0
  89. package/schematics/auth0/index.js.map +1 -0
  90. package/schematics/auth0/schema.json +21 -0
  91. package/schematics/collection.json +30 -0
  92. package/schematics/my-utility.d.ts +58 -0
  93. package/schematics/my-utility.js +257 -0
  94. package/schematics/my-utility.js.map +1 -0
  95. package/schematics/ng-add/files/root-store/index.d.ts +8 -0
  96. package/schematics/ng-add/files/root-store/index.ts +8 -0
  97. package/schematics/ng-add/files/root-store/root-reducer.ts +11 -0
  98. package/schematics/ng-add/files/root-store/root-store.module.ts +29 -0
  99. package/schematics/ng-add/files/root-store/router-store/actions.ts +27 -0
  100. package/schematics/ng-add/files/root-store/router-store/effects.ts +65 -0
  101. package/schematics/ng-add/files/root-store/router-store/index.d.ts +11 -0
  102. package/schematics/ng-add/files/root-store/router-store/index.ts +11 -0
  103. package/schematics/ng-add/files/root-store/router-store/pop-up-base.component.ts +83 -0
  104. package/schematics/ng-add/files/root-store/router-store/pop-up-base.module.ts +24 -0
  105. package/schematics/ng-add/files/root-store/router-store/reducer.ts +31 -0
  106. package/schematics/ng-add/files/root-store/router-store/router-store.module.ts +30 -0
  107. package/schematics/ng-add/files/root-store/router-store/selectors.ts +63 -0
  108. package/schematics/ng-add/files/root-store/router-store/state.ts +18 -0
  109. package/schematics/ng-add/files/root-store/selectors.ts +20 -0
  110. package/schematics/ng-add/files/root-store/slide-menu-store/actions.ts +11 -0
  111. package/schematics/ng-add/files/root-store/slide-menu-store/effects.ts +10 -0
  112. package/schematics/ng-add/files/root-store/slide-menu-store/index.d.ts +13 -0
  113. package/schematics/ng-add/files/root-store/slide-menu-store/index.ts +13 -0
  114. package/schematics/ng-add/files/root-store/slide-menu-store/names.ts +3 -0
  115. package/schematics/ng-add/files/root-store/slide-menu-store/operators.ts +24 -0
  116. package/schematics/ng-add/files/root-store/slide-menu-store/reducer.ts +8 -0
  117. package/schematics/ng-add/files/root-store/slide-menu-store/selectors.ts +41 -0
  118. package/schematics/ng-add/files/root-store/slide-menu-store/slide-menu-store.module.ts +27 -0
  119. package/schematics/ng-add/files/root-store/slide-menu-store/state.ts +14 -0
  120. package/schematics/ng-add/files/root-store/state.ts +5 -0
  121. package/schematics/ng-add/index.d.ts +2 -0
  122. package/schematics/ng-add/index.js +78 -0
  123. package/schematics/ng-add/index.js.map +1 -0
  124. package/schematics/ng-add/schema.json +22 -0
  125. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.html +52 -0
  126. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.ts +57 -0
  127. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.html +7 -0
  128. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.ts +50 -0
  129. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.html +15 -0
  130. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.ts +23 -0
  131. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__-routing.module.ts +36 -0
  132. package/schematics/section/files/ionic/__clazz@dasherize__/__clazz@dasherize__.module.ts +33 -0
  133. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.html +1 -0
  134. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.ts +16 -0
  135. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.html +1 -0
  136. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.ts +27 -0
  137. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.html +1 -0
  138. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.ts +18 -0
  139. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__-routing.module.ts +36 -0
  140. package/schematics/section/files/no-libs/__clazz@dasherize__/__clazz@dasherize__.module.ts +26 -0
  141. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.html +38 -0
  142. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-edit/__clazz@dasherize__-edit.component.ts +50 -0
  143. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.html +30 -0
  144. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-list/__clazz@dasherize__-list.component.ts +101 -0
  145. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.html +12 -0
  146. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-main/__clazz@dasherize__-main.component.ts +21 -0
  147. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__-routing.module.ts +37 -0
  148. package/schematics/section/files/primeng/__clazz@dasherize__/__clazz@dasherize__.module.ts +49 -0
  149. package/schematics/section/files/primeng/__clazz@dasherize__/components/button-create-many-test-__clazz@dasherize__.component.ts +46 -0
  150. package/schematics/section/files/primeng/__clazz@dasherize__/components/button-delete-__clazz@dasherize__.component.ts +35 -0
  151. package/schematics/section/files/primeng/__clazz@dasherize__/components/button-edit-many-test-__clazz@dasherize__.component.ts +45 -0
  152. package/schematics/section/files/primeng/__clazz@dasherize__/components/button-new-__clazz@dasherize__.component.ts +45 -0
  153. package/schematics/section/index.d.ts +2 -0
  154. package/schematics/section/index.js +56 -0
  155. package/schematics/section/index.js.map +1 -0
  156. package/schematics/section/schema.json +39 -0
  157. package/schematics/store/files/base-model/__clazz@dasherize__.ts +8 -0
  158. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__-store.module.ts +26 -0
  159. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.actions.ts +9 -0
  160. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.effects.ts +11 -0
  161. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.names.ts +3 -0
  162. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.reducer.ts +8 -0
  163. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.selectors.ts +18 -0
  164. package/schematics/store/files/base-store/__clazz@dasherize__-store/__clazz@dasherize__.state.ts +6 -0
  165. package/schematics/store/files/base-store/__clazz@dasherize__-store/index.d.ts +13 -0
  166. package/schematics/store/files/base-store/__clazz@dasherize__-store/index.ts +13 -0
  167. package/schematics/store/files/crud-graphql/__clazz@dasherize__-store/__clazz@dasherize__.criteria.ts +39 -0
  168. package/schematics/store/files/crud-graphql/__clazz@dasherize__-store/__clazz@dasherize__.graphql +34 -0
  169. package/schematics/store/files/crud-model/__clazz@dasherize__.ts +8 -0
  170. package/schematics/store/files/crud-service/__clazz@dasherize__.service.ts +11 -0
  171. package/schematics/store/files/crud-service-graphql/__clazz@dasherize__.service.ts +16 -0
  172. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__-store.module.ts +26 -0
  173. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.actions.ts +55 -0
  174. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.effects.ts +90 -0
  175. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.names.ts +3 -0
  176. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.reducer.ts +103 -0
  177. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.selectors.ts +26 -0
  178. package/schematics/store/files/crud-store/__clazz@dasherize__-store/__clazz@dasherize__.state.ts +11 -0
  179. package/schematics/store/files/crud-store/__clazz@dasherize__-store/index.d.ts +15 -0
  180. package/schematics/store/files/crud-store/__clazz@dasherize__-store/index.ts +15 -0
  181. package/schematics/store/index.d.ts +2 -0
  182. package/schematics/store/index.js +100 -0
  183. package/schematics/store/index.js.map +1 -0
  184. package/schematics/store/schema.json +45 -0
@@ -0,0 +1,17 @@
1
+ export class AuthUser {
2
+ public user: string;
3
+ public email: string;
4
+ public password: string;
5
+ public firstname: string;
6
+ public lastname: string;
7
+ public age: number;
8
+ public id: number;
9
+
10
+ }
11
+
12
+ export class Auth {
13
+ token: string;
14
+ user: AuthUser;
15
+ roles: string[];
16
+ }
17
+
@@ -0,0 +1,30 @@
1
+ import {createAction, props} from '@ngrx/store';
2
+ import {HttpErrorResponse} from '@angular/common/http';
3
+ import {Auth} from '@models/vo/auth';
4
+
5
+ export enum ActionTypes {
6
+ LOGIN_REQUEST = '[Auth] Login Request',
7
+ LOGIN_RESULT = '[Auth] Login Result',
8
+ LOGIN_ERROR = '[Auth] Login Error',
9
+
10
+ RESET = '[Auth] Reset',
11
+
12
+ LOGOUT_REQUEST = '[Auth] Logout Request',
13
+ LOGOUT_RESULT = '[Auth] Logout Result',
14
+ LOGOUT_ERROR = '[Auth] Logout Error',
15
+
16
+ GO_TO_LOGIN = '[Auth] Go to login',
17
+ }
18
+
19
+ export const LoginRequest = createAction(ActionTypes.LOGIN_REQUEST, props<{ username: string, password: string }>());
20
+ export const LoginResult = createAction(ActionTypes.LOGIN_RESULT, props<{ isLoggedIn: boolean, auth: Auth }>());
21
+ export const LoginError = createAction(ActionTypes.LOGIN_ERROR, props<{ err: HttpErrorResponse }>());
22
+
23
+ export const Reset = createAction(ActionTypes.RESET);
24
+
25
+ export const LogoutRequest = createAction(ActionTypes.LOGOUT_REQUEST);
26
+ export const LogoutResult = createAction(ActionTypes.LOGOUT_RESULT);
27
+ export const LogoutError = createAction(ActionTypes.LOGOUT_ERROR);
28
+
29
+ export const GoToLogin = createAction(ActionTypes.GO_TO_LOGIN);
30
+
@@ -0,0 +1,95 @@
1
+ import {Injectable} from '@angular/core';
2
+ import {HttpClient} from '@angular/common/http';
3
+ import {Observable, of, throwError} from 'rxjs';
4
+ import {environment} from '../../../environments/environment';
5
+ import {Auth} from '@models/vo/auth';
6
+
7
+ @Injectable({
8
+ providedIn: 'root'
9
+ })
10
+ export class AuthMockService {
11
+
12
+ service = environment.webServiceUri;
13
+
14
+ constructor(public http: HttpClient) {
15
+ }
16
+
17
+ login(user: string, passwd: string): Observable<Auth> {
18
+ console.log('AuthService.login()');
19
+ console.log('user', user);
20
+ console.log('passwd', passwd);
21
+ if (authMocks.hasOwnProperty(user)) {
22
+ const result = authMocks[user];
23
+ if (result.user.password === passwd) {
24
+ return of(result);
25
+ }
26
+ return throwError({message: `error passwd:${passwd} for user: "${user}"`});
27
+ }
28
+ return throwError({message: `user:"${user}" does not exist`});
29
+ }
30
+
31
+ logout(): Observable<boolean> {
32
+ console.log('AuthMockService.logout()');
33
+ return of(true);
34
+ }
35
+ }
36
+
37
+ const cipo: Auth = {
38
+ token: 'xxx.xxx.xxx',
39
+ roles: ['roleA'],
40
+ user: {
41
+ user: 'cipo',
42
+ email: 'cipollino@mail.com',
43
+ password: 'cipo',
44
+ firstname: 'Cipo',
45
+ lastname: 'Lino',
46
+ age: 32,
47
+ id: 1
48
+ }
49
+ };
50
+
51
+ const cino: Auth = {
52
+ token: 'xxx.xxx.xxx',
53
+ roles: ['roleA', 'roleB', 'roleC'],
54
+ user: {
55
+ user: 'cino',
56
+ email: 'leoncino@mail.com',
57
+ password: 'cino',
58
+ firstname: 'Cino',
59
+ lastname: 'Leon',
60
+ age: 32,
61
+ id: 2
62
+ }
63
+ };
64
+
65
+ const pino: Auth = {
66
+ token: 'xxx.xxx.xxx',
67
+ roles: ['roleA', 'roleB', 'roleC'],
68
+ user: {
69
+ user: 'pino',
70
+ email: 'pinosilvestre@mail.com',
71
+ password: 'pino',
72
+ firstname: 'Pino',
73
+ lastname: 'Silvestre',
74
+ age: 32,
75
+ id: 3
76
+ }
77
+ };
78
+ const poli: Auth = {
79
+ token: 'xxx.xxx.xxx',
80
+ roles: ['roleA', 'roleB', 'roleC'],
81
+ user: {
82
+ user: 'poli',
83
+ email: 'poliester@mail.com',
84
+ password: 'poli',
85
+ firstname: 'Poli',
86
+ lastname: 'Ester',
87
+ age: 32,
88
+ id: 4
89
+ }
90
+ };
91
+
92
+ const authMocks: { [key: string]: Auth } = {
93
+ cipo, cino, pino, poli
94
+ };
95
+
@@ -0,0 +1,34 @@
1
+ import {InjectionToken, NgModule} from '@angular/core';
2
+ import {CommonModule} from '@angular/common';
3
+ import {ActionReducer, StoreModule} from '@ngrx/store';
4
+ import {EffectsModule} from '@ngrx/effects';
5
+ import {AuthStoreEffects} from './effects';
6
+ import {featureReducer} from './reducer';
7
+ import {Auth} from '@models/vo/auth';
8
+ import {Names} from './names';
9
+ import {State} from './state';
10
+ import {AuthService} from './auth.service';
11
+ import {AuthMockService} from './auth-mock.service';
12
+
13
+ export const INJECTION_TOKEN = new InjectionToken<ActionReducer<Auth>>(`${Names.NAME}-store Reducers`);
14
+
15
+ @NgModule({
16
+ imports: [
17
+ CommonModule,
18
+ StoreModule.forFeature(Names.NAME, INJECTION_TOKEN),
19
+ EffectsModule.forFeature([AuthStoreEffects]),
20
+ ],
21
+ declarations: [],
22
+ providers: [AuthStoreEffects,
23
+ {
24
+ provide: AuthService,
25
+ useClass: AuthMockService
26
+ },
27
+ {
28
+ provide: INJECTION_TOKEN,
29
+ useFactory: (): ActionReducer<State> => featureReducer
30
+ }
31
+ ]
32
+ })
33
+ export class AuthStoreModule {
34
+ }
@@ -0,0 +1,44 @@
1
+ import {Injectable} from '@angular/core';
2
+ import {ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot} from '@angular/router';
3
+ import {select, Store} from '@ngrx/store';
4
+ import * as AuthStoreSelectors from './selectors';
5
+ import * as AuthStoreActions from './actions';
6
+ import {map} from 'rxjs/operators';
7
+ import {Observable} from 'rxjs';
8
+
9
+ @Injectable({
10
+ providedIn: 'root'
11
+ })
12
+ export class AuthGuard implements CanActivate, CanActivateChild {
13
+
14
+ constructor(private readonly store$: Store) {
15
+
16
+ }
17
+
18
+ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
19
+ console.log('AuthGuard.canActivate()');
20
+ return this.store$.pipe(
21
+ select(AuthStoreSelectors.selectIsLoggedIn),
22
+ map(selectIsLoggedIn => {
23
+ if (!selectIsLoggedIn) {
24
+ this.store$.dispatch(AuthStoreActions.GoToLogin());
25
+ }
26
+ return selectIsLoggedIn;
27
+ })
28
+ );
29
+ }
30
+
31
+ canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
32
+ console.log('AuthGuard.canActivateChild()');
33
+ return this.store$.pipe(
34
+ select(AuthStoreSelectors.selectIsLoggedIn),
35
+ map(selectIsLoggedIn => {
36
+ if (!selectIsLoggedIn) {
37
+ this.store$.dispatch(AuthStoreActions.GoToLogin());
38
+ }
39
+ return selectIsLoggedIn;
40
+ })
41
+ );
42
+ }
43
+
44
+ }
@@ -0,0 +1,28 @@
1
+ import {Injectable} from '@angular/core';
2
+ import {HttpClient} from '@angular/common/http';
3
+ import {Observable} from 'rxjs';
4
+ import {environment} from '../../../environments/environment';
5
+ import {Auth} from '@models/vo/auth';
6
+
7
+ @Injectable({
8
+ providedIn: 'root'
9
+ })
10
+ export class AuthService {
11
+
12
+ service = environment.webServiceUri;
13
+
14
+ constructor(public http: HttpClient) {
15
+ }
16
+
17
+ login(email: string, password: string): Observable<Auth> {
18
+ console.log('AuthService.login()');
19
+ // return this.http.post(this.service + '/login', {user, passwd});
20
+ throw new Error('method not implemented');
21
+ }
22
+
23
+ logout(): Observable<boolean> {
24
+ console.log('AuthService.logout()');
25
+ throw new Error('method not implemented');
26
+ }
27
+
28
+ }
@@ -0,0 +1,2 @@
1
+ export const afterLoginUri = 'home';
2
+ export const afterLogoutUri = 'login';
@@ -0,0 +1,53 @@
1
+ import {Injectable} from '@angular/core';
2
+ import {Actions, createEffect, ofType} from '@ngrx/effects';
3
+ import * as actions from './actions';
4
+ import {catchError, switchMap} from 'rxjs/operators';
5
+ import {RouterGo} from '@root-store/router-store/actions';
6
+ import {AuthService} from './auth.service';
7
+ import {afterLoginUri, afterLogoutUri} from './conf';
8
+
9
+ @Injectable()
10
+ export class AuthStoreEffects {
11
+ constructor(private readonly actions$: Actions, private readonly authService: AuthService) {
12
+ }
13
+
14
+ login$ = createEffect(() =>
15
+ this.actions$.pipe(
16
+ ofType(actions.LoginRequest),
17
+ switchMap((payload) => this.authService.login(payload.username, payload.password).pipe(
18
+ switchMap(auth => [
19
+ RouterGo({path: [afterLoginUri]}),
20
+ actions.LoginResult({auth, isLoggedIn: true})
21
+ ]
22
+ ),
23
+ catchError(err => {
24
+ return [actions.LoginError({err})];
25
+ }),
26
+ )),
27
+ )
28
+ );
29
+
30
+ logout$ = createEffect(() =>
31
+ this.actions$.pipe(
32
+ ofType(actions.LogoutRequest),
33
+ switchMap((payload) => this.authService.logout().pipe(
34
+ switchMap(user => [
35
+ RouterGo({path: [afterLogoutUri]}),
36
+ actions.LogoutResult()
37
+ ]
38
+ ),
39
+ catchError(err => {
40
+ return [actions.LogoutError()];
41
+ }),
42
+ )),
43
+ )
44
+ );
45
+
46
+ goToLogin$ = createEffect(() =>
47
+ this.actions$.pipe(
48
+ ofType(actions.GoToLogin),
49
+ switchMap(() => [RouterGo({path: [afterLogoutUri]})])
50
+ )
51
+ );
52
+
53
+ }
@@ -0,0 +1,13 @@
1
+ import * as AuthStoreActions from './actions';
2
+ import * as AuthStoreSelectors from './selectors';
3
+ import * as AuthStoreState from './state';
4
+
5
+ export {
6
+ AuthStoreModule
7
+ } from './auth-store.module';
8
+
9
+ export {
10
+ AuthStoreActions,
11
+ AuthStoreSelectors,
12
+ AuthStoreState
13
+ };
@@ -0,0 +1,13 @@
1
+ import * as AuthStoreActions from './actions';
2
+ import * as AuthStoreSelectors from './selectors';
3
+ import * as AuthStoreState from './state';
4
+
5
+ export {
6
+ AuthStoreModule
7
+ } from './auth-store.module';
8
+
9
+ export {
10
+ AuthStoreActions,
11
+ AuthStoreSelectors,
12
+ AuthStoreState
13
+ };
@@ -0,0 +1,3 @@
1
+ export class Names {
2
+ static NAME = 'auth';
3
+ }
@@ -0,0 +1,16 @@
1
+ import {initialState, State} from './state';
2
+ import {createReducer, on} from '@ngrx/store';
3
+ import * as actions from './actions';
4
+
5
+ export const featureReducer = createReducer<State>(initialState,
6
+ // on(actions.Open, (state, {open}) => ({...state, ...{open}})),
7
+ // on(actions.Select, (state, {item}) => ({...state, ...{item}})),
8
+ on(actions.LoginResult, (state, {isLoggedIn, auth}) => ({...state, ...{isLoggedIn, auth}})),
9
+ on(actions.LoginError, (state, {err}) => {
10
+ return ({...initialState, err, hasError: true});
11
+ }
12
+ ),
13
+ on(actions.Reset, (state, item) => ({...initialState})),
14
+ on(actions.LogoutResult, (state, item) => ({...initialState})),
15
+ on(actions.LogoutError, (state, item) => ({...initialState})),
16
+ );
@@ -0,0 +1,51 @@
1
+ import {createFeatureSelector, createSelector, MemoizedSelector} from '@ngrx/store';
2
+ import {Names} from './names';
3
+ import {Auth, AuthUser} from '@models/vo/auth';
4
+ import {State} from './state';
5
+ import {HttpErrorResponse} from '@angular/common/http';
6
+
7
+ const getIsLoggedIn = (state: State): boolean => state.isLoggedIn;
8
+ const getAuth = (state: State): Auth => state.auth;
9
+ const getRoles = (data: Auth): string[] => data.roles;
10
+ const getUser = (data: Auth): AuthUser => data.user;
11
+ const getToken = (data: Auth): string => data.token;
12
+ const getHasError = (state: State): boolean => state.hasError;
13
+ const getErr = (state: State): HttpErrorResponse => state.err;
14
+
15
+ export const selectState: MemoizedSelector<object, State> = createFeatureSelector<State>(Names.NAME);
16
+
17
+ export const selectIsLoggedIn: MemoizedSelector<object, boolean> = createSelector(
18
+ selectState,
19
+ getIsLoggedIn
20
+ );
21
+
22
+ export const selectAuth: MemoizedSelector<object, Auth> = createSelector(
23
+ selectState,
24
+ getAuth
25
+ );
26
+
27
+ export const selectRoles: MemoizedSelector<Auth, string[]> = createSelector(
28
+ selectAuth,
29
+ getRoles
30
+ );
31
+
32
+ export const selectUser: MemoizedSelector<Auth, AuthUser> = createSelector(
33
+ selectAuth,
34
+ getUser
35
+ );
36
+
37
+ export const selectToken: MemoizedSelector<Auth, string> = createSelector(
38
+ selectAuth,
39
+ getToken
40
+ );
41
+
42
+ export const selectHasError: MemoizedSelector<object, boolean> = createSelector(
43
+ selectState,
44
+ getHasError
45
+ );
46
+
47
+ export const selectErr: MemoizedSelector<object, HttpErrorResponse> = createSelector(
48
+ selectState,
49
+ getErr
50
+ );
51
+
@@ -0,0 +1,16 @@
1
+ import {HttpErrorResponse} from '@angular/common/http';
2
+ import {Auth} from '@models/vo/auth';
3
+
4
+ export interface State {
5
+ isLoggedIn: boolean;
6
+ auth: Auth;
7
+ hasError: boolean;
8
+ err: HttpErrorResponse;
9
+ }
10
+
11
+ export const initialState: State = {
12
+ isLoggedIn: false,
13
+ auth: new Auth(),
14
+ hasError: false,
15
+ err: null
16
+ };
@@ -0,0 +1,49 @@
1
+ import {ChangeDetectionStrategy, Component, NgModule, OnInit} from '@angular/core';
2
+ import {select, Store} from '@ngrx/store';
3
+ import {CommonModule} from '@angular/common';
4
+ import {ButtonModule} from 'primeng/button';
5
+ import {Observable} from 'rxjs';
6
+ import {AuthStoreActions, AuthStoreSelectors} from '@root-store/auth-store';
7
+
8
+ @Component({
9
+ selector: 'app-logout-button',
10
+ template: `
11
+ <p-button label="Logout" [disabled]="(isLoggedIn$ | async) === false" (click)="logout()"></p-button>
12
+ `,
13
+ styles: [],
14
+ changeDetection: ChangeDetectionStrategy.OnPush
15
+ })
16
+ export class LogoutButtonComponent implements OnInit {
17
+
18
+ isLoggedIn$: Observable<boolean>;
19
+
20
+ constructor(private readonly store$: Store) {
21
+ }
22
+
23
+ ngOnInit(): void {
24
+ this.isLoggedIn$ = this.store$.pipe(
25
+ select(AuthStoreSelectors.selectIsLoggedIn)
26
+ );
27
+ }
28
+
29
+ logout(): void {
30
+ this.store$.dispatch(AuthStoreActions.LogoutRequest());
31
+ }
32
+ }
33
+
34
+ @NgModule({
35
+ declarations: [
36
+ LogoutButtonComponent
37
+ ],
38
+ exports: [
39
+ LogoutButtonComponent
40
+ ],
41
+ imports: [
42
+ CommonModule,
43
+ ButtonModule
44
+ ],
45
+ providers: [],
46
+ entryComponents: []
47
+ })
48
+ export class LogoutButtonModule {
49
+ }
@@ -0,0 +1,25 @@
1
+ <p-card header="Login" [style]="{width: '360px'}" styleClass="p-card-shadow">
2
+
3
+ <div *ngIf="(hasError$ | async)"><small class="p-invalid">{{err$ | async}}</small></div>
4
+ <form class="dynamic-form" [formGroup]="form">
5
+ <div class="p-fluid">
6
+ <div class="p-field">
7
+ <label for="username"><strong>username</strong></label><br>
8
+ <input id="username" name="name" type="text" class="form-control" pInputText [formControl]="username"/>
9
+ <app-form-error-msg [fc]="username"></app-form-error-msg>
10
+ </div>
11
+ <div class="p-field">
12
+ <label for="password"><strong>password</strong></label><br>
13
+ <input id="password" name="name" type="text" class="form-control" pInputText [formControl]="password"/>
14
+ <app-form-error-msg [fc]="password"></app-form-error-msg>
15
+ </div>
16
+ </div>
17
+ </form>
18
+
19
+ <ng-template pTemplate="footer">
20
+ <div class="text-right">
21
+ <p-button label="Login" [disabled]="!form.valid" (click)="submit(form.getRawValue())" icon="pi pi-check mr-2"></p-button>
22
+ </div>
23
+ </ng-template>
24
+ </p-card>
25
+
@@ -0,0 +1,57 @@
1
+ import {Component, OnInit} from '@angular/core';
2
+ import {select, Store} from '@ngrx/store';
3
+ import {AuthStoreActions, AuthStoreSelectors, RootStoreState} from '@root-store/index';
4
+ import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
5
+ import {JValidators} from '@core/utils/j-validators';
6
+ import {Observable} from 'rxjs';
7
+ import {map, tap} from 'rxjs/operators';
8
+
9
+ @Component({
10
+ selector: 'app-login-main',
11
+ templateUrl: 'login-main.component.html',
12
+ styles: []
13
+ })
14
+ export class LoginMainComponent implements OnInit {
15
+
16
+ constructor(
17
+ private readonly store$: Store<RootStoreState.State>,
18
+ private readonly fb: FormBuilder
19
+ ) {
20
+ }
21
+
22
+ form: FormGroup; // form
23
+
24
+ username: FormControl; // attributo
25
+ password: FormControl;
26
+
27
+ hasError$: Observable<boolean>;
28
+ err$: Observable<string>;
29
+
30
+ ngOnInit(): void {
31
+ this.makeFrom();
32
+ this.hasError$ = this.store$.pipe(
33
+ select(AuthStoreSelectors.selectHasError)
34
+ );
35
+
36
+ this.err$ = this.store$.pipe(
37
+ select(AuthStoreSelectors.selectErr),
38
+ tap(sssssssss => console.log('sssssssss', sssssssss)),
39
+ map(value => !!value ? value.message : '')
40
+ );
41
+ }
42
+
43
+ makeFrom(): void {
44
+ this.username = this.fb.control('', JValidators.required());
45
+ this.password = this.fb.control('', JValidators.required());
46
+
47
+ this.form = this.fb.group({
48
+ username: this.username, // attributo
49
+ password: this.password // attributo
50
+ });
51
+ }
52
+
53
+ submit(rawValue: any): void {
54
+ const {username, password} = rawValue;
55
+ this.store$.dispatch(AuthStoreActions.LoginRequest({username, password}));
56
+ }
57
+ }
@@ -0,0 +1,30 @@
1
+ import {NgModule} from '@angular/core';
2
+ import {RouterModule, Routes} from '@angular/router';
3
+ import {LoginMainComponent} from './login-main/login-main.component';
4
+
5
+ const routes: Routes = [
6
+ {
7
+ path: 'main',
8
+ component: LoginMainComponent,
9
+ pathMatch: 'full'
10
+ },
11
+ {
12
+ path: '',
13
+ redirectTo: 'main',
14
+ pathMatch: 'full'
15
+ },
16
+ {
17
+ path: '**',
18
+ redirectTo: 'main',
19
+ pathMatch: 'full'
20
+ }
21
+ ];
22
+
23
+ @NgModule({
24
+ imports: [
25
+ RouterModule.forChild(routes)
26
+ ],
27
+ exports: [RouterModule]
28
+ })
29
+ export class LoginRoutingModule {
30
+ }
@@ -0,0 +1,30 @@
1
+ import {NgModule} from '@angular/core';
2
+ import {CommonModule} from '@angular/common';
3
+
4
+ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
5
+ import {LoginMainComponent} from './login-main/login-main.component';
6
+ import {LoginRoutingModule} from './login-routing.module';
7
+ import {CardModule} from 'primeng/card';
8
+ import {ButtonModule} from 'primeng/button';
9
+ import {FormErrorMsgModule} from '@core/components/form-error-msg/form-error-msg.module';
10
+ import {InputTextModule} from 'primeng/inputtext';
11
+
12
+ @NgModule({
13
+ declarations: [
14
+ LoginMainComponent,
15
+ ],
16
+ imports: [
17
+ CommonModule,
18
+ FormsModule,
19
+ ReactiveFormsModule,
20
+ LoginRoutingModule,
21
+ CardModule,
22
+ ButtonModule,
23
+ FormErrorMsgModule,
24
+ InputTextModule
25
+ ],
26
+ providers: [],
27
+ entryComponents: []
28
+ })
29
+ export class LoginModule {
30
+ }
@@ -0,0 +1,2 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ export declare function makeAuth(options: Auth): Rule;