placidenduwayo 2 роки тому
джерело
коміт
cf0d4cf6a3
82 змінених файлів з 1546 додано та 383 видалено
  1. 2
    1
      angular.json
  2. 58
    17
      db_users_projects_companies.json
  3. 66
    0
      package-lock.json
  4. 3
    1
      package.json
  5. 2
    2
      src/app/app.component.html
  6. 1
    1
      src/app/app.component.ts
  7. 42
    10
      src/app/app.module.ts
  8. 5
    5
      src/app/ngrx/msg.state.ts
  9. 0
    0
      src/app/ngrx/myreducer.ts
  10. 39
    0
      src/app/ngrx/projects/effects.projectcreate.ts
  11. 27
    0
      src/app/ngrx/projects/effects.projectget.ts
  12. 19
    0
      src/app/ngrx/projects/project.action.types.ts
  13. 12
    0
      src/app/ngrx/projects/project.state.ts
  14. 65
    0
      src/app/ngrx/projects/projects.actions.ts
  15. 91
    0
      src/app/ngrx/projects/projects.reducer.ts
  16. 41
    0
      src/app/ngrx/users/effects.user.createuser.ts
  17. 68
    0
      src/app/ngrx/users/effects.user.getsearchuser.ts
  18. 72
    0
      src/app/ngrx/users/effects.user.update.ts
  19. 50
    0
      src/app/ngrx/users/user.action.types.ts
  20. 3
    2
      src/app/ngrx/users/user.state.ts
  21. 55
    69
      src/app/ngrx/users/users.actions.ts
  22. 106
    79
      src/app/ngrx/users/users.effects.ts
  23. 78
    43
      src/app/ngrx/users/users.reducer.ts
  24. 3
    3
      src/app/pages/accueil/accueil-routing.module.ts
  25. 0
    20
      src/app/pages/base-nav-bar/base-nav-bar.component.html
  26. 0
    15
      src/app/pages/base-nav-bar/base-nav-bar.component.ts
  27. 17
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.css
  28. 32
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.html
  29. 40
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.spec.ts
  30. 36
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.ts
  31. 0
    0
      src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.css
  32. 0
    0
      src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.html
  33. 0
    0
      src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.spec.ts
  34. 0
    0
      src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.ts
  35. 0
    0
      src/app/pages/companies-manager/companies-management/companies-management.component.css
  36. 1
    0
      src/app/pages/companies-manager/companies-management/companies-management.component.html
  37. 25
    0
      src/app/pages/companies-manager/companies-management/companies-management.component.spec.ts
  38. 15
    0
      src/app/pages/companies-manager/companies-management/companies-management.component.ts
  39. 0
    0
      src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.css
  40. 3
    3
      src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.html
  41. 0
    0
      src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.spec.ts
  42. 0
    0
      src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.ts
  43. 4
    3
      src/app/pages/companies-manager/companies-manager-routing.module.ts
  44. 5
    3
      src/app/pages/companies-manager/companies-manager.module.ts
  45. 0
    15
      src/app/pages/projects-manager/project-create/project-create.component.ts
  46. 0
    15
      src/app/pages/projects-manager/project-nav-bar/project-nav-bar.component.ts
  47. 0
    0
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.css
  48. 1
    0
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.html
  49. 0
    0
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.spec.ts
  50. 30
    0
      src/app/pages/projects-manager/projects-management/project-create/project-create.component.ts
  51. 0
    0
      src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.css
  52. 4
    4
      src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.html
  53. 0
    0
      src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.spec.ts
  54. 25
    0
      src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.ts
  55. 0
    0
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.css
  56. 61
    0
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.html
  57. 6
    6
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.spec.ts
  58. 18
    0
      src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.ts
  59. 0
    0
      src/app/pages/projects-manager/projects-management/projects-management.component.css
  60. 25
    0
      src/app/pages/projects-manager/projects-management/projects-management.component.html
  61. 25
    0
      src/app/pages/projects-manager/projects-management/projects-management.component.spec.ts
  62. 26
    0
      src/app/pages/projects-manager/projects-management/projects-management.component.ts
  63. 4
    3
      src/app/pages/projects-manager/projects-manager-routing.module.ts
  64. 17
    5
      src/app/pages/projects-manager/projects-manager.module.ts
  65. 18
    16
      src/app/pages/users-manager/users-management/user-create/user-create.component.html
  66. 7
    5
      src/app/pages/users-manager/users-management/user-create/user-create.component.ts
  67. 5
    8
      src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.html
  68. 19
    4
      src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.ts
  69. 3
    0
      src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.css
  70. 64
    0
      src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.html
  71. 25
    0
      src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.spec.ts
  72. 38
    0
      src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.ts
  73. 2
    2
      src/app/pages/users-manager/users-management/user-update/user-update.component.html
  74. 2
    2
      src/app/pages/users-manager/users-management/user-update/user-update.component.ts
  75. 1
    1
      src/app/pages/users-manager/users-management/users-list/users-list.component.html
  76. 9
    10
      src/app/pages/users-manager/users-management/users-management.component.html
  77. 4
    4
      src/app/pages/users-manager/users-management/users-management.component.ts
  78. 2
    0
      src/app/pages/users-manager/users-manager-routing.module.ts
  79. 7
    5
      src/app/pages/users-manager/users-manager.module.ts
  80. 7
    0
      src/app/shared/models/project.priority.ts
  81. 4
    0
      src/app/shared/models/project.state.ts
  82. 1
    1
      src/app/shared/services/users.service.ts

+ 2
- 1
angular.json Переглянути файл

@@ -32,7 +32,8 @@
32 32
               "node_modules/primeng/resources/themes/lara-light-blue/theme.css",
33 33
               "node_modules/primeng/resources/primeng.min.css",
34 34
               "node_modules/bootstrap/dist/css/bootstrap.min.css",
35
-              "node_modules/font-awesome/css/font-awesome.min.css"
35
+              "node_modules/font-awesome/css/font-awesome.min.css",
36
+              "node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
36 37
             ],
37 38
             "scripts": [
38 39
               "node_modules/jquery/dist/jquery.min.js",

+ 58
- 17
db_users_projects_companies.json Переглянути файл

@@ -26,7 +26,7 @@
26 26
       "lastname": "Touitou",
27 27
       "email": "david.touitou@natan.fr",
28 28
       "address": {
29
-        "numRue": 445,
29
+        "numRue": 44,
30 30
         "nomRue": "Rue Notre Dame de Paris",
31 31
         "bp": 75002,
32 32
         "ville": "Paris",
@@ -39,7 +39,7 @@
39 39
       "lastname": "Ben Mohamed",
40 40
       "email": "nadhir.ben-mohamed@natan.fr",
41 41
       "address": {
42
-        "numRue": 44,
42
+        "numRue": 45,
43 43
         "nomRue": "Rue Notre Dame de Paris",
44 44
         "bp": 75002,
45 45
         "ville": "Paris",
@@ -138,19 +138,6 @@
138 138
       }
139 139
     },
140 140
     {
141
-      "id": 13,
142
-      "firstname": "azyd_yiuj",
143
-      "lastname": "azegr_èéiu",
144
-      "email": "zehr@zeuhuh",
145
-      "address": {
146
-        "numRue": 65652,
147
-        "nomRue": "zedtyuhjn",
148
-        "bp": 74512,
149
-        "ville": "zhgaèzty",
150
-        "pays": "sdgauzej"
151
-      }
152
-    },
153
-    {
154 141
       "id": 14,
155 142
       "firstname": "Naolie",
156 143
       "lastname": "Boudouka Tété",
@@ -171,11 +158,65 @@
171 158
       "address": {
172 159
         "numRue": 44,
173 160
         "nomRue": "Rue Notre Dame de Paris",
174
-        "bp": 75002,
161
+        "bp": 75004,
175 162
         "ville": "Paris",
176 163
         "pays": "France"
177 164
       }
165
+    },
166
+    {
167
+      "id": 17,
168
+      "firstname": "user test",
169
+      "lastname": "user test",
170
+      "email": "user.test@test",
171
+      "address": {
172
+        "numRue": 952,
173
+        "nomRue": "user test",
174
+        "bp": 45,
175
+        "ville": "user test",
176
+        "pays": "user test"
177
+      }
178 178
     }
179 179
   ],
180
-  "projects": []
180
+  "projects": [
181
+    {
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
+      "id": 2,
193
+      "projectName": "Project-2",
194
+      "priority": 1,
195
+      "creationDate": "03 06 2022",
196
+      "companyId": 2,
197
+      "description": "Project description for action",
198
+      "userId": 3,
199
+      "state": "END"
200
+    },
201
+    {
202
+      "id": 3,
203
+      "projectName": "Project-3",
204
+      "priority": 1,
205
+      "creationDate": "03 06 2022",
206
+      "companyId": 3,
207
+      "description": "Project description for action",
208
+      "userId": 4,
209
+      "state": "END"
210
+    },
211
+    {
212
+      "id": 4,
213
+      "projectName": "Project-4",
214
+      "priority": 1,
215
+      "creationDate": "03 06 2022",
216
+      "companyId": 3,
217
+      "description": "Project description for action",
218
+      "userId": 12,
219
+      "state": "END"
220
+    }
221
+  ]
181 222
 }

+ 66
- 0
package-lock.json Переглянути файл

@@ -9,10 +9,12 @@
9 9
       "version": "0.0.0",
10 10
       "dependencies": {
11 11
         "@angular/animations": "~13.3.0",
12
+        "@angular/cdk": "~13.3.6",
12 13
         "@angular/common": "~13.3.0",
13 14
         "@angular/compiler": "~13.3.0",
14 15
         "@angular/core": "~13.3.0",
15 16
         "@angular/forms": "~13.3.0",
17
+        "@angular/material": "~13.3.6",
16 18
         "@angular/platform-browser": "~13.3.0",
17 19
         "@angular/platform-browser-dynamic": "~13.3.0",
18 20
         "@angular/router": "~13.3.0",
@@ -358,6 +360,28 @@
358 360
         "@angular/core": "13.3.9"
359 361
       }
360 362
     },
363
+    "node_modules/@angular/cdk": {
364
+      "version": "13.3.9",
365
+      "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.9.tgz",
366
+      "integrity": "sha512-XCuCbeuxWFyo3EYrgEYx7eHzwl76vaWcxtWXl00ka8d+WAOtMQ6Tf1D98ybYT5uwF9889fFpXAPw98mVnlo3MA==",
367
+      "dependencies": {
368
+        "tslib": "^2.3.0"
369
+      },
370
+      "optionalDependencies": {
371
+        "parse5": "^5.0.0"
372
+      },
373
+      "peerDependencies": {
374
+        "@angular/common": "^13.0.0 || ^14.0.0-0",
375
+        "@angular/core": "^13.0.0 || ^14.0.0-0",
376
+        "rxjs": "^6.5.3 || ^7.4.0"
377
+      }
378
+    },
379
+    "node_modules/@angular/cdk/node_modules/parse5": {
380
+      "version": "5.1.1",
381
+      "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz",
382
+      "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==",
383
+      "optional": true
384
+    },
361 385
     "node_modules/@angular/cli": {
362 386
       "version": "13.3.6",
363 387
       "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.6.tgz",
@@ -561,6 +585,23 @@
561 585
         "rxjs": "^6.5.3 || ^7.4.0"
562 586
       }
563 587
     },
588
+    "node_modules/@angular/material": {
589
+      "version": "13.3.9",
590
+      "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.9.tgz",
591
+      "integrity": "sha512-FU8lcMgo+AL8ckd27B4V097ZPoIZNRHiCe3wpgkImT1qC0YwcyXZVn0MqQTTFSdC9a/aI8wPm3AbTClJEVw5Vw==",
592
+      "dependencies": {
593
+        "tslib": "^2.3.0"
594
+      },
595
+      "peerDependencies": {
596
+        "@angular/animations": "^13.0.0 || ^14.0.0-0",
597
+        "@angular/cdk": "13.3.9",
598
+        "@angular/common": "^13.0.0 || ^14.0.0-0",
599
+        "@angular/core": "^13.0.0 || ^14.0.0-0",
600
+        "@angular/forms": "^13.0.0 || ^14.0.0-0",
601
+        "@angular/platform-browser": "^13.0.0 || ^14.0.0-0",
602
+        "rxjs": "^6.5.3 || ^7.4.0"
603
+      }
604
+    },
564 605
     "node_modules/@angular/platform-browser": {
565 606
       "version": "13.3.9",
566 607
       "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-13.3.9.tgz",
@@ -13090,6 +13131,23 @@
13090 13131
         "tslib": "^2.3.0"
13091 13132
       }
13092 13133
     },
13134
+    "@angular/cdk": {
13135
+      "version": "13.3.9",
13136
+      "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-13.3.9.tgz",
13137
+      "integrity": "sha512-XCuCbeuxWFyo3EYrgEYx7eHzwl76vaWcxtWXl00ka8d+WAOtMQ6Tf1D98ybYT5uwF9889fFpXAPw98mVnlo3MA==",
13138
+      "requires": {
13139
+        "parse5": "^5.0.0",
13140
+        "tslib": "^2.3.0"
13141
+      },
13142
+      "dependencies": {
13143
+        "parse5": {
13144
+          "version": "5.1.1",
13145
+          "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.1.tgz",
13146
+          "integrity": "sha512-ugq4DFI0Ptb+WWjAdOK16+u/nHfiIrcE+sh8kZMaM0WllQKLI9rOUq6c2b7cwPkXdzfQESqvoqK6ug7U/Yyzug==",
13147
+          "optional": true
13148
+        }
13149
+      }
13150
+    },
13093 13151
     "@angular/cli": {
13094 13152
       "version": "13.3.6",
13095 13153
       "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-13.3.6.tgz",
@@ -13231,6 +13289,14 @@
13231 13289
         "tslib": "^2.3.0"
13232 13290
       }
13233 13291
     },
13292
+    "@angular/material": {
13293
+      "version": "13.3.9",
13294
+      "resolved": "https://registry.npmjs.org/@angular/material/-/material-13.3.9.tgz",
13295
+      "integrity": "sha512-FU8lcMgo+AL8ckd27B4V097ZPoIZNRHiCe3wpgkImT1qC0YwcyXZVn0MqQTTFSdC9a/aI8wPm3AbTClJEVw5Vw==",
13296
+      "requires": {
13297
+        "tslib": "^2.3.0"
13298
+      }
13299
+    },
13234 13300
     "@angular/platform-browser": {
13235 13301
       "version": "13.3.9",
13236 13302
       "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-13.3.9.tgz",

+ 3
- 1
package.json Переглянути файл

@@ -11,10 +11,12 @@
11 11
   "private": true,
12 12
   "dependencies": {
13 13
     "@angular/animations": "~13.3.0",
14
+    "@angular/cdk": "~13.3.6",
14 15
     "@angular/common": "~13.3.0",
15 16
     "@angular/compiler": "~13.3.0",
16 17
     "@angular/core": "~13.3.0",
17 18
     "@angular/forms": "~13.3.0",
19
+    "@angular/material": "~13.3.6",
18 20
     "@angular/platform-browser": "~13.3.0",
19 21
     "@angular/platform-browser-dynamic": "~13.3.0",
20 22
     "@angular/router": "~13.3.0",
@@ -47,4 +49,4 @@
47 49
     "karma-jasmine-html-reporter": "~1.7.0",
48 50
     "typescript": "~4.6.2"
49 51
   }
50
-}
52
+}

+ 2
- 2
src/app/app.component.html Переглянути файл

@@ -1,2 +1,2 @@
1
-<app-base-nav-bar></app-base-nav-bar>
2
-<router-outlet></router-outlet>
1
+<app-base-nav-menu></app-base-nav-menu>
2
+<!-- <router-outlet></router-outlet> -->

+ 1
- 1
src/app/app.component.ts Переглянути файл

@@ -6,5 +6,5 @@ import { Component } from '@angular/core';
6 6
   styleUrls: ['./app.component.css']
7 7
 })
8 8
 export class AppComponent {
9
-  title = 'users-projects-companies-NgRx';
9
+  title = 'users-projects-companies';
10 10
 }

+ 42
- 10
src/app/app.module.ts Переглянути файл

@@ -1,3 +1,4 @@
1
+import { BaseNavMenuComponent } from './pages/base-nav-menu/base-nav-menu.component';
1 2
 import { FormsModule } from '@angular/forms';
2 3
 import { AccueilModule } from './pages/accueil/accueil.module';
3 4
 import { CompaniesManagerModule } from './pages/companies-manager/companies-manager.module';
@@ -5,19 +6,31 @@ import { ProjectsManagerModule } from './pages/projects-manager/projects-manager
5 6
 import { UsersManagerModule } from './pages/users-manager/users-manager.module';
6 7
 import { NgModule } from '@angular/core';
7 8
 import { BrowserModule } from '@angular/platform-browser';
8
-import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
9
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9 10
 
10 11
 import { AppRoutingModule } from './app-routing.module';
11 12
 import { AppComponent } from './app.component';
12
-import { BaseNavBarComponent } from './pages/base-nav-bar/base-nav-bar.component';
13 13
 import { HttpClientModule } from '@angular/common/http';
14
-
14
+import { LayoutModule } from '@angular/cdk/layout';
15
+import { MatToolbarModule } from '@angular/material/toolbar';
16
+import { MatButtonModule } from '@angular/material/button';
17
+import { MatSidenavModule } from '@angular/material/sidenav';
18
+import { MatIconModule } from '@angular/material/icon';
19
+import { MatListModule } from '@angular/material/list';
20
+import { MatMenuModule } from '@angular/material/menu';
21
+import { EffectsModule } from '@ngrx/effects';
22
+import { StoreModule } from '@ngrx/store';
23
+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';
28
+import { userReducer } from './ngrx/users/users.reducer';
29
+import { projectReducer } from './ngrx/projects/projects.reducer';
30
+import { ProjectGet } from './ngrx/projects/effects.projectget';
15 31
 
16 32
 @NgModule({
17
-  declarations: [
18
-    AppComponent,
19
-    BaseNavBarComponent
20
-  ],
33
+  declarations: [AppComponent, BaseNavMenuComponent],
21 34
   imports: [
22 35
     BrowserModule,
23 36
     AppRoutingModule,
@@ -27,9 +40,28 @@ import { HttpClientModule } from '@angular/common/http';
27 40
     AccueilModule,
28 41
     HttpClientModule,
29 42
     BrowserAnimationsModule,
30
-    FormsModule
43
+    FormsModule,
44
+    LayoutModule,
45
+    MatToolbarModule,
46
+    MatButtonModule,
47
+    MatSidenavModule,
48
+    MatIconModule,
49
+    MatListModule,
50
+    MatMenuModule,
51
+    StoreModule.forRoot({
52
+      userReducerKey: userReducer,
53
+      productReducerKey: projectReducer,
54
+    }),
55
+    EffectsModule.forRoot([
56
+      UserCreateEffects,
57
+      UserGetSearchEffects,
58
+      UserUpdateEffects,
59
+      ProjectCreateEffects,
60
+      ProjectGet
61
+    ]),
62
+    StoreDevtoolsModule.instrument(),
31 63
   ],
32 64
   providers: [],
33
-  bootstrap: [AppComponent]
65
+  bootstrap: [AppComponent],
34 66
 })
35
-export class AppModule { }
67
+export class AppModule {}

+ 5
- 5
src/app/ngrx/msg.state.ts Переглянути файл

@@ -1,8 +1,8 @@
1 1
 export enum MsgState {
2
-  LOADING = '[User] USERS ARE LOADING ...',
3
-  LOADED = '[User] SUCCESSFUL LOADED',
2
+  LOADING = 'LOADING ...',
3
+  LOADED = 'SUCCESSFUL LOADED',
4 4
   ERR = 'ERROR ACCURRED',
5
-  INIT_STATE = '[User] INITIAL STATE',
5
+  INIT_STATE = 'INITIAL STATE',
6 6
   FORM_LOADING = 'FORM LOADING',
7 7
   FORM_LOADED = 'FORM LOADED',
8 8
   FORM_LOAD_ERR= 'FORM LOADING ERROR',
@@ -10,6 +10,6 @@ export enum MsgState {
10 10
   CONFIRM_DEL = 'CONFIRM DELETION OF',
11 11
   ADDED = 'SUCCESSFULLY ADDED',
12 12
   EXIST = 'ALREADY EXISTS',
13
-  UPDATED = '[User] SUCCESSFULLY UPDATED',
14
-  DEFAULT_MSG = 'DEFAULT LOADING MSG'
13
+  UPDATED = ' SUCCESSFULLY UPDATED',
14
+  DEFAULT_MSG = 'DEFAULT MSG LOADING'
15 15
 }

src/app/ngrx/projects/projects.effects.ts → src/app/ngrx/myreducer.ts Переглянути файл


+ 39
- 0
src/app/ngrx/projects/effects.projectcreate.ts Переглянути файл

@@ -0,0 +1,39 @@
1
+import { ProjectActionTypes } from './project.action.types';
2
+import { ProjectActionUnion, CreateProjectFormAddAction, SaveProjectFormDataActionSuccess, SaveProjectFormDataActionError, CreateProjectFormAddActionSuccess } from './projects.actions';
3
+import { map, Observable, mergeMap, catchError, of } from 'rxjs';
4
+import { ProjectsService } from './../../shared/services/projects.service';
5
+import { Actions, createEffect, ofType } from '@ngrx/effects';
6
+import { Injectable } from '@angular/core';
7
+import { Project } from 'src/app/shared/models/project.model';
8
+
9
+@Injectable()
10
+export class ProjectCreateEffects {
11
+
12
+  constructor(
13
+    private projectActions: Actions,
14
+    private projectsService: ProjectsService
15
+  ) {}
16
+
17
+  //create project form effect
18
+  createAddProjectFormEffect:Observable<ProjectActionUnion> = createEffect(
19
+    ()=> this.projectActions.pipe(
20
+      ofType((ProjectActionTypes.CREATE_PROJECT_FORM_ADD)),
21
+      map( (projectAction: ProjectActionUnion)=>{
22
+        return new CreateProjectFormAddActionSuccess(projectAction.payload);
23
+      })
24
+    )
25
+  );
26
+
27
+  //save project form data effect
28
+  saveProjectFormDataEffect : Observable<ProjectActionUnion> = createEffect(
29
+    ()=> this.projectActions.pipe(
30
+      ofType(ProjectActionTypes.SAVE_PROJECT_FORM_DATA),
31
+      mergeMap( (action: ProjectActionUnion) =>{
32
+        return this.projectsService.createProject(action.payload).pipe(
33
+          map((project: Project)=> new SaveProjectFormDataActionSuccess(project)),
34
+          catchError(err=>of(new SaveProjectFormDataActionError(err.message)))
35
+        )
36
+      })
37
+    )
38
+  )
39
+}

+ 27
- 0
src/app/ngrx/projects/effects.projectget.ts Переглянути файл

@@ -0,0 +1,27 @@
1
+import { Project } from './../../shared/models/project.model';
2
+import { ProjectActionTypes } from './project.action.types';
3
+import { ProjectActionUnion, GetAllProjectsActionSuccess, GetAllProjectsActionError } from './projects.actions';
4
+import { Observable, mergeMap, map, catchError, of } from 'rxjs';
5
+import { Actions, createEffect, ofType } from '@ngrx/effects';
6
+import { ProjectsService } from './../../shared/services/projects.service';
7
+import { Injectable } from '@angular/core';
8
+
9
+@Injectable()
10
+export class ProjectGet {
11
+  constructor(
12
+    private projectsService: ProjectsService,
13
+    private projectActions: Actions
14
+  ) {}
15
+
16
+  getAllProjectsEffect: Observable<ProjectActionUnion> = createEffect(
17
+    () => this.projectActions.pipe(
18
+      ofType(ProjectActionTypes.GET_ALL_PROJECTS),
19
+      mergeMap((action: ProjectActionUnion)=>{
20
+        return this.projectsService.getAllProjects().pipe(
21
+          map( (projects: Project[] )=> new GetAllProjectsActionSuccess(projects)),
22
+          catchError( err => of(new GetAllProjectsActionError(err.message)))
23
+        );
24
+      })
25
+    )
26
+  );
27
+}

+ 19
- 0
src/app/ngrx/projects/project.action.types.ts Переглянути файл

@@ -0,0 +1,19 @@
1
+/** Project actions types */
2
+
3
+export enum ProjectActionTypes{
4
+
5
+  //get all project action
6
+  GET_ALL_PROJECTS = '[Project] GET ALL PROJECTS',
7
+  GET_ALL_PROJECTS_SUCCESS = '[Project] GET ALL PROJECTS SUCCESS',
8
+  GET_ALL_PROJECTS_ERROR = '[Project] GET ALL PROJECTS ERROR',
9
+
10
+  //create project form to add a project
11
+  CREATE_PROJECT_FORM_ADD = '[Project] CREATE PROJECT FORM ADD',
12
+  CREATE_PROJECT_FORM_ADD_SUCCESS = '[Project] CREATE PROJECT FORM ADD SUCCESS',
13
+  CREATE_PROJECT_FORM_ADD_ERROR = '[Project] CREATE PROJECT FORM ADD ERROR',
14
+
15
+  //save project form data
16
+  SAVE_PROJECT_FORM_DATA ='[Project] SAVE PROJECT FORM DATA',
17
+  SAVE_PROJECT_FORM_DATA_SUCCESS ='[Project] SAVE PROJECT FORM DATA SUCCESS',
18
+  SAVE_PROJECT_FORM_DATA_ERROR ='[Project] SAVE PROJECT FORM DATA ERROR',
19
+}

+ 12
- 0
src/app/ngrx/projects/project.state.ts Переглянути файл

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

+ 65
- 0
src/app/ngrx/projects/projects.actions.ts Переглянути файл

@@ -0,0 +1,65 @@
1
+import { Project } from './../../shared/models/project.model';
2
+import { ProjectActionTypes } from './project.action.types';
3
+import { Action } from '@ngrx/store';
4
+
5
+/** create actions related to projects */
6
+
7
+//create get all project action
8
+export class GetAllProjectsAction implements Action {
9
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS;
10
+  constructor(public payload: any) {}
11
+}
12
+
13
+export class GetAllProjectsActionSuccess implements Action {
14
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS_SUCCESS;
15
+  constructor(public payload: Project[]) {}
16
+}
17
+
18
+export class GetAllProjectsActionError implements Action {
19
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS_ERROR;
20
+  constructor(public payload: string) {}
21
+}
22
+
23
+//create project form to add a project
24
+
25
+export class CreateProjectFormAddAction implements Action{
26
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_ADD;
27
+  constructor (public payload: any){}
28
+}
29
+
30
+export class CreateProjectFormAddActionSuccess implements Action{
31
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_ADD_SUCCESS;
32
+  constructor (public payload: any){}
33
+}
34
+
35
+export class CreateProjectFormAddActionError implements Action{
36
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_PROJECT_FORM_ADD_ERROR;
37
+  constructor (public payload: string){}
38
+}
39
+
40
+//save project form data
41
+export class SaveProjectFormDataAction implements Action{
42
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA
43
+  constructor (public payload: Project){}
44
+}
45
+//save project form data
46
+export class SaveProjectFormDataActionSuccess implements Action{
47
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_SUCCESS
48
+  constructor (public payload: Project){}
49
+}
50
+//save project form data
51
+export class SaveProjectFormDataActionError implements Action{
52
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_PROJECT_FORM_DATA_ERROR
53
+  constructor (public payload: string){}
54
+}
55
+
56
+export type ProjectActionUnion =
57
+  | GetAllProjectsAction
58
+  | GetAllProjectsActionSuccess
59
+  | GetAllProjectsActionError
60
+  | CreateProjectFormAddAction
61
+  | CreateProjectFormAddActionSuccess
62
+  | CreateProjectFormAddActionError
63
+  | SaveProjectFormDataAction
64
+  | SaveProjectFormDataActionSuccess
65
+  | SaveProjectFormDataActionError;

+ 91
- 0
src/app/ngrx/projects/projects.reducer.ts Переглянути файл

@@ -0,0 +1,91 @@
1
+import { ProjectActionUnion } from './projects.actions';
2
+import { Action } from '@ngrx/store';
3
+import { MsgState } from '../msg.state';
4
+import { ProjectState } from './project.state';
5
+import { ProjectActionTypes } from './project.action.types';
6
+import { Project } from 'src/app/shared/models/project.model';
7
+
8
+/** a reducer need first initial state and action to perform */
9
+
10
+const projectInitState: ProjectState = {
11
+  currentProject: null,
12
+  projectsList: [],
13
+  msgState: MsgState.INIT_STATE,
14
+  serverErrorMsg: 'no error massage',
15
+  currectAction: null,
16
+};
17
+
18
+export function projectReducer(
19
+  state: ProjectState = projectInitState,
20
+  projectAction: Action
21
+): ProjectState {
22
+
23
+  switch (projectAction.type) {
24
+
25
+    // get all projects action reducer
26
+    case ProjectActionTypes.GET_ALL_PROJECTS:
27
+      return {
28
+        ...state,
29
+        msgState: MsgState.LOADING,
30
+      };
31
+
32
+    case ProjectActionTypes.GET_ALL_PROJECTS_SUCCESS:
33
+      return {
34
+        ...state,
35
+        msgState: MsgState.LOADED,
36
+        projectsList: (<ProjectActionUnion> projectAction).payload,
37
+      };
38
+
39
+    case ProjectActionTypes.GET_ALL_PROJECTS_ERROR:
40
+      return {
41
+        ...state,
42
+        msgState: MsgState.ERR,
43
+        serverErrorMsg: (<ProjectActionUnion> projectAction).payload,
44
+      };
45
+
46
+
47
+    // create project form to add action reducer
48
+
49
+    case ProjectActionTypes.CREATE_PROJECT_FORM_ADD:
50
+      return{
51
+        ...state,
52
+        msgState: MsgState.FORM_LOADING,
53
+      };
54
+
55
+    case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_SUCCESS:
56
+      return{
57
+        ...state,
58
+        msgState: MsgState.FORM_LOADED
59
+      };
60
+
61
+    case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_ERROR:
62
+      return{
63
+        ...state,
64
+        msgState: MsgState.ERR,
65
+        serverErrorMsg: (<ProjectActionUnion> projectAction).payload
66
+      }
67
+
68
+    //saving project form data
69
+
70
+    case ProjectActionTypes.SAVE_PROJECT_FORM_DATA:
71
+      return{
72
+        ...state,
73
+        msgState: MsgState.LOADING
74
+      };
75
+
76
+    case ProjectActionTypes.CREATE_PROJECT_FORM_ADD_SUCCESS:
77
+      let createdProject: Project = (<ProjectActionUnion> projectAction).payload;
78
+      let projectsListCopy: Project[] = [...state.projectsList];
79
+      projectsListCopy.push(createdProject);
80
+
81
+      return{
82
+        ...state,
83
+        msgState: MsgState.ADDED,
84
+        projectsList: projectsListCopy
85
+      };
86
+
87
+
88
+    default:
89
+      return { ...state };
90
+  }
91
+}

+ 41
- 0
src/app/ngrx/users/effects.user.createuser.ts Переглянути файл

@@ -0,0 +1,41 @@
1
+import { UsersService } from '../../shared/services/users.service';
2
+import { CreateFormUserAddActionError, CreateFormUserAddActionSuccess, SaveUserFormAddActionError, SaveUserFormAddActionSuccess, UserActionUnion } from './users.actions';
3
+import { Injectable } from "@angular/core";
4
+import { catchError, map, mergeMap, Observable, of } from 'rxjs';
5
+import { Actions, createEffect, ofType } from '@ngrx/effects';
6
+import { UserActionTypes } from './user.action.types';
7
+import { User } from 'src/app/shared/models/user.model';
8
+
9
+@Injectable()
10
+export class UserCreateEffects{
11
+
12
+  constructor(private userActions: Actions, private usersService: UsersService){}
13
+
14
+
15
+
16
+   //create a user add form effect
17
+   createAddUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
18
+   this.userActions.pipe(
19
+     ofType(UserActionTypes.CREATE_FORM_ADD_USER),
20
+     map((userAction: UserActionUnion) => {
21
+       return new CreateFormUserAddActionSuccess(userAction.payload);
22
+     }),
23
+     catchError((err) => of(new CreateFormUserAddActionError(err.message)))
24
+   )
25
+ );
26
+
27
+ //saving user form data effect
28
+
29
+ saveUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
30
+   this.userActions.pipe(
31
+     ofType(UserActionTypes.SAVE_USERFORM_ADD),
32
+     mergeMap((userAction: UserActionUnion) => {
33
+       return this.usersService.createUser(userAction.payload).pipe(
34
+         map((user:User) => new SaveUserFormAddActionSuccess(user)),
35
+         catchError((err) => of(new SaveUserFormAddActionError(err.message)))
36
+       );
37
+     })
38
+   )
39
+ );
40
+
41
+}

+ 68
- 0
src/app/ngrx/users/effects.user.getsearchuser.ts Переглянути файл

@@ -0,0 +1,68 @@
1
+import { Router } from '@angular/router';
2
+import { UsersService } from '../../shared/services/users.service';
3
+import { Actions, createEffect, ofType } from '@ngrx/effects';
4
+import { Injectable } from '@angular/core';
5
+import { GetAllUsersActionError, GetAllUsersActionSuccess, GetUser_s_ProjectsError, GetUser_s_ProjectsSuccess, SearchUserActionError, SearchUserActionSuccess, UserActionUnion } from './users.actions';
6
+import { Observable, mergeMap, map, catchError, of, tap } from 'rxjs';
7
+import { User } from 'src/app/shared/models/user.model';
8
+import { UserActionTypes } from './user.action.types';
9
+
10
+@Injectable()
11
+export class UserGetSearchEffects {
12
+  constructor(
13
+    private userActions: Actions,
14
+    private usersService: UsersService,
15
+    private router: Router
16
+  ) {}
17
+
18
+  //create getAllUsers effect
19
+
20
+  getAllUsersEffect: Observable<UserActionUnion> = createEffect(() =>
21
+    this.userActions.pipe(
22
+      ofType(UserActionTypes.GET_ALL_USERS),
23
+      mergeMap(() => {
24
+        return this.usersService.getAllUsers().pipe(
25
+          map((users: User[]) => new GetAllUsersActionSuccess(users)),
26
+          catchError((err) => of(new GetAllUsersActionError(err.message)))
27
+        );
28
+      })
29
+    )
30
+  );
31
+
32
+  //create searchUser effect
33
+
34
+  searchUserEffect: Observable<UserActionUnion> = createEffect(() =>
35
+    this.userActions.pipe(
36
+      ofType(UserActionTypes.SEARCH_A_USER),
37
+      mergeMap((userAction: UserActionUnion) => {
38
+        return this.usersService.searchUser(userAction.payload).pipe(
39
+          map((users: User[]) => new SearchUserActionSuccess(users)),
40
+          catchError((err) => of(new SearchUserActionError(err.message)))
41
+        );
42
+      })
43
+    )
44
+  );
45
+
46
+  // navigate to another component effect
47
+  navigate:Observable<UserActionUnion> = createEffect(
48
+    () => this.userActions.pipe(
49
+        ofType(UserActionTypes.NAVIGATE_TO_USER_S_PROJECTS_COMPONENT_SUCCESS),
50
+        tap(() => {
51
+            this.router.navigate(['/user-s-projects']);
52
+        })
53
+    ),
54
+    { dispatch: false }
55
+);
56
+
57
+  loadUserSProjectsEffect : Observable<UserActionUnion> = createEffect(
58
+    ()=> this.userActions.pipe(
59
+      ofType(UserActionTypes.GET_USER_S_PROJECTS),
60
+      mergeMap( (action: UserActionUnion)=>{
61
+        return this.usersService.getUser_sProjects().pipe(
62
+          map( (users: any)=> new GetUser_s_ProjectsSuccess(users)),
63
+          catchError(err => of(new GetUser_s_ProjectsError(err.message)))
64
+        )
65
+      })
66
+    )
67
+  );
68
+}

+ 72
- 0
src/app/ngrx/users/effects.user.update.ts Переглянути файл

@@ -0,0 +1,72 @@
1
+import {
2
+  UserActionUnion,
3
+  CreareFormUserEditActionSuccess,
4
+  CreareFormUserEditActionActionError,
5
+  DeleteUserActionSuccess,
6
+  DeleteUserActionError,
7
+  UpdateUserFormActionError,
8
+  UpdateUserFormActionSuccess,
9
+} from './users.actions';
10
+import { map, mergeMap, Observable, catchError, of } from 'rxjs';
11
+import { UsersService } from '../../shared/services/users.service';
12
+import { Injectable } from '@angular/core';
13
+import { Actions, createEffect, ofType } from '@ngrx/effects';
14
+import { User } from 'src/app/shared/models/user.model';
15
+import { UserActionTypes } from './user.action.types';
16
+import { Router } from '@angular/router';
17
+
18
+@Injectable()
19
+
20
+export class UserUpdateEffects {
21
+  constructor(
22
+    private usersService: UsersService,
23
+    private effectActions: Actions,
24
+    private router: Router
25
+  ) {}
26
+
27
+
28
+  // create an update user form effect and fill it with data of a user to update
29
+
30
+  createUpdateUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
31
+    this.effectActions.pipe(
32
+      ofType(UserActionTypes.CREATE_FORM_USER_EDIT),
33
+      mergeMap((userAction: UserActionUnion) => {
34
+        return this.usersService.getUserById(userAction.payload.id).pipe(
35
+          map((user: User) => new CreareFormUserEditActionSuccess(user)),
36
+          catchError((err) =>
37
+            of(new CreareFormUserEditActionActionError(err.message))
38
+          )
39
+        );
40
+      })
41
+    )
42
+  );
43
+
44
+  // update a user with data of form effect
45
+
46
+  updateUserFormDataEffect: Observable<UserActionUnion> = createEffect(() =>
47
+    this.effectActions.pipe(
48
+      ofType(UserActionTypes.UPDATE_USER_FORM),
49
+      mergeMap((userAction: UserActionUnion) => {
50
+        return this.usersService.updateUser(userAction.payload).pipe(
51
+          map((user: User) => new UpdateUserFormActionSuccess(user)),
52
+          catchError((err) => of(new UpdateUserFormActionError(err.message)))
53
+        );
54
+      })
55
+    )
56
+  );
57
+
58
+  //deleteUser effect
59
+
60
+  deleteUserEffect: Observable<UserActionUnion> = createEffect(() =>
61
+    this.effectActions.pipe(
62
+      ofType(UserActionTypes.DELETE_A_USER),
63
+      mergeMap((userAction: UserActionUnion) => {
64
+        return this.usersService.deleteUser(userAction.payload.id).pipe(
65
+          map(() => new DeleteUserActionSuccess(userAction.payload)),
66
+          catchError((err) => of(new DeleteUserActionError(err.message)))
67
+        );
68
+      })
69
+    )
70
+  );
71
+
72
+}

+ 50
- 0
src/app/ngrx/users/user.action.types.ts Переглянути файл

@@ -0,0 +1,50 @@
1
+/**type of actions*/
2
+
3
+export enum UserActionTypes {
4
+
5
+  // action: get all users
6
+  GET_ALL_USERS = '[User] GET ALL USERS',
7
+  GET_ALL_USERS_SUCCESS = '[User] GET-ALL USERS SUCCESS',
8
+  GET_ALL_USERS_ERROR = '[User] GET ALL USERS ERROR',
9
+
10
+  // action: search a user
11
+  SEARCH_A_USER = '[User] SEARCH A USER',
12
+  SEARCH_A_USER_SUCCESS = '[User] SEARCH A USER SUCCESS',
13
+  SEARCH_A_USER_ERROR = '[User] SEARCH A USER ERROR',
14
+
15
+
16
+  // action of button: create a user form
17
+  CREATE_FORM_ADD_USER = '[User] USER FORM ADD',
18
+  CREATE_FORM_ADD_USER_SUCCESS = '[User] USER FORM ADD SUCCESS',
19
+  CREATE_FORM_ADD_USER_ERROR = '[User] USER FORM ADD ERROR',
20
+
21
+  // action of saving user data in the form
22
+  SAVE_USERFORM_ADD = '[User] SAVE USER',
23
+  SAVE_USERFORM_ADD_SUCCESS = '[User] SAVE USER SUCCESS',
24
+  SAVE_USERFORM_ADD_ERROR = '[User] SAVE USER ERROR',
25
+
26
+  // action: create form to edit a user
27
+  CREATE_FORM_USER_EDIT = '[User] USER FORM EDIT',
28
+  CREATE_FORM_USER_EDIT_SUCCESS = '[User] USER FORM EDIT SUCCESS',
29
+  CREATE_FORM_USER_EDIT_ERROR = '[User] USER FORM EDIT ERROR',
30
+
31
+  // action of updating user from user form
32
+  UPDATE_USER_FORM = '[User] USER FORM UPDATE',
33
+  UPDATE_USER_FORM_SUCCESS = '[User] USER FORM UPDATE SUCCESS',
34
+  UPDATE_USER_FORM_ERROR = '[User] USER FORM UPDATE ERROR',
35
+
36
+
37
+  // action: delete a user
38
+  DELETE_A_USER = '[User] DELETE A USER',
39
+  DELETE_A_USER_SUCCESS = '[User] DELETE A USER SUCCESS',
40
+  DELETE_A_USER_ERROR = '[User] DELETE A USER ERROR',
41
+
42
+  //action : load user's projects
43
+
44
+  GET_USER_S_PROJECTS = 'GET USER\'S PROJECTS',
45
+  GET_USER_S_PROJECTS_SUCCESS = 'GET USER\'S PROJECTS SUCCESS',
46
+  GET_USER_S_PROJECTS_ERROR = 'GET USER\'S PROJECTS ERROR',
47
+
48
+  //action:navigate to another component
49
+  NAVIGATE_TO_USER_S_PROJECTS_COMPONENT_SUCCESS = 'NAVIGATE TO USER\'S PROJECTS COMPONENT SUCCESS'
50
+}

+ 3
- 2
src/app/ngrx/users/user.state.ts Переглянути файл

@@ -1,10 +1,11 @@
1
+import { UserActionUnion } from './users.actions';
1 2
 import { User } from "src/app/shared/models/user.model";
2 3
 import { MsgState } from "../msg.state";
3 4
 
4 5
 //create a state
5 6
 export class UserState {
6 7
   currentUser!: User | null;
7
-  usersList!: User[];
8
+  usersList!: any;
8 9
   msgState!: MsgState;
9
-  userServerErrorMsg!: string;
10
+  serverMsgError!: string
10 11
 }

+ 55
- 69
src/app/ngrx/users/users.actions.ts Переглянути файл

@@ -1,172 +1,154 @@
1 1
 import { Action } from '@ngrx/store';
2 2
 import { User } from 'src/app/shared/models/user.model';
3
+import { UserActionTypes } from './user.action.types';
3 4
 
4
-/**type of actions*/
5
-
6
-export enum UserActionType {
7
-
8
-  // action: get all users
9
-  GET_ALL_USERS = '[User] GET ALL USERS',
10
-  GET_ALL_USERS_SUCCESS = '[User] GET-ALL USERS SUCCESS',
11
-  GET_ALL_USERS_ERROR = '[User] GET-ALL USERS ERROR',
12
-
13
-  // action: search a user
14
-  SEARCH_A_USER = '[User] SEARCH A USER',
15
-  SEARCH_A_USER_SUCCESS = '[User] SEARCH A USER SUCCESS',
16
-  SEARCH_A_USER_ERROR = '[User] SEARCH A USER ERROR',
17
-
18
-
19
-  // action of button: create a user form
20
-  CREATE_FORM_ADD_USER = '[User] USER FORM ADD',
21
-  CREATE_FORM_ADD_USER_SUCCESS = '[User] USER FORM ADD SUCCESS',
22
-  CREATE_FORM_ADD_USER_ERROR = '[User] USER FORM ADD ERROR',
23
-
24
-  // action of saving user data in the form
25
-  SAVE_USERFORM_ADD = '[User] SAVE USER',
26
-  SAVE_USERFORM_ADD_SUCCESS = '[User] SAVE USER SUCCESS',
27
-  SAVE_USERFORM_ADD_ERROR = '[User] SAVE USER ERROR',
28
-
29
-  // action: create form to edit a user
30
-  CREATE_FORM_USER_EDIT = '[User] USER FORM EDIT',
31
-  CREATE_FORM_USER_EDIT_SUCCESS = '[User] USER FORM EDIT SUCCESS',
32
-  CREATE_FORM_USER_EDIT_ERROR = '[User] USER FORM EDIT ERROR',
33
-
34
-  // action of updating user from user form
35
-  UPDATE_USER_FORM = '[User] USER FORM UPDATE',
36
-  UPDATE_USER_FORM_SUCCESS = '[User] USER FORM UPDATE SUCCESS',
37
-  UPDATE_USER_FORM_ERROR = '[User] USER FORM UPDATE ERROR',
38
-
39
-
40
-  // action: delete a user
41
-  DELETE_A_USER = '[User] DELETE A USER',
42
-  DELETE_A_USER_SUCCESS = '[User] DELETE A USER SUCCESS',
43
-  DELETE_A_USER_ERROR = '[User] DELETE A USER ERROR',
44
-}
45 5
 
46 6
 /**create actions related to a user*/
47 7
 
48 8
 //get all users actions
49 9
 
50 10
 export class GetAllUsersAction implements Action {
51
-  type: UserActionType = UserActionType.GET_ALL_USERS;
11
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS;
52 12
 
53 13
   constructor(public payload: any) {}
54 14
 }
55 15
 
56 16
 export class GetAllUsersActionSuccess implements Action {
57
-  type: UserActionType = UserActionType.GET_ALL_USERS_SUCCESS;
17
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS_SUCCESS;
58 18
   constructor(public payload: User[]) {}
59 19
 }
60 20
 
61 21
 export class GetAllUsersActionError implements Action {
62
-  type: UserActionType = UserActionType.GET_ALL_USERS_ERROR;
22
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS_ERROR;
63 23
   constructor(public payload: string) {}
64 24
 }
65 25
 
66 26
  // Actios of searching a user
67 27
 
68 28
 export class SearchUsersAction implements Action {
69
-  type: UserActionType = UserActionType.SEARCH_A_USER;
29
+  type: UserActionTypes = UserActionTypes.SEARCH_A_USER;
70 30
 
71 31
   constructor(public payload: any) {}
72 32
 }
73 33
 
74 34
 export class SearchUserActionSuccess implements Action {
75
-  type: UserActionType = UserActionType.SEARCH_A_USER_SUCCESS;
35
+  type: UserActionTypes = UserActionTypes.SEARCH_A_USER_SUCCESS;
76 36
   constructor(public payload: User[]) {}
77 37
 }
78 38
 
79 39
 export class SearchUserActionError implements Action {
80
-  type: UserActionType = UserActionType.SEARCH_A_USER_ERROR;
40
+  type: UserActionTypes = UserActionTypes.SEARCH_A_USER_ERROR;
81 41
   constructor(public payload: string) {}
82 42
 }
83 43
 
84 44
 // Actios of creating a user form to add user
85 45
 
86 46
 export class CreateFormUserAddAction implements Action {
87
-  type: UserActionType = UserActionType.CREATE_FORM_ADD_USER;
47
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER;
88 48
   constructor(public payload: any) {}
89 49
 }
90 50
 
91 51
 export class CreateFormUserAddActionSuccess implements Action {
92
-  type: UserActionType = UserActionType.CREATE_FORM_ADD_USER_SUCCESS;
52
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_SUCCESS;
93 53
   constructor(public payload: any) {}
94 54
 }
95 55
 
96 56
 export class CreateFormUserAddActionError implements Action {
97
-  type: UserActionType = UserActionType.CREATE_FORM_ADD_USER_ERROR;
57
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_ERROR;
98 58
   constructor(public payload: string) {}
99 59
 }
100 60
 
101 61
 //actions of saving a user form data
102
-export class SaveUserFormAction implements Action{
103
-  type: UserActionType = UserActionType.SAVE_USERFORM_ADD;
62
+export class SaveUserFormAddAction implements Action{
63
+  type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD;
104 64
   constructor(public payload: User){}
105 65
 }
106 66
 
107
-export class SaveUserFormActionSuccess implements Action{
108
-  type: UserActionType = UserActionType.SAVE_USERFORM_ADD_SUCCESS;
67
+export class SaveUserFormAddActionSuccess implements Action{
68
+  type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD_SUCCESS;
109 69
   constructor(public payload: User){}
110 70
 }
111 71
 
112
-export class SaveUserFormActionError implements Action{
113
-  type: UserActionType = UserActionType.SAVE_USERFORM_ADD_ERROR;
72
+export class SaveUserFormAddActionError implements Action{
73
+  type: UserActionTypes = UserActionTypes.SAVE_USERFORM_ADD_ERROR;
114 74
   constructor(public payload: string){}
115 75
 }
116 76
 
117 77
 // Actions of creating a user form to edit user
118 78
 
119 79
 export class CreareFormUserEditAction implements Action {
120
-  type: UserActionType = UserActionType.CREATE_FORM_USER_EDIT;
80
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT;
121 81
 
122 82
   constructor(public payload: User) {}
123 83
 }
124 84
 
125 85
 export class CreareFormUserEditActionSuccess implements Action {
126
-  type: UserActionType = UserActionType.CREATE_FORM_USER_EDIT_SUCCESS;
86
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT_SUCCESS;
127 87
   constructor(public payload: User) {}
128 88
 }
129 89
 
130 90
 export class CreareFormUserEditActionActionError implements Action {
131
-  type: UserActionType = UserActionType.CREATE_FORM_USER_EDIT_ERROR;
91
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_USER_EDIT_ERROR;
132 92
   constructor(public payload: string) {}
133 93
 }
134 94
 
135 95
 // action of updating user from user data form
136 96
 
137 97
 export class UpdateUserFormAction implements Action{
138
-  type: UserActionType = UserActionType.UPDATE_USER_FORM;
98
+  type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM;
139 99
   constructor(public payload: User){}
140 100
 }
141 101
 
142 102
 export class UpdateUserFormActionSuccess implements Action{
143
-  type: UserActionType = UserActionType.UPDATE_USER_FORM_SUCCESS;
103
+  type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM_SUCCESS;
144 104
   constructor(public payload: User){}
145 105
 }
146 106
 
147 107
 export class UpdateUserFormActionError implements Action{
148 108
 
149
-  type: UserActionType = UserActionType.UPDATE_USER_FORM_ERROR;
109
+  type: UserActionTypes = UserActionTypes.UPDATE_USER_FORM_ERROR;
150 110
   constructor(public payload: string){}
151 111
 }
152 112
 
153 113
 // Actions of deleting a user
154 114
 export class DeleteUsersAction implements Action {
155
-  type: UserActionType = UserActionType.DELETE_A_USER;
115
+  type: UserActionTypes = UserActionTypes.DELETE_A_USER;
156 116
 
157 117
   constructor(public payload: User) {}
158 118
 }
159 119
 
160 120
 export class DeleteUserActionSuccess implements Action {
161
-  type: UserActionType = UserActionType.DELETE_A_USER_SUCCESS;
121
+  type: UserActionTypes = UserActionTypes.DELETE_A_USER_SUCCESS;
162 122
   constructor(public payload: User) {}
163 123
 }
164 124
 
165 125
 export class DeleteUserActionError implements Action {
166
-  type: UserActionType = UserActionType.DELETE_A_USER_ERROR;
126
+  type: UserActionTypes = UserActionTypes.DELETE_A_USER_ERROR;
167 127
   constructor(public payload: string) {}
168 128
 }
169 129
 
130
+//Action of loading user's projects
131
+export class GetUser_S_Projects implements Action{
132
+  type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS;
133
+  constructor(public payload: any){}
134
+}
135
+
136
+export class GetUser_s_ProjectsSuccess implements Action{
137
+  type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS_SUCCESS;
138
+  constructor(public payload: any){}
139
+}
140
+
141
+export class GetUser_s_ProjectsError implements Action{
142
+  type: UserActionTypes = UserActionTypes.GET_USER_S_PROJECTS_ERROR;
143
+  constructor(public payload: string){}
144
+}
145
+
146
+//action of navigating to another component
147
+export class NavigateActionSuccess implements Action{
148
+  type: UserActionTypes = UserActionTypes.NAVIGATE_TO_USER_S_PROJECTS_COMPONENT_SUCCESS
149
+  constructor(public payload: any){}
150
+}
151
+
170 152
 export type UserActionUnion =
171 153
   | GetAllUsersAction
172 154
   | GetAllUsersActionSuccess
@@ -177,9 +159,9 @@ export type UserActionUnion =
177 159
   | CreateFormUserAddAction
178 160
   | CreateFormUserAddActionSuccess
179 161
   | CreateFormUserAddActionError
180
-  | SaveUserFormAction
181
-  | SaveUserFormActionSuccess
182
-  | SaveUserFormActionError
162
+  | SaveUserFormAddAction
163
+  | SaveUserFormAddActionSuccess
164
+  | SaveUserFormAddActionError
183 165
   | CreareFormUserEditAction
184 166
   | CreareFormUserEditActionSuccess
185 167
   | CreareFormUserEditActionActionError
@@ -188,4 +170,8 @@ export type UserActionUnion =
188 170
   | UpdateUserFormActionError
189 171
   | DeleteUsersAction
190 172
   | DeleteUserActionSuccess
191
-  | DeleteUserActionError;
173
+  | DeleteUserActionError
174
+  | GetUser_S_Projects
175
+  | GetUser_s_ProjectsSuccess
176
+  | GetUser_s_ProjectsError
177
+  | NavigateActionSuccess;

+ 106
- 79
src/app/ngrx/users/users.effects.ts Переглянути файл

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

+ 78
- 43
src/app/ngrx/users/users.reducer.ts Переглянути файл

@@ -1,17 +1,19 @@
1 1
 import { Action } from '@ngrx/store';
2 2
 import { User } from 'src/app/shared/models/user.model';
3 3
 import { MsgState } from '../msg.state';
4
+import { UserActionTypes } from './user.action.types';
4 5
 import { UserState } from './user.state';
5
-import { UserActionUnion, UserActionType } from './users.actions';
6
+import { UserActionUnion } from './users.actions';
6 7
 
7 8
 /** create reducer,
9
+ *
8 10
  * a reducer need a initial state and an action to perform*/
9 11
 
10 12
 const initialUserState: UserState = {
11 13
   usersList: [],
12 14
   currentUser: null,
13 15
   msgState: MsgState.INIT_STATE,
14
-  userServerErrorMsg: 'No error message',
16
+  serverMsgError: 'No error message'
15 17
 };
16 18
 
17 19
 export function userReducer(
@@ -19,119 +21,123 @@ export function userReducer(
19 21
   action: Action
20 22
 ): UserState {
21 23
 
22
-  switch (action.type) {
23 24
 
25
+  switch (action.type) {
24 26
     // get all users actions
25
-    case UserActionType.GET_ALL_USERS:
27
+    case UserActionTypes.GET_ALL_USERS:
26 28
       return { ...state, msgState: MsgState.LOADING };
27 29
 
28
-    case UserActionType.GET_ALL_USERS_SUCCESS:
30
+    case UserActionTypes.GET_ALL_USERS_SUCCESS:
29 31
       return {
30 32
         ...state,
31 33
         msgState: MsgState.LOADED,
32 34
         usersList: (<UserActionUnion>action).payload,
33 35
       };
34 36
 
35
-    case UserActionType.GET_ALL_USERS_ERROR:
37
+    case UserActionTypes.GET_ALL_USERS_ERROR:
36 38
       return {
37 39
         ...state,
38 40
         msgState: MsgState.ERR,
39
-        userServerErrorMsg: (<UserActionUnion>action).payload,
41
+        serverMsgError: (<UserActionUnion>action).payload
40 42
       };
41 43
 
42 44
     // search a user actions
43
-    case UserActionType.SEARCH_A_USER:
44
-      return { ...state, msgState: MsgState.LOADING };
45
+    case UserActionTypes.SEARCH_A_USER:
46
+      return {
47
+        ...state,
48
+        msgState: MsgState.LOADING
49
+      };
45 50
 
46
-    case UserActionType.SEARCH_A_USER_SUCCESS:
51
+    case UserActionTypes.SEARCH_A_USER_SUCCESS:
47 52
       return {
48 53
         ...state,
49 54
         msgState: MsgState.LOADED,
50
-        usersList: (<UserActionUnion>action).payload,
55
+        usersList: (<UserActionUnion>action).payload
51 56
       };
52 57
 
53
-    case UserActionType.SEARCH_A_USER_ERROR:
58
+    case UserActionTypes.SEARCH_A_USER_ERROR:
54 59
       return {
55 60
         ...state,
56 61
         msgState: MsgState.ERR,
57
-        userServerErrorMsg: (<UserActionUnion>action).payload,
62
+        serverMsgError: (<UserActionUnion>action).payload
58 63
       };
59 64
 
60 65
     // create a user form actions
61
-    case UserActionType.CREATE_FORM_ADD_USER:
66
+    case UserActionTypes.CREATE_FORM_ADD_USER:
62 67
       return {
63 68
         ...state,
64
-        msgState: MsgState.FORM_LOADING,
69
+        msgState: MsgState.FORM_LOADING
65 70
       };
66 71
 
67
-    case UserActionType.CREATE_FORM_ADD_USER_SUCCESS:
72
+    case UserActionTypes.CREATE_FORM_ADD_USER_SUCCESS:
68 73
       return {
69 74
         ...state,
70
-        msgState: MsgState.FORM_LOADED,
75
+        msgState: MsgState.FORM_LOADED
71 76
       };
72 77
 
73
-    case UserActionType.CREATE_FORM_ADD_USER_ERROR:
78
+    case UserActionTypes.CREATE_FORM_ADD_USER_ERROR:
74 79
       return {
75 80
         ...state,
76 81
         msgState: MsgState.FORM_LOAD_ERR,
77
-        userServerErrorMsg: (<UserActionUnion>action).payload,
82
+        serverMsgError: (<UserActionUnion>action).payload
78 83
       };
79 84
 
80 85
     // save a user (data of form) action
81
-    case UserActionType.SAVE_USERFORM_ADD:
86
+    case UserActionTypes.SAVE_USERFORM_ADD:
82 87
       return {
83 88
         ...state,
84
-        msgState: MsgState.DEFAULT_MSG,
89
+        msgState: MsgState.DEFAULT_MSG
85 90
       };
86
-    case UserActionType.SAVE_USERFORM_ADD_SUCCESS:
91
+
92
+    case UserActionTypes.SAVE_USERFORM_ADD_SUCCESS:
87 93
       let createdUser: User = (<UserActionUnion>action).payload;
88 94
       let usersListCopy1: User[] = [...state.usersList];
89 95
       usersListCopy1.push(createdUser);
90 96
 
91 97
       return {
92 98
         ...state,
93
-        msgState: MsgState.LOADED,
94
-        usersList: usersListCopy1,
99
+        msgState: MsgState.ADDED,
100
+        usersList: usersListCopy1
95 101
       };
96 102
 
97
-    case UserActionType.SAVE_USERFORM_ADD_ERROR:
103
+    case UserActionTypes.SAVE_USERFORM_ADD_ERROR:
98 104
       return {
99 105
         ...state,
100 106
         msgState: MsgState.ERR,
101
-        userServerErrorMsg: (<UserActionUnion>action).payload,
107
+        serverMsgError: (<UserActionUnion>action).payload
102 108
       };
103 109
 
104 110
     // create a edit user form actions
105
-    case UserActionType.CREATE_FORM_USER_EDIT:
111
+    case UserActionTypes.CREATE_FORM_USER_EDIT:
106 112
       return {
107 113
         ...state,
108 114
         msgState: MsgState.FORM_LOADING,
109 115
       };
110 116
 
111
-    case UserActionType.CREATE_FORM_USER_EDIT_SUCCESS:
117
+    case UserActionTypes.CREATE_FORM_USER_EDIT_SUCCESS:
112 118
       let modifiedUser: User = (<UserActionUnion>action).payload;
113 119
       return {
114 120
         ...state,
115 121
         msgState: MsgState.FORM_LOADED,
116
-        currentUser: modifiedUser,
122
+        currentUser: modifiedUser
117 123
       };
118 124
 
119
-    case UserActionType.CREATE_FORM_USER_EDIT_ERROR:
125
+    case UserActionTypes.CREATE_FORM_USER_EDIT_ERROR:
120 126
       return {
121 127
         ...state,
122 128
         msgState: MsgState.ERR,
123
-        userServerErrorMsg: (<UserActionUnion>action).payload,
129
+        serverMsgError: (<UserActionUnion>action).payload
124 130
       };
125 131
 
126 132
     // update user with user form data
127 133
 
128
-    case UserActionType.UPDATE_USER_FORM:
134
+    case UserActionTypes.UPDATE_USER_FORM:
129 135
       return {
130 136
         ...state,
131
-        msgState: MsgState.DEFAULT_MSG,
137
+        msgState: MsgState.DEFAULT_MSG
132 138
       };
133 139
 
134
-    case UserActionType.UPDATE_USER_FORM_SUCCESS:
140
+    case UserActionTypes.UPDATE_USER_FORM_SUCCESS:
135 141
       let updatedUser: User = (<UserActionUnion>action).payload;
136 142
       let usersListCopy2: User[] = [...state.usersList];
137 143
       usersListCopy2 = usersListCopy2.map((user) =>
@@ -141,24 +147,24 @@ export function userReducer(
141 147
       return {
142 148
         ...state,
143 149
         usersList: usersListCopy2,
144
-        msgState: MsgState.UPDATED,
150
+        msgState: MsgState.UPDATED
145 151
       };
146 152
 
147
-    case UserActionType.UPDATE_USER_FORM_ERROR:
153
+    case UserActionTypes.UPDATE_USER_FORM_ERROR:
148 154
       return {
149 155
         ...state,
150 156
         msgState: MsgState.ERR,
151
-        userServerErrorMsg: (<UserActionUnion>action).payload,
157
+        serverMsgError: (<UserActionUnion>action).payload
152 158
       };
153 159
 
154 160
     // delete a user actions
155
-    case UserActionType.DELETE_A_USER:
161
+    case UserActionTypes.DELETE_A_USER:
156 162
       return {
157 163
         ...state,
158
-        msgState: MsgState.LOADING,
164
+        msgState: MsgState.LOADING
159 165
       };
160 166
 
161
-    case UserActionType.DELETE_A_USER_SUCCESS:
167
+    case UserActionTypes.DELETE_A_USER_SUCCESS:
162 168
       let deletedUser: User = (<UserActionUnion>action).payload;
163 169
       let deletedUserIndex = state.usersList.indexOf(deletedUser);
164 170
       let usersListCopy3: User[] = [...state.usersList];
@@ -166,16 +172,45 @@ export function userReducer(
166 172
       return {
167 173
         ...state,
168 174
         msgState: MsgState.LOADED,
169
-        usersList: usersListCopy3,
175
+        usersList: usersListCopy3
170 176
       };
171 177
 
172
-    case UserActionType.DELETE_A_USER_ERROR:
178
+    case UserActionTypes.DELETE_A_USER_ERROR:
173 179
       return {
174 180
         ...state,
175 181
         msgState: MsgState.ERR,
176
-        userServerErrorMsg: (<UserActionUnion>action).payload,
182
+        serverMsgError: (<UserActionUnion>action).payload
177 183
       };
178 184
 
185
+      //load user's project actions
186
+
187
+    case UserActionTypes.GET_USER_S_PROJECTS:
188
+      return{
189
+        ... state,
190
+        msgState: MsgState.LOADING
191
+      };
192
+
193
+    case UserActionTypes.GET_USER_S_PROJECTS_SUCCESS:
194
+      return{
195
+        ...state,
196
+        msgState: MsgState.LOADED,
197
+        usersList: (<UserActionUnion> action).payload
198
+      };
199
+
200
+      case UserActionTypes.GET_USER_S_PROJECTS_ERROR:
201
+        return{
202
+          ...state,
203
+          msgState: MsgState.ERR,
204
+          serverMsgError: (<UserActionUnion> action).payload
205
+        };
206
+
207
+    case UserActionTypes.NAVIGATE_TO_USER_S_PROJECTS_COMPONENT_SUCCESS:
208
+      return{
209
+        ...state,
210
+        msgState: MsgState.DEFAULT_MSG
211
+      };
212
+
213
+
179 214
     default:
180 215
       return { ...state };
181 216
   }

+ 3
- 3
src/app/pages/accueil/accueil-routing.module.ts Переглянути файл

@@ -3,9 +3,9 @@ import { RouterModule, Routes } from '@angular/router';
3 3
 import { AccueilComponent } from './accueil/accueil.component';
4 4
 
5 5
 const routes: Routes = [
6
-  {
7
-    path:'', component: AccueilComponent
8
-  }
6
+  // {
7
+  //   path:'', component: AccueilComponent
8
+  // }
9 9
 ];
10 10
 
11 11
 @NgModule({

+ 0
- 20
src/app/pages/base-nav-bar/base-nav-bar.component.html Переглянути файл

@@ -1,20 +0,0 @@
1
-<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
2
-
3
-  <a routerLink="/"
4
-    ><img src="../assets/images/logo-natan.png" width="100"
5
-  /></a>
6
-  <ul class="navbar-nav">
7
-
8
-    <li class="nav-item">
9
-      <a class="nav-link" routerLink="/users-management"><h6>users</h6></a>
10
-    </li>
11
-
12
-    <li class="nav-item">
13
-      <a class="nav-link" routerLink="/project-nav-bar"><h6>projects</h6></a>
14
-    </li>
15
-
16
-    <li class="nav-item">
17
-      <a class="nav-link" routerLink="/company-nav-bar"><h6>companies</h6></a>
18
-    </li>
19
-  </ul>
20
-</nav>

+ 0
- 15
src/app/pages/base-nav-bar/base-nav-bar.component.ts Переглянути файл

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

+ 17
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.css Переглянути файл

@@ -0,0 +1,17 @@
1
+.sidenav-container {
2
+  height: 100%;
3
+}
4
+
5
+.sidenav {
6
+  width: 200px;
7
+}
8
+
9
+.sidenav .mat-toolbar {
10
+  background: inherit;
11
+}
12
+
13
+.mat-toolbar.mat-primary {
14
+  position: sticky;
15
+  top: 0;
16
+  z-index: 1;
17
+}

+ 32
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.html Переглянути файл

@@ -0,0 +1,32 @@
1
+<mat-sidenav-container class="sidenav-container">
2
+  <mat-sidenav #drawer class="sidenav" fixedInViewport
3
+      [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
4
+      [mode]="(isHandset$ | async) ? 'over' : 'side'"
5
+      [opened]="(isHandset$ | async) === false">
6
+    <mat-toolbar>
7
+      <img src="../assets/images/logo-natan.png" width="100"/>
8
+    </mat-toolbar>
9
+
10
+      <mat-nav-list>
11
+        <a mat-list-item routerLink="/users-management"> User Manager</a>
12
+        <a mat-list-item routerLink="/projects-management">project Manager</a>
13
+        <a mat-list-item routerLink="/companies-management">company Manager</a>
14
+      </mat-nav-list>
15
+  </mat-sidenav>
16
+
17
+  <mat-sidenav-content>
18
+    <mat-toolbar>
19
+      <button
20
+        type="button"
21
+        aria-label="Toggle sidenav"
22
+        mat-icon-button
23
+        (click)="drawer.toggle()"
24
+        *ngIf="isHandset$ | async">
25
+        <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
26
+      </button>
27
+      <span>Users, Projects and Companies Management</span>
28
+    </mat-toolbar>
29
+    <!-- Add Content Here -->
30
+    <router-outlet></router-outlet>
31
+  </mat-sidenav-content>
32
+</mat-sidenav-container>

+ 40
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.spec.ts Переглянути файл

@@ -0,0 +1,40 @@
1
+import { LayoutModule } from '@angular/cdk/layout';
2
+import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
3
+import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4
+import { MatButtonModule } from '@angular/material/button';
5
+import { MatIconModule } from '@angular/material/icon';
6
+import { MatListModule } from '@angular/material/list';
7
+import { MatSidenavModule } from '@angular/material/sidenav';
8
+import { MatToolbarModule } from '@angular/material/toolbar';
9
+
10
+import { BaseNavMenuComponent } from './base-nav-menu.component';
11
+
12
+describe('BaseNavMenuComponent', () => {
13
+  let component: BaseNavMenuComponent;
14
+  let fixture: ComponentFixture<BaseNavMenuComponent>;
15
+
16
+  beforeEach(waitForAsync(() => {
17
+    TestBed.configureTestingModule({
18
+      declarations: [BaseNavMenuComponent],
19
+      imports: [
20
+        NoopAnimationsModule,
21
+        LayoutModule,
22
+        MatButtonModule,
23
+        MatIconModule,
24
+        MatListModule,
25
+        MatSidenavModule,
26
+        MatToolbarModule,
27
+      ]
28
+    }).compileComponents();
29
+  }));
30
+
31
+  beforeEach(() => {
32
+    fixture = TestBed.createComponent(BaseNavMenuComponent);
33
+    component = fixture.componentInstance;
34
+    fixture.detectChanges();
35
+  });
36
+
37
+  it('should compile', () => {
38
+    expect(component).toBeTruthy();
39
+  });
40
+});

+ 36
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.ts Переглянути файл

@@ -0,0 +1,36 @@
1
+import { Router } from '@angular/router';
2
+import { Component } from '@angular/core';
3
+import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
4
+import { Observable } from 'rxjs';
5
+import { map, shareReplay } from 'rxjs/operators';
6
+import { GetAllUsersAction } from 'src/app/ngrx/users/users.actions';
7
+import { Store } from '@ngrx/store';
8
+import { UserState } from 'src/app/ngrx/users/user.state';
9
+
10
+@Component({
11
+  selector: 'app-base-nav-menu',
12
+  templateUrl: './base-nav-menu.component.html',
13
+  styleUrls: ['./base-nav-menu.component.css'],
14
+})
15
+export class BaseNavMenuComponent {
16
+  isHandset$: Observable<boolean> = this.breakpointObserver
17
+    .observe(Breakpoints.Handset)
18
+    .pipe(
19
+      map((result) => result.matches),
20
+      shareReplay()
21
+    );
22
+
23
+  constructor(
24
+    private breakpointObserver: BreakpointObserver,
25
+    private router: Router,
26
+    private store: Store<{ userReducerKey: UserState }>,
27
+  ) {}
28
+
29
+  onUserCreate(): void {
30
+    this.router.navigateByUrl('/user-create');
31
+  }
32
+
33
+  onUsersGetAll(){
34
+    this.store.dispatch(new GetAllUsersAction({}));
35
+  }
36
+}

src/app/pages/companies-manager/companies-create/companies-create.component.css → src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.css Переглянути файл


src/app/pages/companies-manager/companies-create/companies-create.component.html → src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.html Переглянути файл


src/app/pages/companies-manager/companies-create/companies-create.component.spec.ts → src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.spec.ts Переглянути файл


src/app/pages/companies-manager/companies-create/companies-create.component.ts → src/app/pages/companies-manager/companies-management/companies-create/companies-create.component.ts Переглянути файл


src/app/pages/base-nav-bar/base-nav-bar.component.css → src/app/pages/companies-manager/companies-management/companies-management.component.css Переглянути файл


+ 1
- 0
src/app/pages/companies-manager/companies-management/companies-management.component.html Переглянути файл

@@ -0,0 +1 @@
1
+<app-company-nav-bar></app-company-nav-bar>

+ 25
- 0
src/app/pages/companies-manager/companies-management/companies-management.component.spec.ts Переглянути файл

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

+ 15
- 0
src/app/pages/companies-manager/companies-management/companies-management.component.ts Переглянути файл

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

src/app/pages/companies-manager/company-nav-bar/company-nav-bar.component.css → src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.css Переглянути файл


src/app/pages/companies-manager/company-nav-bar/company-nav-bar.component.html → src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.html Переглянути файл

@@ -5,7 +5,7 @@
5 5
         pButton
6 6
         type="button"
7 7
         label="create company"
8
-        class="p-button-outlined"
8
+        class="btn btn-outline-primary"
9 9
         (click)="onCompanyCreate()"
10 10
       ></button>
11 11
       &nbsp;
@@ -13,7 +13,7 @@
13 13
         pButton
14 14
         type="button"
15 15
         label="all companies"
16
-        class="p-button-outlined"
16
+        class="btn btn-outline-primary"
17 17
         (click)="onCompaniesGetAll()"
18 18
 
19 19
       ></button>
@@ -22,7 +22,7 @@
22 22
         pButton
23 23
         type="button"
24 24
         label="company's projects"
25
-        class="p-button-outlined"
25
+        class="btn btn-outline-primary"
26 26
         (click)="onProjectsOfCampany()"
27 27
       ></button>
28 28
     </div>

src/app/pages/companies-manager/company-nav-bar/company-nav-bar.component.spec.ts → src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.spec.ts Переглянути файл


src/app/pages/companies-manager/company-nav-bar/company-nav-bar.component.ts → src/app/pages/companies-manager/companies-management/company-nav-bar/company-nav-bar.component.ts Переглянути файл


+ 4
- 3
src/app/pages/companies-manager/companies-manager-routing.module.ts Переглянути файл

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

+ 5
- 3
src/app/pages/companies-manager/companies-manager.module.ts Переглянути файл

@@ -3,14 +3,16 @@ import { NgModule } from '@angular/core';
3 3
 import { CommonModule } from '@angular/common';
4 4
 
5 5
 import { CompaniesManagerRoutingModule } from './companies-manager-routing.module';
6
-import { CompaniesCreateComponent } from './companies-create/companies-create.component';
7
-import { CompanyNavBarComponent } from './company-nav-bar/company-nav-bar.component';
6
+import { CompaniesCreateComponent } from './companies-management/companies-create/companies-create.component';
7
+import { CompanyNavBarComponent } from './companies-management/company-nav-bar/company-nav-bar.component';
8
+import { CompaniesManagementComponent } from './companies-management/companies-management.component';
8 9
 
9 10
 
10 11
 @NgModule({
11 12
   declarations: [
12 13
     CompaniesCreateComponent,
13
-    CompanyNavBarComponent
14
+    CompanyNavBarComponent,
15
+    CompaniesManagementComponent
14 16
   ],
15 17
   imports: [
16 18
     CommonModule,

+ 0
- 15
src/app/pages/projects-manager/project-create/project-create.component.ts Переглянути файл

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

+ 0
- 15
src/app/pages/projects-manager/project-nav-bar/project-nav-bar.component.ts Переглянути файл

@@ -1,15 +0,0 @@
1
-import { Component } from '@angular/core';
2
-
3
-@Component({
4
-  selector: 'app-project-nav-bar',
5
-  templateUrl: './project-nav-bar.component.html',
6
-  styleUrls: ['./project-nav-bar.component.css']
7
-})
8
-export class ProjectNavBarComponent {
9
-
10
-  onProjectCreate(){}
11
-  onProjectsGetAll(){}
12
-  onProjectsVsUsersGet(){}
13
-  onProjectCompanyAssociated(){}
14
-
15
-}

src/app/pages/projects-manager/project-create/project-create.component.css → src/app/pages/projects-manager/projects-management/project-create/project-create.component.css Переглянути файл


src/app/pages/projects-manager/project-create/project-create.component.html → src/app/pages/projects-manager/projects-management/project-create/project-create.component.html Переглянути файл

@@ -1 +1,2 @@
1 1
 <p>project-create works!</p>
2
+

src/app/pages/projects-manager/project-create/project-create.component.spec.ts → src/app/pages/projects-manager/projects-management/project-create/project-create.component.spec.ts Переглянути файл


+ 30
- 0
src/app/pages/projects-manager/projects-management/project-create/project-create.component.ts Переглянути файл

@@ -0,0 +1,30 @@
1
+
2
+import { UserState } from 'src/app/ngrx/users/user.state';
3
+import { GetAllUsersAction } from './../../../../ngrx/users/users.actions';
4
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
5
+import { CreateProjectFormAddAction } from './../../../../ngrx/projects/projects.actions';
6
+import { ProjectState } from './../../../../ngrx/projects/project.state';
7
+import { Component, OnInit } from '@angular/core';
8
+import { Store } from '@ngrx/store';
9
+import { DatePipe } from '@angular/common';
10
+
11
+@Component({
12
+  selector: 'app-project-create',
13
+  templateUrl: './project-create.component.html',
14
+  styleUrls: ['./project-create.component.css'],
15
+})
16
+export class ProjectCreateComponent implements OnInit {
17
+
18
+  projectFormGroup!: FormGroup;
19
+
20
+  constructor(
21
+  ) {}
22
+
23
+  ngOnInit(): void {
24
+
25
+  }
26
+
27
+  onProjectCreate(){}
28
+  onNewProject(){}
29
+  tryEgain(){}
30
+}

src/app/pages/projects-manager/project-nav-bar/project-nav-bar.component.css → src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.css Переглянути файл


src/app/pages/projects-manager/project-nav-bar/project-nav-bar.component.html → src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.html Переглянути файл

@@ -5,7 +5,7 @@
5 5
         pButton
6 6
         type="button"
7 7
         label="create project"
8
-        class="p-button-outlined"
8
+        class="btn btn-outline-primary"
9 9
         (click)="onProjectCreate()"
10 10
       ></button>
11 11
       &nbsp;
@@ -13,7 +13,7 @@
13 13
         pButton
14 14
         type="button"
15 15
         label="all projects"
16
-        class="p-button-outlined"
16
+        class="btn btn-outline-primary"
17 17
         (click)="onProjectsGetAll()"
18 18
       ></button>
19 19
       &nbsp;
@@ -21,7 +21,7 @@
21 21
         pButton
22 22
         type="button"
23 23
         label="project->user involved"
24
-        class="p-button-outlined"
24
+        class="btn btn-outline-primary"
25 25
         (click)="onProjectsVsUsersGet()"
26 26
       ></button>
27 27
       &nbsp;
@@ -29,7 +29,7 @@
29 29
         pButton
30 30
         type="button"
31 31
         label="project->company"
32
-        class="p-button-outlined"
32
+        class="btn btn-outline-primary"
33 33
         (click)="onProjectCompanyAssociated()"
34 34
       ></button>
35 35
     </div>

src/app/pages/projects-manager/project-nav-bar/project-nav-bar.component.spec.ts → src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.spec.ts Переглянути файл


+ 25
- 0
src/app/pages/projects-manager/projects-management/project-nav-bar/project-nav-bar.component.ts Переглянути файл

@@ -0,0 +1,25 @@
1
+import { Router } from '@angular/router';
2
+import {
3
+  GetAllProjectsAction
4
+} from './../../../../ngrx/projects/projects.actions';
5
+import { Component } from '@angular/core';
6
+import { Store } from '@ngrx/store';
7
+
8
+@Component({
9
+  selector: 'app-project-nav-bar',
10
+  templateUrl: './project-nav-bar.component.html',
11
+  styleUrls: ['./project-nav-bar.component.css'],
12
+})
13
+export class ProjectNavBarComponent {
14
+  constructor(private store: Store<any>, private router: Router) {}
15
+
16
+  onProjectCreate() {
17
+    this.router.navigateByUrl('/project-create');
18
+  }
19
+
20
+  onProjectsGetAll() {
21
+    this.store.dispatch(new GetAllProjectsAction({}));
22
+  }
23
+  onProjectsVsUsersGet() {}
24
+  onProjectCompanyAssociated() {}
25
+}

+ 0
- 0
src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.css Переглянути файл


+ 61
- 0
src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.html Переглянути файл

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

src/app/pages/base-nav-bar/base-nav-bar.component.spec.ts → src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.spec.ts Переглянути файл

@@ -1,20 +1,20 @@
1 1
 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 2
 
3
-import { BaseNavBarComponent } from './base-nav-bar.component';
3
+import { ProjectsListComponent } from './projects-list.component';
4 4
 
5
-describe('BaseNavBarComponent', () => {
6
-  let component: BaseNavBarComponent;
7
-  let fixture: ComponentFixture<BaseNavBarComponent>;
5
+describe('ProjectsListComponent', () => {
6
+  let component: ProjectsListComponent;
7
+  let fixture: ComponentFixture<ProjectsListComponent>;
8 8
 
9 9
   beforeEach(async () => {
10 10
     await TestBed.configureTestingModule({
11
-      declarations: [ BaseNavBarComponent ]
11
+      declarations: [ ProjectsListComponent ]
12 12
     })
13 13
     .compileComponents();
14 14
   });
15 15
 
16 16
   beforeEach(() => {
17
-    fixture = TestBed.createComponent(BaseNavBarComponent);
17
+    fixture = TestBed.createComponent(ProjectsListComponent);
18 18
     component = fixture.componentInstance;
19 19
     fixture.detectChanges();
20 20
   });

+ 18
- 0
src/app/pages/projects-manager/projects-management/projects-list/projects-list.component.ts Переглянути файл

@@ -0,0 +1,18 @@
1
+import { ProjectState } from './../../../../ngrx/projects/project.state';
2
+import { Component, Input, OnInit } from '@angular/core';
3
+
4
+@Component({
5
+  selector: 'app-projects-list',
6
+  templateUrl: './projects-list.component.html',
7
+  styleUrls: ['./projects-list.component.css']
8
+})
9
+export class ProjectsListComponent implements OnInit {
10
+
11
+  constructor() { }
12
+
13
+  @Input() inputProjectState!: ProjectState;
14
+
15
+  ngOnInit(): void {
16
+  }
17
+
18
+}

+ 0
- 0
src/app/pages/projects-manager/projects-management/projects-management.component.css Переглянути файл


+ 25
- 0
src/app/pages/projects-manager/projects-management/projects-management.component.html Переглянути файл

@@ -0,0 +1,25 @@
1
+<app-project-nav-bar></app-project-nav-bar>
2
+
3
+<div class="container">
4
+
5
+  <ng-container *ngIf="projectState$ | async as projectState "[ngSwitch]="projectState.msgState">
6
+
7
+    <ng-container *ngSwitchCase="msgState.INIT_STATE">
8
+      <div class="p-2">{{projectState.msgState}}</div>
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.LOADING">
12
+      <div class="p-2">{{projectState.msgState}}</div>
13
+    </ng-container>
14
+
15
+    <ng-container *ngSwitchCase="msgState.ERR">
16
+      <div class="p-2 text-danger"> {{projectState.msgState}} </div>
17
+    </ng-container>
18
+
19
+    <ng-container *ngSwitchCase="msgState.LOADED">
20
+      <app-projects-list [inputProjectState]="projectState"></app-projects-list>
21
+    </ng-container>
22
+
23
+  </ng-container>
24
+
25
+</div>

+ 25
- 0
src/app/pages/projects-manager/projects-management/projects-management.component.spec.ts Переглянути файл

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

+ 26
- 0
src/app/pages/projects-manager/projects-management/projects-management.component.ts Переглянути файл

@@ -0,0 +1,26 @@
1
+import { Observable } from 'rxjs';
2
+import { ProjectState } from './../../../ngrx/projects/project.state';
3
+import { Component, OnInit } from '@angular/core';
4
+import { Store } from '@ngrx/store';
5
+import { MsgState } from 'src/app/ngrx/msg.state';
6
+
7
+
8
+@Component({
9
+  selector: 'app-projects-management',
10
+  templateUrl: './projects-management.component.html',
11
+  styleUrls: ['./projects-management.component.css']
12
+})
13
+export class ProjectsManagementComponent implements OnInit {
14
+
15
+  constructor(private store: Store<{productReducerKey: ProjectState}>) { }
16
+
17
+  projectState$!:Observable<ProjectState>
18
+
19
+  readonly msgState = MsgState;
20
+
21
+  ngOnInit(): void {
22
+
23
+    this.projectState$= this.store.select("productReducerKey");
24
+  }
25
+
26
+}

+ 4
- 3
src/app/pages/projects-manager/projects-manager-routing.module.ts Переглянути файл

@@ -1,11 +1,12 @@
1
-import { ProjectNavBarComponent } from './project-nav-bar/project-nav-bar.component';
2
-import { ProjectCreateComponent } from './project-create/project-create.component';
1
+import { ProjectsManagementComponent } from './projects-management/projects-management.component';
2
+import { ProjectNavBarComponent } from './projects-management/project-nav-bar/project-nav-bar.component';
3
+import { ProjectCreateComponent } from './projects-management/project-create/project-create.component';
3 4
 import { NgModule } from '@angular/core';
4 5
 import { RouterModule, Routes } from '@angular/router';
5 6
 
6 7
 const routes: Routes = [
7 8
   {path:'project-create', component: ProjectCreateComponent},
8
-  {path:'project-nav-bar', component: ProjectNavBarComponent}
9
+  {path: 'projects-management', component:ProjectsManagementComponent}
9 10
 ];
10 11
 
11 12
 @NgModule({

+ 17
- 5
src/app/pages/projects-manager/projects-manager.module.ts Переглянути файл

@@ -1,21 +1,33 @@
1
+import { TableModule } from 'primeng/table';
1 2
 import { ButtonModule } from 'primeng/button';
2 3
 import { NgModule } from '@angular/core';
3
-import { CommonModule } from '@angular/common';
4
+import { CommonModule, DatePipe } from '@angular/common';
4 5
 
5 6
 import { ProjectsManagerRoutingModule } from './projects-manager-routing.module';
6
-import { ProjectCreateComponent } from './project-create/project-create.component';
7
-import { ProjectNavBarComponent } from './project-nav-bar/project-nav-bar.component';
7
+import { ProjectCreateComponent } from './projects-management/project-create/project-create.component';
8
+import { ProjectNavBarComponent } from './projects-management/project-nav-bar/project-nav-bar.component';
9
+import { ProjectsManagementComponent } from './projects-management/projects-management.component';
10
+import { ProjectsListComponent } from './projects-management/projects-list/projects-list.component';
11
+
12
+
8 13
 
9 14
 
10 15
 @NgModule({
11 16
   declarations: [
12 17
     ProjectCreateComponent,
13
-    ProjectNavBarComponent
18
+    ProjectNavBarComponent,
19
+    ProjectsManagementComponent,
20
+    ProjectsListComponent
21
+
14 22
   ],
15 23
   imports: [
16 24
     CommonModule,
17 25
     ProjectsManagerRoutingModule,
18
-    ButtonModule
26
+    ButtonModule,
27
+    TableModule
28
+  ],
29
+  providers:[
30
+    DatePipe
19 31
   ]
20 32
 })
21 33
 

+ 18
- 16
src/app/pages/users-manager/users-management/user-create/user-create.component.html Переглянути файл

@@ -1,31 +1,37 @@
1 1
 <div class="container">
2 2
 
3
-    <ng-container *ngIf="userState">
3
+    <ng-container *ngIf="userState as state" [ngSwitch]="state.msgState">
4 4
 
5
-      <ng-container *ngIf="userState.msgState == msgState.LOADED">
5
+      <ng-container *ngSwitchCase="msgState.DEFAULT_MSG">
6
+        {{state.msgState}}
7
+      </ng-container>
8
+
9
+      <ng-container *ngSwitchCase="msgState.ADDED">
6 10
         <div class="alert-success container p-3 m-3">
7
-          <span> {{msgState.ADDED}}</span> &nbsp;
11
+          <span> {{state.msgState}}</span> &nbsp;
8 12
           <button class="btn btn-success" (click)="onNewUser()"> create user</button>
9 13
         </div>
10 14
       </ng-container>
11 15
 
12
-      <ng-container *ngIf="userState.msgState == msgState.LOADING">
16
+      <ng-container *ngSwitchCase="msgState.ERR">
13 17
         <div class="alert-danger container pt-3 mt-3">
14
-          <span> {{msgState.ERR}}</span> &nbsp;
18
+          <span> {{state.msgState}}</span> &nbsp;
15 19
           <button class="btn btn-danger ml-3" (click)="tryEgain()"> try again</button>
16 20
         </div>
17 21
       </ng-container>
18 22
 
19
-      <ng-container *ngIf="userState.msgState==msgState.FORM_LOADED">
23
+
24
+
25
+      <ng-container *ngSwitchCase="msgState.FORM_LOADED">
20 26
 
21 27
         <div class="card mt-3">
22
-          <div class="card-header bg-light">Update user informations</div>
28
+          <div class="card-header bg-light">Input form of User information</div>
23 29
           <div class="card-body">
24 30
             <form [formGroup]="userFormGroup" (ngSubmit)="onUserSave(); userFormGroup.reset()">
25 31
 
26 32
               <div class="row">
27 33
 
28
-                <div class="col">
34
+                <div class="col card">
29 35
 
30 36
                   <div class="col-md-auto mb-3">
31 37
                     <label for="id">Firstname</label>
@@ -109,8 +115,8 @@
109 115
                   </div>
110 116
 
111 117
                 </div>
112
-
113
-                <div class="col">
118
+                &nbsp;
119
+                <div class="col card">
114 120
 
115 121
                   <div formGroupName="address">
116 122
                     <div class="col-md-auto mb-3">
@@ -245,13 +251,12 @@
245 251
                       </div>
246 252
                     </div>
247 253
                   </div>
248
-
249 254
                 </div>
250 255
 
251 256
               </div>
252 257
 
253
-              <div class="row">
254
-                <div class="text-center">
258
+
259
+              <div class="text-center col-md-auto mt-3">
255 260
                   <button
256 261
                     class="btn btn-outline-primary"
257 262
                     type="submit"
@@ -260,14 +265,11 @@
260 265
                     save</button
261 266
                   >&nbsp;
262 267
                   <button class="btn btn-outline-danger" type="reset">reset</button>
263
-                </div>
264 268
               </div>
265 269
 
266 270
             </form>
267 271
           </div>
268 272
         </div>
269
-
270
-
271 273
       </ng-container>
272 274
 
273 275
     </ng-container>

+ 7
- 5
src/app/pages/users-manager/users-management/user-create/user-create.component.ts Переглянути файл

@@ -1,10 +1,10 @@
1
-import { UsersService } from './../../../../shared/services/users.service';
2
-import { User } from './../../../../shared/models/user.model';
1
+import { UsersService } from '../../../../shared/services/users.service';
2
+import { User } from '../../../../shared/models/user.model';
3 3
 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
4 4
 import {
5 5
   CreateFormUserAddAction,
6
-  SaveUserFormAction,
7
-} from './../../../../ngrx/users/users.actions';
6
+  SaveUserFormAddAction,
7
+} from '../../../../ngrx/users/users.actions';
8 8
 import { Store } from '@ngrx/store';
9 9
 import { Component, OnInit } from '@angular/core';
10 10
 import { MsgState } from 'src/app/ngrx/msg.state';
@@ -16,6 +16,7 @@ import { UserState } from 'src/app/ngrx/users/user.state';
16 16
   styleUrls: ['./user-create.component.css'],
17 17
 })
18 18
 export class UserCreateComponent implements OnInit {
19
+
19 20
   userFormGroup!: FormGroup;
20 21
 
21 22
   constructor(
@@ -27,6 +28,7 @@ export class UserCreateComponent implements OnInit {
27 28
   readonly msgState = MsgState;
28 29
 
29 30
   ngOnInit(): void {
31
+
30 32
     this.store.dispatch(new CreateFormUserAddAction({}));
31 33
 
32 34
     this.store.subscribe((myState) => {
@@ -96,7 +98,7 @@ export class UserCreateComponent implements OnInit {
96 98
      else{
97 99
 
98 100
       if (window.confirm(MsgState.CONFIRM_ADD+' '+user.firstname+' '+user.lastname)) {
99
-        this.store.dispatch(new SaveUserFormAction(user));
101
+        this.store.dispatch(new SaveUserFormAddAction(user));
100 102
       }
101 103
      }
102 104
    });

+ 5
- 8
src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.html Переглянути файл

@@ -5,7 +5,7 @@
5 5
         pButton
6 6
         type="button"
7 7
         label="create user"
8
-        class="p-button-outlined"
8
+        class="btn btn-outline-primary"
9 9
         (click)="onUserCreate()"
10 10
       ></button>
11 11
       &nbsp;
@@ -13,25 +13,22 @@
13 13
         pButton
14 14
         type="button"
15 15
         label="all users"
16
-        class="p-button-outlined"
17 16
         (click)="onUsersGetAll()"
17
+        class="btn btn-outline-primary"
18 18
       ></button>
19 19
       &nbsp;
20 20
       <button
21 21
         pButton
22 22
         type="button"
23 23
         label="user's projects"
24
-        class="p-button-outlined"
25
-        (click)="onGetUsersVsProjects()"
24
+        class="btn btn-outline-primary"
25
+        (click)="onGetUser_s_Projects()"
26 26
       ></button>
27 27
     </div>
28 28
 
29 29
     <ul class="navbar-nav ml-auto">
30 30
       <li>
31
-        <form #form="ngForm"
32
-          (ngSubmit)="onSearch(form.value)"
33
-          novalidate
34
-        >
31
+        <form #form="ngForm" (ngSubmit)="onSearch(form.value)" novalidate>
35 32
           <div class="input-group">
36 33
             <input
37 34
               type="text"

+ 19
- 4
src/app/pages/users-manager/users-management/user-nav-bar/user-nav-bar.component.ts Переглянути файл

@@ -1,24 +1,36 @@
1 1
 import { UserState } from './../../../../ngrx/users/user.state';
2 2
 import {
3
+  NavigateActionSuccess,
3 4
   SearchUsersAction,
4
-  CreateFormUserAddAction,
5 5
 } from './../../../../ngrx/users/users.actions';
6 6
 import { GetAllUsersAction } from '../../../../ngrx/users/users.actions';
7
-import { Component } from '@angular/core';
7
+import { Component, OnInit } from '@angular/core';
8 8
 import { Store } from '@ngrx/store';
9 9
 import { Router } from '@angular/router';
10
+import { UserActionTypes } from 'src/app/ngrx/users/user.action.types';
10 11
 
11 12
 @Component({
12 13
   selector: 'app-user-nav-bar',
13 14
   templateUrl: './user-nav-bar.component.html',
14 15
   styleUrls: ['./user-nav-bar.component.css'],
15 16
 })
16
-export class UserNavBarComponent {
17
+export class UserNavBarComponent implements OnInit{
17 18
   constructor(
18 19
     private store: Store<{ userReducerKey: UserState }>,
19 20
     private router: Router
20 21
   ) {}
21 22
 
23
+  userActionTypes = UserActionTypes;
24
+  userState!: UserState;
25
+
26
+  ngOnInit(): void {
27
+
28
+    this.store.subscribe((userState)=>{
29
+      this.userState = userState.userReducerKey;
30
+    })
31
+  }
32
+
33
+
22 34
 
23 35
   onUserCreate(): void {
24 36
     this.router.navigateByUrl('/user-create');
@@ -27,7 +39,10 @@ export class UserNavBarComponent {
27 39
   onUsersGetAll(): any {
28 40
     this.store.dispatch(new GetAllUsersAction({}));
29 41
   }
30
-  onGetUsersVsProjects(): any {}
42
+
43
+  onGetUser_s_Projects(): any {
44
+   this.store.dispatch(new NavigateActionSuccess({}))
45
+  }
31 46
 
32 47
   onSearch(searchForm: any) {
33 48
     this.store.dispatch(new SearchUsersAction(searchForm.keyword));

+ 3
- 0
src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.css Переглянути файл

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

+ 64
- 0
src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.html Переглянути файл

@@ -0,0 +1,64 @@
1
+<div class="container m-3 p-3">
2
+  <ng-container
3
+    *ngIf="usersState$ | async as userState"
4
+    [ngSwitch]="userState.msgState"
5
+  >
6
+    <ng-container *ngSwitchCase="msgState.LOADING">
7
+      {{ msgState.LOADING }}
8
+    </ng-container>
9
+
10
+    <ng-container *ngSwitchCase="msgState.ERR">
11
+      {{ msgState.ERR }}
12
+    </ng-container>
13
+
14
+    <ng-container *ngSwitchCase="msgState.LOADED">
15
+      <p-table
16
+        [value]="userState.usersList"
17
+        responsiveLayout="scroll"
18
+        styleClass="p-datatable-striped"
19
+        *ngIf="userState.usersList && userState.usersList.length > 0"
20
+        [paginator]="true"
21
+        [rows]="2"
22
+        [showCurrentPageReport]="true"
23
+        currentPageReportTemplate="{first} - {last} of {totalRecords} users"
24
+        [rowsPerPageOptions]="[2, 3, 5]"
25
+      >
26
+        <ng-template pTemplate="header">
27
+          <tr>
28
+            <th>ID</th>
29
+            <th>Firstname</th>
30
+            <th>Lastname</th>
31
+            <th>Projects involving user</th>
32
+            <th>Email</th>
33
+          </tr>
34
+        </ng-template>
35
+        <ng-template pTemplate="body" let-user>
36
+          <tr>
37
+            <td>{{ user.id }}</td>
38
+            <td>{{ user.firstname }}</td>
39
+            <td>{{ user.lastname }}</td>
40
+            <td>
41
+              <ul *ngFor="let project of user.projects">
42
+                <li>
43
+                  <span style="font-weight: bold"
44
+                    >Project ID: {{ project.id }}</span
45
+                  >
46
+                </li>
47
+
48
+                <li>Project Name: {{ project.projectName }}</li>
49
+                <li>Priority: {{ project.priority }}</li>
50
+                <li>Creation Date: {{ project.creationDate }}</li>
51
+                <li>Company ID: {{ project.companyId }}</li>
52
+                <li>Description: {{ project.description }}</li>
53
+                <li>User ID: {{ project.userId }}</li>
54
+                <li>Project State: {{ project.state }}</li>
55
+              </ul>
56
+            </td>
57
+
58
+            <td>{{ user.email }}</td>
59
+          </tr>
60
+        </ng-template>
61
+      </p-table>
62
+    </ng-container>
63
+  </ng-container>
64
+</div>

+ 25
- 0
src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.spec.ts Переглянути файл

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

+ 38
- 0
src/app/pages/users-manager/users-management/user-s-projects/user-s-projects.component.ts Переглянути файл

@@ -0,0 +1,38 @@
1
+import { MsgState } from './../../../../ngrx/msg.state';
2
+import { Observable } from 'rxjs';
3
+import { GetUser_S_Projects, UserActionUnion } from './../../../../ngrx/users/users.actions';
4
+import { UserState } from './../../../../ngrx/users/user.state';
5
+import { Component, OnInit } from '@angular/core';
6
+import { Store } from '@ngrx/store';
7
+import { User } from 'src/app/shared/models/user.model';
8
+
9
+@Component({
10
+  selector: 'app-user-s-projects',
11
+  templateUrl: './user-s-projects.component.html',
12
+  styleUrls: ['./user-s-projects.component.css'],
13
+})
14
+export class UserSProjectsComponent implements OnInit {
15
+  constructor(
16
+    private store: Store<{ userReducerKey: UserState }>,
17
+  ) {
18
+
19
+  }
20
+
21
+  usersState$!: Observable<{
22
+    currentUser: User| null,
23
+    usersList: any,
24
+    msgState: MsgState,
25
+    serverMsgError: string
26
+  }>
27
+
28
+  msgState = MsgState;
29
+
30
+  ngOnInit(): void {
31
+
32
+    this.store.dispatch(new GetUser_S_Projects({}));
33
+
34
+    this.usersState$= this.store.select("userReducerKey");
35
+    console.log(this.usersState$)
36
+
37
+  }
38
+}

+ 2
- 2
src/app/pages/users-manager/users-management/user-update/user-update.component.html Переглянути файл

@@ -24,7 +24,7 @@
24 24
 
25 25
             <div class="row">
26 26
 
27
-              <div class="col">
27
+              <div class="col card">
28 28
 
29 29
                 <div class="col-md-auto mb-3">
30 30
                   <label for="id">Firstname</label>
@@ -109,7 +109,7 @@
109 109
 
110 110
               </div>
111 111
 
112
-              <div class="col">
112
+              <div class="col card">
113 113
 
114 114
                 <div formGroupName="address">
115 115
                   <div class="col-md-auto mb-3">

+ 2
- 2
src/app/pages/users-manager/users-management/user-update/user-update.component.ts Переглянути файл

@@ -1,7 +1,7 @@
1 1
 import { MsgState } from 'src/app/ngrx/msg.state';
2
-import { UsersService } from './../../../../shared/services/users.service';
2
+import { UsersService } from '../../../../shared/services/users.service';
3 3
 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
4
-import { CreareFormUserEditAction, UpdateUserFormAction } from './../../../../ngrx/users/users.actions';
4
+import { CreareFormUserEditAction, UpdateUserFormAction } from '../../../../ngrx/users/users.actions';
5 5
 import { UserState } from 'src/app/ngrx/users/user.state';
6 6
 import { Component, OnInit } from '@angular/core';
7 7
 import { ActivatedRoute, Router } from '@angular/router';

+ 1
- 1
src/app/pages/users-manager/users-management/users-list/users-list.component.html Переглянути файл

@@ -1,4 +1,4 @@
1
-<p-table #tbl
1
+<p-table
2 2
 [value]="inputState.usersList"
3 3
 responsiveLayout="scroll"
4 4
 *ngIf="inputState.usersList && inputState.usersList.length > 0"

+ 9
- 10
src/app/pages/users-manager/users-management/users-management.component.html Переглянути файл

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

+ 4
- 4
src/app/pages/users-manager/users-management/users-management.component.ts Переглянути файл

@@ -14,12 +14,12 @@ export class UsersManagementComponent implements OnInit {
14 14
 
15 15
   userState$!: Observable<{
16 16
     currentUser: User | null,
17
-    usersList: User[],
17
+    usersList: any,
18 18
     msgState: MsgState,
19
-    userServerErrorMsg: string
19
+    serverMsgError: string
20 20
   }>;
21 21
 
22
-  readonly userMsg = MsgState;
22
+  readonly msgState = MsgState;
23 23
 
24 24
   constructor(private store: Store<{ userReducerKey: UserState }>) {}
25 25
 
@@ -27,7 +27,7 @@ export class UsersManagementComponent implements OnInit {
27 27
    // this.userState$ = this.store.select('userReducerKey');
28 28
     //or
29 29
     this.userState$ = this.store.pipe(
30
-      map( (userState) => userState.userReducerKey)
30
+      map( (userState) => userState.userReducerKey),
31 31
     )
32 32
   }
33 33
 }

+ 2
- 0
src/app/pages/users-manager/users-manager-routing.module.ts Переглянути файл

@@ -1,3 +1,4 @@
1
+import { UserSProjectsComponent } from './users-management/user-s-projects/user-s-projects.component';
1 2
 import { UserUpdateComponent } from './users-management/user-update/user-update.component';
2 3
 import { UsersManagementComponent } from './users-management/users-management.component';
3 4
 import { NgModule } from '@angular/core';
@@ -8,6 +9,7 @@ const routes: Routes = [
8 9
   { path: 'user-create', component: UserCreateComponent },
9 10
   { path: 'users-management', component: UsersManagementComponent },
10 11
   { path: 'user-update/:id', component: UserUpdateComponent },
12
+  { path: 'user-s-projects', component: UserSProjectsComponent },
11 13
 ];
12 14
 
13 15
 @NgModule({

+ 7
- 5
src/app/pages/users-manager/users-manager.module.ts Переглянути файл

@@ -8,12 +8,16 @@ import { UserNavBarComponent } from './users-management/user-nav-bar/user-nav-ba
8 8
 import { EffectsModule } from '@ngrx/effects';
9 9
 import { StoreDevtoolsModule } from '@ngrx/store-devtools';
10 10
 import { StoreModule } from '@ngrx/store';
11
-import { UserEffects } from 'src/app/ngrx/users/users.effects';
12 11
 import { userReducer } from 'src/app/ngrx/users/users.reducer';
13 12
 import { TableModule } from "primeng/table";
14 13
 import { UsersListComponent } from './users-management/users-list/users-list.component';
15 14
 import { FormsModule, ReactiveFormsModule } from '@angular/forms';
16 15
 import { UserUpdateComponent } from './users-management/user-update/user-update.component';
16
+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';
17 21
 
18 22
 
19 23
 
@@ -23,15 +27,13 @@ import { UserUpdateComponent } from './users-management/user-update/user-update.
23 27
     UserNavBarComponent,
24 28
     UsersManagementComponent,
25 29
     UsersListComponent,
26
-    UserUpdateComponent
30
+    UserUpdateComponent,
31
+    UserSProjectsComponent
27 32
   ],
28 33
   imports: [
29 34
     CommonModule,
30 35
     UsersManagerRoutingModule,
31 36
     ButtonModule,
32
-    StoreModule.forRoot({userReducerKey: userReducer}),
33
-    EffectsModule.forRoot([UserEffects]),
34
-    StoreDevtoolsModule.instrument(),
35 37
     TableModule,
36 38
     FormsModule,
37 39
     ReactiveFormsModule

+ 7
- 0
src/app/shared/models/project.priority.ts Переглянути файл

@@ -0,0 +1,7 @@
1
+export enum Priority{
2
+  PRIORITY1=1,
3
+  PRIORITY2=2,
4
+  PRIORITY3=3,
5
+  PRIORITY4=4,
6
+  PRIORITY5=5,
7
+}

+ 4
- 0
src/app/shared/models/project.state.ts Переглянути файл

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

+ 1
- 1
src/app/shared/services/users.service.ts Переглянути файл

@@ -25,7 +25,7 @@ export class UsersService {
25 25
     });
26 26
   }
27 27
 
28
-  baseUrl: string = Math.random() > 0.2 ? environment.host : environment.unreachibleHost;
28
+  baseUrl: string = Math.random() > 0.01 ? environment.host : environment.unreachibleHost;
29 29
   headers = { 'content-type': 'application/json' };
30 30
 
31 31
   getAllUsers(): Observable<User[]> {

Powered by TurnKey Linux.