placidenduwayo před 2 roky
rodič
revize
3f0651b593
24 změnil soubory, kde provedl 879 přidání a 147 odebrání
  1. 101
    41
      db_users_projects_companies.json
  2. 22
    0
      package-lock.json
  3. 1
    0
      package.json
  4. 3
    2
      src/app/app.module.ts
  5. 9
    0
      src/app/ngrx/msg.state.ts
  6. 9
    0
      src/app/ngrx/users/user.state.ts
  7. 107
    3
      src/app/ngrx/users/users.actions.ts
  8. 55
    7
      src/app/ngrx/users/users.effects.ts
  9. 108
    24
      src/app/ngrx/users/users.reducer.ts
  10. 0
    1
      src/app/pages/users-manager/user-create/user-create.component.html
  11. 0
    15
      src/app/pages/users-manager/user-create/user-create.component.ts
  12. 0
    0
      src/app/pages/users-manager/users-management/user-create/user-create.component.css
  13. 267
    0
      src/app/pages/users-manager/users-management/user-create/user-create.component.html
  14. 0
    0
      src/app/pages/users-manager/users-management/user-create/user-create.component.spec.ts
  15. 97
    0
      src/app/pages/users-manager/users-management/user-create/user-create.component.ts
  16. 20
    6
      src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.html
  17. 19
    11
      src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.ts
  18. 3
    0
      src/app/pages/users-manager/users-management/users-list/users-list.component.css
  19. 7
    8
      src/app/pages/users-manager/users-management/users-list/users-list.component.html
  20. 18
    2
      src/app/pages/users-manager/users-management/users-list/users-list.component.ts
  21. 8
    8
      src/app/pages/users-manager/users-management/users-management.component.html
  22. 19
    14
      src/app/pages/users-manager/users-management/users-management.component.ts
  23. 1
    1
      src/app/pages/users-manager/users-manager-routing.module.ts
  24. 5
    4
      src/app/pages/users-manager/users-manager.module.ts

+ 101
- 41
db_users_projects_companies.json Zobrazit soubor

@@ -1,5 +1,4 @@
1 1
 {
2
-
3 2
   "companies": [
4 3
     {
5 4
       "id": 2,
@@ -29,10 +28,10 @@
29 28
         "ville": "Paris",
30 29
         "pays": "France"
31 30
       },
32
-      "firstname": "David",
33
-      "lastname": "Touitou",
34
-      "email": "david.touitou@natan.fr",
35
-      "id": 1
31
+      "firstname": "Placide",
32
+      "lastname": "Nduwayo",
33
+      "email": "placide.nduwayo@natan.fr",
34
+      "id": 2
36 35
     },
37 36
     {
38 37
       "address": {
@@ -42,10 +41,10 @@
42 41
         "ville": "Paris",
43 42
         "pays": "France"
44 43
       },
45
-      "firstname": "Placide",
46
-      "lastname": "Nduwayo",
47
-      "email": "placide.nduwayo@natan.fr",
48
-      "id": 2
44
+      "firstname": "David",
45
+      "lastname": "Touitou",
46
+      "email": "david.touitou@natan.fr",
47
+      "id": 3
49 48
     },
50 49
     {
51 50
       "address": {
@@ -58,21 +57,102 @@
58 57
       "firstname": "Nadhir",
59 58
       "lastname": "Ben Mohamed",
60 59
       "email": "nadhir.ben-mohamed@natan.fr",
61
-      "id": 3
60
+      "id": 4
61
+    },
62
+    {
63
+      "address": {
64
+        "numRue": 44,
65
+        "nomRue": "Rue Notre Dame de Paris",
66
+        "bp": 75002,
67
+        "ville": "Paris",
68
+        "pays": "France"
69
+      },
70
+      "firstname": "Smail",
71
+      "lastname": "Sellah",
72
+      "email": "smail.sellah@natan.fr",
73
+      "id": 5
74
+    },
75
+    {
76
+      "address": {
77
+        "numRue": 44,
78
+        "nomRue": "Rue Notre Dame de Paris",
79
+        "bp": 75002,
80
+        "ville": "Paris",
81
+        "pays": "France"
82
+      },
83
+      "firstname": "Sarah",
84
+      "lastname": "Leray",
85
+      "email": "sarah.leray@natan.fr",
86
+      "id": 6
87
+    },
88
+    {
89
+      "address": {
90
+        "numRue": 44,
91
+        "nomRue": "Rue Notre Dame de Paris",
92
+        "bp": 75002,
93
+        "ville": "Paris",
94
+        "pays": "France"
95
+      },
96
+      "firstname": "Naolie",
97
+      "lastname": "Boudouka",
98
+      "email": "naolie.boudouka@natan.fr",
99
+      "id": 7
100
+    },
101
+    {
102
+      "address": {
103
+        "numRue": 44,
104
+        "nomRue": "Rue Notre Dame de Paris",
105
+        "bp": 75002,
106
+        "ville": "Paris",
107
+        "pays": "France"
108
+      },
109
+      "firstname": "Syrine",
110
+      "lastname": "Ait Haddad",
111
+      "email": "syrine.ait-haddadene@natan.fr",
112
+      "id": 8
113
+    },
114
+    {
115
+      "address": {
116
+        "numRue": 44,
117
+        "nomRue": "Rue Notre Dame de Paris",
118
+        "bp": 75002,
119
+        "ville": "Paris",
120
+        "pays": "France"
121
+      },
122
+      "firstname": "Marion",
123
+      "lastname": "Jaillot",
124
+      "email": "marion.jaillot@natan.fr",
125
+      "id": 9
126
+    },
127
+    {
128
+      "address": {
129
+        "numRue": 44,
130
+        "nomRue": "Rue Notre Dame de Paris",
131
+        "bp": 75002,
132
+        "ville": "Paris",
133
+        "pays": "France"
134
+      },
135
+      "firstname": "avraham",
136
+      "lastname": "Benassaya",
137
+      "email": "avraham.benassaya@natan.fr",
138
+      "id": 10
139
+    },
140
+    {
141
+      "id": 11,
142
+      "firstname": "Charles",
143
+      "lastname": "Benassaya",
144
+      "email": "charles.benassaya@natan.fr",
145
+      "address": {
146
+        "numRue": 44,
147
+        "nomRue": "Rue Notre Dame de Paris",
148
+        "bp": 75002,
149
+        "ville": "Paris",
150
+        "pays": "France"
151
+      }
62 152
     }
63 153
   ],
64 154
   "projects": [
65 155
     {
66
-      "id": 1,
67
-      "projectName": "Project-1",
68
-      "priority": 1,
69
-      "creationDate": "05 18 2022",
70
-      "companyId": 3,
71
-      "description": "Project of training users to angular",
72
-      "userId": 1,
73
-      "state": "END"
74
-    },
75
-    {
76 156
       "id": 2,
77 157
       "projectName": "Project-2",
78 158
       "priority": 1,
@@ -91,26 +171,6 @@
91 171
       "description": "Project description",
92 172
       "userId": 2,
93 173
       "state": "IN PROGRESS"
94
-    },
95
-    {
96
-      "id": 4,
97
-      "projectName": "Project-4",
98
-      "priority": 3,
99
-      "creationDate": "05 18 2022",
100
-      "companyId": 4,
101
-      "description": "Project description",
102
-      "userId": 3,
103
-      "state": "END"
104
-    },
105
-    {
106
-      "id": 5,
107
-      "projectName": "Project-5",
108
-      "priority": 1,
109
-      "creationDate": "05 18 2022",
110
-      "companyId": 3,
111
-      "description": "project of training Natan users on backend tools",
112
-      "userId": 1,
113
-      "state": "IN PROGRESS"
114 174
     }
115 175
   ]
116
-}
176
+}

+ 22
- 0
package-lock.json Zobrazit soubor

@@ -17,6 +17,7 @@
17 17
         "@angular/platform-browser-dynamic": "~13.3.0",
18 18
         "@angular/router": "~13.3.0",
19 19
         "@ngrx/effects": "^13.2.0",
20
+        "@ngrx/entity": "^13.2.0",
20 21
         "@ngrx/store": "^13.2.0",
21 22
         "@ngrx/store-devtools": "^13.2.0",
22 23
         "bootstrap": "^5.1.3",
@@ -2415,6 +2416,19 @@
2415 2416
         "rxjs": "^6.5.3 || ^7.4.0"
2416 2417
       }
2417 2418
     },
2419
+    "node_modules/@ngrx/entity": {
2420
+      "version": "13.2.0",
2421
+      "resolved": "https://registry.npmjs.org/@ngrx/entity/-/entity-13.2.0.tgz",
2422
+      "integrity": "sha512-2zgz2/3BpYSvVNLqQM034lK3kQ0UoHj7kxmtf5Bkf2yWrjEGVmwyRUYDt1/vlfoBUE/KU7DDPHWJT8r5Li0ALA==",
2423
+      "dependencies": {
2424
+        "tslib": "^2.0.0"
2425
+      },
2426
+      "peerDependencies": {
2427
+        "@angular/core": "^13.0.0",
2428
+        "@ngrx/store": "13.2.0",
2429
+        "rxjs": "^6.5.3 || ^7.4.0"
2430
+      }
2431
+    },
2418 2432
     "node_modules/@ngrx/store": {
2419 2433
       "version": "13.2.0",
2420 2434
       "resolved": "https://registry.npmjs.org/@ngrx/store/-/store-13.2.0.tgz",
@@ -14508,6 +14522,14 @@
14508 14522
         "tslib": "^2.0.0"
14509 14523
       }
14510 14524
     },
14525
+    "@ngrx/entity": {
14526
+      "version": "13.2.0",
14527
+      "resolved": "https://registry.npmjs.org/@ngrx/entity/-/entity-13.2.0.tgz",
14528
+      "integrity": "sha512-2zgz2/3BpYSvVNLqQM034lK3kQ0UoHj7kxmtf5Bkf2yWrjEGVmwyRUYDt1/vlfoBUE/KU7DDPHWJT8r5Li0ALA==",
14529
+      "requires": {
14530
+        "tslib": "^2.0.0"
14531
+      }
14532
+    },
14511 14533
     "@ngrx/store": {
14512 14534
       "version": "13.2.0",
14513 14535
       "resolved": "https://registry.npmjs.org/@ngrx/store/-/store-13.2.0.tgz",

+ 1
- 0
package.json Zobrazit soubor

@@ -19,6 +19,7 @@
19 19
     "@angular/platform-browser-dynamic": "~13.3.0",
20 20
     "@angular/router": "~13.3.0",
21 21
     "@ngrx/effects": "^13.2.0",
22
+    "@ngrx/entity": "^13.2.0",
22 23
     "@ngrx/store": "^13.2.0",
23 24
     "@ngrx/store-devtools": "^13.2.0",
24 25
     "bootstrap": "^5.1.3",

+ 3
- 2
src/app/app.module.ts Zobrazit soubor

@@ -1,4 +1,4 @@
1
-
1
+import { FormsModule } from '@angular/forms';
2 2
 import { AccueilModule } from './pages/accueil/accueil.module';
3 3
 import { CompaniesManagerModule } from './pages/companies-manager/companies-manager.module';
4 4
 import { ProjectsManagerModule } from './pages/projects-manager/projects-manager.module';
@@ -26,7 +26,8 @@ import { HttpClientModule } from '@angular/common/http';
26 26
     CompaniesManagerModule,
27 27
     AccueilModule,
28 28
     HttpClientModule,
29
-    BrowserAnimationsModule
29
+    BrowserAnimationsModule,
30
+    FormsModule
30 31
   ],
31 32
   providers: [],
32 33
   bootstrap: [AppComponent]

+ 9
- 0
src/app/ngrx/msg.state.ts Zobrazit soubor

@@ -0,0 +1,9 @@
1
+export enum MsgState {
2
+  LOADING = '[User] LOADING ...',
3
+  LOADED = '[User] LOADED',
4
+  ERROR = '[User] ERROR',
5
+  INIT_STATE = '[User] INITIAL STATE',
6
+  CONFIRM = 'CONFIRM',
7
+  NEW ='NEW',
8
+  SUCCESS = 'SUCCESSFUL SAVED'
9
+}

+ 9
- 0
src/app/ngrx/users/user.state.ts Zobrazit soubor

@@ -0,0 +1,9 @@
1
+import { User } from "src/app/shared/models/user.model";
2
+import { MsgState } from "../msg.state";
3
+
4
+//create a state
5
+export class UserState {
6
+  usersList!: User[];
7
+  msgState!: MsgState;
8
+  userServerErrorMsg!: string;
9
+}

+ 107
- 3
src/app/ngrx/users/users.actions.ts Zobrazit soubor

@@ -13,6 +13,28 @@ export enum UserActionType {
13 13
   SEARCH_A_USER = '[User] SEARCH A USER',
14 14
   SEARCH_A_USER_SUCCESS = '[User] SEARCH A USER SUCCESS',
15 15
   SEARCH_A_USER_ERROR = '[User] SEARCH A USER ERROR',
16
+
17
+  /* action: edit a user */
18
+
19
+  EDIT_A_USER = '[User] EDIT A USER',
20
+  EDIT_A_USER_SUCCESS = '[User] EDIT A USER SUCCESS',
21
+  EDIT_A_USER_ERROR = '[User] EDIT A USER ERROR',
22
+
23
+  /* action of button: create a user form*/
24
+
25
+  CREATE_A_USERFORM = '[User] CREATE USER FORM',
26
+  CREATE_A_USERFORM_SUCCESS = '[User] CREATE A USER FORM SUCCESS',
27
+  CREATE_A_USERFORM_ERROR = '[User] CREATE A USER FORM ERROR',
28
+
29
+  SAVE_A_USERFORM ='[User] SAVE A USER',
30
+  SAVE_A_USERFORM_SUCCESS ='[User] SAVE A USER SUCCESS',
31
+  SAVE_A_USERFORM_ERROR='[User] SAVE A USER ERROR',
32
+
33
+   /* action: delete a user */
34
+
35
+   DELETE_A_USER = '[User] DELETE A USER',
36
+   DELETE_A_USER_SUCCESS = '[User] DELETE A USER SUCCESS',
37
+   DELETE_A_USER_ERROR = '[User] DELETE A USER ERROR'
16 38
 }
17 39
 
18 40
 //create actions
@@ -33,7 +55,7 @@ export class GetAllUsersActionError implements Action {
33 55
   constructor(public payload: string) {}
34 56
 }
35 57
 
36
-/* Actios nof searching a user */
58
+/* Actios of searching a user */
37 59
 
38 60
 export class SearchUsersAction implements Action {
39 61
   type: UserActionType = UserActionType.SEARCH_A_USER;
@@ -51,10 +73,92 @@ export class SearchUserActionError implements Action {
51 73
   constructor(public payload: string) {}
52 74
 }
53 75
 
54
-export type UserAction =
76
+/* Actios of editing a user */
77
+
78
+export class EditUsersAction implements Action {
79
+  type: UserActionType = UserActionType.EDIT_A_USER;
80
+
81
+  constructor(public payload: {user: User}) {}
82
+}
83
+
84
+export class EditUserActionSuccess implements Action {
85
+  type: UserActionType = UserActionType.EDIT_A_USER_SUCCESS;
86
+  constructor(public payload: User) {}
87
+}
88
+
89
+export class EditUserActionError implements Action {
90
+  type: UserActionType = UserActionType.EDIT_A_USER_ERROR;
91
+  constructor(public payload: string) {}
92
+}
93
+
94
+/* Actios of creating a user form */
95
+
96
+export class CreateUserFormAction implements Action {
97
+  type: UserActionType = UserActionType.CREATE_A_USERFORM;
98
+
99
+  constructor(public payload: any) {}
100
+}
101
+
102
+export class CreateUserFormActionSuccess implements Action {
103
+  type: UserActionType = UserActionType.CREATE_A_USERFORM_SUCCESS;
104
+  constructor(public payload: any) {}
105
+}
106
+
107
+export class CreateUserFormActionError implements Action {
108
+  type: UserActionType = UserActionType.CREATE_A_USERFORM_ERROR;
109
+  constructor(public payload: string) {}
110
+}
111
+
112
+/**action of saving a user */
113
+export class SaveUserFormAction implements Action{
114
+  type: UserActionType = UserActionType.SAVE_A_USERFORM;
115
+  constructor(public payload: User){}
116
+}
117
+
118
+export class SaveUserFormActionSuccess implements Action{
119
+  type: UserActionType = UserActionType.SAVE_A_USERFORM_SUCCESS;
120
+  constructor(public payload: User){}
121
+}
122
+
123
+export class SaveUserFormActionError implements Action{
124
+  type: UserActionType = UserActionType.SAVE_A_USERFORM_ERROR;
125
+  constructor(public payload: string){}
126
+}
127
+
128
+/* Actios of deleting a user */
129
+
130
+export class DeleteUsersAction implements Action {
131
+  type: UserActionType = UserActionType.DELETE_A_USER;
132
+
133
+  constructor(public payload: User) {}
134
+}
135
+
136
+export class DeleteUserActionSuccess implements Action {
137
+  type: UserActionType = UserActionType.DELETE_A_USER_SUCCESS;
138
+  constructor(public payload: User) {}
139
+}
140
+
141
+export class DeleteUserActionError implements Action {
142
+  type: UserActionType = UserActionType.DELETE_A_USER_ERROR;
143
+  constructor(public payload: string) {}
144
+}
145
+
146
+export type UserActionUnion =
55 147
   | GetAllUsersAction
56 148
   | GetAllUsersActionSuccess
57 149
   | GetAllUsersActionError
58 150
   | SearchUsersAction
59 151
   | SearchUserActionSuccess
60
-  | SearchUserActionError;
152
+  | SearchUserActionError
153
+  | EditUsersAction
154
+  | EditUserActionSuccess
155
+  | EditUserActionError
156
+  | CreateUserFormAction
157
+  | CreateUserFormActionSuccess
158
+  | CreateUserFormActionError
159
+  | SaveUserFormAction
160
+  | SaveUserFormActionSuccess
161
+  | SaveUserFormActionError
162
+  | DeleteUsersAction
163
+  | DeleteUserActionSuccess
164
+  | DeleteUserActionError;

+ 55
- 7
src/app/ngrx/users/users.effects.ts Zobrazit soubor

@@ -1,4 +1,4 @@
1
-import { UserActionType, GetAllUsersActionSuccess, GetAllUsersActionError, UserAction, SearchUserActionSuccess, SearchUserActionError } from './users.actions';
1
+import { UserActionType, GetAllUsersActionSuccess, GetAllUsersActionError, UserActionUnion, SearchUserActionSuccess, SearchUserActionError, EditUserActionSuccess, EditUserActionError, DeleteUserActionSuccess, DeleteUserActionError, CreateUserFormActionSuccess, CreateUserFormActionError, SaveUserFormActionSuccess, SaveUserFormActionError } from './users.actions';
2 2
 import { map, mergeMap, Observable, catchError, of } from 'rxjs';
3 3
 import { UsersService } from './../../shared/services/users.service';
4 4
 import { Injectable } from "@angular/core";
@@ -12,12 +12,12 @@ export class UserEffects{
12 12
 
13 13
   //create getAllUsers effects
14 14
 
15
-  getAllUsersEffect: Observable<UserAction> = createEffect(
15
+  getAllUsersEffect: Observable<UserActionUnion> = createEffect(
16 16
 
17 17
     () => this.effectActions.pipe(
18 18
       ofType(UserActionType.GET_ALL_USERS),
19 19
       mergeMap(
20
-        (userAction: UserAction) =>{
20
+        () =>{
21 21
 
22 22
           return this.usersService.getAllUsers().pipe(
23 23
               map((users: User[])=> new GetAllUsersActionSuccess(users)),
@@ -28,15 +28,13 @@ export class UserEffects{
28 28
 
29 29
     )
30 30
   );
31
-
32 31
    //create searchUser effects
33
-
34
-   searchUserEffect: Observable<UserAction> = createEffect(
32
+   searchUserEffect: Observable<UserActionUnion> = createEffect(
35 33
 
36 34
     () => this.effectActions.pipe(
37 35
       ofType(UserActionType.SEARCH_A_USER),
38 36
       mergeMap(
39
-        (userAction: UserAction) =>{
37
+        (userAction: UserActionUnion) =>{
40 38
 
41 39
           return this.usersService.searchUser(userAction.payload).pipe(
42 40
               map((users: User[])=> new SearchUserActionSuccess(users)),
@@ -47,4 +45,54 @@ export class UserEffects{
47 45
 
48 46
     )
49 47
   );
48
+
49
+  //create editUser effect
50
+  editUserEffect: Observable<UserActionUnion> = createEffect(
51
+    () => this.effectActions.pipe(
52
+      ofType(UserActionType.EDIT_A_USER),
53
+      mergeMap( (userAction: UserActionUnion)=>{
54
+        return this.usersService.updateUser(userAction.payload).pipe(
55
+          map( (user: User)=> new EditUserActionSuccess(user)),
56
+          catchError( (err) => of(new EditUserActionError(err.message)))
57
+        )
58
+      })
59
+    )
60
+  );
61
+
62
+  //create deleteUser effect
63
+  deleteUserEffect: Observable<UserActionUnion> = createEffect(
64
+    ()=> this.effectActions.pipe(
65
+      ofType(UserActionType.DELETE_A_USER),
66
+      mergeMap( (userAction: UserActionUnion) => {
67
+        return this.usersService.deleteUser(userAction.payload.id).pipe(
68
+          map( ()=> new DeleteUserActionSuccess(userAction.payload)),
69
+          catchError( (err) => of(new DeleteUserActionError(err.message)))
70
+        )
71
+      })
72
+    )
73
+  );
74
+
75
+  //create createUser effect: action of button to create user form
76
+  createUserFormEffect: Observable<UserActionUnion> = createEffect(
77
+    () => this.effectActions.pipe(
78
+      ofType(UserActionType.CREATE_A_USERFORM),
79
+      map( ()=>{
80
+        return new CreateUserFormActionSuccess({});
81
+      }),
82
+      catchError( (err) => of(new CreateUserFormActionError(err.message)))
83
+    )
84
+  );
85
+
86
+  //create save a user effect: action of saving data of the form
87
+  saveUserFormEffect : Observable<UserActionUnion> = createEffect(
88
+    () => this.effectActions.pipe(
89
+      ofType(UserActionType.SAVE_A_USERFORM),
90
+      mergeMap( (userAction: UserActionUnion) => {
91
+        return this.usersService.createUser(userAction.payload).pipe(
92
+          map (user => new SaveUserFormActionSuccess(user)),
93
+          catchError( err => of(new SaveUserFormActionError(err.message)))
94
+        );
95
+      })
96
+    )
97
+  );
50 98
 }

+ 108
- 24
src/app/ngrx/users/users.reducer.ts Zobrazit soubor

@@ -1,26 +1,20 @@
1 1
 import { Action } from '@ngrx/store';
2 2
 import { User } from 'src/app/shared/models/user.model';
3
-import { UserAction, UserActionType } from './users.actions';
4
-
5
-export enum UserStateEnum {
6
-  LOADING = '[User] LOADING',
7
-  LOADED = '[User] LOADED',
8
-  ERROR = '[User] ERROR',
9
-  INIT_STATE = '[User] INITIAL STATE',
10
-}
3
+import { MsgState } from '../msg.state';
4
+import { UserActionUnion, UserActionType } from './users.actions';
11 5
 
12 6
 //create a state
13
-export interface UserState {
14
-  usersList: User[];
15
-  serverErrorMsg: string;
16
-  dataState: UserStateEnum;
7
+export class UserState {
8
+  usersList!: User[];
9
+  msgState!: MsgState;
10
+  userServerErrorMsg!: string;
17 11
 }
18 12
 
19 13
 //create reducer, a reducer need a initial state and an action
20 14
 const initUserState: UserState = {
21 15
   usersList: [],
22
-  serverErrorMsg: '',
23
-  dataState: UserStateEnum.INIT_STATE,
16
+  msgState: MsgState.INIT_STATE,
17
+  userServerErrorMsg: 'No error message',
24 18
 };
25 19
 
26 20
 export function userReducer(
@@ -28,38 +22,128 @@ export function userReducer(
28 22
   action: Action
29 23
 ): UserState {
30 24
   switch (action.type) {
25
+    /** get all users actions */
31 26
     case UserActionType.GET_ALL_USERS:
32
-      return { ...state, dataState: UserStateEnum.LOADING };
27
+      return { ...state, msgState: MsgState.LOADING };
33 28
 
34 29
     case UserActionType.GET_ALL_USERS_SUCCESS:
35 30
       return {
36 31
         ...state,
37
-        dataState: UserStateEnum.LOADED,
38
-        usersList: (<UserAction>action).payload,
32
+        msgState: MsgState.LOADED,
33
+        usersList: (<UserActionUnion>action).payload,
39 34
       };
40 35
 
41 36
     case UserActionType.GET_ALL_USERS_ERROR:
42 37
       return {
43 38
         ...state,
44
-        dataState: UserStateEnum.ERROR,
45
-        serverErrorMsg: (<UserAction>action).payload,
39
+        msgState: MsgState.ERROR,
40
+        userServerErrorMsg: (<UserActionUnion>action).payload,
46 41
       };
47 42
 
43
+    /** search a user actions */
48 44
     case UserActionType.SEARCH_A_USER:
49
-      return { ...state, dataState: UserStateEnum.LOADING };
45
+      return { ...state, msgState: MsgState.LOADING };
50 46
 
51 47
     case UserActionType.SEARCH_A_USER_SUCCESS:
52 48
       return {
53 49
         ...state,
54
-        dataState: UserStateEnum.LOADED,
55
-        usersList: (<UserAction>action).payload,
50
+        msgState: MsgState.LOADED,
51
+        usersList: (<UserActionUnion>action).payload,
56 52
       };
57 53
 
58 54
     case UserActionType.SEARCH_A_USER_ERROR:
59 55
       return {
60 56
         ...state,
61
-        dataState: UserStateEnum.ERROR,
62
-        serverErrorMsg: (<UserAction>action).payload,
57
+        msgState: MsgState.ERROR,
58
+        userServerErrorMsg: (<UserActionUnion>action).payload,
59
+      };
60
+
61
+    /** edit a user actions */
62
+    case UserActionType.EDIT_A_USER:
63
+      return {
64
+        ...state,
65
+        msgState: MsgState.LOADING,
66
+      };
67
+
68
+    case UserActionType.EDIT_A_USER_SUCCESS:
69
+      let modifiedUser: User = (<UserActionUnion>action).payload;
70
+      let usersListCopy1: User[] = [...state.usersList];
71
+      let usersListNew1: User[] = usersListCopy1.map((user) =>
72
+        user.id == modifiedUser.id ? modifiedUser : user
73
+      );
74
+      return {
75
+        ...state,
76
+        msgState: MsgState.LOADED,
77
+        usersList: usersListNew1,
78
+      };
79
+
80
+    case UserActionType.EDIT_A_USER_ERROR:
81
+      return {
82
+        ...state,
83
+        msgState: MsgState.ERROR,
84
+        userServerErrorMsg: (<UserActionUnion>action).payload,
85
+      };
86
+
87
+    /** create a user form actions */
88
+    case UserActionType.CREATE_A_USERFORM:
89
+      return {
90
+        ...state,
91
+        msgState: MsgState.LOADING,
92
+      };
93
+
94
+    case UserActionType.CREATE_A_USERFORM_SUCCESS:
95
+      return {
96
+        ...state,
97
+        msgState: MsgState.NEW,
98
+      };
99
+
100
+    case UserActionType.CREATE_A_USERFORM_ERROR:
101
+      return {
102
+        ...state,
103
+        msgState: MsgState.ERROR,
104
+        userServerErrorMsg: (<UserActionUnion>action).payload,
105
+      };
106
+
107
+    /** save a user (data of form) action*/
108
+    case UserActionType.SAVE_A_USERFORM:
109
+      return {
110
+        ...state,
111
+        msgState: MsgState.LOADING,
112
+      };
113
+    case UserActionType.CREATE_A_USERFORM_SUCCESS:
114
+      let createdUser: User = (<UserActionUnion>action).payload;
115
+      let usersListCopy2: User[] = [...state.usersList];
116
+      usersListCopy2.push(createdUser);
117
+
118
+      return {
119
+        ...state,
120
+        msgState: MsgState.SUCCESS,
121
+        usersList: usersListCopy2,
122
+      };
123
+
124
+    /** delete a user actions */
125
+    case UserActionType.DELETE_A_USER:
126
+      return {
127
+        ...state,
128
+        msgState: MsgState.LOADING,
129
+      };
130
+
131
+    case UserActionType.DELETE_A_USER_SUCCESS:
132
+      let deletedUser: User = (<UserActionUnion>action).payload;
133
+      let deletedUserIndex = state.usersList.indexOf(deletedUser);
134
+      let usersListNew3: User[] = [...state.usersList];
135
+      usersListNew3.splice(deletedUserIndex, 1);
136
+      return {
137
+        ...state,
138
+        msgState: MsgState.LOADED,
139
+        usersList: usersListNew3,
140
+      };
141
+
142
+    case UserActionType.DELETE_A_USER_ERROR:
143
+      return {
144
+        ...state,
145
+        msgState: MsgState.ERROR,
146
+        userServerErrorMsg: (<UserActionUnion>action).payload,
63 147
       };
64 148
 
65 149
     default:

+ 0
- 1
src/app/pages/users-manager/user-create/user-create.component.html Zobrazit soubor

@@ -1 +0,0 @@
1
-<p>user-create works!</p>

+ 0
- 15
src/app/pages/users-manager/user-create/user-create.component.ts Zobrazit soubor

@@ -1,15 +0,0 @@
1
-import { Component, OnInit } from '@angular/core';
2
-
3
-@Component({
4
-  selector: 'app-user-create',
5
-  templateUrl: './user-create.component.html',
6
-  styleUrls: ['./user-create.component.css']
7
-})
8
-export class UserCreateComponent implements OnInit {
9
-
10
-  constructor() { }
11
-
12
-  ngOnInit(): void {
13
-  }
14
-
15
-}

src/app/pages/users-manager/user-create/user-create.component.css → src/app/pages/users-manager/users-management/user-create/user-create.component.css Zobrazit soubor


+ 267
- 0
src/app/pages/users-manager/users-management/user-create/user-create.component.html Zobrazit soubor

@@ -0,0 +1,267 @@
1
+<div class="container" *ngIf="userFormGroup">
2
+  <ng-container *ngIf="userState as userData">
3
+   
4
+    <ng-container *ngIf="userData.msgState == msgState.LOADED">
5
+      <div class="alert-success container p-3 m-3">
6
+        <span>  User form is loaded</span>
7
+        <button class="btn btn-success ml-3" (click)="onNewUser()"> create user</button>
8
+      </div>
9
+    </ng-container>
10
+
11
+    <ng-container *ngIf="userData.msgState==msgState.NEW">
12
+
13
+      <div class="card mt-3">
14
+        <div class="card-header bg-light">Update user informations</div>
15
+        <div class="card-body">
16
+          <form [formGroup]="userFormGroup" (ngSubmit)="onUserSave(); userFormGroup.reset()">
17
+
18
+            <div class="row">
19
+
20
+              <div class="col">
21
+
22
+                <div class="col-md-auto mb-3">
23
+                  <label for="id">Firstname</label>
24
+                  <input
25
+                    type="text"
26
+                    class="form-control"
27
+                    formControlName="firstname"
28
+                    [ngClass]="{
29
+                      'is-invalid':
30
+                        userFormGroup.controls['firstname'].touched &&
31
+                        !userFormGroup.controls['firstname'].valid
32
+                    }"
33
+                  />
34
+
35
+                  <div class="invalid-feedback">
36
+                    <span
37
+                      *ngIf="userFormGroup.controls['firstname'].errors?.['required']"
38
+                      >required</span
39
+                    >
40
+                    <span
41
+                      *ngIf="userFormGroup.controls['firstname'].errors?.['minlength']"
42
+                      >min nbr chars 3</span
43
+                    >
44
+                    <span
45
+                      *ngIf="userFormGroup.controls['firstname'].errors?.['maxlength']"
46
+                      >max nbr chars 20</span
47
+                    >
48
+                  </div>
49
+                </div>
50
+
51
+                <div class="col-md-auto mb-3">
52
+                  <label for="id">Lastname</label>
53
+                  <input
54
+                    type="text"
55
+                    class="form-control"
56
+                    formControlName="lastname"
57
+                    [ngClass]="{
58
+                      'is-invalid':
59
+                        userFormGroup.controls['lastname'].touched &&
60
+                        !userFormGroup.controls['lastname'].valid
61
+                    }"
62
+                  />
63
+
64
+                  <div class="invalid-feedback">
65
+                    <span
66
+                      *ngIf="userFormGroup.controls['lastname'].errors?.['required']"
67
+                      >required</span
68
+                    >
69
+                    <span
70
+                      *ngIf="userFormGroup.controls['lastname'].errors?.['minlength']"
71
+                      >min nbr char 3</span
72
+                    >
73
+                    <span
74
+                      *ngIf="userFormGroup.controls['lastname'].errors?.['maxlength']"
75
+                      >max nbr char 20</span
76
+                    >
77
+                  </div>
78
+                </div>
79
+
80
+                <div class="col-md-auto mb-3">
81
+                  <label for="email">Email</label>
82
+                  <input
83
+                    type="text"
84
+                    class="form-control"
85
+                    formControlName="email"
86
+                    [ngClass]="{
87
+                      'is-invalid':
88
+                        userFormGroup.controls['email'].touched &&
89
+                        !userFormGroup.controls['email'].valid
90
+                    }"
91
+                  />
92
+
93
+                  <div class="invalid-feedback">
94
+                    <span *ngIf="userFormGroup.controls['email'].errors?.['required']">
95
+                      required
96
+                    </span>
97
+                    <span *ngIf="userFormGroup.controls['email'].errors?.['email']">
98
+                      not valid
99
+                    </span>
100
+                  </div>
101
+                </div>
102
+
103
+              </div>
104
+
105
+              <div class="col">
106
+
107
+                <div formGroupName="address">
108
+                  <div class="col-md-auto mb-3">
109
+                    <label for="numRue">Street number</label>
110
+                    <input
111
+                      type="number"
112
+                      class="form-control"
113
+                      formControlName="numRue"
114
+                      [ngClass]="{
115
+                        'is-invalid':
116
+                          userFormGroup.controls['address'].get('numRue')?.touched &&
117
+                          !userFormGroup.controls['address'].get('numRue')?.valid
118
+                      }"
119
+                    />
120
+                    <div class="invalid-feedback">
121
+                      <span
122
+                        *ngIf="userFormGroup.controls['address'].get('numRue')?.errors?.['required']"
123
+                        >required</span
124
+                      >
125
+                      <span
126
+                        *ngIf="userFormGroup.controls['address'].get('numRue')?.errors?.['min']"
127
+                        >street num >0
128
+                      </span>
129
+                    </div>
130
+                  </div>
131
+
132
+                  <div class="col-md-auto mb-3">
133
+                    <label for="nomRue">Street Name</label>
134
+                    <input
135
+                      type="text"
136
+                      class="form-control"
137
+                      formControlName="nomRue"
138
+                      [ngClass]="{
139
+                        'is-invalid':
140
+                          userFormGroup.controls['address'].get('nomRue')?.touched &&
141
+                          !userFormGroup.controls['address'].get('nomRue')?.valid
142
+                      }"
143
+                    />
144
+                    <div class="invalid-feedback">
145
+                      <span
146
+                        *ngIf="userFormGroup.controls['address'].get('nomRue')?.errors?.['required']"
147
+                        >required</span
148
+                      >
149
+                      <span
150
+                        *ngIf="userFormGroup.controls['address'].get('nomRue')?.errors?.['minlength']"
151
+                        >min chars 3
152
+                      </span>
153
+                      <span
154
+                        *ngIf="userFormGroup.controls['address'].get('nomRue')?.errors?.['maxlength']"
155
+                        >max chars 15
156
+                      </span>
157
+                    </div>
158
+                  </div>
159
+
160
+                  <div class="col-md-auto mb-3">
161
+                    <label for="bp">PB</label>
162
+                    <input
163
+                      type="number"
164
+                      class="form-control"
165
+                      formControlName="bp"
166
+                      [ngClass]="{
167
+                        'is-invalid':
168
+                          userFormGroup.controls['address'].get('bp')?.touched &&
169
+                          !userFormGroup.controls['address'].get('bp')?.valid
170
+                      }"
171
+                    />
172
+                    <div class="invalid-feedback">
173
+                      <span
174
+                        *ngIf="userFormGroup.controls['address'].get('bp')?.errors?.['required']"
175
+                        >required</span
176
+                      >
177
+                      <span
178
+                        *ngIf="userFormGroup.controls['address'].get('bp')?.errors?.['min']"
179
+                        >pb >0
180
+                      </span>
181
+                    </div>
182
+                  </div>
183
+
184
+                  <div class="col-md-auto mb-3">
185
+                    <label for="city">City</label>
186
+                    <input
187
+                      type="text"
188
+                      class="form-control"
189
+                      formControlName="ville"
190
+                      [ngClass]="{
191
+                        'is-invalid':
192
+                          userFormGroup.controls['address'].get('ville')?.touched &&
193
+                          !userFormGroup.controls['address'].get('vile')?.valid
194
+                      }"
195
+                    />
196
+                    <div class="invalid-feedback">
197
+                      <span
198
+                        *ngIf="userFormGroup.controls['address'].get('ville')?.errors?.['required']"
199
+                        >required</span
200
+                      >
201
+                      <span
202
+                        *ngIf="userFormGroup.controls['address'].get('ville')?.errors?.['minlength']"
203
+                        >min chars 3
204
+                      </span>
205
+                      <span
206
+                        *ngIf="userFormGroup.controls['address'].get('ville')?.errors?.['maxlength']"
207
+                        >max chars 15
208
+                      </span>
209
+                    </div>
210
+                  </div>
211
+
212
+                  <div class="col-md-auto mb-3">
213
+                    <label for="pays">Country</label>
214
+                    <input
215
+                      type="text"
216
+                      class="form-control"
217
+                      formControlName="pays"
218
+                      [ngClass]="{
219
+                        'is-invalid':
220
+                          userFormGroup.controls['address'].get('pays')?.touched &&
221
+                          !userFormGroup.controls['address'].get('pays')?.valid
222
+                      }"
223
+                    />
224
+                    <div class="invalid-feedback">
225
+                      <span
226
+                        *ngIf="userFormGroup.controls['address'].get('pays')?.errors?.['required']"
227
+                        >required</span
228
+                      >
229
+                      <span
230
+                        *ngIf="userFormGroup.controls['address'].get('pays')?.errors?.['minlength']"
231
+                        >min chars 3
232
+                      </span>
233
+                      <span
234
+                        *ngIf="userFormGroup.controls['address'].get('pays')?.errors?.['maxlength']"
235
+                        >max chars 15
236
+                      </span>
237
+                    </div>
238
+                  </div>
239
+                </div>
240
+
241
+              </div>
242
+
243
+            </div>
244
+
245
+            <div class="row">
246
+              <div class="text-center">
247
+                <button
248
+                  class="btn btn-outline-primary"
249
+                  type="submit"
250
+                  [disabled]="!userFormGroup.valid"
251
+                >
252
+                  save</button
253
+                >&nbsp;
254
+                <button class="btn btn-outline-danger" type="reset">reset</button>
255
+              </div>
256
+            </div>
257
+
258
+          </form>
259
+        </div>
260
+      </div>
261
+
262
+
263
+    </ng-container>
264
+
265
+  </ng-container>
266
+
267
+</div>

src/app/pages/users-manager/user-create/user-create.component.spec.ts → src/app/pages/users-manager/users-management/user-create/user-create.component.spec.ts Zobrazit soubor


+ 97
- 0
src/app/pages/users-manager/users-management/user-create/user-create.component.ts Zobrazit soubor

@@ -0,0 +1,97 @@
1
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
2
+import {
3
+  CreateUserFormAction,
4
+  SaveUserFormAction,
5
+} from './../../../../ngrx/users/users.actions';
6
+import { Store } from '@ngrx/store';
7
+import { Component, OnInit } from '@angular/core';
8
+import { MsgState } from 'src/app/ngrx/msg.state';
9
+import { UserState } from 'src/app/ngrx/users/user.state';
10
+
11
+
12
+@Component({
13
+  selector: 'app-user-create',
14
+  templateUrl: './user-create.component.html',
15
+  styleUrls: ['./user-create.component.css'],
16
+})
17
+export class UserCreateComponent implements OnInit {
18
+  userFormGroup!: FormGroup;
19
+
20
+  constructor(
21
+    private store: Store<{ userReducerKey: UserState }>,
22
+    private fb: FormBuilder
23
+  ) {}
24
+  userState!: UserState;
25
+  readonly msgState = MsgState;
26
+
27
+  ngOnInit(): void {
28
+
29
+    this.store.dispatch(new CreateUserFormAction({}));
30
+
31
+    this.store.subscribe((state) => {
32
+      this.userState = state.userReducerKey;
33
+
34
+      if(this.userState.msgState==this.msgState.NEW){
35
+
36
+        this.userFormGroup = this.fb.group({
37
+          id: [0, Validators.required],
38
+          firstname: [
39
+            '',
40
+            [
41
+              Validators.required,
42
+              Validators.minLength(3),
43
+              Validators.maxLength(15),
44
+            ],
45
+          ],
46
+          lastname: [
47
+            '',
48
+            [
49
+              Validators.required,
50
+              Validators.minLength(3),
51
+              Validators.maxLength(15),
52
+            ],
53
+          ],
54
+          email: ['', [Validators.required, Validators.email]],
55
+          address: this.fb.group({
56
+            numRue: [0, [Validators.required, Validators.min(1)]],
57
+            nomRue: [
58
+              '',
59
+              [
60
+                Validators.required,
61
+                Validators.minLength(3),
62
+                Validators.maxLength(25),
63
+              ],
64
+            ],
65
+            bp: [0, [Validators.required, Validators.min(1)]],
66
+            ville: [
67
+              '',
68
+              [
69
+                Validators.required,
70
+                Validators.minLength(3),
71
+                Validators.maxLength(15),
72
+              ],
73
+            ],
74
+            pays: [
75
+              '',
76
+              [
77
+                Validators.required,
78
+                Validators.minLength(3),
79
+                Validators.maxLength(15),
80
+              ],
81
+            ],
82
+          }),
83
+        });
84
+      }
85
+    });
86
+  }
87
+
88
+  onUserSave() {
89
+    if (window.confirm(MsgState.CONFIRM)) {
90
+      this.store.dispatch(new SaveUserFormAction(this.userFormGroup.value));
91
+    }
92
+  }
93
+
94
+  onNewUser() {
95
+    this.store.dispatch(new CreateUserFormAction({}));
96
+  }
97
+}

+ 20
- 6
src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.html Zobrazit soubor

@@ -25,17 +25,31 @@
25 25
         (click)="onGetUsersVsProjects()"
26 26
       ></button>
27 27
     </div>
28
+
28 29
     <ul class="navbar-nav ml-auto">
29 30
       <li>
30
-        <form #f="ngForm" (ngSubmit)="onSearch(f.value)" class="form-inline">
31
-            <div class="form-group">
32
-              <input type="text" class="form-control" ngModel name="keyword">
33
-              <button class="btn btn-outline-primary"type="submit" [disabled]="!f.valid"> <i class="fa fa-search"></i>search</button>
31
+        <form #form="ngForm"
32
+          (ngSubmit)="onSearch(form.value)"
33
+          novalidate
34
+        >
35
+          <div class="input-group">
36
+            <input
37
+              type="text"
38
+              class="form-control"
39
+              name="keyword"
40
+              ngModel
41
+              placeholder="firstname keyword"
42
+            />
43
+            <div class="input-group-append">
44
+              <span class="input-group-text" id="basic-addon2">
45
+                <button class="btn" type="submit" [disabled]="!form.valid">
46
+                  <i class="fa fa-search"></i>search
47
+                </button>
48
+              </span>
34 49
             </div>
50
+          </div>
35 51
         </form>
36 52
       </li>
37 53
     </ul>
38 54
   </nav>
39 55
 </div>
40
-
41
-

+ 19
- 11
src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.ts Zobrazit soubor

@@ -1,27 +1,35 @@
1
-import { SearchUsersAction } from './../../../../ngrx/users/users.actions';
1
+import { UserState } from './../../../../ngrx/users/user.state';
2
+import {
3
+  SearchUsersAction,
4
+  CreateUserFormAction,
5
+} from './../../../../ngrx/users/users.actions';
2 6
 import { GetAllUsersAction } from '../../../../ngrx/users/users.actions';
3 7
 import { Component } from '@angular/core';
4 8
 import { Store } from '@ngrx/store';
9
+import { Router } from '@angular/router';
5 10
 
6 11
 @Component({
7 12
   selector: 'app-user-nav-bar',
8 13
   templateUrl: './user-nav-bar.component.html',
9
-  styleUrls: ['./user-nav-bar.component.css']
14
+  styleUrls: ['./user-nav-bar.component.css'],
10 15
 })
11 16
 export class UserNavBarComponent {
17
+  constructor(
18
+    private store: Store<{ userReducerKey: UserState }>,
19
+    private router: Router
20
+  ) {}
12 21
 
13
-  constructor(private store: Store) { }
14 22
 
15
-   onUserCreate(): any{}
16
-
17
-  onUsersGetAll(): any{
18
-
19
-    this.store.dispatch(new GetAllUsersAction({}))
23
+  onUserCreate(): void {
24
+    this.router.navigateByUrl('/user-create');
20 25
   }
21
-  onGetUsersVsProjects(): any{}
22 26
 
23
-  onSearch(searchForm:any){
27
+  onUsersGetAll(): any {
28
+    this.store.dispatch(new GetAllUsersAction({}));
29
+  }
30
+  onGetUsersVsProjects(): any {}
24 31
 
25
-    this.store.dispatch(new SearchUsersAction(searchForm.keyword))
32
+  onSearch(searchForm: any) {
33
+    this.store.dispatch(new SearchUsersAction(searchForm.keyword));
26 34
   }
27 35
 }

+ 3
- 0
src/app/pages/users-manager/users-management/users-list/users-list.component.css Zobrazit soubor

@@ -0,0 +1,3 @@
1
+ul{
2
+  list-style-type: none;
3
+}

+ 7
- 8
src/app/pages/users-manager/users-management/users-list/users-list.component.html Zobrazit soubor

@@ -1,13 +1,13 @@
1
-<p-table
1
+<p-table #tbl
2 2
 [value]="inputState.usersList"
3 3
 responsiveLayout="scroll"
4 4
 *ngIf="inputState.usersList && inputState.usersList.length > 0"
5 5
 styleClass="p-datatable-striped"
6 6
 [paginator]="true"
7
-[rows]="2"
7
+[rows]="3"
8 8
 [showCurrentPageReport]="true"
9 9
 currentPageReportTemplate="{first} - {last} of {totalRecords} users"
10
-[rowsPerPageOptions]="[2, 5, 10]"
10
+[rowsPerPageOptions]="[3, 5, 10]"
11 11
 >
12 12
 <ng-template pTemplate="header">
13 13
   <tr>
@@ -27,10 +27,9 @@ currentPageReportTemplate="{first} - {last} of {totalRecords} users"
27 27
     <td>{{ user.lastname }}</td>
28 28
     <td>
29 29
       <ul>
30
-        <li>{{user.address.numRue}}</li>
30
+        <li>{{user.address.numRue}}</li>
31 31
         <li> {{user.address.nomRue}}</li>
32
-        <li> {{user.address.bp}}</li>
33
-        <li> {{user.address.ville}}</li>
32
+        <li> {{user.address.bp}} {{user.address.ville}}
34 33
         <li>{{user.address.pays}}</li>
35 34
       </ul>
36 35
     </td>
@@ -40,7 +39,7 @@ currentPageReportTemplate="{first} - {last} of {totalRecords} users"
40 39
         <i
41 40
           class="fa fa-pencil"
42 41
           style="color: mediumturquoise"
43
-
42
+          (click)="onUserEdit(user)"
44 43
         ></i>
45 44
       </button>
46 45
     </td>
@@ -49,7 +48,7 @@ currentPageReportTemplate="{first} - {last} of {totalRecords} users"
49 48
         <i
50 49
           class="fa fa-trash"
51 50
           style="color: red"
52
-
51
+          (click)="onUserDelete(user)"
53 52
         ></i>
54 53
       </button>
55 54
     </td>

+ 18
- 2
src/app/pages/users-manager/users-management/users-list/users-list.component.ts Zobrazit soubor

@@ -1,6 +1,10 @@
1
-import { UserState } from './../../../../ngrx/users/users.reducer';
1
+import { EditUsersAction, DeleteUsersAction } from './../../../../ngrx/users/users.actions';
2
+import { User } from 'src/app/shared/models/user.model';
2 3
 import { Input } from '@angular/core';
3 4
 import { Component } from '@angular/core';
5
+import { UserState } from 'src/app/ngrx/users/user.state';
6
+import { Store } from '@ngrx/store';
7
+import { MsgState } from 'src/app/ngrx/msg.state';
4 8
 
5 9
 @Component({
6 10
   selector: 'app-users-list',
@@ -9,6 +13,18 @@ import { Component } from '@angular/core';
9 13
 })
10 14
 export class UsersListComponent {
11 15
 
12
- @Input ()  inputState!: UserState
16
+ @Input()  inputState!: UserState
13 17
 
18
+ constructor(private store: Store<any>){}
19
+
20
+ onUserEdit(user:User){
21
+   this.store.dispatch(new EditUsersAction({user}))
22
+ }
23
+
24
+ onUserDelete(user: User){
25
+
26
+  if(window.confirm(MsgState.CONFIRM)){
27
+    this.store.dispatch(new DeleteUsersAction(user));
28
+  }
29
+ }
14 30
 }

+ 8
- 8
src/app/pages/users-manager/users-management/users-management.component.html Zobrazit soubor

@@ -1,21 +1,21 @@
1 1
 <div class="p-4">
2 2
   <app-user-nav-bar></app-user-nav-bar>
3 3
 
4
-  <ng-container *ngIf="userState$ | async as userState" [ngSwitch]="userState.dataState">
4
+  <ng-container *ngIf="userState$ | async as userState" [ngSwitch]="userState.msgState">
5 5
 
6
-    <ng-container *ngSwitchCase="userStateEnum.INIT_STATE">
7
-      <div class="p-2">initial state</div>
6
+    <ng-container *ngSwitchCase="userMsg.INIT_STATE">
7
+      <div class="p-2">{{userState.msgState}}</div>
8 8
     </ng-container>
9 9
 
10
-    <ng-container *ngSwitchCase="userStateEnum.LOADING">
11
-      <div class="p-2">Data are looding ...</div>
10
+    <ng-container *ngSwitchCase="userMsg.LOADING">
11
+      <div class="p-2">{{userMsg.LOADING}}</div>
12 12
     </ng-container>
13 13
 
14
-    <ng-container *ngSwitchCase="userStateEnum.ERROR">
15
-      <div class="p-2 text-danger"> {{userState.serverErrorMsg}} </div>
14
+    <ng-container *ngSwitchCase="userMsg.ERROR">
15
+      <div class="p-2 text-danger"> {{userState.userServerErrorMsg}} </div>
16 16
     </ng-container>
17 17
 
18
-    <ng-container *ngSwitchCase="userStateEnum.LOADED">
18
+    <ng-container *ngSwitchCase="userMsg.LOADED">
19 19
       <app-users-list [inputState]="userState"></app-users-list>
20 20
     </ng-container>
21 21
 

+ 19
- 14
src/app/pages/users-manager/users-management/users-management.component.ts Zobrazit soubor

@@ -1,27 +1,32 @@
1
-import { userReducer } from 'src/app/ngrx/users/users.reducer';
2
-import { UserState, UserStateEnum } from './../../../ngrx/users/users.reducer';
3
-import { Observable, map } from 'rxjs';
1
+import { UserState } from './../../../ngrx/users/user.state';
4 2
 import { Component, OnInit } from '@angular/core';
5
-import { Store } from '@ngrx/store';
3
+import {  Store } from '@ngrx/store';
4
+import { map, Observable } from 'rxjs';
5
+import { User } from 'src/app/shared/models/user.model';
6
+import { MsgState } from 'src/app/ngrx/msg.state';
6 7
 
7 8
 @Component({
8 9
   selector: 'app-users-management',
9 10
   templateUrl: './users-management.component.html',
10
-  styleUrls: ['./users-management.component.css']
11
+  styleUrls: ['./users-management.component.css'],
11 12
 })
12 13
 export class UsersManagementComponent implements OnInit {
13 14
 
14
-  userState$ !: Observable<UserState>
15
-  readonly userStateEnum = UserStateEnum
15
+  userState$!: Observable<{
16
+    usersList: User[];
17
+    msgState: MsgState;
18
+    userServerErrorMsg: string;
19
+  }>;
16 20
 
17
-  constructor(private store: Store<any>) { }
21
+  readonly userMsg = MsgState;
18 22
 
19
-  ngOnInit(): void {
20
-
21
-  this.userState$ = this.store.pipe(
23
+  constructor(private store: Store<{ userReducerKey: UserState }>) {}
22 24
 
23
-    map( (state) => state.userReducer)
24
-  )
25
+  ngOnInit(): void {
26
+   // this.userState$ = this.store.select('userReducerKey');
27
+    //or
28
+    this.userState$ = this.store.pipe(
29
+      map( (userState) => userState.userReducerKey)
30
+    )
25 31
   }
26
-
27 32
 }

+ 1
- 1
src/app/pages/users-manager/users-manager-routing.module.ts Zobrazit soubor

@@ -1,7 +1,7 @@
1 1
 import { UsersManagementComponent } from './users-management/users-management.component';
2 2
 import { NgModule } from '@angular/core';
3 3
 import { RouterModule, Routes } from '@angular/router';
4
-import { UserCreateComponent } from './user-create/user-create.component';
4
+import { UserCreateComponent } from './users-management/user-create/user-create.component';
5 5
 
6 6
 const routes: Routes = [
7 7
   {path: 'user-create',component: UserCreateComponent},

+ 5
- 4
src/app/pages/users-manager/users-manager.module.ts Zobrazit soubor

@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
2 2
 import { CommonModule } from '@angular/common';
3 3
 import { ButtonModule } from "primeng/button";
4 4
 import { UsersManagerRoutingModule } from './users-manager-routing.module';
5
-import { UserCreateComponent } from './user-create/user-create.component';
5
+import { UserCreateComponent } from './users-management/user-create/user-create.component';
6 6
 import { UsersManagementComponent } from './users-management/users-management.component';
7 7
 import { UserNavBarComponent } from './users-management/user-nav-bar/user-nav-bar.component';
8 8
 import { EffectsModule } from '@ngrx/effects';
@@ -12,7 +12,7 @@ import { UserEffects } from 'src/app/ngrx/users/users.effects';
12 12
 import { userReducer } from 'src/app/ngrx/users/users.reducer';
13 13
 import { TableModule } from "primeng/table";
14 14
 import { UsersListComponent } from './users-management/users-list/users-list.component';
15
-import { FormsModule } from '@angular/forms';
15
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
16 16
 
17 17
 
18 18
 
@@ -27,11 +27,12 @@ import { FormsModule } from '@angular/forms';
27 27
     CommonModule,
28 28
     UsersManagerRoutingModule,
29 29
     ButtonModule,
30
-    StoreModule.forRoot({userReducer: userReducer}),
30
+    StoreModule.forRoot({userReducerKey: userReducer}),
31 31
     EffectsModule.forRoot([UserEffects]),
32 32
     StoreDevtoolsModule.instrument(),
33 33
     TableModule,
34
-    FormsModule
34
+    FormsModule,
35
+    ReactiveFormsModule
35 36
   ]
36 37
 })
37 38
 export class UsersManagerModule { }

Powered by TurnKey Linux.