Browse Source

commit modification

placidenduwayo 2 years ago
parent
commit
ec72e70986

+ 35
- 9
db_users_projects_companies.json View File

26
       "lastname": "Touitou",
26
       "lastname": "Touitou",
27
       "email": "david.touitou@natan.fr",
27
       "email": "david.touitou@natan.fr",
28
       "address": {
28
       "address": {
29
-        "numRue": 44,
29
+        "numRue": 445,
30
         "nomRue": "Rue Notre Dame de Paris",
30
         "nomRue": "Rue Notre Dame de Paris",
31
         "bp": 75002,
31
         "bp": 75002,
32
         "ville": "Paris",
32
         "ville": "Paris",
139
     },
139
     },
140
     {
140
     {
141
       "id": 13,
141
       "id": 13,
142
-      "firstname": null,
143
-      "lastname": null,
144
-      "email": null,
142
+      "firstname": "azyd_yiuj",
143
+      "lastname": "azegr_èéiu",
144
+      "email": "zehr@zeuhuh",
145
+      "address": {
146
+        "numRue": 65652,
147
+        "nomRue": "zedtyuhjn",
148
+        "bp": 74512,
149
+        "ville": "zhgaèzty",
150
+        "pays": "sdgauzej"
151
+      }
152
+    },
153
+    {
154
+      "id": 14,
155
+      "firstname": "Naolie",
156
+      "lastname": "Boudouka Tété",
157
+      "email": "naolie.boudouka-tete@natan.fr",
145
       "address": {
158
       "address": {
146
-        "numRue": null,
147
-        "nomRue": null,
148
-        "bp": null,
149
-        "ville": null,
150
-        "pays": null
159
+        "numRue": 44,
160
+        "nomRue": "Rue Notre Dame de Paris",
161
+        "bp": 75002,
162
+        "ville": "Paris",
163
+        "pays": "France"
164
+      }
165
+    },
166
+    {
167
+      "id": 15,
168
+      "firstname": "Rayene",
169
+      "lastname": "Bessrour",
170
+      "email": "rayene.bessrour@natan.fr",
171
+      "address": {
172
+        "numRue": 44,
173
+        "nomRue": "Rue Notre Dame de Paris",
174
+        "bp": 75002,
175
+        "ville": "Paris",
176
+        "pays": "France"
151
       }
177
       }
152
     }
178
     }
153
   ],
179
   ],

+ 2
- 1
src/app/ngrx/msg.state.ts View File

6
   FORM_LOADING = 'FORM LOADING',
6
   FORM_LOADING = 'FORM LOADING',
7
   FORM_LOADED = 'FORM LOADED',
7
   FORM_LOADED = 'FORM LOADED',
8
   FORM_LOAD_ERR= 'FORM LOADING ERROR',
8
   FORM_LOAD_ERR= 'FORM LOADING ERROR',
9
-  CONFIRM = 'CONFIRM',
9
+  CONFIRM_ADD = 'CONFIRM ADDING OF',
10
+  CONFIRM_DEL = 'CONFIRM DELETION OF',
10
   ADDED = 'SUCCESSFULLY ADDED',
11
   ADDED = 'SUCCESSFULLY ADDED',
11
   EXIST = 'ALREADY EXISTS',
12
   EXIST = 'ALREADY EXISTS',
12
   UPDATED = '[User] SUCCESSFULLY UPDATED',
13
   UPDATED = '[User] SUCCESSFULLY UPDATED',

+ 1
- 1
src/app/ngrx/users/users.actions.ts View File

85
 
85
 
86
 export class CreateFormUserAddAction implements Action {
86
 export class CreateFormUserAddAction implements Action {
87
   type: UserActionType = UserActionType.CREATE_FORM_ADD_USER;
87
   type: UserActionType = UserActionType.CREATE_FORM_ADD_USER;
88
-  constructor(public payload: void) {}
88
+  constructor(public payload: any) {}
89
 }
89
 }
90
 
90
 
91
 export class CreateFormUserAddActionSuccess implements Action {
91
 export class CreateFormUserAddActionSuccess implements Action {

+ 86
- 66
src/app/ngrx/users/users.effects.ts View File

1
-import { UserActionType, GetAllUsersActionSuccess, GetAllUsersActionError, UserActionUnion, SearchUserActionSuccess, SearchUserActionError, CreareFormUserEditActionSuccess, CreareFormUserEditActionActionError, DeleteUserActionSuccess, DeleteUserActionError, CreateFormUserAddActionSuccess, CreateFormUserAddActionError, SaveUserFormActionSuccess, SaveUserFormActionError, UpdateUserFormAction, UpdateUserFormActionError, UpdateUserFormActionSuccess } from './users.actions';
1
+import {
2
+  UserActionType,
3
+  GetAllUsersActionSuccess,
4
+  GetAllUsersActionError,
5
+  UserActionUnion,
6
+  SearchUserActionSuccess,
7
+  SearchUserActionError,
8
+  CreareFormUserEditActionSuccess,
9
+  CreareFormUserEditActionActionError,
10
+  DeleteUserActionSuccess,
11
+  DeleteUserActionError,
12
+  CreateFormUserAddActionSuccess,
13
+  CreateFormUserAddActionError,
14
+  SaveUserFormActionSuccess,
15
+  SaveUserFormActionError,
16
+  UpdateUserFormAction,
17
+  UpdateUserFormActionError,
18
+  UpdateUserFormActionSuccess,
19
+} from './users.actions';
2
 import { map, mergeMap, Observable, catchError, of } from 'rxjs';
20
 import { map, mergeMap, Observable, catchError, of } from 'rxjs';
3
 import { UsersService } from './../../shared/services/users.service';
21
 import { UsersService } from './../../shared/services/users.service';
4
-import { Injectable } from "@angular/core";
22
+import { Injectable } from '@angular/core';
5
 import { Actions, createEffect, ofType } from '@ngrx/effects';
23
 import { Actions, createEffect, ofType } from '@ngrx/effects';
6
 import { User } from 'src/app/shared/models/user.model';
24
 import { User } from 'src/app/shared/models/user.model';
7
 
25
 
8
 @Injectable()
26
 @Injectable()
9
-export class UserEffects{
27
+export class UserEffects {
28
+  constructor(
29
+    private usersService: UsersService,
30
+    private effectActions: Actions
31
+  ) {}
10
 
32
 
11
-  constructor(private usersService: UsersService, private effectActions: Actions){}
33
+  /** creation of effects about all cations related to a user */
12
 
34
 
13
-  //create getAllUsers effects
35
+  //create getAllUsers effect
14
 
36
 
15
-  getAllUsersEffect: Observable<UserActionUnion> = createEffect(
16
-
17
-    () => this.effectActions.pipe(
37
+  getAllUsersEffect: Observable<UserActionUnion> = createEffect(() =>
38
+    this.effectActions.pipe(
18
       ofType(UserActionType.GET_ALL_USERS),
39
       ofType(UserActionType.GET_ALL_USERS),
19
-      mergeMap(
20
-        () =>{
21
-
22
-          return this.usersService.getAllUsers().pipe(
23
-              map((users: User[])=> new GetAllUsersActionSuccess(users)),
24
-              catchError((err) => of(new GetAllUsersActionError(err.message)))
25
-            );
26
-        }
27
-      )
28
-
29
-    )
30
-  );
31
-   //create searchUser effects
32
-   searchUserEffect: Observable<UserActionUnion> = createEffect(
33
-
34
-    () => this.effectActions.pipe(
35
-      ofType(UserActionType.SEARCH_A_USER),
36
-      mergeMap(
37
-        (userAction: UserActionUnion) =>{
38
-
39
-          return this.usersService.searchUser(userAction.payload).pipe(
40
-              map((users: User[])=> new SearchUserActionSuccess(users)),
41
-              catchError((err) => of(new SearchUserActionError(err.message)))
42
-            );
43
-        }
44
-      )
45
-
40
+      mergeMap(() => {
41
+        return this.usersService.getAllUsers().pipe(
42
+          map((users: User[]) => new GetAllUsersActionSuccess(users)),
43
+          catchError((err) => of(new GetAllUsersActionError(err.message)))
44
+        );
45
+      })
46
     )
46
     )
47
   );
47
   );
48
 
48
 
49
+  //create searchUser effect
49
 
50
 
50
-  //create deleteUser effect
51
-  deleteUserEffect: Observable<UserActionUnion> = createEffect(
52
-    ()=> this.effectActions.pipe(
53
-      ofType(UserActionType.DELETE_A_USER),
54
-      mergeMap( (userAction: UserActionUnion) => {
55
-        return this.usersService.deleteUser(userAction.payload.id).pipe(
56
-          map( ()=> new DeleteUserActionSuccess(userAction.payload)),
57
-          catchError( (err) => of(new DeleteUserActionError(err.message)))
58
-        )
51
+  searchUserEffect: Observable<UserActionUnion> = createEffect(() =>
52
+    this.effectActions.pipe(
53
+      ofType(UserActionType.SEARCH_A_USER),
54
+      mergeMap((userAction: UserActionUnion) => {
55
+        return this.usersService.searchUser(userAction.payload).pipe(
56
+          map((users: User[]) => new SearchUserActionSuccess(users)),
57
+          catchError((err) => of(new SearchUserActionError(err.message)))
58
+        );
59
       })
59
       })
60
     )
60
     )
61
   );
61
   );
62
 
62
 
63
   //create a user add form effect
63
   //create a user add form effect
64
-  createAddUserFormEffect: Observable<UserActionUnion> = createEffect(
65
-    () => this.effectActions.pipe(
64
+  createAddUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
65
+    this.effectActions.pipe(
66
       ofType(UserActionType.CREATE_FORM_ADD_USER),
66
       ofType(UserActionType.CREATE_FORM_ADD_USER),
67
-      map( ()=>{
67
+      map(() => {
68
         return new CreateFormUserAddActionSuccess({});
68
         return new CreateFormUserAddActionSuccess({});
69
       }),
69
       }),
70
-      catchError( (err) => of(new CreateFormUserAddActionError(err.message)))
70
+      catchError((err) => of(new CreateFormUserAddActionError(err.message)))
71
     )
71
     )
72
   );
72
   );
73
 
73
 
74
-  //action of saving user form data effect
75
-  saveUserFormEffect : Observable<UserActionUnion> = createEffect(
76
-    () => this.effectActions.pipe(
74
+  //saving user form data effect
75
+
76
+  saveUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
77
+    this.effectActions.pipe(
77
       ofType(UserActionType.SAVE_USERFORM_ADD),
78
       ofType(UserActionType.SAVE_USERFORM_ADD),
78
-      mergeMap( (userAction: UserActionUnion) => {
79
+      mergeMap((userAction: UserActionUnion) => {
79
         return this.usersService.createUser(userAction.payload).pipe(
80
         return this.usersService.createUser(userAction.payload).pipe(
80
-          map (user => new SaveUserFormActionSuccess(user)),
81
-          catchError( err => of(new SaveUserFormActionError(err.message)))
81
+          map((user) => new SaveUserFormActionSuccess(user)),
82
+          catchError((err) => of(new SaveUserFormActionError(err.message)))
82
         );
83
         );
83
       })
84
       })
84
     )
85
     )
85
   );
86
   );
86
 
87
 
87
-  //create update user form with data of user to update effect
88
-  createUpdateUserFormEffect: Observable<UserActionUnion> = createEffect(
89
-    () => this.effectActions.pipe(
88
+  // create an update user form effect and fill it with data of a user to update
89
+
90
+  createUpdateUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
91
+    this.effectActions.pipe(
90
       ofType(UserActionType.CREATE_FORM_USER_EDIT),
92
       ofType(UserActionType.CREATE_FORM_USER_EDIT),
91
-      mergeMap( (userAction: UserActionUnion)=>{
93
+      mergeMap((userAction: UserActionUnion) => {
92
         return this.usersService.getUserById(userAction.payload.id).pipe(
94
         return this.usersService.getUserById(userAction.payload.id).pipe(
93
-          map( (user: User)=> new CreareFormUserEditActionSuccess(user)),
94
-          catchError( (err) => of(new CreareFormUserEditActionActionError(err.message)))
95
-        )
95
+          map((user: User) => new CreareFormUserEditActionSuccess(user)),
96
+          catchError((err) =>
97
+            of(new CreareFormUserEditActionActionError(err.message))
98
+          )
99
+        );
96
       })
100
       })
97
     )
101
     )
98
   );
102
   );
99
 
103
 
100
-  updateUserFormDataEffect: Observable<UserActionUnion> = createEffect(
101
-    () => this.effectActions.pipe(
104
+  // update a user with data of form effect
105
+
106
+  updateUserFormDataEffect: Observable<UserActionUnion> = createEffect(() =>
107
+    this.effectActions.pipe(
102
       ofType(UserActionType.UPDATE_USER_FORM),
108
       ofType(UserActionType.UPDATE_USER_FORM),
103
-      mergeMap( (userAction: UserActionUnion) =>{
109
+      mergeMap((userAction: UserActionUnion) => {
104
         return this.usersService.updateUser(userAction.payload).pipe(
110
         return this.usersService.updateUser(userAction.payload).pipe(
105
-          map( (user: User) => new UpdateUserFormActionSuccess(user)),
106
-          catchError( err => of(new UpdateUserFormActionError(err.message)))
111
+          map((user: User) => new UpdateUserFormActionSuccess(user)),
112
+          catchError((err) => of(new UpdateUserFormActionError(err.message)))
113
+        );
114
+      })
115
+    )
116
+  );
117
+
118
+  //deleteUser effect
119
+
120
+  deleteUserEffect: Observable<UserActionUnion> = createEffect(() =>
121
+    this.effectActions.pipe(
122
+      ofType(UserActionType.DELETE_A_USER),
123
+      mergeMap((userAction: UserActionUnion) => {
124
+        return this.usersService.deleteUser(userAction.payload.id).pipe(
125
+          map(() => new DeleteUserActionSuccess(userAction.payload)),
126
+          catchError((err) => of(new DeleteUserActionError(err.message)))
107
         );
127
         );
108
       })
128
       })
109
     )
129
     )

+ 36
- 44
src/app/ngrx/users/users.reducer.ts View File

1
 import { Action } from '@ngrx/store';
1
 import { Action } from '@ngrx/store';
2
 import { User } from 'src/app/shared/models/user.model';
2
 import { User } from 'src/app/shared/models/user.model';
3
 import { MsgState } from '../msg.state';
3
 import { MsgState } from '../msg.state';
4
+import { UserState } from './user.state';
4
 import { UserActionUnion, UserActionType } from './users.actions';
5
 import { UserActionUnion, UserActionType } from './users.actions';
5
 
6
 
6
-//create a state
7
-export class UserState {
8
-  currentUser!: User | null;
9
-  usersList!: User[];
10
-  msgState!: MsgState;
11
-  userServerErrorMsg!: string;
12
-}
7
+/** create reducer,
8
+ * a reducer need a initial state and an action to perform*/
13
 
9
 
14
-//create reducer, a reducer need a initial state and an action
15
-const initUserState: UserState = {
10
+const initialUserState: UserState = {
16
   usersList: [],
11
   usersList: [],
17
   currentUser: null,
12
   currentUser: null,
18
   msgState: MsgState.INIT_STATE,
13
   msgState: MsgState.INIT_STATE,
20
 };
15
 };
21
 
16
 
22
 export function userReducer(
17
 export function userReducer(
23
-  state: UserState = initUserState,
18
+  state: UserState = initialUserState,
24
   action: Action
19
   action: Action
25
 ): UserState {
20
 ): UserState {
26
 
21
 
27
   switch (action.type) {
22
   switch (action.type) {
28
 
23
 
29
-    /** get all users actions */
24
+    // get all users actions
30
     case UserActionType.GET_ALL_USERS:
25
     case UserActionType.GET_ALL_USERS:
31
       return { ...state, msgState: MsgState.LOADING };
26
       return { ...state, msgState: MsgState.LOADING };
32
 
27
 
34
       return {
29
       return {
35
         ...state,
30
         ...state,
36
         msgState: MsgState.LOADED,
31
         msgState: MsgState.LOADED,
37
-        usersList: (<UserActionUnion> action).payload,
32
+        usersList: (<UserActionUnion>action).payload,
38
       };
33
       };
39
 
34
 
40
     case UserActionType.GET_ALL_USERS_ERROR:
35
     case UserActionType.GET_ALL_USERS_ERROR:
44
         userServerErrorMsg: (<UserActionUnion>action).payload,
39
         userServerErrorMsg: (<UserActionUnion>action).payload,
45
       };
40
       };
46
 
41
 
47
-
48
-    /** search a user actions */
42
+    // search a user actions
49
     case UserActionType.SEARCH_A_USER:
43
     case UserActionType.SEARCH_A_USER:
50
       return { ...state, msgState: MsgState.LOADING };
44
       return { ...state, msgState: MsgState.LOADING };
51
 
45
 
63
         userServerErrorMsg: (<UserActionUnion>action).payload,
57
         userServerErrorMsg: (<UserActionUnion>action).payload,
64
       };
58
       };
65
 
59
 
66
-
67
-    /** create a user form actions */
60
+    // create a user form actions
68
     case UserActionType.CREATE_FORM_ADD_USER:
61
     case UserActionType.CREATE_FORM_ADD_USER:
69
       return {
62
       return {
70
         ...state,
63
         ...state,
84
         userServerErrorMsg: (<UserActionUnion>action).payload,
77
         userServerErrorMsg: (<UserActionUnion>action).payload,
85
       };
78
       };
86
 
79
 
87
-    /** save a user (data of form) action*/
80
+    // save a user (data of form) action
88
     case UserActionType.SAVE_USERFORM_ADD:
81
     case UserActionType.SAVE_USERFORM_ADD:
89
       return {
82
       return {
90
         ...state,
83
         ...state,
108
         userServerErrorMsg: (<UserActionUnion>action).payload,
101
         userServerErrorMsg: (<UserActionUnion>action).payload,
109
       };
102
       };
110
 
103
 
111
-
112
-      /**create a edit user form actions */
104
+    // create a edit user form actions
113
     case UserActionType.CREATE_FORM_USER_EDIT:
105
     case UserActionType.CREATE_FORM_USER_EDIT:
114
       return {
106
       return {
115
         ...state,
107
         ...state,
121
       return {
113
       return {
122
         ...state,
114
         ...state,
123
         msgState: MsgState.FORM_LOADED,
115
         msgState: MsgState.FORM_LOADED,
124
-        currentUser: modifiedUser
116
+        currentUser: modifiedUser,
125
       };
117
       };
126
 
118
 
127
     case UserActionType.CREATE_FORM_USER_EDIT_ERROR:
119
     case UserActionType.CREATE_FORM_USER_EDIT_ERROR:
131
         userServerErrorMsg: (<UserActionUnion>action).payload,
123
         userServerErrorMsg: (<UserActionUnion>action).payload,
132
       };
124
       };
133
 
125
 
126
+    // update user with user form data
134
 
127
 
135
-      /** update user with user form data*/
136
-
137
-      case UserActionType.UPDATE_USER_FORM:
138
-        return {
139
-          ...state,
140
-          msgState:MsgState.DEFAULT_MSG
141
-        };
142
-
143
-      case UserActionType.UPDATE_USER_FORM_SUCCESS:
144
-        let updatedUser: User = (<UserActionUnion> action).payload;
145
-        let usersListCopy2 : User[] = state.usersList.map(
146
-          (user)=>(user.id==updatedUser.id)?updatedUser:user);
128
+    case UserActionType.UPDATE_USER_FORM:
129
+      return {
130
+        ...state,
131
+        msgState: MsgState.DEFAULT_MSG,
132
+      };
147
 
133
 
148
-          return{
149
-          ...state,
150
-          currentUser: updatedUser,
151
-          msgState: MsgState.UPDATED
152
-        }
134
+    case UserActionType.UPDATE_USER_FORM_SUCCESS:
135
+      let updatedUser: User = (<UserActionUnion>action).payload;
136
+      let usersListCopy2: User[] = [...state.usersList];
137
+      usersListCopy2 = usersListCopy2.map((user) =>
138
+        user.id == updatedUser.id ? updatedUser : user
139
+      );
153
 
140
 
154
-      case UserActionType.UPDATE_USER_FORM_ERROR:
155
-        return{
156
-          ...state,
157
-          msgState: MsgState.ERR,
158
-          userServerErrorMsg: (<UserActionUnion>action).payload,
159
-        }
141
+      return {
142
+        ...state,
143
+        usersList: usersListCopy2,
144
+        msgState: MsgState.UPDATED,
145
+      };
160
 
146
 
147
+    case UserActionType.UPDATE_USER_FORM_ERROR:
148
+      return {
149
+        ...state,
150
+        msgState: MsgState.ERR,
151
+        userServerErrorMsg: (<UserActionUnion>action).payload,
152
+      };
161
 
153
 
162
-    /** delete a user actions */
154
+    // delete a user actions
163
     case UserActionType.DELETE_A_USER:
155
     case UserActionType.DELETE_A_USER:
164
       return {
156
       return {
165
         ...state,
157
         ...state,

+ 7
- 5
src/app/pages/users-manager/users-management/user-create/user-create.component.ts View File

27
   readonly msgState = MsgState;
27
   readonly msgState = MsgState;
28
 
28
 
29
   ngOnInit(): void {
29
   ngOnInit(): void {
30
-    this.store.dispatch(new CreateFormUserAddAction());
30
+    this.store.dispatch(new CreateFormUserAddAction({}));
31
 
31
 
32
     this.store.subscribe((myState) => {
32
     this.store.subscribe((myState) => {
33
       this.userState = myState.userReducerKey;
33
       this.userState = myState.userReducerKey;
93
        alert(lastname + ' ' + this.msgState.EXIST);
93
        alert(lastname + ' ' + this.msgState.EXIST);
94
        return;
94
        return;
95
      }
95
      }
96
+     else{
96
 
97
 
97
-     if (window.confirm(MsgState.CONFIRM)) {
98
-       this.store.dispatch(new SaveUserFormAction(this.userFormGroup.value));
98
+      if (window.confirm(MsgState.CONFIRM_ADD+' '+user.firstname+' '+user.lastname)) {
99
+        this.store.dispatch(new SaveUserFormAction(user));
100
+      }
99
      }
101
      }
100
    });
102
    });
101
   }
103
   }
102
 
104
 
103
   onNewUser() {
105
   onNewUser() {
104
-    this.store.dispatch(new CreateFormUserAddAction());
106
+    this.store.dispatch(new CreateFormUserAddAction({}));
105
   }
107
   }
106
 
108
 
107
   tryEgain() {
109
   tryEgain() {
108
-    this.store.dispatch(new CreateFormUserAddAction());
110
+    this.store.dispatch(new CreateFormUserAddAction({}));
109
   }
111
   }
110
 }
112
 }

+ 1
- 1
src/app/pages/users-manager/users-management/user-update/user-update.component.ts View File

99
   }
99
   }
100
 
100
 
101
   onUserUpdate() {
101
   onUserUpdate() {
102
-    if(window.confirm(MsgState.CONFIRM)){
102
+    if(window.confirm(MsgState.CONFIRM_ADD)){
103
       this.store.dispatch(new UpdateUserFormAction(this.userFormGrp.value));
103
       this.store.dispatch(new UpdateUserFormAction(this.userFormGrp.value));
104
     }
104
     }
105
   }
105
   }

+ 1
- 3
src/app/pages/users-manager/users-management/users-list/users-list.component.ts View File

1
 import { Router } from '@angular/router';
1
 import { Router } from '@angular/router';
2
-import { userReducer } from 'src/app/ngrx/users/users.reducer';
3
 import {
2
 import {
4
-  CreareFormUserEditAction,
5
   DeleteUsersAction,
3
   DeleteUsersAction,
6
 } from './../../../../ngrx/users/users.actions';
4
 } from './../../../../ngrx/users/users.actions';
7
 import { User } from 'src/app/shared/models/user.model';
5
 import { User } from 'src/app/shared/models/user.model';
29
   }
27
   }
30
 
28
 
31
   onUserDelete(user: User) {
29
   onUserDelete(user: User) {
32
-    if (window.confirm(MsgState.CONFIRM)) {
30
+    if (window.confirm(MsgState.CONFIRM_DEL+' '+user.firstname+' '+user.lastname)) {
33
       this.store.dispatch(new DeleteUsersAction(user));
31
       this.store.dispatch(new DeleteUsersAction(user));
34
     }
32
     }
35
   }
33
   }

Powered by TurnKey Linux.