소스 검색

commit modification

placidenduwayo 2 년 전
부모
커밋
1e998c08d6
67개의 변경된 파일1700개의 추가작업 그리고 215개의 파일을 삭제
  1. 4
    1
      .vscode/extensions.json
  2. 59
    27
      db_users_projects_companies.json
  3. 17
    8
      src/app/app.module.ts
  4. 85
    0
      src/app/ngrx/companies/companies.actions.ts
  5. 122
    0
      src/app/ngrx/companies/companies.reducer.ts
  6. 31
    0
      src/app/ngrx/companies/company.action.types.ts
  7. 8
    0
      src/app/ngrx/companies/company.state.ts
  8. 27
    0
      src/app/ngrx/companies/effects.company.get.search.ts
  9. 55
    0
      src/app/ngrx/companies/effects.company.update.delete.ts
  10. 4
    1
      src/app/ngrx/msg.state.ts
  11. 3
    2
      src/app/ngrx/projects/effects.project.create.ts
  12. 1
    1
      src/app/ngrx/projects/effects.project.get.ts
  13. 71
    0
      src/app/ngrx/projects/effects.project.update.delete.ts
  14. 16
    0
      src/app/ngrx/projects/project.action.types.ts
  15. 2
    4
      src/app/ngrx/projects/project.state.ts
  16. 58
    5
      src/app/ngrx/projects/projects.actions.ts
  17. 86
    21
      src/app/ngrx/projects/projects.reducer.ts
  18. 1
    1
      src/app/ngrx/users/effects.user.create.ts
  19. 1
    1
      src/app/ngrx/users/effects.user.get.search.ts
  20. 2
    3
      src/app/ngrx/users/effects.user.update.delete.ts
  21. 1
    2
      src/app/ngrx/users/user.state.ts
  22. 1
    1
      src/app/ngrx/users/users.actions.ts
  23. 1
    1
      src/app/ngrx/users/users.effects.ts
  24. 1
    2
      src/app/ngrx/users/users.reducer.ts
  25. 0
    0
      src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.css
  26. 60
    0
      src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.html
  27. 25
    0
      src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.spec.ts
  28. 35
    0
      src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.ts
  29. 20
    1
      src/app/pages/companies-manager/companies-management/companies-management.component.html
  30. 11
    1
      src/app/pages/companies-manager/companies-management/companies-management.component.ts
  31. 15
    1
      src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.ts
  32. 0
    0
      src/app/pages/companies-manager/companies-management/company-update/company-update.component.css
  33. 77
    0
      src/app/pages/companies-manager/companies-management/company-update/company-update.component.html
  34. 25
    0
      src/app/pages/companies-manager/companies-management/company-update/company-update.component.spec.ts
  35. 75
    0
      src/app/pages/companies-manager/companies-management/company-update/company-update.component.ts
  36. 3
    1
      src/app/pages/companies-manager/companies-manager-routing.module.ts
  37. 10
    2
      src/app/pages/companies-manager/companies-manager.module.ts
  38. 163
    1
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.html
  39. 92
    9
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.ts
  40. 2
    0
      src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.ts
  41. 0
    0
      src/app/pages/projects-manager/projects-management/project-update/project-update.component.css
  42. 150
    0
      src/app/pages/projects-manager/projects-management/project-update/project-update.component.html
  43. 25
    0
      src/app/pages/projects-manager/projects-management/project-update/project-update.component.spec.ts
  44. 109
    0
      src/app/pages/projects-manager/projects-management/project-update/project-update.component.ts
  45. 2
    2
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.html
  46. 19
    4
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.ts
  47. 2
    2
      src/app/pages/projects-manager/projects-management/projects-management.component.ts
  48. 6
    5
      src/app/pages/projects-manager/projects-manager-routing.module.ts
  49. 6
    3
      src/app/pages/projects-manager/projects-manager.module.ts
  50. 3
    2
      src/app/pages/users-manager/users-management/user-create/user-create.component.html
  51. 54
    52
      src/app/pages/users-manager/users-management/user-create/user-create.component.ts
  52. 1
    3
      src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.ts
  53. 39
    27
      src/app/pages/users-manager/users-management/user-update/user-update.component.html
  54. 2
    0
      src/app/pages/users-manager/users-management/users-list/users-list.component.html
  55. 1
    1
      src/app/pages/users-manager/users-management/users-list/users-list.component.ts
  56. 1
    1
      src/app/pages/users-manager/users-management/users-management.component.ts
  57. 2
    10
      src/app/pages/users-manager/users-manager.module.ts
  58. 0
    0
      src/app/shared/models/company/company.model.ts
  59. 0
    0
      src/app/shared/models/company/company.type.ts
  60. 2
    2
      src/app/shared/models/project/project.model.ts
  61. 1
    1
      src/app/shared/models/project/project.msgstate.ts
  62. 0
    0
      src/app/shared/models/project/project.priority.ts
  63. 0
    0
      src/app/shared/models/user/address.model.ts
  64. 2
    0
      src/app/shared/models/user/user.model.ts
  65. 1
    1
      src/app/shared/services/companies.service.ts
  66. 1
    1
      src/app/shared/services/projects.service.ts
  67. 1
    1
      src/app/shared/services/users.service.ts

+ 4
- 1
.vscode/extensions.json 파일 보기

@@ -1,4 +1,7 @@
1 1
 {
2 2
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3
-  "recommendations": ["angular.ng-template"]
3
+  "recommendations": [
4
+    "angular.ng-template",
5
+    "Angular.ng-template"
6
+  ]
4 7
 }

+ 59
- 27
db_users_projects_companies.json 파일 보기

@@ -1,20 +1,26 @@
1 1
 {
2 2
   "companies": [
3 3
     {
4
-      "id": 2,
5
-      "companyName": "Company-2",
4
+      "id": 1,
5
+      "companyName": "NATAN",
6 6
       "companyType": "PROSPECT",
7
-      "creationDate": "05/17/2022"
7
+      "creationDate": "05 17 2022"
8 8
     },
9 9
     {
10
-      "id": 3,
11
-      "companyName": "Natan",
12
-      "companyType": "PROSPECT",
10
+      "id": 2,
11
+      "companyName": "Company-1",
12
+      "companyType": "CLIENT",
13 13
       "creationDate": "05 17 2022"
14 14
     },
15 15
     {
16 16
       "id": 4,
17
-      "companyName": "Company-1",
17
+      "companyName": "Company-4",
18
+      "companyType": "PROSPECT",
19
+      "creationDate": "05 18 2022"
20
+    },
21
+    {
22
+      "id": 3,
23
+      "companyName": "Company-3",
18 24
       "companyType": "CLIENT",
19 25
       "creationDate": "05 18 2022"
20 26
     }
@@ -26,12 +32,13 @@
26 32
       "lastname": "Touitou",
27 33
       "email": "david.touitou@natan.fr",
28 34
       "address": {
29
-        "numRue": 44,
35
+        "numRue": 45,
30 36
         "nomRue": "Rue Notre Dame de Paris",
31 37
         "bp": 75002,
32 38
         "ville": "Paris",
33 39
         "pays": "France"
34
-      }
40
+      },
41
+      "creationDate": "05 15 2022"
35 42
     },
36 43
     {
37 44
       "id": 4,
@@ -44,7 +51,8 @@
44 51
         "bp": 75002,
45 52
         "ville": "Paris",
46 53
         "pays": "France"
47
-      }
54
+      },
55
+      "creationDate": "05 15 2022"
48 56
     },
49 57
     {
50 58
       "address": {
@@ -54,6 +62,7 @@
54 62
         "ville": "Paris",
55 63
         "pays": "France"
56 64
       },
65
+      "creationDate": "05 15 2022",
57 66
       "firstname": "Smail",
58 67
       "lastname": "Sellah",
59 68
       "email": "smail.sellah@natan.fr",
@@ -67,6 +76,7 @@
67 76
         "ville": "Paris",
68 77
         "pays": "France"
69 78
       },
79
+      "creationDate": "05 15 2022",
70 80
       "firstname": "Sarah",
71 81
       "lastname": "Leray",
72 82
       "email": "sarah.leray@natan.fr",
@@ -80,6 +90,7 @@
80 90
         "ville": "Paris",
81 91
         "pays": "France"
82 92
       },
93
+      "creationDate": "05 15 2022",
83 94
       "firstname": "Syrine",
84 95
       "lastname": "Ait Haddad",
85 96
       "email": "syrine.ait-haddadene@natan.fr",
@@ -93,6 +104,7 @@
93 104
         "ville": "Paris",
94 105
         "pays": "France"
95 106
       },
107
+      "creationDate": "05 15 2022",
96 108
       "firstname": "Marion",
97 109
       "lastname": "Jaillot",
98 110
       "email": "marion.jaillot@natan.fr",
@@ -106,6 +118,7 @@
106 118
         "ville": "Paris",
107 119
         "pays": "France"
108 120
       },
121
+      "creationDate": "05 15 2022",
109 122
       "firstname": "avraham",
110 123
       "lastname": "Benassaya",
111 124
       "email": "avraham.benassaya@natan.fr",
@@ -122,7 +135,8 @@
122 135
         "bp": 75002,
123 136
         "ville": "Paris",
124 137
         "pays": "France"
125
-      }
138
+      },
139
+      "creationDate": "05 15 2022"
126 140
     },
127 141
     {
128 142
       "id": 12,
@@ -135,7 +149,8 @@
135 149
         "bp": 75002,
136 150
         "ville": "Paris",
137 151
         "pays": "France"
138
-      }
152
+      },
153
+      "creationDate": "05 15 2022"
139 154
     },
140 155
     {
141 156
       "id": 14,
@@ -148,7 +163,8 @@
148 163
         "bp": 75002,
149 164
         "ville": "Paris",
150 165
         "pays": "France"
151
-      }
166
+      },
167
+      "creationDate": "05 15 2022"
152 168
     },
153 169
     {
154 170
       "id": 15,
@@ -161,7 +177,8 @@
161 177
         "bp": 75004,
162 178
         "ville": "Paris",
163 179
         "pays": "France"
164
-      }
180
+      },
181
+      "creationDate": "05 15 2022"
165 182
     },
166 183
     {
167 184
       "id": 17,
@@ -174,28 +191,33 @@
174 191
         "bp": 45,
175 192
         "ville": "user test",
176 193
         "pays": "user test"
177
-      }
194
+      },
195
+      "creationDate": "05 15 2022"
196
+    },
197
+    {
198
+      "id": 18,
199
+      "firstname": "test2",
200
+      "lastname": "test2",
201
+      "email": "test2@test2",
202
+      "address": {
203
+        "numRue": 121,
204
+        "nomRue": "test2",
205
+        "bp": 120,
206
+        "ville": "test2",
207
+        "pays": "test2"
208
+      },
209
+      "createDate": "06 07 2022"
178 210
     }
179 211
   ],
180 212
   "projects": [
181 213
     {
182
-      "id": 1,
183
-      "projectName": "Project-1",
184
-      "priority": 1,
185
-      "creationDate": "03 06 2022",
186
-      "companyId": 2,
187
-      "description": "Training users to frontend in angular",
188
-      "userId": 3,
189
-      "state": "END"
190
-    },
191
-    {
192 214
       "id": 2,
193 215
       "projectName": "Project-2",
194
-      "priority": 1,
216
+      "priority": 3,
195 217
       "creationDate": "03 06 2022",
196 218
       "companyId": 2,
197 219
       "description": "Project description for action",
198
-      "userId": 3,
220
+      "userId": 12,
199 221
       "state": "END"
200 222
     },
201 223
     {
@@ -215,6 +237,16 @@
215 237
       "creationDate": "03 06 2022",
216 238
       "companyId": 3,
217 239
       "description": "Project description for action",
240
+      "userId": 3,
241
+      "state": "END"
242
+    },
243
+    {
244
+      "id": 5,
245
+      "projectName": "Project-5",
246
+      "priority": 1,
247
+      "creationDate": "06 07 2022",
248
+      "companyId": 4,
249
+      "description": "Project of  creating and training models",
218 250
       "userId": 12,
219 251
       "state": "END"
220 252
     }

+ 17
- 8
src/app/app.module.ts 파일 보기

@@ -1,3 +1,5 @@
1
+import { CompanyUpdateDeleteEffects } from './ngrx/companies/effects.company.update.delete';
2
+import { CompanyGetSearchEffects } from './ngrx/companies/effects.company.get.search';
1 3
 import { BaseNavMenuComponent } from './pages/base-nav-menu/base-nav-menu.component';
2 4
 import { FormsModule } from '@angular/forms';
3 5
 import { AccueilModule } from './pages/accueil/accueil.module';
@@ -21,13 +23,16 @@ import { MatMenuModule } from '@angular/material/menu';
21 23
 import { EffectsModule } from '@ngrx/effects';
22 24
 import { StoreModule } from '@ngrx/store';
23 25
 import { StoreDevtoolsModule } from '@ngrx/store-devtools';
24
-import { ProjectCreateEffects } from './ngrx/projects/effects.projectcreate';
25
-import { UserCreateEffects } from './ngrx/users/effects.user.createuser';
26
-import { UserGetSearchEffects } from './ngrx/users/effects.user.getsearchuser';
27
-import { UserUpdateEffects } from './ngrx/users/effects.user.update';
26
+import { UserCreateEffects } from './ngrx/users/effects.user.create';
27
+import { UserGetSearchEffects } from './ngrx/users/effects.user.get.search';
28
+import { UserUpdateEffects } from './ngrx/users/effects.user.update.delete';
28 29
 import { userReducer } from './ngrx/users/users.reducer';
29 30
 import { projectReducer } from './ngrx/projects/projects.reducer';
30
-import { ProjectGet } from './ngrx/projects/effects.projectget';
31
+import { ProjectUpdateEffects } from './ngrx/projects/effects.project.update.delete';
32
+import { ProjectCreateEffects } from './ngrx/projects/effects.project.create';
33
+import { ProjectGet } from './ngrx/projects/effects.project.get';
34
+import { DatePipe } from '@angular/common';
35
+import { companyReducer } from './ngrx/companies/companies.reducer';
31 36
 
32 37
 @NgModule({
33 38
   declarations: [AppComponent, BaseNavMenuComponent],
@@ -50,18 +55,22 @@ import { ProjectGet } from './ngrx/projects/effects.projectget';
50 55
     MatMenuModule,
51 56
     StoreModule.forRoot({
52 57
       userReducerKey: userReducer,
53
-      productReducerKey: projectReducer,
58
+      projectReducerKey: projectReducer,
59
+      companyReducerKey: companyReducer
54 60
     }),
55 61
     EffectsModule.forRoot([
56 62
       UserCreateEffects,
57 63
       UserGetSearchEffects,
58 64
       UserUpdateEffects,
59 65
       ProjectCreateEffects,
60
-      ProjectGet
66
+      ProjectGet,
67
+      ProjectUpdateEffects,
68
+      CompanyGetSearchEffects,
69
+      CompanyUpdateDeleteEffects
61 70
     ]),
62 71
     StoreDevtoolsModule.instrument(),
63 72
   ],
64
-  providers: [],
73
+  providers: [DatePipe],
65 74
   bootstrap: [AppComponent],
66 75
 })
67 76
 export class AppModule {}

+ 85
- 0
src/app/ngrx/companies/companies.actions.ts 파일 보기

@@ -0,0 +1,85 @@
1
+import { CompanyActionTypes } from './company.action.types';
2
+import { Action } from '@ngrx/store';
3
+import { Company } from 'src/app/shared/models/company/company.model';
4
+/** all actions related to company */
5
+
6
+//get all companies
7
+export class GetAllCompaniesAction implements Action {
8
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES;
9
+  constructor(public payload: any) {}
10
+}
11
+
12
+export class GetAllCompaniesActionSuccess implements Action {
13
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES_SUCCESS;
14
+  constructor(public payload: Company[]) {}
15
+}
16
+
17
+export class GetAllCompaniesActionError implements Action {
18
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES_ERROR;
19
+  constructor(public payload: string) {}
20
+}
21
+
22
+//create form to create campany
23
+
24
+//create form to update company
25
+export class CreateFormToUpdateCompanyAction implements Action {
26
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE;
27
+  constructor(public payload: Company) {}
28
+}
29
+
30
+export class CreateFormToUpdateCompanyActionSuccess implements Action {
31
+  type: CompanyActionTypes =
32
+    CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE_SUCCESS;
33
+  constructor(public payload: Company) {}
34
+}
35
+
36
+export class CreateFormToUpdateCompanyActionError implements Action {
37
+  type: CompanyActionTypes =
38
+    CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE_ERROR;
39
+  constructor(public payload: string) {}
40
+}
41
+
42
+//save form data to update company
43
+export class UpdateCompanyWithFormDataAction implements Action {
44
+  type: CompanyActionTypes = CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA;
45
+  constructor(public payload: Company) {}
46
+}
47
+
48
+export class UpdateCompanyWithFormDataActionSuccess implements Action {
49
+  type: CompanyActionTypes =
50
+    CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA_SUCCESS;
51
+  constructor(public payload: Company) {}
52
+}
53
+
54
+export class UpdateCompanyWithFormDataActionError implements Action {
55
+  type: CompanyActionTypes =
56
+    CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA_ERROR;
57
+  constructor(public payload: string) {}
58
+}
59
+
60
+// detele a company
61
+export class DeleteCompany implements Action{
62
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY;
63
+  constructor(public payload: Company){}
64
+}
65
+
66
+export class DeleteCompanySuccess implements Action{
67
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY_SUCCESS;
68
+  constructor(public payload: Company){}
69
+}
70
+
71
+export class DeleteCompanyError implements Action{
72
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY_ERROR;
73
+  constructor(public payload: string){}
74
+}
75
+
76
+export type CompanyActionUnion =
77
+  | GetAllCompaniesAction
78
+  | GetAllCompaniesActionSuccess
79
+  | GetAllCompaniesActionError
80
+  | CreateFormToUpdateCompanyAction
81
+  | CreateFormToUpdateCompanyActionSuccess
82
+  | CreateFormToUpdateCompanyActionError
83
+  | UpdateCompanyWithFormDataAction
84
+  | UpdateCompanyWithFormDataActionSuccess
85
+  | UpdateCompanyWithFormDataActionError;

+ 122
- 0
src/app/ngrx/companies/companies.reducer.ts 파일 보기

@@ -0,0 +1,122 @@
1
+import { ProjectActionTypes } from './../projects/project.action.types';
2
+import { CompanyActionUnion } from './companies.actions';
3
+import { CompanyActionTypes } from './company.action.types';
4
+import { Action } from '@ngrx/store';
5
+import { MsgState } from '../msg.state';
6
+import { CompanyState } from './company.state';
7
+import { state } from '@angular/animations';
8
+import { Company } from 'src/app/shared/models/company/company.model';
9
+
10
+/**reducer fonction to handle actions
11
+a reducer function need initial state and an action to handle*/
12
+
13
+const companyInitialState: CompanyState = {
14
+  currentCompany: null,
15
+  companiesList: [],
16
+  msgState: MsgState.INIT_STATE,
17
+  serverMsgErron: 'no error msg',
18
+};
19
+
20
+export function companyReducer(
21
+  companyState: CompanyState = companyInitialState,
22
+  action: Action
23
+) {
24
+  switch (action.type) {
25
+    // get all companies
26
+    case CompanyActionTypes.GET_ALL_COMPANIES:
27
+      return {
28
+        ...companyState,
29
+        msgState: MsgState.LOADING,
30
+      };
31
+
32
+    case CompanyActionTypes.GET_ALL_COMPANIES_SUCCESS:
33
+      return {
34
+        ...companyState,
35
+        msgState: MsgState.LOADED,
36
+        companiesList: (<CompanyActionUnion>action).payload,
37
+      };
38
+
39
+    case CompanyActionTypes.GET_ALL_COMPANIES_ERROR:
40
+      return {
41
+        ...companyState,
42
+        msgState: MsgState.ERR,
43
+        serverMsgError: (<CompanyActionUnion>action).payload,
44
+      };
45
+
46
+    //create form to update company
47
+    case CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE:
48
+      return {
49
+        ...companyState,
50
+        msgState: MsgState.FORM_LOADING,
51
+      };
52
+    case CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE_SUCCESS:
53
+      let companyToUpdate: Company = (<CompanyActionUnion>action).payload;
54
+      return {
55
+        ...companyState,
56
+        msgState: MsgState.FORM_LOADED,
57
+        currentCompany: companyToUpdate,
58
+      };
59
+
60
+    case CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE_ERROR:
61
+      return {
62
+        ...companyState,
63
+        msgState: MsgState.FORM_LOAD_ERR,
64
+        serverMsgError: (<CompanyActionUnion>action).payload,
65
+      };
66
+
67
+    //save form data to update company
68
+    case CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA:
69
+      return {
70
+        ...companyState,
71
+        msgState: MsgState.DEFAULT_MSG,
72
+      };
73
+    case CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA_SUCCESS:
74
+      let updatedCompany: Company = (<CompanyActionUnion>action).payload;
75
+      let companiesListCopy1: Company[] = [...companyState.companiesList];
76
+      companiesListCopy1 = companiesListCopy1.map((company) =>
77
+        company.id == updatedCompany.id ? updatedCompany : company
78
+      );
79
+
80
+      return{
81
+        ...companyState,
82
+        msgState: MsgState.UPDATED,
83
+        companiesList: companiesListCopy1
84
+      }
85
+
86
+      case CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA_ERROR:
87
+        return{
88
+          ...companyState,
89
+          msgState: MsgState.ERR,
90
+          serverMsgError: (<CompanyActionUnion>action).payload
91
+        };
92
+
93
+        // delete a company
94
+      case CompanyActionTypes.DELETE_COMPANY:
95
+        return{
96
+          ...companyState,
97
+          msgState: MsgState.DELETE
98
+        }
99
+
100
+      case CompanyActionTypes.DELETE_COMPANY_SUCCESS:
101
+        let deletedCompany: Company = (<CompanyActionUnion> action).payload;
102
+        let deletedCompanyIndex = companyState.companiesList.indexOf(deletedCompany);
103
+        let companiesListCopy2: Company[] = [...companyState.companiesList];
104
+        companiesListCopy2 = companiesListCopy2.splice(deletedCompanyIndex);
105
+
106
+        return{
107
+          ...companyState,
108
+          msgState: MsgState.DELETED,
109
+          companiesList: companiesListCopy2
110
+        };
111
+
112
+      case CompanyActionTypes.DELETE_COMPANY_ERROR:
113
+        return{
114
+          ... companyState,
115
+          msgState: MsgState.ERR,
116
+          serverMsgError: (<CompanyActionUnion> action).payload
117
+        };
118
+
119
+    default:
120
+      return { ...companyState };
121
+  }
122
+}

+ 31
- 0
src/app/ngrx/companies/company.action.types.ts 파일 보기

@@ -0,0 +1,31 @@
1
+export enum CompanyActionTypes{
2
+  //get all companies action
3
+  GET_ALL_COMPANIES = '[Company] GET ALL COMPANIES',
4
+  GET_ALL_COMPANIES_SUCCESS = '[Company] GET ALL COMPANIES SUCCESS',
5
+  GET_ALL_COMPANIES_ERROR = '[Company] GET ALL COMPANIES ERROR',
6
+
7
+  //create a company form to add a project
8
+  CREATE_COMPANY_FORM_ADD = '[Company] CREATE COMPANY FORM ADD',
9
+  CREATE_COMPANY_FORM_ADD_SUCCESS = '[Company] CREATE COMPANY FORM ADD SUCCESS',
10
+  CREATE_COMPANY_FORM_ADD_ERROR = '[Company] CREATE COMPANY FORM ADD ERROR',
11
+
12
+  //save a company form data
13
+  SAVE_COMPANY_FORM_DATA ='[Company] SAVE COMPANY FORM DATA',
14
+  SAVE_COMPANY_FORM_DATA_SUCCESS ='[Company] SAVE COMPANY FORM DATA SUCCESS',
15
+  SAVE_COMPANY_FORM_DATA_ERROR ='[Company] SAVE COMPANY FORM DATA ERROR',
16
+
17
+  // create form to update a company
18
+  CREATE_COMPANY_FORM_UPDATE = '[Company] CREATE COMPANY FORM UPDATE',
19
+  CREATE_COMPANY_FORM_UPDATE_SUCCESS = '[Company] CREATE COMPANY FORM UPDATE SUCCESS',
20
+  CREATE_COMPANY_FORM_UPDATE_ERROR = '[Company] CREATE COMPANY FORM UPDATE ERROR',
21
+
22
+  //update a company with form data
23
+  UPDATE_COMPANY_WITH_FORM_DATA ='[Company] UPDATE COMPANY WITH FORM DATA',
24
+  UPDATE_COMPANY_WITH_FORM_DATA_SUCCESS ='[Company] UPDATE COMPANY WITH FORM DATA SUCCESS',
25
+  UPDATE_COMPANY_WITH_FORM_DATA_ERROR ='[Company] UPDATE COMPANY WITH FORM DATA ERROR',
26
+
27
+  //Delete a company
28
+  DELETE_COMPANY = '[Company] DELETE COMPANY',
29
+  DELETE_COMPANY_SUCCESS = '[Company] DELETE COMPANY SUCCESS',
30
+  DELETE_COMPANY_ERROR = '[Company] DELETE COMPANY ERROR',
31
+}

+ 8
- 0
src/app/ngrx/companies/company.state.ts 파일 보기

@@ -0,0 +1,8 @@
1
+import { MsgState } from './../msg.state';
2
+import { Company } from './../../shared/models/company/company.model';
3
+export class CompanyState{
4
+  currentCompany!: Company | null;
5
+  companiesList!: Company[];
6
+  msgState!: MsgState;
7
+  serverMsgErron!: string;
8
+}

+ 27
- 0
src/app/ngrx/companies/effects.company.get.search.ts 파일 보기

@@ -0,0 +1,27 @@
1
+import { Injectable } from '@angular/core';
2
+import { CompanyActionTypes } from './company.action.types';
3
+import { CompanyActionUnion, GetAllCompaniesActionSuccess, GetAllCompaniesActionError } from './companies.actions';
4
+import { Observable, mergeMap, catchError, map, of } from 'rxjs';
5
+import { CompaniesService } from './../../shared/services/companies.service';
6
+import { Actions, createEffect, ofType } from '@ngrx/effects';
7
+import { Company } from 'src/app/shared/models/company/company.model';
8
+
9
+@Injectable()
10
+export class CompanyGetSearchEffects {
11
+  constructor(
12
+    private companyActions: Actions,
13
+    private companiesService: CompaniesService
14
+  ) {}
15
+
16
+  getAllCompaniesEffect : Observable<CompanyActionUnion> = createEffect(
17
+    () => this.companyActions.pipe(
18
+      ofType(CompanyActionTypes.GET_ALL_COMPANIES),
19
+      mergeMap(()=>{
20
+        return this.companiesService.getAllCompanies().pipe(
21
+          map( (companies: Company[])=> new GetAllCompaniesActionSuccess(companies)),
22
+          catchError(err=> of(new GetAllCompaniesActionError(err.message)))
23
+        )
24
+      })
25
+    )
26
+  );
27
+}

+ 55
- 0
src/app/ngrx/companies/effects.company.update.delete.ts 파일 보기

@@ -0,0 +1,55 @@
1
+import { CompanyActionTypes } from './company.action.types';
2
+import { CompanyActionUnion, CreateFormToUpdateCompanyActionSuccess, CreateFormToUpdateCompanyActionError, UpdateCompanyWithFormDataActionSuccess, UpdateCompanyWithFormDataActionError, DeleteCompany, DeleteCompanySuccess, DeleteCompanyError } from './companies.actions';
3
+import { Observable, mergeMap, map, catchError, of } from 'rxjs';
4
+import { Actions, createEffect, ofType } from '@ngrx/effects';
5
+import { CompaniesService } from './../../shared/services/companies.service';
6
+import { Injectable } from '@angular/core';
7
+import { Company } from 'src/app/shared/models/company/company.model';
8
+
9
+@Injectable()
10
+export class CompanyUpdateDeleteEffects {
11
+  constructor(
12
+    private companiesService: CompaniesService,
13
+    private companyActions: Actions
14
+  ) {}
15
+
16
+  //create form to update company effect
17
+  createFormToUpdateCompanyEffect : Observable<CompanyActionUnion> = createEffect(
18
+    () => this.companyActions.pipe(
19
+      ofType(CompanyActionTypes.CREATE_COMPANY_FORM_UPDATE),
20
+      mergeMap((action: CompanyActionUnion) =>{
21
+        return this.companiesService.getCompanyById(action.payload.id).pipe(
22
+          map( (company: Company) => new CreateFormToUpdateCompanyActionSuccess(company)),
23
+          catchError(err => of(new CreateFormToUpdateCompanyActionError(err.message)))
24
+        )
25
+      })
26
+    )
27
+  );
28
+
29
+  //update company with form data
30
+
31
+  updateCompanyWithFormDataEffect : Observable<CompanyActionUnion> = createEffect(
32
+    () => this.companyActions.pipe(
33
+      ofType(CompanyActionTypes.UPDATE_COMPANY_WITH_FORM_DATA),
34
+      mergeMap((action: CompanyActionUnion)=>{
35
+        return this.companiesService.updateCompany(action.payload).pipe(
36
+          map((company: Company) => new UpdateCompanyWithFormDataActionSuccess(company)),
37
+          catchError(err=> of(new UpdateCompanyWithFormDataActionError(err.message)))
38
+        )
39
+      })
40
+    )
41
+  );
42
+
43
+  // delete a company
44
+  deleteCompany: Observable<CompanyActionUnion> = createEffect(
45
+    () => this.companyActions.pipe(
46
+      ofType(CompanyActionTypes.DELETE_COMPANY),
47
+      mergeMap((action: CompanyActionUnion)=>{
48
+        return this.companiesService.deleteCompany(action.payload.id).pipe(
49
+          map(()=>new DeleteCompanySuccess(action.payload)),
50
+          catchError(err=> of(new DeleteCompanyError(err.message)))
51
+        )
52
+      })
53
+    )
54
+  );
55
+}

+ 4
- 1
src/app/ngrx/msg.state.ts 파일 보기

@@ -7,9 +7,12 @@ export enum MsgState {
7 7
   FORM_LOADED = 'FORM LOADED',
8 8
   FORM_LOAD_ERR= 'FORM LOADING ERROR',
9 9
   CONFIRM_ADD = 'CONFIRM ADDING OF',
10
+  CONFIRM_UPDATE = 'CONFIRM UPDATE',
10 11
   CONFIRM_DEL = 'CONFIRM DELETION OF',
11 12
   ADDED = 'SUCCESSFULLY ADDED',
12 13
   EXIST = 'ALREADY EXISTS',
13 14
   UPDATED = ' SUCCESSFULLY UPDATED',
14
-  DEFAULT_MSG = 'DEFAULT MSG LOADING'
15
+  DEFAULT_MSG = 'DEFAULT MSG LOADING',
16
+  DELETE = 'DELETE',
17
+  DELETED = 'SUCCESSFULLY DELETED'
15 18
 }

src/app/ngrx/projects/effects.projectcreate.ts → src/app/ngrx/projects/effects.project.create.ts 파일 보기

@@ -4,7 +4,7 @@ import { map, Observable, mergeMap, catchError, of } from 'rxjs';
4 4
 import { ProjectsService } from './../../shared/services/projects.service';
5 5
 import { Actions, createEffect, ofType } from '@ngrx/effects';
6 6
 import { Injectable } from '@angular/core';
7
-import { Project } from 'src/app/shared/models/project.model';
7
+import { Project } from 'src/app/shared/models/project/project.model';
8 8
 
9 9
 @Injectable()
10 10
 export class ProjectCreateEffects {
@@ -35,5 +35,6 @@ export class ProjectCreateEffects {
35 35
         )
36 36
       })
37 37
     )
38
-  )
38
+  );
39
+
39 40
 }

src/app/ngrx/projects/effects.projectget.ts → src/app/ngrx/projects/effects.project.get.ts 파일 보기

@@ -1,4 +1,4 @@
1
-import { Project } from './../../shared/models/project.model';
1
+import { Project } from './../../shared/models/project/project.model';
2 2
 import { ProjectActionTypes } from './project.action.types';
3 3
 import { ProjectActionUnion, GetAllProjectsActionSuccess, GetAllProjectsActionError } from './projects.actions';
4 4
 import { Observable, mergeMap, map, catchError, of } from 'rxjs';

+ 71
- 0
src/app/ngrx/projects/effects.project.update.delete.ts 파일 보기

@@ -0,0 +1,71 @@
1
+import { Project } from '../../shared/models/project/project.model';
2
+import { ProjectActionTypes } from './project.action.types';
3
+import {
4
+  ProjectActionUnion,
5
+  CreateProjectFormUpdateActionSuccess,
6
+  CreateProjectFormUpdateActionError,
7
+  UpdateProjectWithFormDataActionSuccess,
8
+  UpdateProjectWithFormDataActionError,
9
+  DeleteProjectActionSuccess,
10
+  DeleteProjectActionError,
11
+} from './projects.actions';
12
+import { Observable, mergeMap, map, catchError, of } from 'rxjs';
13
+import { Actions, createEffect, ofType } from '@ngrx/effects';
14
+import { ProjectsService } from '../../shared/services/projects.service';
15
+import { Injectable } from '@angular/core';
16
+
17
+@Injectable()
18
+export class ProjectUpdateEffects {
19
+  constructor(
20
+    private projectsService: ProjectsService,
21
+    private projectActions: Actions
22
+  ) {}
23
+
24
+  //create form filled with current data to update
25
+  createUpdateFormEffect: Observable<ProjectActionUnion> = createEffect(() =>
26
+    this.projectActions.pipe(
27
+      ofType(ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE),
28
+      mergeMap((action: ProjectActionUnion) => {
29
+        return this.projectsService.getProjectById(action.payload.id).pipe(
30
+          map(
31
+            (project: Project) =>
32
+              new CreateProjectFormUpdateActionSuccess(project)
33
+          ),
34
+          catchError((err) =>
35
+            of(new CreateProjectFormUpdateActionError(err.message))
36
+          )
37
+        );
38
+      })
39
+    )
40
+  );
41
+
42
+  //update project with form data
43
+  updateProjectWithFormDataEffect: Observable<ProjectActionUnion> =
44
+    createEffect(() =>
45
+      this.projectActions.pipe(
46
+        ofType(ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA),
47
+        mergeMap((action: ProjectActionUnion) => {
48
+          return this.projectsService.updateProject(action.payload).pipe(
49
+            map(
50
+              (project: Project) =>
51
+                new UpdateProjectWithFormDataActionSuccess(project)
52
+            ),
53
+            catchError((err) =>
54
+              of(new UpdateProjectWithFormDataActionError(err.message))
55
+            )
56
+          );
57
+        })
58
+      )
59
+    );
60
+
61
+  deleteProjectEffect: Observable<ProjectActionUnion> = createEffect(() =>
62
+    this.projectActions.pipe(
63
+      ofType(ProjectActionTypes.DELETE_PROJECT),
64
+      mergeMap((action: ProjectActionUnion) => {
65
+        return this.projectsService.deleteProject(action.payload.id).pipe(
66
+          map(() => new DeleteProjectActionSuccess(action.payload)),
67
+        );
68
+      })
69
+    )
70
+  );
71
+}

+ 16
- 0
src/app/ngrx/projects/project.action.types.ts 파일 보기

@@ -16,4 +16,20 @@ export enum ProjectActionTypes{
16 16
   SAVE_PROJECT_FORM_DATA ='[Project] SAVE PROJECT FORM DATA',
17 17
   SAVE_PROJECT_FORM_DATA_SUCCESS ='[Project] SAVE PROJECT FORM DATA SUCCESS',
18 18
   SAVE_PROJECT_FORM_DATA_ERROR ='[Project] SAVE PROJECT FORM DATA ERROR',
19
+
20
+  // create form to update project
21
+  CREATE_PROJECT_FORM_UPDATE = '[Project] CREATE PROJECT FORM UPDATE',
22
+  CREATE_PROJECT_FORM_UPDATE_SUCCESS = '[Project] CREATE PROJECT FORM UPDATE SUCCESS',
23
+  CREATE_PROJECT_FORM_UPDATE_ERROR = '[Project] CREATE PROJECT FORM UPDATE ERROR',
24
+
25
+  //update project with form data
26
+
27
+  UPDATE_PROJECT_WITH_FORM_DATA ='[Project] UPDATE_PROJECT_WITH_FORM_DATA',
28
+  UPDATE_PROJECT_WITH_FORM_DATA_SUCCESS ='[Project] UPDATE_PROJECT_WITH_FORM_DATA SUCCESS',
29
+  UPDATE_PROJECT_WITH_FORM_DATA_ERROR ='[Project] UPDATE_PROJECT_WITH_FORM_DATA ERROR',
30
+
31
+  //Delete project
32
+  DELETE_PROJECT = '[Project] DELETE PROJECT',
33
+  DELETE_PROJECT_SUCCESS = '[Project] DELETE PROJECT SUCCESS',
34
+  DELETE_PROJECT_ERROR = '[Project] DELETE PROJECT ERROR',
19 35
 }

+ 2
- 4
src/app/ngrx/projects/project.state.ts 파일 보기

@@ -1,12 +1,10 @@
1 1
 import { MsgState } from 'src/app/ngrx/msg.state';
2
-import { Project } from './../../shared/models/project.model';
3
-import { ProjectActionUnion } from './projects.actions';
2
+import { Project } from './../../shared/models/project/project.model';
4 3
 
5 4
 export class ProjectState{
6 5
   currentProject !: Project| null;
7 6
   projectsList: any;
8 7
   msgState!: MsgState;
9
-  serverErrorMsg!: string;
10
-  currectAction!: ProjectActionUnion | null;
8
+  serverErrorMsg!: string
11 9
 }
12 10
 

+ 58
- 5
src/app/ngrx/projects/projects.actions.ts 파일 보기

@@ -1,4 +1,4 @@
1
-import { Project } from './../../shared/models/project.model';
1
+import { Project } from './../../shared/models/project/project.model';
2 2
 import { ProjectActionTypes } from './project.action.types';
3 3
 import { Action } from '@ngrx/store';
4 4
 
@@ -39,20 +39,64 @@ export class CreateProjectFormAddActionError implements Action{
39 39
 
40 40
 //save project form data
41 41
 export class SaveProjectFormDataAction implements Action{
42
-  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA
42
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA;
43 43
   constructor (public payload: Project){}
44 44
 }
45 45
 //save project form data
46 46
 export class SaveProjectFormDataActionSuccess implements Action{
47
-  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_SUCCESS
47
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_SUCCESS;
48 48
   constructor (public payload: Project){}
49 49
 }
50 50
 //save project form data
51 51
 export class SaveProjectFormDataActionError implements Action{
52
-  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_ERROR
52
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_ERROR;
53 53
   constructor (public payload: string){}
54 54
 }
55 55
 
56
+//create form for project update
57
+export class CreateProjectFormUpdateAction implements Action{
58
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE;
59
+  constructor(public payload: Project){}
60
+}
61
+
62
+export class CreateProjectFormUpdateActionSuccess implements Action{
63
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE_SUCCESS;
64
+  constructor(public payload: Project){}
65
+}
66
+
67
+export class CreateProjectFormUpdateActionError implements Action{
68
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE_ERROR;
69
+  constructor(public payload: string){}
70
+}
71
+
72
+// update project with form data
73
+export class UpdateProjectWithFormDataAction implements Action{
74
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA;
75
+  constructor (public payload: Project){}
76
+}
77
+export class UpdateProjectWithFormDataActionSuccess implements Action{
78
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA_SUCCESS;
79
+  constructor (public payload: Project){}
80
+}
81
+export class UpdateProjectWithFormDataActionError implements Action{
82
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA_ERROR;
83
+  constructor (public payload: string){}
84
+}
85
+
86
+// delete a project
87
+export class DeleteProjectAction implements Action{
88
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT;
89
+  constructor(public payload: Project){}
90
+}
91
+export class DeleteProjectActionSuccess implements Action{
92
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT_SUCCESS;
93
+  constructor(public payload: Project){}
94
+}
95
+export class DeleteProjectActionError implements Action{
96
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT_ERROR;
97
+  constructor(public payload: string){}
98
+}
99
+
56 100
 export type ProjectActionUnion =
57 101
   | GetAllProjectsAction
58 102
   | GetAllProjectsActionSuccess
@@ -62,4 +106,13 @@ export type ProjectActionUnion =
62 106
   | CreateProjectFormAddActionError
63 107
   | SaveProjectFormDataAction
64 108
   | SaveProjectFormDataActionSuccess
65
-  | SaveProjectFormDataActionError;
109
+  | SaveProjectFormDataActionError
110
+  | CreateProjectFormUpdateAction
111
+  | CreateProjectFormUpdateActionSuccess
112
+  | CreateProjectFormUpdateActionError
113
+  | UpdateProjectWithFormDataAction
114
+  | UpdateProjectWithFormDataActionSuccess
115
+  | UpdateProjectWithFormDataActionError
116
+  | DeleteProjectAction
117
+  | DeleteProjectActionSuccess
118
+  | DeleteProjectActionError;

+ 86
- 21
src/app/ngrx/projects/projects.reducer.ts 파일 보기

@@ -3,7 +3,7 @@ import { Action } from '@ngrx/store';
3 3
 import { MsgState } from '../msg.state';
4 4
 import { ProjectState } from './project.state';
5 5
 import { ProjectActionTypes } from './project.action.types';
6
-import { Project } from 'src/app/shared/models/project.model';
6
+import { Project } from 'src/app/shared/models/project/project.model';
7 7
 
8 8
 /** a reducer need first initial state and action to perform */
9 9
 
@@ -11,17 +11,14 @@ const projectInitState: ProjectState = {
11 11
   currentProject: null,
12 12
   projectsList: [],
13 13
   msgState: MsgState.INIT_STATE,
14
-  serverErrorMsg: 'no error massage',
15
-  currectAction: null,
14
+  serverErrorMsg: 'no error massage'
16 15
 };
17 16
 
18 17
 export function projectReducer(
19 18
   state: ProjectState = projectInitState,
20 19
   projectAction: Action
21 20
 ): ProjectState {
22
-
23 21
   switch (projectAction.type) {
24
-
25 22
     // get all projects action reducer
26 23
     case ProjectActionTypes.GET_ALL_PROJECTS:
27 24
       return {
@@ -33,57 +30,125 @@ export function projectReducer(
33 30
       return {
34 31
         ...state,
35 32
         msgState: MsgState.LOADED,
36
-        projectsList: (<ProjectActionUnion> projectAction).payload,
33
+        projectsList: (<ProjectActionUnion>projectAction).payload,
37 34
       };
38 35
 
39 36
     case ProjectActionTypes.GET_ALL_PROJECTS_ERROR:
40 37
       return {
41 38
         ...state,
42 39
         msgState: MsgState.ERR,
43
-        serverErrorMsg: (<ProjectActionUnion> projectAction).payload,
40
+        serverErrorMsg: (<ProjectActionUnion>projectAction).payload,
44 41
       };
45 42
 
46
-
47 43
     // create project form to add action reducer
48 44
 
49 45
     case ProjectActionTypes.CREATE_PROJECT_FORM_ADD:
50
-      return{
46
+      return {
51 47
         ...state,
52 48
         msgState: MsgState.FORM_LOADING,
53 49
       };
54 50
 
55 51
     case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_SUCCESS:
56
-      return{
52
+      return {
57 53
         ...state,
58
-        msgState: MsgState.FORM_LOADED
54
+        msgState: MsgState.FORM_LOADED,
59 55
       };
60 56
 
61 57
     case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_ERROR:
62
-      return{
58
+      return {
63 59
         ...state,
64 60
         msgState: MsgState.ERR,
65
-        serverErrorMsg: (<ProjectActionUnion> projectAction).payload
66
-      }
61
+        serverErrorMsg: (<ProjectActionUnion>projectAction).payload,
62
+      };
67 63
 
68 64
     //saving project form data
69 65
 
70 66
     case ProjectActionTypes.SAVE_PROJECT_FORM_DATA:
71
-      return{
67
+      return {
72 68
         ...state,
73
-        msgState: MsgState.LOADING
69
+        msgState: MsgState.LOADING,
74 70
       };
75 71
 
76 72
     case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_SUCCESS:
77
-      let createdProject: Project = (<ProjectActionUnion> projectAction).payload;
78
-      let projectsListCopy: Project[] = [...state.projectsList];
79
-      projectsListCopy.push(createdProject);
73
+      let createdProject: Project = (<ProjectActionUnion>projectAction).payload;
74
+      let projectsListCopy1: Project[] = [...state.projectsList];
75
+      projectsListCopy1.push(createdProject);
80 76
 
81
-      return{
77
+      return {
82 78
         ...state,
83 79
         msgState: MsgState.ADDED,
84
-        projectsList: projectsListCopy
80
+        projectsList: projectsListCopy1,
85 81
       };
86 82
 
83
+    // create form to update project
84
+    case ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE:
85
+      return {
86
+        ...state,
87
+        msgState: MsgState.FORM_LOADING,
88
+      };
89
+
90
+    case ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE_SUCCESS:
91
+      let projectToUpdate: Project = (<ProjectActionUnion>projectAction)
92
+        .payload;
93
+      return {
94
+        ...state,
95
+        msgState: MsgState.FORM_LOADED,
96
+        currentProject: projectToUpdate,
97
+      };
98
+
99
+    case ProjectActionTypes.CREATE_PROJECT_FORM_UPDATE_ERROR:
100
+      return {
101
+        ...state,
102
+        msgState: MsgState.FORM_LOAD_ERR,
103
+        serverErrorMsg: (<ProjectActionUnion>projectAction).payload,
104
+      };
105
+
106
+    //update project with form data
107
+
108
+    case ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA:
109
+      return {
110
+        ...state,
111
+        msgState: MsgState.DEFAULT_MSG,
112
+      };
113
+
114
+    case ProjectActionTypes.UPDATE_PROJECT_WITH_FORM_DATA_SUCCESS:
115
+      let updatedProject: Project = (<ProjectActionUnion>projectAction).payload;
116
+      let projectsListCopy2 = [...state.projectsList];
117
+      projectsListCopy2 = projectsListCopy2.map((project) =>
118
+        project.id == updatedProject.id ? updatedProject : project
119
+      );
120
+
121
+      return{
122
+        ...state,
123
+        msgState: MsgState.UPDATED,
124
+        projectsList : projectsListCopy2
125
+      }
126
+
127
+      // delete project
128
+      case ProjectActionTypes.DELETE_PROJECT:
129
+        return {
130
+          ...state,
131
+          msgState: MsgState.DELETE
132
+        }
133
+
134
+      case ProjectActionTypes.DELETE_PROJECT_SUCCESS:
135
+        let deletedProject = (<ProjectActionUnion> projectAction).payload;
136
+        let deletedProjectIndex = state.projectsList.indexOf(deletedProject);
137
+        let projectsListCopy3 : Project[] = [...state.projectsList];
138
+        projectsListCopy3 = projectsListCopy3.splice(deletedProjectIndex);
139
+
140
+        return{
141
+          ...state,
142
+          msgState: MsgState.DELETED,
143
+          projectsList: projectsListCopy3
144
+        };
145
+
146
+      case ProjectActionTypes.DELETE_PROJECT_ERROR:
147
+        return{
148
+          ...state,
149
+          msgState: MsgState.ERR,
150
+          serverErrorMsg: (<ProjectActionUnion>projectAction).payload
151
+        };
87 152
 
88 153
     default:
89 154
       return { ...state };

src/app/ngrx/users/effects.user.createuser.ts → src/app/ngrx/users/effects.user.create.ts 파일 보기

@@ -4,7 +4,7 @@ import { Injectable } from "@angular/core";
4 4
 import { catchError, map, mergeMap, Observable, of } from 'rxjs';
5 5
 import { Actions, createEffect, ofType } from '@ngrx/effects';
6 6
 import { UserActionTypes } from './user.action.types';
7
-import { User } from 'src/app/shared/models/user.model';
7
+import { User } from 'src/app/shared/models/user/user.model';
8 8
 
9 9
 @Injectable()
10 10
 export class UserCreateEffects{

src/app/ngrx/users/effects.user.getsearchuser.ts → src/app/ngrx/users/effects.user.get.search.ts 파일 보기

@@ -4,7 +4,7 @@ import { Actions, createEffect, ofType } from '@ngrx/effects';
4 4
 import { Injectable } from '@angular/core';
5 5
 import { GetAllUsersActionError, GetAllUsersActionSuccess, GetUser_s_ProjectsError, GetUser_s_ProjectsSuccess, SearchUserActionError, SearchUserActionSuccess, UserActionUnion } from './users.actions';
6 6
 import { Observable, mergeMap, map, catchError, of, tap } from 'rxjs';
7
-import { User } from 'src/app/shared/models/user.model';
7
+import { User } from 'src/app/shared/models/user/user.model';
8 8
 import { UserActionTypes } from './user.action.types';
9 9
 
10 10
 @Injectable()

src/app/ngrx/users/effects.user.update.ts → src/app/ngrx/users/effects.user.update.delete.ts 파일 보기

@@ -11,7 +11,7 @@ import { map, mergeMap, Observable, catchError, of } from 'rxjs';
11 11
 import { UsersService } from '../../shared/services/users.service';
12 12
 import { Injectable } from '@angular/core';
13 13
 import { Actions, createEffect, ofType } from '@ngrx/effects';
14
-import { User } from 'src/app/shared/models/user.model';
14
+import { User } from 'src/app/shared/models/user/user.model';
15 15
 import { UserActionTypes } from './user.action.types';
16 16
 import { Router } from '@angular/router';
17 17
 
@@ -20,8 +20,7 @@ import { Router } from '@angular/router';
20 20
 export class UserUpdateEffects {
21 21
   constructor(
22 22
     private usersService: UsersService,
23
-    private effectActions: Actions,
24
-    private router: Router
23
+    private effectActions: Actions
25 24
   ) {}
26 25
 
27 26
 

+ 1
- 2
src/app/ngrx/users/user.state.ts 파일 보기

@@ -1,5 +1,4 @@
1
-import { UserActionUnion } from './users.actions';
2
-import { User } from "src/app/shared/models/user.model";
1
+import { User } from "src/app/shared/models/user/user.model";
3 2
 import { MsgState } from "../msg.state";
4 3
 
5 4
 //create a state

+ 1
- 1
src/app/ngrx/users/users.actions.ts 파일 보기

@@ -1,5 +1,5 @@
1 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/user.model';
3 3
 import { UserActionTypes } from './user.action.types';
4 4
 
5 5
 

+ 1
- 1
src/app/ngrx/users/users.effects.ts 파일 보기

@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
2 2
 import { Router } from '@angular/router';
3 3
 import { Actions, createEffect, ofType } from '@ngrx/effects';
4 4
 import { Observable, mergeMap, map, catchError, of, tap } from 'rxjs';
5
-import { User } from 'src/app/shared/models/user.model';
5
+import { User } from 'src/app/shared/models/user/user.model';
6 6
 import { UsersService } from 'src/app/shared/services/users.service';
7 7
 import { UserActionTypes } from './user.action.types';
8 8
 import {

+ 1
- 2
src/app/ngrx/users/users.reducer.ts 파일 보기

@@ -1,5 +1,5 @@
1 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/user.model';
3 3
 import { MsgState } from '../msg.state';
4 4
 import { UserActionTypes } from './user.action.types';
5 5
 import { UserState } from './user.state';
@@ -210,7 +210,6 @@ export function userReducer(
210 210
         msgState: MsgState.DEFAULT_MSG
211 211
       };
212 212
 
213
-
214 213
     default:
215 214
       return { ...state };
216 215
   }

src/app/ngrx/companies/companies.effects.ts → src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.css 파일 보기


+ 60
- 0
src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.html 파일 보기

@@ -0,0 +1,60 @@
1
+<div class="container">
2
+  <div *ngIf="inputCompaniesList && inputCompaniesList.length>0">
3
+    <input
4
+      type="text"
5
+      class="form-control"
6
+      id="search"
7
+      placeholder="search a company by name"
8
+    />
9
+  </div>
10
+
11
+
12
+  <p-table
13
+    [value]="inputCompaniesList"
14
+    responsiveLayout="scroll"
15
+    styleClass="p-datatable-striped"
16
+    [paginator]="true"
17
+    [rows]="4"
18
+    [showCurrentPageReport]="true"
19
+    currentPageReportTemplate="{first} - {last} of {totalRecords} companies"
20
+    [rowsPerPageOptions]="[4, 6, 8]"
21
+  >
22
+    <ng-template pTemplate="header">
23
+      <tr>
24
+        <th>ID</th>
25
+        <th>Name</th>
26
+        <th>type</th>
27
+        <th>Creaton date</th>
28
+        <th>action1</th>
29
+        <th>action2</th>
30
+      </tr>
31
+    </ng-template>
32
+    <ng-template pTemplate="body" let-company>
33
+      <tr>
34
+        <td>{{ company.id }}</td>
35
+        <td>{{ company.companyName }}</td>
36
+        <td>{{ company.companyType }}</td>
37
+        <td>{{ company.creationDate | date: "dd MM yyyy" }}</td>
38
+
39
+        <td>
40
+          <button class="btn">
41
+            <i
42
+              class="fa fa-pencil"
43
+              style="color: mediumturquoise"
44
+              (click)="onCompanyEdit(company)"
45
+            ></i>
46
+          </button>
47
+        </td>
48
+        <td>
49
+          <button class="btn">
50
+            <i
51
+              class="fa fa-trash"
52
+              style="color: red"
53
+              (click)="onCompanyDelete(company)"
54
+            ></i>
55
+          </button>
56
+        </td>
57
+      </tr>
58
+    </ng-template>
59
+  </p-table>
60
+</div>

+ 25
- 0
src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.spec.ts 파일 보기

@@ -0,0 +1,25 @@
1
+import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { CompaniesListComponent } from './companies-list.component';
4
+
5
+describe('CompaniesListComponent', () => {
6
+  let component: CompaniesListComponent;
7
+  let fixture: ComponentFixture<CompaniesListComponent>;
8
+
9
+  beforeEach(async () => {
10
+    await TestBed.configureTestingModule({
11
+      declarations: [ CompaniesListComponent ]
12
+    })
13
+    .compileComponents();
14
+  });
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(CompaniesListComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 35
- 0
src/app/pages/companies-manager/companies-management/companies-list/companies-list.component.ts 파일 보기

@@ -0,0 +1,35 @@
1
+import { MsgState } from 'src/app/ngrx/msg.state';
2
+import { DeleteCompany } from './../../../../ngrx/companies/companies.actions';
3
+import { CompanyState } from './../../../../ngrx/companies/company.state';
4
+import { Router } from '@angular/router';
5
+import { Component, Input, OnInit } from '@angular/core';
6
+import { Company } from 'src/app/shared/models/company/company.model';
7
+import { Store } from '@ngrx/store';
8
+
9
+@Component({
10
+  selector: 'app-companies-list',
11
+  templateUrl: './companies-list.component.html',
12
+  styleUrls: ['./companies-list.component.css'],
13
+})
14
+export class CompaniesListComponent implements OnInit {
15
+  constructor(
16
+    private router: Router,
17
+    private store: Store<{ companyReducerKey: CompanyState }>
18
+  ) {}
19
+
20
+  @Input() inputCompaniesList!: Company[];
21
+  msgState = MsgState;
22
+
23
+  ngOnInit(): void {}
24
+
25
+  onCompanyEdit(company: Company) {
26
+    this.router.navigate(['/company-update/' + company.id]);
27
+  }
28
+
29
+  onCompanyDelete(company: Company) {
30
+    if(window.confirm(this.msgState.CONFIRM_DEL)){
31
+      this.store.dispatch(new DeleteCompany(company));
32
+    }
33
+  }
34
+
35
+}

+ 20
- 1
src/app/pages/companies-manager/companies-management/companies-management.component.html 파일 보기

@@ -1 +1,20 @@
1
-<app-company-nav-bar></app-company-nav-bar>
1
+<div class="container">
2
+  <app-company-nav-bar></app-company-nav-bar>
3
+
4
+  <ng-container *ngIf="companyState"  [ngSwitch]="companyState.msgState">
5
+
6
+    <ng-container *ngSwitchCase="msgState.LOADING">
7
+      {{companyState.msgState}}
8
+    </ng-container>
9
+
10
+    <ng-container *ngSwitchCase="msgState.ERR">
11
+      {{companyState.msgState}}
12
+    </ng-container>
13
+
14
+    <ng-container *ngSwitchCase="msgState.LOADED">
15
+      <app-companies-list [inputCompaniesList]="companyState.companiesList"></app-companies-list>
16
+    </ng-container>
17
+
18
+  </ng-container>
19
+
20
+</div>

+ 11
- 1
src/app/pages/companies-manager/companies-management/companies-management.component.ts 파일 보기

@@ -1,4 +1,7 @@
1
+import { MsgState } from './../../../ngrx/msg.state';
2
+import { CompanyState } from './../../../ngrx/companies/company.state';
1 3
 import { Component, OnInit } from '@angular/core';
4
+import { Store } from '@ngrx/store';
2 5
 
3 6
 @Component({
4 7
   selector: 'app-companies-management',
@@ -7,9 +10,16 @@ import { Component, OnInit } from '@angular/core';
7 10
 })
8 11
 export class CompaniesManagementComponent implements OnInit {
9 12
 
10
-  constructor() { }
13
+  constructor(private store: Store<{companyReducerKey: CompanyState}>) { }
14
+
15
+  companyState!: CompanyState;
16
+  msgState = MsgState;
11 17
 
12 18
   ngOnInit(): void {
19
+
20
+    this.store.subscribe( state =>{
21
+      this.companyState = state.companyReducerKey;
22
+    })
13 23
   }
14 24
 
15 25
 }

+ 15
- 1
src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.ts 파일 보기

@@ -1,4 +1,7 @@
1
+import { GetAllCompaniesAction } from './../../../../ngrx/companies/companies.actions';
2
+import { CompanyState } from './../../../../ngrx/companies/company.state';
1 3
 import { Component, OnInit } from '@angular/core';
4
+import { Store } from '@ngrx/store';
2 5
 
3 6
 @Component({
4 7
   selector: 'app-company-nav-bar',
@@ -7,8 +10,19 @@ import { Component, OnInit } from '@angular/core';
7 10
 })
8 11
 export class CompanyNavBarComponent{
9 12
 
13
+  constructor(private store: Store<{companyReducerKey: CompanyState}>){}
14
+
15
+  companyState!: CompanyState
16
+
10 17
   onCompanyCreate(){}
11
-  onCompaniesGetAll(){}
18
+
19
+  onCompaniesGetAll(){
20
+    this.store.dispatch(new GetAllCompaniesAction({}));
21
+    this.store.subscribe((state)=>{
22
+      this.companyState = state.companyReducerKey;
23
+    })
24
+  }
25
+
12 26
   onProjectsOfCampany(){}
13 27
 
14 28
 }

src/app/ngrx/myreducer.ts → src/app/pages/companies-manager/companies-management/company-update/company-update.component.css 파일 보기


+ 77
- 0
src/app/pages/companies-manager/companies-management/company-update/company-update.component.html 파일 보기

@@ -0,0 +1,77 @@
1
+<div class="container" *ngIf="companyFormGroup">
2
+  <ng-container *ngIf="companyState.msgState == msgState.FORM_LOADING">
3
+    {{companyState.msgState}}
4
+  </ng-container>
5
+  <ng-container *ngIf="companyState.msgState == msgState.FORM_LOAD_ERR">
6
+    {{companyState.msgState}}
7
+  </ng-container>
8
+
9
+  <ng-container *ngIf="companyState.msgState == msgState.FORM_LOADED">
10
+
11
+    <div class="card mt-3" style="width: 18rem">
12
+      <div class="card-header">Update company informations</div>
13
+
14
+      <div class="card-body">
15
+        <form [formGroup]="companyFormGroup"
16
+          (ngSubmit)="onCompanyUpdate(); companyFormGroup.reset()"
17
+        >
18
+          <div class="col-md-auto mb-3">
19
+            <label for="companyName">Company name</label>
20
+            <input
21
+              type="text"
22
+              formControlName="companyName"
23
+              class="form-control"
24
+              [ngClass]="{
25
+                'is-invalid':
26
+                companyFormGroup.controls['companyName'].touched &&
27
+                  !companyFormGroup.controls['companyName'].valid
28
+              }"
29
+            />
30
+            <div class="invalid-feedback">
31
+              <span
32
+                *ngIf="companyFormGroup.controls['companyName'].errors?.['required']"
33
+              >
34
+                required
35
+              </span>
36
+              <span
37
+                *ngIf="companyFormGroup.controls['companyName'].errors?.['minlength']"
38
+              >
39
+                min nbr chars 5
40
+              </span>
41
+            </div>
42
+          </div>
43
+
44
+          <div class="col-md-auto mb-3">
45
+            <label for="type">Company type</label>
46
+            <select formControlName="companyType" class="form-control">
47
+
48
+              <option *ngFor="let companyType of companyTypes | keyvalue " [ngValue]="companyType.value">
49
+                  {{companyType.value}}
50
+              </option>
51
+
52
+            </select>
53
+          </div>
54
+
55
+          <div class="text-center col-md-auto mt-3">
56
+            <button
57
+              class="btn btn-outline-primary"
58
+              type="submit" [disabled]="!companyFormGroup.valid"
59
+            >
60
+              update
61
+            </button>
62
+          </div>
63
+
64
+        </form>
65
+      </div>
66
+    </div>
67
+  </ng-container>
68
+
69
+
70
+  <ng-container *ngIf="companyState.msgState == msgState.UPDATED">
71
+    <div class="alert-success container p-3 m-3" style="width: 30em">
72
+      <span> {{ msgState.UPDATED }}</span> &nbsp;&nbsp;
73
+      <button class="btn btn-success" (click)="onUpdateOk()">OK</button>
74
+    </div>
75
+  </ng-container>
76
+
77
+</div>

+ 25
- 0
src/app/pages/companies-manager/companies-management/company-update/company-update.component.spec.ts 파일 보기

@@ -0,0 +1,25 @@
1
+import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { CompanyUpdateComponent } from './company-update.component';
4
+
5
+describe('CompanyUpdateComponent', () => {
6
+  let component: CompanyUpdateComponent;
7
+  let fixture: ComponentFixture<CompanyUpdateComponent>;
8
+
9
+  beforeEach(async () => {
10
+    await TestBed.configureTestingModule({
11
+      declarations: [ CompanyUpdateComponent ]
12
+    })
13
+    .compileComponents();
14
+  });
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(CompanyUpdateComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 75
- 0
src/app/pages/companies-manager/companies-management/company-update/company-update.component.ts 파일 보기

@@ -0,0 +1,75 @@
1
+import { CompanyType } from './../../../../shared/models/company/company.type';
2
+import { MsgState } from './../../../../ngrx/msg.state';
3
+import {
4
+  CreateFormToUpdateCompanyAction,
5
+  UpdateCompanyWithFormDataAction,
6
+} from './../../../../ngrx/companies/companies.actions';
7
+import { CompaniesService } from './../../../../shared/services/companies.service';
8
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
9
+import { CompanyState } from './../../../../ngrx/companies/company.state';
10
+import { ActivatedRoute, Router } from '@angular/router';
11
+import { Component, OnInit } from '@angular/core';
12
+import { Store } from '@ngrx/store';
13
+import { Company } from 'src/app/shared/models/company/company.model';
14
+
15
+@Component({
16
+  selector: 'app-company-update',
17
+  templateUrl: './company-update.component.html',
18
+  styleUrls: ['./company-update.component.css'],
19
+})
20
+export class CompanyUpdateComponent implements OnInit {
21
+  companyId: number;
22
+  companyFormGroup!: FormGroup;
23
+  companyState!: CompanyState;
24
+  msgState = MsgState;
25
+  companyTypes = CompanyType;
26
+
27
+  constructor(
28
+    activatedRoute: ActivatedRoute,
29
+    private store: Store<{ companyReducerKey: CompanyState }>,
30
+    private formBuilder: FormBuilder,
31
+    private companiesService: CompaniesService,
32
+    private router: Router
33
+  ) {
34
+    this.companyId = activatedRoute.snapshot.params['companyId'];
35
+  }
36
+
37
+  ngOnInit(): void {
38
+    this.companiesService
39
+      .getCompanyById(this.companyId)
40
+      .subscribe((company: Company) => {
41
+        this.store.dispatch(new CreateFormToUpdateCompanyAction(company));
42
+
43
+        this.store.subscribe((state) => {
44
+          this.companyState = state.companyReducerKey;
45
+          this.companyFormGroup = this.formBuilder.group({
46
+            id: [this.companyState.currentCompany?.id, Validators.required],
47
+            companyName: [
48
+              this.companyState.currentCompany?.companyName,
49
+              [Validators.required, Validators.minLength(5)],
50
+            ],
51
+            companyType: [
52
+              this.companyState.currentCompany?.companyType,
53
+              Validators.required,
54
+            ],
55
+            creationDate: [
56
+              this.companyState.currentCompany?.creationDate,
57
+              Validators.required,
58
+            ],
59
+          });
60
+        });
61
+      });
62
+  }
63
+
64
+  onCompanyUpdate() {
65
+    let company: Company = this.companyFormGroup.value;
66
+
67
+    if (window.confirm(this.msgState.CONFIRM_UPDATE)) {
68
+      this.store.dispatch(new UpdateCompanyWithFormDataAction(company));
69
+    }
70
+  }
71
+
72
+  onUpdateOk() {
73
+    this.router.navigate(['/companies-management']);
74
+  }
75
+}

+ 3
- 1
src/app/pages/companies-manager/companies-manager-routing.module.ts 파일 보기

@@ -1,3 +1,4 @@
1
+import { CompanyUpdateComponent } from './companies-management/company-update/company-update.component';
1 2
 import { CompaniesManagementComponent } from './companies-management/companies-management.component';
2 3
 import { CompanyNavBarComponent } from './companies-management/company-nav-bar/company-nav-bar.component';
3 4
 import { CompaniesCreateComponent } from './companies-management/companies-create/companies-create.component';
@@ -6,7 +7,8 @@ import { RouterModule, Routes } from '@angular/router';
6 7
 
7 8
 const routes: Routes = [
8 9
   {path: 'company-create', component: CompaniesCreateComponent},
9
-  {path: 'companies-management', component: CompaniesManagementComponent}
10
+  {path: 'companies-management', component: CompaniesManagementComponent},
11
+  {path:'company-update/:companyId', component: CompanyUpdateComponent}
10 12
 ];
11 13
 
12 14
 @NgModule({

+ 10
- 2
src/app/pages/companies-manager/companies-manager.module.ts 파일 보기

@@ -1,3 +1,5 @@
1
+import { ReactiveFormsModule } from '@angular/forms';
2
+import { TableModule } from 'primeng/table';
1 3
 import { ButtonModule } from 'primeng/button';
2 4
 import { NgModule } from '@angular/core';
3 5
 import { CommonModule } from '@angular/common';
@@ -6,18 +8,24 @@ import { CompaniesManagerRoutingModule } from './companies-manager-routing.modul
6 8
 import { CompaniesCreateComponent } from './companies-management/companies-create/companies-create.component';
7 9
 import { CompanyNavBarComponent } from './companies-management/company-nav-bar/company-nav-bar.component';
8 10
 import { CompaniesManagementComponent } from './companies-management/companies-management.component';
11
+import { CompaniesListComponent } from './companies-management/companies-list/companies-list.component';
12
+import { CompanyUpdateComponent } from './companies-management/company-update/company-update.component';
9 13
 
10 14
 
11 15
 @NgModule({
12 16
   declarations: [
13 17
     CompaniesCreateComponent,
14 18
     CompanyNavBarComponent,
15
-    CompaniesManagementComponent
19
+    CompaniesManagementComponent,
20
+    CompaniesListComponent,
21
+    CompanyUpdateComponent
16 22
   ],
17 23
   imports: [
18 24
     CommonModule,
19 25
     CompaniesManagerRoutingModule,
20
-    ButtonModule
26
+    ButtonModule,
27
+    TableModule,
28
+    ReactiveFormsModule
21 29
   ]
22 30
 })
23 31
 export class CompaniesManagerModule { }

+ 163
- 1
src/app/pages/projects-manager/projects-management/project-create/project-create.component.html 파일 보기

@@ -1,2 +1,164 @@
1
-<p>project-create works!</p>
1
+<div class="container" *ngIf="projectFormGroup">
2
+  <ng-container *ngIf="projectState" [ngSwitch]="projectState.msgState">
3
+    <ng-container *ngSwitchCase="msgState.FORM_LOADING">
4
+      {{ projectState.msgState }}
5
+    </ng-container>
2 6
 
7
+    <ng-container *ngSwitchCase="msgState.FORM_LOAD_ERR">
8
+      {{ projectState.msgState }}
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.FORM_LOADED">
12
+      <!-- create form -->
13
+      <div class="card mt-3">
14
+        <div class="card-header bg-light">
15
+          <b>Informations Card for Project to Create </b>
16
+        </div>
17
+        <div class="card-body">
18
+
19
+          <form
20
+        [formGroup]="projectFormGroup"
21
+        (ngSubmit)="onProjectSave(); projectFormGroup.reset()"
22
+      >
23
+        <div class="row">
24
+          <!-- 1ère colonne -->
25
+          <div class="col">
26
+            <div class="col-md-auto mb-3">
27
+              <label for="projectName">Project name</label>
28
+              <input
29
+                type="text"
30
+                formControlName="projectName"
31
+                class="form-control"
32
+                [ngClass]="{
33
+                  'is-invalid':
34
+                    projectFormGroup.controls['projectName'].touched &&
35
+                    !projectFormGroup.controls['projectName'].valid
36
+                }"
37
+              />
38
+              <div class="invalid-feedback">
39
+                <span
40
+                  *ngIf="projectFormGroup.controls['projectName'].errors?.['required']"
41
+                  >required</span
42
+                >
43
+                <span
44
+                  *ngIf="projectFormGroup.controls['projectName'].errors?.['minlength']"
45
+                  >min nbr chars 5</span
46
+                >
47
+                <span
48
+                  *ngIf="projectFormGroup.controls['projectName'].errors?.['maxlength']"
49
+                  >min nbr chars 20</span
50
+                >
51
+              </div>
52
+            </div>
53
+
54
+            <div class="col-md-auto mb-3">
55
+              <label for="priority">Priority</label>
56
+              <select formControlName="priority" class="form-control">
57
+                <option value="" disabled> select a priority</option>
58
+                <option
59
+                  *ngFor="let priority of priorities"
60
+                  [ngValue]="priority"
61
+                >
62
+                  {{ priority }}
63
+                </option>
64
+              </select>
65
+            </div>
66
+
67
+
68
+
69
+
70
+            <div class="col-md-auto mb-3">
71
+              <label for="companyId">Company ID</label>
72
+              <select formControlName="companyId" class="form-control">
73
+                <option value="" disabled>select company ID</option>
74
+                <option
75
+                  *ngFor="let company of companyState.companiesList" [ngValue]="company.id"
76
+
77
+                >
78
+                  {{ company.id }}
79
+                </option>
80
+              </select>
81
+            </div>
82
+          </div>
83
+
84
+          <!-- 2ème colonne -->
85
+          <div class="col">
86
+            <div class="col-md-auto mb-3">
87
+              <label for="description">Description</label>
88
+              <textarea
89
+                type="text"
90
+                formControlName="description"
91
+                class="form-control"
92
+                [ngClass]="{
93
+                  'is-invalid':
94
+                    projectFormGroup.controls['description'].touched &&
95
+                    !projectFormGroup.controls['description'].valid
96
+                }"
97
+
98
+                rows="2"
99
+              ></textarea>
100
+              <div class="invalid-feedback">
101
+                <span
102
+                  *ngIf="projectFormGroup.controls['description'].errors?.['required']"
103
+                  >required</span
104
+                >
105
+                <span
106
+                  *ngIf="projectFormGroup.controls['description'].errors?.['minlength']"
107
+                  >min desc chars 25</span
108
+                >
109
+              </div>
110
+            </div>
111
+
112
+            <div class="col-md-auto mb-3">
113
+              <label for="userId">User ID</label>
114
+              <select formControlName="userId" class="form-control">
115
+                <option value="" disabled>select user ID</option>
116
+                <option *ngFor="let user of userState.usersList" [ngValue]="user.id">
117
+                  {{ user.id }}
118
+                </option>
119
+              </select>
120
+            </div>
121
+
122
+            <div class="col-md-auto mb-3">
123
+              <label for="state">State</label>
124
+              <select formControlName="state" class="form-control">
125
+                <option value="" desabled>
126
+                  select project state
127
+                </option>
128
+                <option
129
+                  *ngFor="let state of projectMsgState | keyvalue"
130
+                  [ngValue]="state.value"
131
+                >
132
+                  {{ state.value }}
133
+                </option>
134
+              </select>
135
+            </div>
136
+          </div>
137
+        </div>
138
+
139
+        <div class="text-center col-md-auto mt-3">
140
+          <button
141
+            class="btn btn-outline-primary"
142
+            type="submit"
143
+            [disabled]="(!projectFormGroup.valid)"
144
+          >
145
+            save
146
+          </button>
147
+          &nbsp;
148
+          <button class="btn btn-outline-primary" type="reset">reset</button>
149
+        </div>
150
+      </form>
151
+
152
+        </div>
153
+      </div>
154
+    </ng-container>
155
+
156
+    <ng-container *ngSwitchCase="msgState.ADDED">
157
+      <div class="alert-success container p-3 m-3" style="width: 30em">
158
+        <button class="btn btn-success" (click)="onSaveOk()">
159
+          {{ projectState.msgState }}
160
+        </button>
161
+      </div>
162
+    </ng-container>
163
+  </ng-container>
164
+</div>

+ 92
- 9
src/app/pages/projects-manager/projects-management/project-create/project-create.component.ts 파일 보기

@@ -1,12 +1,19 @@
1
-
2
-import { UserState } from 'src/app/ngrx/users/user.state';
1
+import { GetAllCompaniesAction } from './../../../../ngrx/companies/companies.actions';
2
+import { CompanyState } from './../../../../ngrx/companies/company.state';
3
+import { Router } from '@angular/router';
4
+import { ProjectsService } from './../../../../shared/services/projects.service';
5
+import { MsgState } from './../../../../ngrx/msg.state';
6
+import { DatePipe } from '@angular/common';
3 7
 import { GetAllUsersAction } from './../../../../ngrx/users/users.actions';
4
-import { FormGroup, FormBuilder, Validators } from '@angular/forms';
5
-import { CreateProjectFormAddAction } from './../../../../ngrx/projects/projects.actions';
8
+import { CreateProjectFormAddAction, SaveProjectFormDataAction } from './../../../../ngrx/projects/projects.actions';
6 9
 import { ProjectState } from './../../../../ngrx/projects/project.state';
10
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
7 11
 import { Component, OnInit } from '@angular/core';
8 12
 import { Store } from '@ngrx/store';
9
-import { DatePipe } from '@angular/common';
13
+import { Priority } from 'src/app/shared/models/project/project.priority';
14
+import { ProjectMsgState } from 'src/app/shared/models/project/project.msgstate';
15
+import { UserState } from 'src/app/ngrx/users/user.state';
16
+import { Project } from 'src/app/shared/models/project/project.model';
10 17
 
11 18
 @Component({
12 19
   selector: 'app-project-create',
@@ -14,17 +21,93 @@ import { DatePipe } from '@angular/common';
14 21
   styleUrls: ['./project-create.component.css'],
15 22
 })
16 23
 export class ProjectCreateComponent implements OnInit {
17
-
18 24
   projectFormGroup!: FormGroup;
25
+  projectState!: ProjectState;
26
+
27
+  priorities = [
28
+    Priority.PRIORITY1,
29
+    Priority.PRIORITY2,
30
+    Priority.PRIORITY3,
31
+    Priority.PRIORITY4,
32
+    Priority.PRIORITY5,
33
+  ];
34
+
35
+  projectMsgState = ProjectMsgState;
36
+  msgState = MsgState;
37
+
38
+  userState!: UserState;
39
+  companyState!: CompanyState;
19 40
 
20 41
   constructor(
42
+    private fb: FormBuilder,
43
+    private store: Store<{
44
+      projectReducerKey: ProjectState,
45
+      userReducerKey: UserState,
46
+      companyReducerKey: CompanyState
47
+    }>,
48
+    private datePipe: DatePipe,
49
+    private projectsServices: ProjectsService,
50
+    private router: Router
21 51
   ) {}
22 52
 
23 53
   ngOnInit(): void {
24 54
 
55
+    this.store.dispatch(new GetAllUsersAction({}));
56
+    this.store.subscribe(
57
+      (userState) => (this.userState = userState.userReducerKey)
58
+    );
59
+
60
+    this.store.dispatch(new GetAllCompaniesAction({}));
61
+    this.store.subscribe(companyState=>(this.companyState = companyState.companyReducerKey));
62
+
63
+    this.store.dispatch(new CreateProjectFormAddAction({}));
64
+    this.store.subscribe((projectState) => {
65
+      this.projectState = projectState.projectReducerKey;
66
+
67
+      this.projectFormGroup = this.fb.group({
68
+        id: [0, Validators.required],
69
+        projectName: [
70
+          'Project-',
71
+          [
72
+            Validators.required,
73
+            Validators.minLength(5),
74
+            Validators.maxLength(15),
75
+          ],
76
+        ],
77
+        priority: [this.priorities[0], Validators.required],
78
+        creationDate: [
79
+          this.datePipe.transform(new Date(), 'MM dd yyyy'),
80
+          Validators.required,
81
+        ],
82
+        companyId: ['', Validators.required],
83
+        description: ['', [Validators.required, Validators.minLength(20)]],
84
+        userId: ['', Validators.required],
85
+        state: [this.projectMsgState.INPROGRESS, Validators.required]
86
+      });
87
+    });
25 88
   }
26 89
 
27
-  onProjectCreate(){}
28
-  onNewProject(){}
29
-  tryEgain(){}
90
+  onProjectSave(){
91
+
92
+    let project: Project = this.projectFormGroup.value;
93
+    let projectName: string = project.projectName;
94
+    this.projectsServices.getProjectByName(projectName).subscribe((projects: Project[])=>{
95
+      if(projects.length>0){
96
+        alert(projectName+' '+this.msgState.EXIST);
97
+        return;
98
+      }
99
+      else{
100
+        if(window.confirm(this.msgState.CONFIRM_ADD)){
101
+          this.store.dispatch(new SaveProjectFormDataAction(project));
102
+        }
103
+      }
104
+    })
105
+
106
+  }
107
+  onSaveOk() {
108
+    this.router.navigateByUrl('/projects-management')
109
+  }
110
+  tryEgain() {
111
+    this.router.navigateByUrl('/project-create')
112
+  }
30 113
 }

+ 2
- 0
src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.ts 파일 보기

@@ -20,6 +20,8 @@ export class ProjectNavBarComponent {
20 20
   onProjectsGetAll() {
21 21
     this.store.dispatch(new GetAllProjectsAction({}));
22 22
   }
23
+
23 24
   onProjectsVsUsersGet() {}
25
+
24 26
   onProjectCompanyAssociated() {}
25 27
 }

+ 0
- 0
src/app/pages/projects-manager/projects-management/project-update/project-update.component.css 파일 보기


+ 150
- 0
src/app/pages/projects-manager/projects-management/project-update/project-update.component.html 파일 보기

@@ -0,0 +1,150 @@
1
+<div class="container" *ngIf="projectFormGroup">
2
+  <ng-container *ngIf="projectState" [ngSwitch]="projectState.msgState">
3
+    <ng-container *ngSwitchCase="msgState.FORM_LOADING">
4
+      {{ projectState.msgState }}
5
+    </ng-container>
6
+
7
+    <ng-container *ngSwitchCase="msgState.FORM_LOAD_ERR">
8
+      {{ projectState.msgState }}
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.FORM_LOADED">
12
+      <!-- create form -->
13
+
14
+      <div class="card mt-3">
15
+        <div class="card-header bg-light">
16
+          >> Project ID: <b>{{ projectState.currentProject?.id }}</b>, User ID:
17
+            <b>{{ projectState.currentProject?.userId }}</b>, Company ID:
18
+            <b>{{ projectState.currentProject?.companyId }}</b>
19
+
20
+        </div>
21
+        <div class="card-body">
22
+          <form
23
+            [formGroup]="projectFormGroup"
24
+            (ngSubmit)="onProjectUpdate(); projectFormGroup.reset()"
25
+          >
26
+            <div class="row">
27
+              <!-- 1ère colonne -->
28
+              <div class="col">
29
+                <div class="col-md-auto mb-3">
30
+                  <label for="projectName">Project name</label>
31
+                  <input
32
+                    type="text"
33
+                    formControlName="projectName"
34
+                    class="form-control"
35
+                    [ngClass]="{
36
+                      'is-invalid':
37
+                        projectFormGroup.controls['projectName'].touched &&
38
+                        !projectFormGroup.controls['projectName'].valid
39
+                    }"
40
+                  />
41
+                  <div class="invalid-feedback">
42
+                    <span
43
+                      *ngIf="projectFormGroup.controls['projectName'].errors?.['required']"
44
+                      >required</span
45
+                    >
46
+                    <span
47
+                      *ngIf="projectFormGroup.controls['projectName'].errors?.['minlength']"
48
+                      >min nbr chars 5</span
49
+                    >
50
+                    <span
51
+                      *ngIf="projectFormGroup.controls['projectName'].errors?.['maxlength']"
52
+                      >min nbr chars 20</span
53
+                    >
54
+                  </div>
55
+                </div>
56
+
57
+                <div class="col-md-auto mb-3">
58
+                  <label for="priority">Priority</label>
59
+                  <select formControlName="priority" class="form-control">
60
+                    <option value="Choose a priority" disabled>
61
+                      Choose a priority
62
+                    </option>
63
+                    <option
64
+                      *ngFor="let priority of priorities"
65
+                      [ngValue]="priority"
66
+                    >
67
+                      {{ priority }}
68
+                    </option>
69
+                  </select>
70
+                </div>
71
+              </div>
72
+
73
+              <!-- 2ème colonne -->
74
+              <div class="col">
75
+                <div class="col-md-auto mb-3">
76
+                  <label for="description">Description</label>
77
+                  <input
78
+                    type="text"
79
+                    formControlName="description"
80
+                    class="form-control"
81
+                    [ngClass]="{
82
+                      'is-invalid':
83
+                        projectFormGroup.controls['description'].touched &&
84
+                        !projectFormGroup.controls['description'].valid
85
+                    }"
86
+                  />
87
+                  <div class="invalid-feedback">
88
+                    <span
89
+                      *ngIf="projectFormGroup.controls['description'].errors?.['required']"
90
+                      >required</span
91
+                    >
92
+                    <span
93
+                      *ngIf="projectFormGroup.controls['description'].errors?.['minlength']"
94
+                      >min desc chars 25</span
95
+                    >
96
+                  </div>
97
+                </div>
98
+
99
+                <div class="col-md-auto mb-3">
100
+                  <label for="state">State</label>
101
+                  <select formControlName="state" class="form-control">
102
+                    <option
103
+                      *ngFor="let state of projectMsgState | keyvalue"
104
+                      [ngValue]="state.value"
105
+                    >
106
+                      {{ state.value }}
107
+                    </option>
108
+                  </select>
109
+                </div>
110
+              </div>
111
+            </div>
112
+
113
+            <div class="col-md-auto mb-3">
114
+              <label for="userId"
115
+                >ReAssign project to another user, choose user ID</label
116
+              >
117
+              <select formControlName="userId" class="form-control">
118
+                <option [ngValue]="null" desabled>choose user ID</option>
119
+                <option
120
+                  *ngFor="let user of userState.usersList"
121
+                  [ngValue]="user.id"
122
+                >
123
+                  {{ user.id }}
124
+                </option>
125
+              </select>
126
+            </div>
127
+
128
+            <div class="text-center col-md-auto mt-3">
129
+              <button
130
+                class="btn btn-outline-primary"
131
+                type="submit"
132
+                [disabled]="!projectFormGroup.valid"
133
+              >
134
+                update
135
+              </button>
136
+            </div>
137
+          </form>
138
+        </div>
139
+      </div>
140
+    </ng-container>
141
+
142
+    <ng-container *ngSwitchCase="msgState.UPDATED">
143
+      <div class="alert-success container p-3 m-3" style="width: 30em">
144
+        <button class="btn btn-success" (click)="onUpdateOk()">
145
+          {{ projectState.msgState }}
146
+        </button>
147
+      </div>
148
+    </ng-container>
149
+  </ng-container>
150
+</div>

+ 25
- 0
src/app/pages/projects-manager/projects-management/project-update/project-update.component.spec.ts 파일 보기

@@ -0,0 +1,25 @@
1
+import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { ProjectUpdateComponent } from './project-update.component';
4
+
5
+describe('ProjectUpdateComponent', () => {
6
+  let component: ProjectUpdateComponent;
7
+  let fixture: ComponentFixture<ProjectUpdateComponent>;
8
+
9
+  beforeEach(async () => {
10
+    await TestBed.configureTestingModule({
11
+      declarations: [ ProjectUpdateComponent ]
12
+    })
13
+    .compileComponents();
14
+  });
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(ProjectUpdateComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 109
- 0
src/app/pages/projects-manager/projects-management/project-update/project-update.component.ts 파일 보기

@@ -0,0 +1,109 @@
1
+import { UpdateProjectWithFormDataAction } from './../../../../ngrx/projects/projects.actions';
2
+import { GetAllUsersAction } from 'src/app/ngrx/users/users.actions';
3
+import { UserState } from './../../../../ngrx/users/user.state';
4
+import { ProjectMsgState } from '../../../../shared/models/project/project.msgstate';
5
+import { Priority } from '../../../../shared/models/project/project.priority';
6
+import { MsgState } from './../../../../ngrx/msg.state';
7
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
8
+import { ProjectsService } from './../../../../shared/services/projects.service';
9
+import { ProjectState } from './../../../../ngrx/projects/project.state';
10
+import { ActivatedRoute, Router } from '@angular/router';
11
+import { Component, OnInit } from '@angular/core';
12
+import { Store } from '@ngrx/store';
13
+import { CreateProjectFormUpdateAction } from 'src/app/ngrx/projects/projects.actions';
14
+
15
+
16
+@Component({
17
+  selector: 'app-project-update',
18
+  templateUrl: './project-update.component.html',
19
+  styleUrls: ['./project-update.component.css'],
20
+})
21
+export class ProjectUpdateComponent implements OnInit {
22
+  projectId!: number;
23
+  projectState!: ProjectState;
24
+  projectFormGroup!: FormGroup;
25
+  msgState = MsgState;
26
+
27
+  constructor(
28
+    activatedRoute: ActivatedRoute,
29
+    private projectsService: ProjectsService,
30
+    private store: Store<{
31
+      projectReducerKey: ProjectState;
32
+      userReducerKey: UserState;
33
+    }>,
34
+    private fb: FormBuilder,
35
+    private router: Router
36
+  ) {
37
+    this.projectId = activatedRoute.snapshot.params['projectId'];
38
+  }
39
+
40
+  priorities = [
41
+    Priority.PRIORITY1,
42
+    Priority.PRIORITY2,
43
+    Priority.PRIORITY3,
44
+    Priority.PRIORITY4,
45
+    Priority.PRIORITY5,
46
+  ];
47
+
48
+  projectMsgState = ProjectMsgState;
49
+
50
+  userState!: UserState;
51
+
52
+  ngOnInit(): void {
53
+    this.store.dispatch(new GetAllUsersAction({}));
54
+    this.store
55
+      .select('userReducerKey')
56
+      .subscribe((userState) => (this.userState = userState));
57
+
58
+    this.projectsService.getProjectById(this.projectId).subscribe((project) => {
59
+      this.store.dispatch(new CreateProjectFormUpdateAction(project));
60
+
61
+      this.store.subscribe((state) => {
62
+        this.projectState = state.projectReducerKey;
63
+
64
+        this.projectFormGroup = this.fb.group({
65
+          id: [this.projectState.currentProject?.id, Validators.required],
66
+          projectName: [
67
+            this.projectState.currentProject?.projectName,
68
+            [
69
+              Validators.required,
70
+              Validators.minLength(5),
71
+              Validators.maxLength(20),
72
+            ],
73
+          ],
74
+          priority: [
75
+            this.projectState.currentProject?.priority,
76
+            Validators.required,
77
+          ],
78
+          creationDate: [
79
+            this.projectState.currentProject?.creationDate,
80
+            Validators.required,
81
+          ],
82
+          companyId: [
83
+            this.projectState.currentProject?.companyId,
84
+            Validators.required,
85
+          ],
86
+          description: [
87
+            this.projectState.currentProject?.description,
88
+            [Validators.required, Validators.minLength(15)],
89
+          ],
90
+          userId: [
91
+            this.projectState.currentProject?.userId,
92
+            Validators.required,
93
+          ],
94
+          state: [this.projectState.currentProject?.state, Validators.required],
95
+        });
96
+      });
97
+    });
98
+  }
99
+
100
+  onProjectUpdate() {
101
+    this.store.dispatch(
102
+      new UpdateProjectWithFormDataAction(this.projectFormGroup.value)
103
+    );
104
+  }
105
+
106
+  onUpdateOk() {
107
+    this.router.navigate(['/projects-management']);
108
+  }
109
+}

+ 2
- 2
src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.html 파일 보기

@@ -47,12 +47,12 @@
47 47
         <td>{{ project.state }}</td>
48 48
         <td>
49 49
           <button class="btn">
50
-            <i class="fa fa-pencil" style="color:mediumturquoise"></i>
50
+            <i class="fa fa-pencil" style="color:mediumturquoise" (click)="onEditProject(project)"></i>
51 51
           </button>
52 52
         </td>
53 53
         <td>
54 54
           <button class="btn">
55
-            <i class="fa fa-trash" style="color:red"></i>
55
+            <i class="fa fa-trash" style="color:red" (click)="onProjectDelete(project)"></i>
56 56
           </button>
57 57
         </td>
58 58
       </tr>

+ 19
- 4
src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.ts 파일 보기

@@ -1,18 +1,33 @@
1
+import { MsgState } from 'src/app/ngrx/msg.state';
2
+import { Store } from '@ngrx/store';
3
+import { Router } from '@angular/router';
4
+import { Project } from './../../../../shared/models/project/project.model';
1 5
 import { ProjectState } from './../../../../ngrx/projects/project.state';
2 6
 import { Component, Input, OnInit } from '@angular/core';
7
+import { DeleteProjectAction } from 'src/app/ngrx/projects/projects.actions';
3 8
 
4 9
 @Component({
5 10
   selector: 'app-projects-list',
6 11
   templateUrl: './projects-list.component.html',
7
-  styleUrls: ['./projects-list.component.css']
12
+  styleUrls: ['./projects-list.component.css'],
8 13
 })
9 14
 export class ProjectsListComponent implements OnInit {
10
-
11
-  constructor() { }
15
+  constructor(
16
+    private router: Router,
17
+    private store: Store<{ projectReducerKey: ProjectState }>
18
+  ) {}
12 19
 
13 20
   @Input() inputProjectState!: ProjectState;
14 21
 
15
-  ngOnInit(): void {
22
+  ngOnInit(): void {}
23
+
24
+  onEditProject(project: Project) {
25
+    this.router.navigate(['/project-update/' + project.id]);
16 26
   }
17 27
 
28
+  onProjectDelete(project: Project) {
29
+    if(window.confirm(MsgState.CONFIRM_DEL)){
30
+      this.store.dispatch(new DeleteProjectAction(project));
31
+    }
32
+  }
18 33
 }

+ 2
- 2
src/app/pages/projects-manager/projects-management/projects-management.component.ts 파일 보기

@@ -12,7 +12,7 @@ import { MsgState } from 'src/app/ngrx/msg.state';
12 12
 })
13 13
 export class ProjectsManagementComponent implements OnInit {
14 14
 
15
-  constructor(private store: Store<{productReducerKey: ProjectState}>) { }
15
+  constructor(private store: Store<{projectReducerKey: ProjectState}>) { }
16 16
 
17 17
   projectState$!:Observable<ProjectState>
18 18
 
@@ -20,7 +20,7 @@ export class ProjectsManagementComponent implements OnInit {
20 20
 
21 21
   ngOnInit(): void {
22 22
 
23
-    this.projectState$= this.store.select("productReducerKey");
23
+    this.projectState$= this.store.select("projectReducerKey");
24 24
   }
25 25
 
26 26
 }

+ 6
- 5
src/app/pages/projects-manager/projects-manager-routing.module.ts 파일 보기

@@ -1,16 +1,17 @@
1
+import { ProjectUpdateComponent } from './projects-management/project-update/project-update.component';
1 2
 import { ProjectsManagementComponent } from './projects-management/projects-management.component';
2
-import { ProjectNavBarComponent } from './projects-management/project-nav-bar/project-nav-bar.component';
3 3
 import { ProjectCreateComponent } from './projects-management/project-create/project-create.component';
4 4
 import { NgModule } from '@angular/core';
5 5
 import { RouterModule, Routes } from '@angular/router';
6 6
 
7 7
 const routes: Routes = [
8
-  {path:'project-create', component: ProjectCreateComponent},
9
-  {path: 'projects-management', component:ProjectsManagementComponent}
8
+  { path: 'project-create', component: ProjectCreateComponent },
9
+  { path: 'projects-management', component: ProjectsManagementComponent },
10
+  { path: 'project-update/:projectId', component: ProjectUpdateComponent },
10 11
 ];
11 12
 
12 13
 @NgModule({
13 14
   imports: [RouterModule.forChild(routes)],
14
-  exports: [RouterModule]
15
+  exports: [RouterModule],
15 16
 })
16
-export class ProjectsManagerRoutingModule { }
17
+export class ProjectsManagerRoutingModule {}

+ 6
- 3
src/app/pages/projects-manager/projects-manager.module.ts 파일 보기

@@ -8,6 +8,8 @@ import { ProjectCreateComponent } from './projects-management/project-create/pro
8 8
 import { ProjectNavBarComponent } from './projects-management/project-nav-bar/project-nav-bar.component';
9 9
 import { ProjectsManagementComponent } from './projects-management/projects-management.component';
10 10
 import { ProjectsListComponent } from './projects-management/projects-list/projects-list.component';
11
+import { ProjectUpdateComponent } from './projects-management/project-update/project-update.component';
12
+import { ReactiveFormsModule } from '@angular/forms';
11 13
 
12 14
 
13 15
 
@@ -17,17 +19,18 @@ import { ProjectsListComponent } from './projects-management/projects-list/proje
17 19
     ProjectCreateComponent,
18 20
     ProjectNavBarComponent,
19 21
     ProjectsManagementComponent,
20
-    ProjectsListComponent
22
+    ProjectsListComponent,
23
+    ProjectUpdateComponent
21 24
 
22 25
   ],
23 26
   imports: [
24 27
     CommonModule,
25 28
     ProjectsManagerRoutingModule,
26 29
     ButtonModule,
27
-    TableModule
30
+    TableModule,
31
+    ReactiveFormsModule
28 32
   ],
29 33
   providers:[
30
-    DatePipe
31 34
   ]
32 35
 })
33 36
 

+ 3
- 2
src/app/pages/users-manager/users-management/user-create/user-create.component.html 파일 보기

@@ -196,7 +196,7 @@
196 196
                     </div>
197 197
 
198 198
                     <div class="col-md-auto mb-3">
199
-                      <label for="city">City</label>
199
+                      <label for="ville">City</label>
200 200
                       <input
201 201
                         type="text"
202 202
                         class="form-control"
@@ -204,7 +204,7 @@
204 204
                         [ngClass]="{
205 205
                           'is-invalid':
206 206
                             userFormGroup.controls['address'].get('ville')?.touched &&
207
-                            !userFormGroup.controls['address'].get('vile')?.valid
207
+                            !userFormGroup.controls['address'].get('ville')?.valid
208 208
                         }"
209 209
                       />
210 210
                       <div class="invalid-feedback">
@@ -249,6 +249,7 @@
249 249
                           >max chars 15
250 250
                         </span>
251 251
                       </div>
252
+
252 253
                     </div>
253 254
                   </div>
254 255
                 </div>

+ 54
- 52
src/app/pages/users-manager/users-management/user-create/user-create.component.ts 파일 보기

@@ -1,5 +1,6 @@
1
+import { DatePipe } from '@angular/common';
1 2
 import { UsersService } from '../../../../shared/services/users.service';
2
-import { User } from '../../../../shared/models/user.model';
3
+import { User } from '../../../../shared/models/user/user.model';
3 4
 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
4 5
 import {
5 6
   CreateFormUserAddAction,
@@ -16,35 +17,54 @@ import { UserState } from 'src/app/ngrx/users/user.state';
16 17
   styleUrls: ['./user-create.component.css'],
17 18
 })
18 19
 export class UserCreateComponent implements OnInit {
19
-
20 20
   userFormGroup!: FormGroup;
21 21
 
22 22
   constructor(
23 23
     private store: Store<{ userReducerKey: UserState }>,
24 24
     private fb: FormBuilder,
25
-    private usersService: UsersService
25
+    private usersService: UsersService,
26
+    private datePipe: DatePipe
26 27
   ) {}
27 28
   userState!: UserState;
28 29
   readonly msgState = MsgState;
29 30
 
30 31
   ngOnInit(): void {
31
-
32 32
     this.store.dispatch(new CreateFormUserAddAction({}));
33 33
 
34 34
     this.store.subscribe((myState) => {
35 35
       this.userState = myState.userReducerKey;
36 36
 
37
-        this.userFormGroup = this.fb.group({
38
-          id: [0, Validators.required],
39
-          firstname: [
37
+      this.userFormGroup = this.fb.group({
38
+        id: [0, Validators.required],
39
+        firstname: [
40
+          '',
41
+          [
42
+            Validators.required,
43
+            Validators.minLength(3),
44
+            Validators.maxLength(15),
45
+          ],
46
+        ],
47
+        lastname: [
48
+          '',
49
+          [
50
+            Validators.required,
51
+            Validators.minLength(3),
52
+            Validators.maxLength(15),
53
+          ],
54
+        ],
55
+        email: ['', [Validators.required, Validators.email]],
56
+        address: this.fb.group({
57
+          numRue: [0, [Validators.required, Validators.min(1)]],
58
+          nomRue: [
40 59
             '',
41 60
             [
42 61
               Validators.required,
43 62
               Validators.minLength(3),
44
-              Validators.maxLength(15),
63
+              Validators.maxLength(25),
45 64
             ],
46 65
           ],
47
-          lastname: [
66
+          bp: [0, [Validators.required, Validators.min(1)]],
67
+          ville: [
48 68
             '',
49 69
             [
50 70
               Validators.required,
@@ -52,56 +72,38 @@ export class UserCreateComponent implements OnInit {
52 72
               Validators.maxLength(15),
53 73
             ],
54 74
           ],
55
-          email: ['', [Validators.required, Validators.email]],
56
-          address: this.fb.group({
57
-            numRue: [0, [Validators.required, Validators.min(1)]],
58
-            nomRue: [
59
-              '',
60
-              [
61
-                Validators.required,
62
-                Validators.minLength(3),
63
-                Validators.maxLength(25),
64
-              ],
65
-            ],
66
-            bp: [0, [Validators.required, Validators.min(1)]],
67
-            ville: [
68
-              '',
69
-              [
70
-                Validators.required,
71
-                Validators.minLength(3),
72
-                Validators.maxLength(15),
73
-              ],
74
-            ],
75
-            pays: [
76
-              '',
77
-              [
78
-                Validators.required,
79
-                Validators.minLength(3),
80
-                Validators.maxLength(15),
81
-              ],
75
+          pays: [
76
+            '',
77
+            [
78
+              Validators.required,
79
+              Validators.minLength(3),
80
+              Validators.maxLength(15),
82 81
             ],
83
-          }),
84
-        });
82
+          ],
83
+        }),
84
+        createDate: [this.datePipe.transform(new Date(), 'MM dd yyyy')],
85
+      });
85 86
     });
86 87
   }
87 88
 
88 89
   onUserSave() {
90
+    let user: User = this.userFormGroup.value;
91
+    let lastname: string = user.lastname;
89 92
 
90
-   let user: User = this.userFormGroup.value;
91
-   let lastname: string = user.lastname;
92
-
93
-   this.usersService.getUserByName(lastname).subscribe((users: User[]) => {
94
-     if (users.length > 0) {
95
-       alert(lastname + ' ' + this.msgState.EXIST);
96
-       return;
97
-     }
98
-     else{
99
-
100
-      if (window.confirm(MsgState.CONFIRM_ADD+' '+user.firstname+' '+user.lastname)) {
101
-        this.store.dispatch(new SaveUserFormAddAction(user));
93
+    this.usersService.getUserByName(lastname).subscribe((users: User[]) => {
94
+      if (users.length > 0) {
95
+        alert(lastname + ' ' + this.msgState.EXIST);
96
+        return;
97
+      } else {
98
+        if (
99
+          window.confirm(
100
+            MsgState.CONFIRM_ADD + ' ' + user.firstname + ' ' + user.lastname
101
+          )
102
+        ) {
103
+          this.store.dispatch(new SaveUserFormAddAction(user));
104
+        }
102 105
       }
103
-     }
104
-   });
106
+    });
105 107
   }
106 108
 
107 109
   onNewUser() {

+ 1
- 3
src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.ts 파일 보기

@@ -4,7 +4,7 @@ import { GetUser_S_Projects, UserActionUnion } from './../../../../ngrx/users/us
4 4
 import { UserState } from './../../../../ngrx/users/user.state';
5 5
 import { Component, OnInit } from '@angular/core';
6 6
 import { Store } from '@ngrx/store';
7
-import { User } from 'src/app/shared/models/user.model';
7
+import { User } from 'src/app/shared/models/user/user.model';
8 8
 
9 9
 @Component({
10 10
   selector: 'app-user-s-projects',
@@ -32,7 +32,5 @@ export class UserSProjectsComponent implements OnInit {
32 32
     this.store.dispatch(new GetUser_S_Projects({}));
33 33
 
34 34
     this.usersState$= this.store.select("userReducerKey");
35
-    console.log(this.usersState$)
36
-
37 35
   }
38 36
 }

+ 39
- 27
src/app/pages/users-manager/users-management/user-update/user-update.component.html 파일 보기

@@ -1,31 +1,34 @@
1 1
 <div class="container" *ngIf="userFormGrp">
2
-
3 2
   <ng-container *ngIf="userState">
3
+    <ng-container *ngIf="userState.msgState == msg.FORM_LOADING">
4
+      msg.FORM_LOADING
5
+    </ng-container>
4 6
 
5
-    <ng-container *ngIf="userState.msgState==msg.ERR">
7
+    <ng-container *ngIf="userState.msgState == msg.FORM_LOAD_ERR">
6 8
       <div class="alert-danger container">
7
-        {{msg.ERR}}
9
+        {{ msg.FORM_LOAD_ERR }}
8 10
       </div>
9 11
     </ng-container>
10 12
 
11
-    <ng-container *ngIf="userState.msgState == msg.UPDATED">
12
-      <div class="alert-success container p-3 m-3" style="width: 30em;">
13
-        <span>   {{msg.UPDATED}}</span> &nbsp;&nbsp;
14
-        <button class="btn btn-success" (click)="onUpdateOk()"> OK </button>
13
+    <ng-container *ngIf="userState.msgState == msg.FORM_LOAD_ERR">
14
+      <div class="alert-danger container">
15
+        {{ msg.FORM_LOAD_ERR }}
15 16
       </div>
16 17
     </ng-container>
17 18
 
18
-    <ng-container *ngIf="userState.msgState==msg.FORM_LOADED">
19
-
19
+    <ng-container *ngIf="userState.msgState == msg.FORM_LOADED">
20 20
       <div class="card mt-3">
21
-        <div class="card-header bg-light">User informations to modify: ID of user: <b>{{userId}}</b> </div>
21
+        <div class="card-header bg-light">
22
+          User informations to modify: <b>ID of user:
23
+          {{ userState.currentUser?.id }}</b>
24
+        </div>
22 25
         <div class="card-body">
23
-          <form [formGroup]="userFormGrp" (ngSubmit)="onUserUpdate(); userFormGrp.reset()">
24
-
26
+          <form
27
+            [formGroup]="userFormGrp"
28
+            (ngSubmit)="onUserUpdate(); userFormGrp.reset()"
29
+          >
25 30
             <div class="row">
26
-
27 31
               <div class="col card">
28
-
29 32
                 <div class="col-md-auto mb-3">
30 33
                   <label for="id">Firstname</label>
31 34
                   <input
@@ -34,7 +37,7 @@
34 37
                     formControlName="firstname"
35 38
                     [ngClass]="{
36 39
                       'is-invalid':
37
-                      userFormGrp.controls['firstname'].touched &&
40
+                        userFormGrp.controls['firstname'].touched &&
38 41
                         !userFormGrp.controls['firstname'].valid
39 42
                     }"
40 43
                   />
@@ -63,7 +66,7 @@
63 66
                     formControlName="lastname"
64 67
                     [ngClass]="{
65 68
                       'is-invalid':
66
-                      userFormGrp.controls['lastname'].touched &&
69
+                        userFormGrp.controls['lastname'].touched &&
67 70
                         !userFormGrp.controls['lastname'].valid
68 71
                     }"
69 72
                   />
@@ -98,19 +101,21 @@
98 101
                   />
99 102
 
100 103
                   <div class="invalid-feedback">
101
-                    <span *ngIf="userFormGrp.controls['email'].errors?.['required']">
104
+                    <span
105
+                      *ngIf="userFormGrp.controls['email'].errors?.['required']"
106
+                    >
102 107
                       required
103 108
                     </span>
104
-                    <span *ngIf="userFormGrp.controls['email'].errors?.['email']">
109
+                    <span
110
+                      *ngIf="userFormGrp.controls['email'].errors?.['email']"
111
+                    >
105 112
                       not valid
106 113
                     </span>
107 114
                   </div>
108 115
                 </div>
109
-
110 116
               </div>
111 117
 
112 118
               <div class="col card">
113
-
114 119
                 <div formGroupName="address">
115 120
                   <div class="col-md-auto mb-3">
116 121
                     <label for="numRue">Street number</label>
@@ -120,7 +125,8 @@
120 125
                       formControlName="numRue"
121 126
                       [ngClass]="{
122 127
                         'is-invalid':
123
-                          userFormGrp.controls['address'].get('numRue')?.touched &&
128
+                          userFormGrp.controls['address'].get('numRue')
129
+                            ?.touched &&
124 130
                           !userFormGrp.controls['address'].get('numRue')?.valid
125 131
                       }"
126 132
                     />
@@ -144,7 +150,8 @@
144 150
                       formControlName="nomRue"
145 151
                       [ngClass]="{
146 152
                         'is-invalid':
147
-                          userFormGrp.controls['address'].get('nomRue')?.touched &&
153
+                          userFormGrp.controls['address'].get('nomRue')
154
+                            ?.touched &&
148 155
                           !userFormGrp.controls['address'].get('nomRue')?.valid
149 156
                       }"
150 157
                     />
@@ -196,7 +203,8 @@
196 203
                       formControlName="ville"
197 204
                       [ngClass]="{
198 205
                         'is-invalid':
199
-                           userFormGrp.controls['address'].get('ville')?.touched &&
206
+                          userFormGrp.controls['address'].get('ville')
207
+                            ?.touched &&
200 208
                           !userFormGrp.controls['address'].get('vile')?.valid
201 209
                       }"
202 210
                     />
@@ -224,7 +232,8 @@
224 232
                       formControlName="pays"
225 233
                       [ngClass]="{
226 234
                         'is-invalid':
227
-                          userFormGrp.controls['address'].get('pays')?.touched &&
235
+                          userFormGrp.controls['address'].get('pays')
236
+                            ?.touched &&
228 237
                           !userFormGrp.controls['address'].get('pays')?.valid
229 238
                       }"
230 239
                     />
@@ -244,9 +253,7 @@
244 253
                     </div>
245 254
                   </div>
246 255
                 </div>
247
-
248 256
               </div>
249
-
250 257
             </div>
251 258
 
252 259
             <div class="text-center col-md-auto mt-3">
@@ -261,9 +268,14 @@
261 268
           </form>
262 269
         </div>
263 270
       </div>
271
+    </ng-container>
264 272
 
273
+    <ng-container *ngIf="userState.msgState == msg.UPDATED">
274
+      <div class="alert-success container p-3 m-3" style="width: 30em">
275
+        <span> {{ msg.UPDATED }}</span> &nbsp;&nbsp;
276
+        <button class="btn btn-success" (click)="onUpdateOk()">OK</button>
277
+      </div>
265 278
     </ng-container>
266 279
 
267 280
   </ng-container>
268
-
269 281
 </div>

+ 2
- 0
src/app/pages/users-manager/users-management/users-list/users-list.component.html 파일 보기

@@ -16,6 +16,7 @@ currentPageReportTemplate="{first} - {last} of {totalRecords} users"
16 16
     <th>Lastname</th>
17 17
     <th>Address</th>
18 18
     <th>Email</th>
19
+    <th>Creation Date</th>
19 20
     <th>action1</th>
20 21
     <th>action2</th>
21 22
   </tr>
@@ -34,6 +35,7 @@ currentPageReportTemplate="{first} - {last} of {totalRecords} users"
34 35
       </ul>
35 36
     </td>
36 37
     <td>{{ user.email }}</td>
38
+    <td>{{ user.creationDate }}</td>
37 39
     <td>
38 40
       <button class="btn">
39 41
         <i

+ 1
- 1
src/app/pages/users-manager/users-management/users-list/users-list.component.ts 파일 보기

@@ -2,7 +2,7 @@ import { Router } from '@angular/router';
2 2
 import {
3 3
   DeleteUsersAction,
4 4
 } from './../../../../ngrx/users/users.actions';
5
-import { User } from 'src/app/shared/models/user.model';
5
+import { User } from 'src/app/shared/models/user/user.model';
6 6
 import { Input } from '@angular/core';
7 7
 import { Component } from '@angular/core';
8 8
 import { UserState } from 'src/app/ngrx/users/user.state';

+ 1
- 1
src/app/pages/users-manager/users-management/users-management.component.ts 파일 보기

@@ -2,8 +2,8 @@ import { UserState } from './../../../ngrx/users/user.state';
2 2
 import { Component, OnInit } from '@angular/core';
3 3
 import {  Store } from '@ngrx/store';
4 4
 import { map, Observable } from 'rxjs';
5
-import { User } from 'src/app/shared/models/user.model';
6 5
 import { MsgState } from 'src/app/ngrx/msg.state';
6
+import { User } from 'src/app/shared/models/user/user.model';
7 7
 
8 8
 @Component({
9 9
   selector: 'app-users-management',

+ 2
- 10
src/app/pages/users-manager/users-manager.module.ts 파일 보기

@@ -1,23 +1,15 @@
1 1
 import { NgModule } from '@angular/core';
2
-import { CommonModule } from '@angular/common';
2
+import { CommonModule, DatePipe } from '@angular/common';
3 3
 import { ButtonModule } from "primeng/button";
4 4
 import { UsersManagerRoutingModule } from './users-manager-routing.module';
5 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
-import { EffectsModule } from '@ngrx/effects';
9
-import { StoreDevtoolsModule } from '@ngrx/store-devtools';
10
-import { StoreModule } from '@ngrx/store';
11
-import { userReducer } from 'src/app/ngrx/users/users.reducer';
12 8
 import { TableModule } from "primeng/table";
13 9
 import { UsersListComponent } from './users-management/users-list/users-list.component';
14 10
 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
15 11
 import { UserUpdateComponent } from './users-management/user-update/user-update.component';
16 12
 import { UserSProjectsComponent } from './users-management/user-s-projects/user-s-projects.component';
17
-import { UserCreateEffects } from 'src/app/ngrx/users/effects.user.createuser';
18
-import { UserGetSearchEffects } from 'src/app/ngrx/users/effects.user.getsearchuser';
19
-import { UserUpdateEffects } from 'src/app/ngrx/users/effects.user.update';
20
-import { ProjectCreateEffects } from 'src/app/ngrx/projects/effects.projectcreate';
21 13
 
22 14
 
23 15
 
@@ -37,6 +29,6 @@ import { ProjectCreateEffects } from 'src/app/ngrx/projects/effects.projectcreat
37 29
     TableModule,
38 30
     FormsModule,
39 31
     ReactiveFormsModule
40
-  ]
32
+  ],
41 33
 })
42 34
 export class UsersManagerModule { }

src/app/shared/models/company.model.ts → src/app/shared/models/company/company.model.ts 파일 보기


src/app/shared/models/company.type.ts → src/app/shared/models/company/company.type.ts 파일 보기


src/app/shared/models/project.model.ts → src/app/shared/models/project/project.model.ts 파일 보기

@@ -1,6 +1,6 @@
1 1
 import { DatePipe } from '@angular/common';
2 2
 import { Priority } from './project.priority';
3
-import { State } from './project.state';
3
+import { ProjectMsgState } from './project.msgstate';
4 4
 
5 5
 export class Project{
6 6
   id!: number;
@@ -10,5 +10,5 @@ export class Project{
10 10
   companyId!: number;
11 11
   description!: string;
12 12
   userId!: number;
13
-  state!:State ;
13
+  state!:ProjectMsgState ;
14 14
 }

src/app/shared/models/project.state.ts → src/app/shared/models/project/project.msgstate.ts 파일 보기

@@ -1,4 +1,4 @@
1
-export enum State {
1
+export enum ProjectMsgState {
2 2
   END = "END",
3 3
   INPROGRESS = "IN PROGRESS"
4 4
 }

src/app/shared/models/project.priority.ts → src/app/shared/models/project/project.priority.ts 파일 보기


src/app/shared/models/address.model.ts → src/app/shared/models/user/address.model.ts 파일 보기


src/app/shared/models/user.model.ts → src/app/shared/models/user/user.model.ts 파일 보기

@@ -1,3 +1,4 @@
1
+import { DatePipe } from '@angular/common';
1 2
 import { Address } from './address.model';
2 3
 export class User{
3 4
   id!:number;
@@ -5,4 +6,5 @@ export class User{
5 6
   lastname!: string;
6 7
   email!: string;
7 8
   address: Address = new Address();
9
+  createDate!: DatePipe
8 10
 }

+ 1
- 1
src/app/shared/services/companies.service.ts 파일 보기

@@ -2,7 +2,7 @@ import { HttpErrorResponse, HttpClient } from '@angular/common/http';
2 2
 import { Injectable } from '@angular/core';
3 3
 import { catchError, Observable, throwError } from 'rxjs';
4 4
 import { environment } from 'src/environments/environment';
5
-import { Company } from '../models/company.model';
5
+import { Company } from '../models/company/company.model'
6 6
 
7 7
 @Injectable({
8 8
   providedIn: 'root'

+ 1
- 1
src/app/shared/services/projects.service.ts 파일 보기

@@ -2,7 +2,7 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
2 2
 import { Injectable, OnInit } from '@angular/core';
3 3
 import { catchError, Observable, retry, throwError } from 'rxjs';
4 4
 import { environment } from 'src/environments/environment';
5
-import { Project } from '../models/project.model';
5
+import { Project } from '../models/project/project.model';
6 6
 
7 7
 @Injectable({
8 8
   providedIn: 'root',

+ 1
- 1
src/app/shared/services/users.service.ts 파일 보기

@@ -1,8 +1,8 @@
1
-import { User } from 'src/app/shared/models/user.model';
2 1
 import { HttpClient, HttpErrorResponse } from '@angular/common/http';
3 2
 import { Injectable } from '@angular/core';
4 3
 import { catchError, Observable, throwError } from 'rxjs';
5 4
 import { environment } from 'src/environments/environment';
5
+import { User } from '../models/user/user.model';
6 6
 
7 7
 @Injectable({
8 8
   providedIn: 'root',

Powered by TurnKey Linux.