placidenduwayo 2 лет назад
Сommit
48428bcbb4
100 измененных файлов: 24644 добавлений и 0 удалений
  1. 16
    0
      .browserslistrc
  2. 16
    0
      .editorconfig
  3. 42
    0
      .gitignore
  4. 4
    0
      .vscode/extensions.json
  5. 20
    0
      .vscode/launch.json
  6. 42
    0
      .vscode/tasks.json
  7. 27
    0
      README.md
  8. 115
    0
      angular.json
  9. 44
    0
      karma.conf.js
  10. 20466
    0
      package-lock.json
  11. 48
    0
      package.json
  12. 10
    0
      src/app/app-routing.module.ts
  13. 0
    0
      src/app/app.component.css
  14. 2
    0
      src/app/app.component.html
  15. 35
    0
      src/app/app.component.spec.ts
  16. 10
    0
      src/app/app.component.ts
  17. 85
    0
      src/app/app.module.ts
  18. 25
    0
      src/app/ngrx/company/company.action.type.ts
  19. 107
    0
      src/app/ngrx/company/company.actions.ts
  20. 45
    0
      src/app/ngrx/company/company.effects.create.ts
  21. 26
    0
      src/app/ngrx/company/company.effects.delete.ts
  22. 35
    0
      src/app/ngrx/company/company.effects.get.ts
  23. 56
    0
      src/app/ngrx/company/company.effects.update.ts
  24. 150
    0
      src/app/ngrx/company/company.reducer.ts
  25. 9
    0
      src/app/ngrx/company/company.state.ts
  26. 19
    0
      src/app/ngrx/msg.state.ts
  27. 150
    0
      src/app/ngrx/project/project.action.ts
  28. 25
    0
      src/app/ngrx/project/project.action.type.ts
  29. 60
    0
      src/app/ngrx/project/project.effects.create.ts
  30. 26
    0
      src/app/ngrx/project/project.effects.delete.ts
  31. 29
    0
      src/app/ngrx/project/project.effects.get.ts
  32. 59
    0
      src/app/ngrx/project/project.effects.update.ts
  33. 151
    0
      src/app/ngrx/project/project.reducer.ts
  34. 8
    0
      src/app/ngrx/project/project.state.ts
  35. 101
    0
      src/app/ngrx/user-s-address/address.action.ts
  36. 26
    0
      src/app/ngrx/user-s-address/address.action.type.ts
  37. 103
    0
      src/app/ngrx/user-s-address/address.effects.ts
  38. 146
    0
      src/app/ngrx/user-s-address/address.reducer.ts
  39. 9
    0
      src/app/ngrx/user-s-address/address.state.ts
  40. 29
    0
      src/app/ngrx/user/user.action.type.ts
  41. 123
    0
      src/app/ngrx/user/user.actions.ts
  42. 46
    0
      src/app/ngrx/user/user.effects.create.ts
  43. 28
    0
      src/app/ngrx/user/user.effects.delete.ts
  44. 29
    0
      src/app/ngrx/user/user.effects.get.ts
  45. 45
    0
      src/app/ngrx/user/user.effects.update.ts
  46. 150
    0
      src/app/ngrx/user/user.reducer.ts
  47. 8
    0
      src/app/ngrx/user/user.state.ts
  48. 17
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.css
  49. 25
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.html
  50. 40
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.spec.ts
  51. 21
    0
      src/app/pages/base-nav-menu/base-nav-menu.component.ts
  52. 13
    0
      src/app/pages/base-page-accueil/base-page-accueil-routing.module.ts
  53. 17
    0
      src/app/pages/base-page-accueil/base-page-accueil.module.ts
  54. 0
    0
      src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.css
  55. 14
    0
      src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.html
  56. 25
    0
      src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.spec.ts
  57. 15
    0
      src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.ts
  58. 0
    0
      src/app/pages/company-manager/company-management/companies-list/companies-list.component.css
  59. 63
    0
      src/app/pages/company-manager/company-management/companies-list/companies-list.component.html
  60. 25
    0
      src/app/pages/company-manager/company-management/companies-list/companies-list.component.spec.ts
  61. 47
    0
      src/app/pages/company-manager/company-management/companies-list/companies-list.component.ts
  62. 0
    0
      src/app/pages/company-manager/company-management/company-create/company-create.component.css
  63. 100
    0
      src/app/pages/company-manager/company-management/company-create/company-create.component.html
  64. 25
    0
      src/app/pages/company-manager/company-management/company-create/company-create.component.spec.ts
  65. 62
    0
      src/app/pages/company-manager/company-management/company-create/company-create.component.ts
  66. 0
    0
      src/app/pages/company-manager/company-management/company-management.component.css
  67. 30
    0
      src/app/pages/company-manager/company-management/company-management.component.html
  68. 25
    0
      src/app/pages/company-manager/company-management/company-management.component.spec.ts
  69. 23
    0
      src/app/pages/company-manager/company-management/company-management.component.ts
  70. 0
    0
      src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.css
  71. 21
    0
      src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.html
  72. 25
    0
      src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.spec.ts
  73. 25
    0
      src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.ts
  74. 0
    0
      src/app/pages/company-manager/company-management/company-update/company-update.component.css
  75. 96
    0
      src/app/pages/company-manager/company-management/company-update/company-update.component.html
  76. 25
    0
      src/app/pages/company-manager/company-management/company-update/company-update.component.spec.ts
  77. 71
    0
      src/app/pages/company-manager/company-management/company-update/company-update.component.ts
  78. 17
    0
      src/app/pages/company-manager/company-manager-routing.module.ts
  79. 34
    0
      src/app/pages/company-manager/company-manager.module.ts
  80. 0
    0
      src/app/pages/project-manager/project-management/project-create/project-create.component.css
  81. 165
    0
      src/app/pages/project-manager/project-management/project-create/project-create.component.html
  82. 25
    0
      src/app/pages/project-manager/project-management/project-create/project-create.component.spec.ts
  83. 98
    0
      src/app/pages/project-manager/project-management/project-create/project-create.component.ts
  84. 0
    0
      src/app/pages/project-manager/project-management/project-management.component.css
  85. 21
    0
      src/app/pages/project-manager/project-management/project-management.component.html
  86. 25
    0
      src/app/pages/project-manager/project-management/project-management.component.spec.ts
  87. 22
    0
      src/app/pages/project-manager/project-management/project-management.component.ts
  88. 0
    0
      src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.css
  89. 21
    0
      src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.html
  90. 25
    0
      src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.spec.ts
  91. 25
    0
      src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.ts
  92. 0
    0
      src/app/pages/project-manager/project-management/project-update/project-update.component.css
  93. 167
    0
      src/app/pages/project-manager/project-management/project-update/project-update.component.html
  94. 25
    0
      src/app/pages/project-manager/project-management/project-update/project-update.component.spec.ts
  95. 123
    0
      src/app/pages/project-manager/project-management/project-update/project-update.component.ts
  96. 0
    0
      src/app/pages/project-manager/project-management/projects-list/projects-list.component.css
  97. 98
    0
      src/app/pages/project-manager/project-management/projects-list/projects-list.component.html
  98. 25
    0
      src/app/pages/project-manager/project-management/projects-list/projects-list.component.spec.ts
  99. 73
    0
      src/app/pages/project-manager/project-management/projects-list/projects-list.component.ts
  100. 0
    0
      src/app/pages/project-manager/project-manager-routing.module.ts

+ 16
- 0
.browserslistrc Просмотреть файл

@@ -0,0 +1,16 @@
1
+# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2
+# For additional information regarding the format and rule options, please see:
3
+# https://github.com/browserslist/browserslist#queries
4
+
5
+# For the full list of supported browsers by the Angular framework, please see:
6
+# https://angular.io/guide/browser-support
7
+
8
+# You can see what browsers were selected by your queries by running:
9
+#   npx browserslist
10
+
11
+last 1 Chrome version
12
+last 1 Firefox version
13
+last 2 Edge major versions
14
+last 2 Safari major versions
15
+last 2 iOS major versions
16
+Firefox ESR

+ 16
- 0
.editorconfig Просмотреть файл

@@ -0,0 +1,16 @@
1
+# Editor configuration, see https://editorconfig.org
2
+root = true
3
+
4
+[*]
5
+charset = utf-8
6
+indent_style = space
7
+indent_size = 2
8
+insert_final_newline = true
9
+trim_trailing_whitespace = true
10
+
11
+[*.ts]
12
+quote_type = single
13
+
14
+[*.md]
15
+max_line_length = off
16
+trim_trailing_whitespace = false

+ 42
- 0
.gitignore Просмотреть файл

@@ -0,0 +1,42 @@
1
+# See http://help.github.com/ignore-files/ for more about ignoring files.
2
+
3
+# Compiled output
4
+/dist
5
+/tmp
6
+/out-tsc
7
+/bazel-out
8
+
9
+# Node
10
+/node_modules
11
+npm-debug.log
12
+yarn-error.log
13
+
14
+# IDEs and editors
15
+.idea/
16
+.project
17
+.classpath
18
+.c9/
19
+*.launch
20
+.settings/
21
+*.sublime-workspace
22
+
23
+# Visual Studio Code
24
+.vscode/*
25
+!.vscode/settings.json
26
+!.vscode/tasks.json
27
+!.vscode/launch.json
28
+!.vscode/extensions.json
29
+.history/*
30
+
31
+# Miscellaneous
32
+/.angular/cache
33
+.sass-cache/
34
+/connect.lock
35
+/coverage
36
+/libpeerconnection.log
37
+testem.log
38
+/typings
39
+
40
+# System files
41
+.DS_Store
42
+Thumbs.db

+ 4
- 0
.vscode/extensions.json Просмотреть файл

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

+ 20
- 0
.vscode/launch.json Просмотреть файл

@@ -0,0 +1,20 @@
1
+{
2
+  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3
+  "version": "0.2.0",
4
+  "configurations": [
5
+    {
6
+      "name": "ng serve",
7
+      "type": "pwa-chrome",
8
+      "request": "launch",
9
+      "preLaunchTask": "npm: start",
10
+      "url": "http://localhost:4200/"
11
+    },
12
+    {
13
+      "name": "ng test",
14
+      "type": "chrome",
15
+      "request": "launch",
16
+      "preLaunchTask": "npm: test",
17
+      "url": "http://localhost:9876/debug.html"
18
+    }
19
+  ]
20
+}

+ 42
- 0
.vscode/tasks.json Просмотреть файл

@@ -0,0 +1,42 @@
1
+{
2
+  // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3
+  "version": "2.0.0",
4
+  "tasks": [
5
+    {
6
+      "type": "npm",
7
+      "script": "start",
8
+      "isBackground": true,
9
+      "problemMatcher": {
10
+        "owner": "typescript",
11
+        "pattern": "$tsc",
12
+        "background": {
13
+          "activeOnStart": true,
14
+          "beginsPattern": {
15
+            "regexp": "(.*?)"
16
+          },
17
+          "endsPattern": {
18
+            "regexp": "bundle generation complete"
19
+          }
20
+        }
21
+      }
22
+    },
23
+    {
24
+      "type": "npm",
25
+      "script": "test",
26
+      "isBackground": true,
27
+      "problemMatcher": {
28
+        "owner": "typescript",
29
+        "pattern": "$tsc",
30
+        "background": {
31
+          "activeOnStart": true,
32
+          "beginsPattern": {
33
+            "regexp": "(.*?)"
34
+          },
35
+          "endsPattern": {
36
+            "regexp": "bundle generation complete"
37
+          }
38
+        }
39
+      }
40
+    }
41
+  ]
42
+}

+ 27
- 0
README.md Просмотреть файл

@@ -0,0 +1,27 @@
1
+# UsersProjectsCompaniesAngularNgrxFrontend
2
+
3
+This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.3.4.
4
+
5
+## Development server
6
+
7
+Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
8
+
9
+## Code scaffolding
10
+
11
+Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12
+
13
+## Build
14
+
15
+Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
16
+
17
+## Running unit tests
18
+
19
+Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20
+
21
+## Running end-to-end tests
22
+
23
+Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
24
+
25
+## Further help
26
+
27
+To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.

+ 115
- 0
angular.json Просмотреть файл

@@ -0,0 +1,115 @@
1
+{
2
+  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
+  "version": 1,
4
+  "newProjectRoot": "projects",
5
+  "projects": {
6
+    "users-projects-companies-angular-ngrx-frontend": {
7
+      "projectType": "application",
8
+      "schematics": {
9
+        "@schematics/angular:application": {
10
+          "strict": true
11
+        }
12
+      },
13
+      "root": "",
14
+      "sourceRoot": "src",
15
+      "prefix": "app",
16
+      "architect": {
17
+        "build": {
18
+          "builder": "@angular-devkit/build-angular:browser",
19
+          "options": {
20
+            "outputPath": "dist/users-projects-companies-angular-ngrx-frontend",
21
+            "index": "src/index.html",
22
+            "main": "src/main.ts",
23
+            "polyfills": "src/polyfills.ts",
24
+            "tsConfig": "tsconfig.app.json",
25
+            "assets": [
26
+              "src/favicon.ico",
27
+              "src/assets"
28
+            ],
29
+             "styles": [
30
+              "src/styles.css",
31
+              "node_modules/primeicons/primeicons.css",
32
+              "node_modules/primeng/resources/themes/lara-light-blue/theme.css",
33
+              "node_modules/primeng/resources/primeng.min.css",
34
+              "node_modules/bootstrap/dist/css/bootstrap.min.css",
35
+              "node_modules/font-awesome/css/font-awesome.min.css",
36
+              "node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
37
+            ],
38
+            "scripts": [
39
+
40
+            ]
41
+          },
42
+          "configurations": {
43
+            "production": {
44
+              "budgets": [
45
+                {
46
+                  "type": "initial",
47
+                  "maximumWarning": "500kb",
48
+                  "maximumError": "1mb"
49
+                },
50
+                {
51
+                  "type": "anyComponentStyle",
52
+                  "maximumWarning": "2kb",
53
+                  "maximumError": "4kb"
54
+                }
55
+              ],
56
+              "fileReplacements": [
57
+                {
58
+                  "replace": "src/environments/environment.ts",
59
+                  "with": "src/environments/environment.prod.ts"
60
+                }
61
+              ],
62
+              "outputHashing": "all"
63
+            },
64
+            "development": {
65
+              "buildOptimizer": false,
66
+              "optimization": false,
67
+              "vendorChunk": true,
68
+              "extractLicenses": false,
69
+              "sourceMap": true,
70
+              "namedChunks": true
71
+            }
72
+          },
73
+          "defaultConfiguration": "production"
74
+        },
75
+        "serve": {
76
+          "builder": "@angular-devkit/build-angular:dev-server",
77
+          "configurations": {
78
+            "production": {
79
+              "browserTarget": "users-projects-companies-angular-ngrx-frontend:build:production"
80
+            },
81
+            "development": {
82
+              "browserTarget": "users-projects-companies-angular-ngrx-frontend:build:development"
83
+            }
84
+          },
85
+          "defaultConfiguration": "development"
86
+        },
87
+        "extract-i18n": {
88
+          "builder": "@angular-devkit/build-angular:extract-i18n",
89
+          "options": {
90
+            "browserTarget": "users-projects-companies-angular-ngrx-frontend:build"
91
+          }
92
+        },
93
+        "test": {
94
+          "builder": "@angular-devkit/build-angular:karma",
95
+          "options": {
96
+            "main": "src/test.ts",
97
+            "polyfills": "src/polyfills.ts",
98
+            "tsConfig": "tsconfig.spec.json",
99
+            "karmaConfig": "karma.conf.js",
100
+            "assets": [
101
+              "src/favicon.ico",
102
+              "src/assets"
103
+            ],
104
+            "styles": [
105
+              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
106
+              "src/styles.css"
107
+            ],
108
+            "scripts": []
109
+          }
110
+        }
111
+      }
112
+    }
113
+  },
114
+  "defaultProject": "users-projects-companies-angular-ngrx-frontend"
115
+}

+ 44
- 0
karma.conf.js Просмотреть файл

@@ -0,0 +1,44 @@
1
+// Karma configuration file, see link for more information
2
+// https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+module.exports = function (config) {
5
+  config.set({
6
+    basePath: '',
7
+    frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+    plugins: [
9
+      require('karma-jasmine'),
10
+      require('karma-chrome-launcher'),
11
+      require('karma-jasmine-html-reporter'),
12
+      require('karma-coverage'),
13
+      require('@angular-devkit/build-angular/plugins/karma')
14
+    ],
15
+    client: {
16
+      jasmine: {
17
+        // you can add configuration options for Jasmine here
18
+        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+        // for example, you can disable the random execution with `random: false`
20
+        // or set a specific seed with `seed: 4321`
21
+      },
22
+      clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+    },
24
+    jasmineHtmlReporter: {
25
+      suppressAll: true // removes the duplicated traces
26
+    },
27
+    coverageReporter: {
28
+      dir: require('path').join(__dirname, './coverage/users-projects-companies-angular-ngrx-frontend'),
29
+      subdir: '.',
30
+      reporters: [
31
+        { type: 'html' },
32
+        { type: 'text-summary' }
33
+      ]
34
+    },
35
+    reporters: ['progress', 'kjhtml'],
36
+    port: 9876,
37
+    colors: true,
38
+    logLevel: config.LOG_INFO,
39
+    autoWatch: true,
40
+    browsers: ['Chrome'],
41
+    singleRun: false,
42
+    restartOnFileChange: true
43
+  });
44
+};

+ 20466
- 0
package-lock.json
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 48
- 0
package.json Просмотреть файл

@@ -0,0 +1,48 @@
1
+{
2
+  "name": "users-projects-companies-angular-ngrx-frontend",
3
+  "version": "0.0.0",
4
+  "scripts": {
5
+    "ng": "ng",
6
+    "start": "ng serve",
7
+    "build": "ng build",
8
+    "watch": "ng build --watch --configuration development",
9
+    "test": "ng test"
10
+  },
11
+  "private": true,
12
+  "dependencies": {
13
+    "@angular/animations": "~13.3.0",
14
+    "@angular/cdk": "~13.3.6",
15
+    "@angular/common": "~13.3.0",
16
+    "@angular/compiler": "~13.3.0",
17
+    "@angular/core": "~13.3.0",
18
+    "@angular/forms": "~13.3.0",
19
+    "@angular/material": "~13.3.6",
20
+    "@angular/platform-browser": "~13.3.0",
21
+    "@angular/platform-browser-dynamic": "~13.3.0",
22
+    "@angular/router": "~13.3.0",
23
+    "@ngrx/effects": "^13.2.0",
24
+    "@ngrx/store": "^13.2.0",
25
+    "@ngrx/store-devtools": "^13.2.0",
26
+    "bootstrap": "^5.1.3",
27
+    "font-awesome": "^4.7.0",
28
+    "primeicons": "^5.0.0",
29
+    "primeng": "^13.4.1",
30
+    "rxjs": "~7.5.0",
31
+    "tslib": "^2.3.0",
32
+    "zone.js": "~0.11.4"
33
+  },
34
+  "devDependencies": {
35
+    "@angular-devkit/build-angular": "~13.3.4",
36
+    "@angular/cli": "~13.3.4",
37
+    "@angular/compiler-cli": "~13.3.0",
38
+    "@types/jasmine": "~3.10.0",
39
+    "@types/node": "^12.11.1",
40
+    "jasmine-core": "~4.0.0",
41
+    "karma": "~6.3.0",
42
+    "karma-chrome-launcher": "~3.1.0",
43
+    "karma-coverage": "~2.1.0",
44
+    "karma-jasmine": "~4.0.0",
45
+    "karma-jasmine-html-reporter": "~1.7.0",
46
+    "typescript": "~4.6.2"
47
+  }
48
+}

+ 10
- 0
src/app/app-routing.module.ts Просмотреть файл

@@ -0,0 +1,10 @@
1
+import { NgModule } from '@angular/core';
2
+import { RouterModule, Routes } from '@angular/router';
3
+
4
+const routes: Routes = [];
5
+
6
+@NgModule({
7
+  imports: [RouterModule.forRoot(routes)],
8
+  exports: [RouterModule]
9
+})
10
+export class AppRoutingModule { }

+ 0
- 0
src/app/app.component.css Просмотреть файл


+ 2
- 0
src/app/app.component.html Просмотреть файл

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

+ 35
- 0
src/app/app.component.spec.ts Просмотреть файл

@@ -0,0 +1,35 @@
1
+import { TestBed } from '@angular/core/testing';
2
+import { RouterTestingModule } from '@angular/router/testing';
3
+import { AppComponent } from './app.component';
4
+
5
+describe('AppComponent', () => {
6
+  beforeEach(async () => {
7
+    await TestBed.configureTestingModule({
8
+      imports: [
9
+        RouterTestingModule
10
+      ],
11
+      declarations: [
12
+        AppComponent
13
+      ],
14
+    }).compileComponents();
15
+  });
16
+
17
+  it('should create the app', () => {
18
+    const fixture = TestBed.createComponent(AppComponent);
19
+    const app = fixture.componentInstance;
20
+    expect(app).toBeTruthy();
21
+  });
22
+
23
+  it(`should have as title 'users-projects-companies-angular-ngrx-frontend'`, () => {
24
+    const fixture = TestBed.createComponent(AppComponent);
25
+    const app = fixture.componentInstance;
26
+    expect(app.title).toEqual('users-projects-companies-angular-ngrx-frontend');
27
+  });
28
+
29
+  it('should render title', () => {
30
+    const fixture = TestBed.createComponent(AppComponent);
31
+    fixture.detectChanges();
32
+    const compiled = fixture.nativeElement as HTMLElement;
33
+    expect(compiled.querySelector('.content span')?.textContent).toContain('users-projects-companies-angular-ngrx-frontend app is running!');
34
+  });
35
+});

+ 10
- 0
src/app/app.component.ts Просмотреть файл

@@ -0,0 +1,10 @@
1
+import { Component } from '@angular/core';
2
+
3
+@Component({
4
+  selector: 'app-root',
5
+  templateUrl: './app.component.html',
6
+  styleUrls: ['./app.component.css']
7
+})
8
+export class AppComponent {
9
+  title = 'users-projects-companies-angular-ngrx-frontend';
10
+}

+ 85
- 0
src/app/app.module.ts Просмотреть файл

@@ -0,0 +1,85 @@
1
+import { ProjectDeleteEffect } from './ngrx/project/project.effects.delete';
2
+import { ProjectUpdateEffect } from './ngrx/project/project.effects.update';
3
+import { ProjectGetEffects } from './ngrx/project/project.effects.get';
4
+import { ProjectCreateEffects } from './ngrx/project/project.effects.create';
5
+import { CompanyDeleteEffect } from './ngrx/company/company.effects.delete';
6
+import { CompanyUpdateEffects } from './ngrx/company/company.effects.update';
7
+import { CompanyGetEffects } from './ngrx/company/company.effects.get';
8
+import { CompanyCreateEffects } from './ngrx/company/company.effects.create';
9
+import { UserUpdateEffects } from './ngrx/user/user.effects.update';
10
+import { UserDeleteEffect } from './ngrx/user/user.effects.delete';
11
+import { UserSAddressManagerModule } from './pages/user-s-address-manager/user-s-address-manager.module';
12
+import { AddressEffects } from './ngrx/user-s-address/address.effects';
13
+import { UserGetAllEffects } from './ngrx/user/user.effects.get';
14
+import { UserManagerModule } from './pages/user-manager/user-manager.module';
15
+import { BasePageAccueilModule } from './pages/base-page-accueil/base-page-accueil.module';
16
+import { ProjectManagerModule } from './pages/project-manager/project-manager.module';
17
+import { CompanyManagerModule } from './pages/company-manager/company-manager.module';
18
+import { NgModule } from '@angular/core';
19
+import { BrowserModule } from '@angular/platform-browser';
20
+import { EffectsModule } from '@ngrx/effects';
21
+import { StoreModule } from '@ngrx/store';
22
+import { StoreDevtoolsModule } from '@ngrx/store-devtools';
23
+
24
+import { AppRoutingModule } from './app-routing.module';
25
+import { AppComponent } from './app.component';
26
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
27
+import { BaseNavMenuComponent } from './pages/base-nav-menu/base-nav-menu.component';
28
+import { LayoutModule } from '@angular/cdk/layout';
29
+import { MatToolbarModule } from '@angular/material/toolbar';
30
+import { MatButtonModule } from '@angular/material/button';
31
+import { MatSidenavModule } from '@angular/material/sidenav';
32
+import { MatIconModule } from '@angular/material/icon';
33
+import { MatListModule } from '@angular/material/list';
34
+import { HttpClientModule } from '@angular/common/http';
35
+import { userReducer } from './ngrx/user/user.reducer';
36
+import { addressReducer } from './ngrx/user-s-address/address.reducer';
37
+import { UserCreateEffects } from './ngrx/user/user.effects.create';
38
+import { companyReducer } from './ngrx/company/company.reducer';
39
+import { projectReducer } from './ngrx/project/project.reducer';
40
+
41
+@NgModule({
42
+  declarations: [AppComponent, BaseNavMenuComponent],
43
+  imports: [
44
+    BrowserModule,
45
+    AppRoutingModule,
46
+    StoreModule.forRoot({
47
+      userReducerSelector: userReducer,
48
+      addressReducerSelector: addressReducer,
49
+      companyReducerSelector: companyReducer,
50
+      projectReducerSelector: projectReducer,
51
+    }),
52
+    EffectsModule.forRoot([
53
+      AddressEffects,
54
+      UserGetAllEffects,
55
+      UserCreateEffects,
56
+      UserDeleteEffect,
57
+      UserUpdateEffects,
58
+      CompanyCreateEffects,
59
+      CompanyGetEffects,
60
+      CompanyUpdateEffects,
61
+      CompanyDeleteEffect,
62
+      ProjectCreateEffects,
63
+      ProjectGetEffects,
64
+      ProjectUpdateEffect,
65
+      ProjectDeleteEffect
66
+    ]),
67
+    StoreDevtoolsModule.instrument(),
68
+    BrowserAnimationsModule,
69
+    LayoutModule,
70
+    MatToolbarModule,
71
+    MatButtonModule,
72
+    MatSidenavModule,
73
+    MatIconModule,
74
+    MatListModule,
75
+    BasePageAccueilModule,
76
+    UserManagerModule,
77
+    UserSAddressManagerModule,
78
+    CompanyManagerModule,
79
+    ProjectManagerModule,
80
+    HttpClientModule,
81
+  ],
82
+  providers: [],
83
+  bootstrap: [AppComponent],
84
+})
85
+export class AppModule {}

+ 25
- 0
src/app/ngrx/company/company.action.type.ts Просмотреть файл

@@ -0,0 +1,25 @@
1
+export enum CompanyActionTypes{
2
+  CREATE_FORM_ADD_COMPANY = '[Company] CREATE FORM ADD COMPANY',
3
+  CREATE_FORM_ADD_COMPANY_SUCCESS = '[Company] CREATE FORM ADD COMPANY SUCCESS',
4
+  CREATE_FORM_ADD_COMPANY_ERROR = '[Company] CREATE FORM ADD COMPANY ERROR',
5
+
6
+  SAVE_NEW_CAMPANY = '[Company] SAVE NEW CAMPANY',
7
+  SAVE_NEW_CAMPANY_SUCCESS = '[Company] SAVE NEW CAMPANY SUCCESS',
8
+  SAVE_NEW_CAMPANY_ERROR = '[Company] SAVE NEW CAMPANY ERROR',
9
+
10
+  GET_ALL_COMPANIES ='[Company] GET ALL COMPANIES',
11
+  GET_ALL_COMPANIES_SUCCESS ='[Company] GET ALL COMPANIES SUCCESS',
12
+  GET_ALL_COMPANIES_ERROR ='[Company] GET ALL COMPANIES ERROR',
13
+
14
+  CREATE_FORM_UPDATE_COMPANY= '[Company] CREATE FORM UPDATE COMPANY',
15
+  CREATE_FORM_UPDATE_COMPANY_SUCCESS= '[Company] CREATE FORM UPDATE COMPANY SUCCESS',
16
+  CREATE_FORM_UPDATE_COMPANY_ERROR= '[Company] CREATE FORM UPDATE COMPANY ERROR',
17
+
18
+  UPDATE_COMPANY= '[Company] UPDATE COMPANY',
19
+  UPDATE_COMPANY_SUCCESS= '[Company] UPDATE COMPANY SUCCESS',
20
+  UPDATE_COMPANY_ERROR= '[Company] UPDATE COMPANY ERROR',
21
+
22
+  DELETE_COMPANY = '[Company] DELETE COMPANY',
23
+  DELETE_COMPANY_SUCCESS = '[Company] DELETE COMPANY SUCCESS',
24
+  DELETE_COMPANY_ERROR = '[Company] DELETE COMPANY ERROR',
25
+}

+ 107
- 0
src/app/ngrx/company/company.actions.ts Просмотреть файл

@@ -0,0 +1,107 @@
1
+import { Company } from './../../shared/models/company/company.model';
2
+import { CompanyActionTypes } from './company.action.type';
3
+import { Action } from '@ngrx/store';
4
+
5
+//create form to add new company
6
+export class CreateFormAddCompanyAction implements Action{
7
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_ADD_COMPANY;
8
+  constructor(public payload: any){}
9
+}
10
+export class CreateFormAddCompanyActionSuccess implements Action{
11
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_ADD_COMPANY_SUCCESS;
12
+  constructor(public payload: any){}
13
+}
14
+export class CreateFormAddCompanyActionError implements Action{
15
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_ADD_COMPANY_ERROR;
16
+  constructor(public payload: string){}
17
+}
18
+
19
+// save new company
20
+export class SaveNewCompanyAction implements Action{
21
+  type: CompanyActionTypes = CompanyActionTypes.SAVE_NEW_CAMPANY;
22
+  constructor(public payload: Company){}
23
+}
24
+export class SaveNewCompanyActionSuccess implements Action{
25
+  type: CompanyActionTypes = CompanyActionTypes.SAVE_NEW_CAMPANY_SUCCESS;
26
+  constructor(public payload: Company){}
27
+}
28
+export class SaveNewCompanyActionError implements Action{
29
+  type: CompanyActionTypes = CompanyActionTypes.SAVE_NEW_CAMPANY_ERROR;
30
+  constructor(public payload: string){}
31
+}
32
+
33
+//get all companies
34
+export class GetAllComapaniesAction implements Action{
35
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES;
36
+  constructor(public payload: any){}
37
+}
38
+export class GetAllComapaniesActionSuccess implements Action{
39
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES_SUCCESS;
40
+  constructor(public payload: Array<Company>){}
41
+}
42
+export class GetAllComapaniesActionError implements Action{
43
+  type: CompanyActionTypes = CompanyActionTypes.GET_ALL_COMPANIES_ERROR;
44
+  constructor(public payload: string){}
45
+}
46
+
47
+//create form to update company
48
+export class CreateFormUpdateCompanyAction implements Action{
49
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY;
50
+  constructor(public payload: Company){}
51
+}
52
+export class CreateFormUpdateCompanyActionSuccess implements Action{
53
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY_SUCCESS;
54
+  constructor(public payload: Company){}
55
+}
56
+export class CreateFormUpdateCompanyActionError implements Action{
57
+  type: CompanyActionTypes = CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY_ERROR;
58
+  constructor(public payload: string){}
59
+}
60
+
61
+//update company
62
+export class UpdateCompanyAction implements Action{
63
+  type: CompanyActionTypes = CompanyActionTypes.UPDATE_COMPANY;
64
+  constructor(public payload: Company){}
65
+}
66
+export class UpdateCompanyActionSuccss implements Action{
67
+  type: CompanyActionTypes = CompanyActionTypes.UPDATE_COMPANY_SUCCESS;
68
+  constructor(public payload: Company){}
69
+}
70
+export class UpdateCompanyActionError implements Action{
71
+  type: CompanyActionTypes = CompanyActionTypes.UPDATE_COMPANY_ERROR;
72
+  constructor(public payload: string){}
73
+}
74
+
75
+//delete a company
76
+export class DeleteCompanyAction implements Action{
77
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY;
78
+  constructor(public payload: Company){}
79
+}
80
+export class DeleteCompanyActionSuccess implements Action{
81
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY_SUCCESS;
82
+  constructor(public payload: Company){}
83
+}
84
+export class DeleteCompanyActionError implements Action{
85
+  type: CompanyActionTypes = CompanyActionTypes.DELETE_COMPANY_ERROR;
86
+  constructor(public payload: string){}
87
+}
88
+
89
+export type CompanyActionUnion =
90
+| CreateFormAddCompanyAction
91
+| CreateFormAddCompanyActionSuccess
92
+| CreateFormAddCompanyActionError
93
+| SaveNewCompanyAction
94
+| SaveNewCompanyActionSuccess
95
+| SaveNewCompanyActionError
96
+| GetAllComapaniesAction
97
+| GetAllComapaniesActionSuccess
98
+| GetAllComapaniesActionError
99
+| CreateFormUpdateCompanyAction
100
+| CreateFormUpdateCompanyActionSuccess
101
+| CreateFormUpdateCompanyActionError
102
+| UpdateCompanyAction
103
+| UpdateCompanyActionSuccss
104
+| UpdateCompanyActionError
105
+| DeleteCompanyAction
106
+| DeleteCompanyActionSuccess
107
+| DeleteCompanyActionError;

+ 45
- 0
src/app/ngrx/company/company.effects.create.ts Просмотреть файл

@@ -0,0 +1,45 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { CompanyActionTypes } from './company.action.type';
3
+import {
4
+  CompanyActionUnion,
5
+  CreateFormAddCompanyActionSuccess,
6
+  CreateFormAddCompanyActionError,
7
+  SaveNewCompanyActionSuccess,
8
+  SaveNewCompanyActionError,
9
+} from './company.actions';
10
+import { Observable, of, mergeMap } from 'rxjs';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { CompanyService } from './../../shared/services/company.service';
13
+import { Injectable } from '@angular/core';
14
+import { Company } from 'src/app/shared/models/company/company.model';
15
+
16
+@Injectable()
17
+export class CompanyCreateEffects {
18
+  constructor(
19
+    private companyService: CompanyService,
20
+    private companyActions: Actions
21
+  ) {}
22
+
23
+  //create form to add company
24
+  createFormAddCompanyEffect: Observable<CompanyActionUnion> = createEffect(
25
+    () =>
26
+      this.companyActions.pipe(
27
+        ofType(CompanyActionTypes.CREATE_FORM_ADD_COMPANY),
28
+        map(() => new CreateFormAddCompanyActionSuccess({})),
29
+        catchError((err) => of(new CreateFormAddCompanyActionError(err)))
30
+      )
31
+  );
32
+
33
+  // save new company
34
+  saveNewCompany: Observable<CompanyActionUnion> = createEffect(() =>
35
+    this.companyActions.pipe(
36
+      ofType(CompanyActionTypes.SAVE_NEW_CAMPANY),
37
+      mergeMap((action: CompanyActionUnion) => {
38
+        return this.companyService.createCompanyService(action.payload).pipe(
39
+          map((company: Company) => new SaveNewCompanyActionSuccess(company)),
40
+          catchError((err) => of(new SaveNewCompanyActionError(err)))
41
+        );
42
+      })
43
+    )
44
+  );
45
+}

+ 26
- 0
src/app/ngrx/company/company.effects.delete.ts Просмотреть файл

@@ -0,0 +1,26 @@
1
+import { map, catchError } from 'rxjs/operators';
2
+import { CompanyActionTypes } from './company.action.type';
3
+import { CompanyActionUnion, DeleteCompanyActionSuccess, DeleteCompanyActionError } from './company.actions';
4
+import { Observable, mergeMap, of } from 'rxjs';
5
+import { Actions, createEffect, ofType } from '@ngrx/effects';
6
+import { CompanyService } from './../../shared/services/company.service';
7
+import { Injectable } from "@angular/core";
8
+
9
+@Injectable()
10
+export class CompanyDeleteEffect {
11
+
12
+  constructor(private companyService: CompanyService, private companyActions: Actions){}
13
+
14
+  //delete company effect
15
+  DeleteCompanyEffect: Observable<CompanyActionUnion> = createEffect(
16
+    ()=> this.companyActions.pipe(
17
+      ofType(CompanyActionTypes.DELETE_COMPANY),
18
+      mergeMap((action: CompanyActionUnion) =>{
19
+        return this.companyService.deleteCompany(action.payload.companyID).pipe(
20
+          map( ()=> new DeleteCompanyActionSuccess(action.payload)),
21
+          catchError( err => of( new DeleteCompanyActionError(err)) )
22
+        )
23
+      })
24
+    )
25
+  );
26
+}

+ 35
- 0
src/app/ngrx/company/company.effects.get.ts Просмотреть файл

@@ -0,0 +1,35 @@
1
+import { Company } from 'src/app/shared/models/company/company.model';
2
+import { catchError } from 'rxjs/operators';
3
+import { CompanyActionTypes } from './company.action.type';
4
+import {
5
+  CompanyActionUnion,
6
+  GetAllComapaniesActionSuccess,
7
+  GetAllComapaniesActionError,
8
+} from './company.actions';
9
+import { Observable, mergeMap, map, of } from 'rxjs';
10
+import { Actions, createEffect, ofType } from '@ngrx/effects';
11
+import { CompanyService } from './../../shared/services/company.service';
12
+import { Injectable } from '@angular/core';
13
+
14
+@Injectable()
15
+export class CompanyGetEffects {
16
+  constructor(
17
+    private companyService: CompanyService,
18
+    private companyActions: Actions
19
+  ) {}
20
+
21
+  geAllCompanyEffect: Observable<CompanyActionUnion> = createEffect(() =>
22
+    this.companyActions.pipe(
23
+      ofType(CompanyActionTypes.GET_ALL_COMPANIES),
24
+      mergeMap((action: CompanyActionUnion) => {
25
+        return this.companyService.getAllCompaniesService().pipe(
26
+          map(
27
+            (companies: Array<Company>) =>
28
+              new GetAllComapaniesActionSuccess(companies)
29
+          ),
30
+          catchError((err) => of(new GetAllComapaniesActionError(err)))
31
+        );
32
+      })
33
+    )
34
+  );
35
+}

+ 56
- 0
src/app/ngrx/company/company.effects.update.ts Просмотреть файл

@@ -0,0 +1,56 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { CompanyActionTypes } from './company.action.type';
3
+import {
4
+  CompanyActionUnion,
5
+  CreateFormUpdateCompanyActionSuccess,
6
+  CreateFormUpdateCompanyActionError,
7
+  UpdateCompanyActionSuccss,
8
+  UpdateCompanyActionError,
9
+} from './company.actions';
10
+import { Observable, mergeMap, of } from 'rxjs';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { CompanyService } from './../../shared/services/company.service';
13
+import { Injectable } from '@angular/core';
14
+import { Company } from 'src/app/shared/models/company/company.model';
15
+
16
+@Injectable()
17
+export class CompanyUpdateEffects {
18
+  constructor(
19
+    private companyService: CompanyService,
20
+    private companyActions: Actions
21
+  ) {}
22
+
23
+  //create form update company effect
24
+  createFormUpdateCompanyEffect: Observable<CompanyActionUnion> = createEffect(
25
+    () =>
26
+      this.companyActions.pipe(
27
+        ofType(CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY),
28
+        mergeMap((action: CompanyActionUnion) => {
29
+          return this.companyService
30
+            .getCompanyByIDService(action.payload.companyID)
31
+            .pipe(
32
+              map(
33
+                (company: Company) =>
34
+                  new CreateFormUpdateCompanyActionSuccess(company)
35
+              ),
36
+              catchError((err) =>
37
+                of(new CreateFormUpdateCompanyActionError(err))
38
+              )
39
+            );
40
+        })
41
+      )
42
+  );
43
+
44
+  //update company
45
+  updateCompanyEffect : Observable<CompanyActionUnion> = createEffect(
46
+    ()=> this.companyActions.pipe(
47
+      ofType(CompanyActionTypes.UPDATE_COMPANY),
48
+      mergeMap( (action: CompanyActionUnion) =>{
49
+        return this.companyService.updateCompanyService(action.payload).pipe(
50
+          map( (company: Company) => new UpdateCompanyActionSuccss(company)),
51
+          catchError( err => of (new UpdateCompanyActionError(err)) )
52
+        )
53
+      })
54
+    )
55
+  )
56
+}

+ 150
- 0
src/app/ngrx/company/company.reducer.ts Просмотреть файл

@@ -0,0 +1,150 @@
1
+import { CompanyActionTypes } from './company.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { CompanyActionUnion } from './company.actions';
4
+import { MsgState } from '../msg.state';
5
+import { CompanyState } from './company.state';
6
+import { Company } from 'src/app/shared/models/company/company.model';
7
+
8
+const companyInitState : CompanyState = {
9
+  currentCompany: null,
10
+  companiesList: [],
11
+  msgState: MsgState.INIT_STATE,
12
+  errorMsg: "no error"
13
+}
14
+
15
+export function companyReducer(state: CompanyState = companyInitState, action: Action): CompanyState{
16
+
17
+  switch(action.type){
18
+
19
+    case CompanyActionTypes.CREATE_FORM_ADD_COMPANY:
20
+      return {
21
+        ...state,
22
+        msgState: MsgState.FORM_LOADING
23
+      };
24
+    case CompanyActionTypes.CREATE_FORM_ADD_COMPANY_SUCCESS:
25
+      return{
26
+        ...state,
27
+        msgState:MsgState.FORM_LOADED
28
+      };
29
+    case CompanyActionTypes.CREATE_FORM_ADD_COMPANY_ERROR:
30
+      return {
31
+        ...state,
32
+        msgState:MsgState.ERR,
33
+        errorMsg: (<CompanyActionUnion> action).payload
34
+      };
35
+
36
+      //save new company
37
+    case CompanyActionTypes.SAVE_NEW_CAMPANY:
38
+      return {
39
+        ...state,
40
+        msgState: MsgState.ADD
41
+      };
42
+    case CompanyActionTypes.SAVE_NEW_CAMPANY_SUCCESS:
43
+      let newCompany: Company = (<CompanyActionUnion> action).payload;
44
+      let companiesListCopy1: Array<Company> = [...state.companiesList];
45
+      companiesListCopy1.push(newCompany);
46
+      return {
47
+        ...state,
48
+        msgState: MsgState.ADDED,
49
+        companiesList: companiesListCopy1,
50
+        currentCompany:newCompany
51
+      };
52
+    case CompanyActionTypes.SAVE_NEW_CAMPANY_ERROR:
53
+      return {
54
+        ...state,
55
+        msgState: MsgState.ERR,
56
+        errorMsg:(<CompanyActionUnion> action).payload
57
+      };
58
+
59
+    // get all companies
60
+    case CompanyActionTypes.GET_ALL_COMPANIES:
61
+      return {
62
+        ...state,
63
+        msgState: MsgState.LOADING
64
+      };
65
+    case CompanyActionTypes.GET_ALL_COMPANIES_SUCCESS:
66
+      let companiesListCopy2 : Array<Company> = (<CompanyActionUnion> action).payload;
67
+      return {
68
+        ...state,
69
+        msgState: MsgState.LOADED,
70
+        companiesList: companiesListCopy2
71
+      };
72
+    case CompanyActionTypes.GET_ALL_COMPANIES_ERROR:
73
+      return {
74
+        ...state,
75
+        msgState:MsgState.ERR,
76
+        errorMsg: (<CompanyActionUnion> action).payload
77
+      };
78
+
79
+    // create form to update company
80
+    case CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY:
81
+      return{
82
+        ...state,
83
+        msgState: MsgState.FORM_LOADING
84
+      };
85
+    case CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY_SUCCESS:
86
+      let companyToUpdate: Company = (<CompanyActionUnion>  action).payload;
87
+      return {
88
+        ...state,
89
+        msgState: MsgState.FORM_LOADED,
90
+        currentCompany:companyToUpdate
91
+      };
92
+    case CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY_ERROR:
93
+      return {
94
+        ...state,
95
+        msgState: MsgState.ERR,
96
+        errorMsg:(<CompanyActionUnion> action).payload
97
+      };
98
+
99
+    // update company
100
+    case CompanyActionTypes.UPDATE_COMPANY:
101
+      return {
102
+        ...state,
103
+        msgState:MsgState.UPDATE
104
+      };
105
+    case CompanyActionTypes.UPDATE_COMPANY_SUCCESS:
106
+      let updatedCompany: Company = (<CompanyActionUnion> action).payload;
107
+      let companiesListCopy3: Array<Company> = [...state.companiesList];
108
+      companiesListCopy3.map(
109
+        (company: Company) => (company.companyID==updatedCompany.companyID)?updatedCompany:company
110
+      );
111
+      return {
112
+        ...state,
113
+        msgState:MsgState.UPDATED,
114
+        companiesList: companiesListCopy3,
115
+        currentCompany: updatedCompany
116
+      };
117
+      case CompanyActionTypes.UPDATE_COMPANY_ERROR:
118
+        return {
119
+          ...state,
120
+          msgState: MsgState.ERR,
121
+          errorMsg:(<CompanyActionUnion> action).payload
122
+        };
123
+
124
+        //delete company
125
+      case CompanyActionTypes.DELETE_COMPANY:
126
+        return {
127
+          ...state,
128
+          msgState: MsgState.DELETE
129
+        };
130
+      case CompanyActionTypes.DELETE_COMPANY_SUCCESS:
131
+        let deletedCompany: Company = (<CompanyActionUnion> action).payload;
132
+        let indexDeletedCompany = state.companiesList.indexOf(deletedCompany);
133
+        let companiesListCopy4: Array<Company> = [...state.companiesList];
134
+        companiesListCopy4.splice(indexDeletedCompany,1);
135
+        return{
136
+          ...state,
137
+          msgState: MsgState.DELETED,
138
+          companiesList: companiesListCopy4,
139
+          currentCompany: deletedCompany
140
+        };
141
+      case CompanyActionTypes.DELETE_COMPANY_ERROR:
142
+        return{
143
+          ...state,
144
+          msgState: MsgState.ERR,
145
+          errorMsg:(<CompanyActionUnion> action).payload
146
+        };
147
+    default:
148
+      return {...state};
149
+  }
150
+}

+ 9
- 0
src/app/ngrx/company/company.state.ts Просмотреть файл

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

+ 19
- 0
src/app/ngrx/msg.state.ts Просмотреть файл

@@ -0,0 +1,19 @@
1
+export enum MsgState {
2
+  LOADING = 'LOADING ...',
3
+  LOADED = 'SUCCESSFUL LOADED',
4
+  ERR = 'ERROR ACCURRED',
5
+  INIT_STATE = 'INITIAL STATE',
6
+  FORM_LOADING = 'FORM LOADING',
7
+  FORM_LOADED = 'FORM LOADED',
8
+  FORM_LOAD_ERR= 'FORM LOADING ERROR',
9
+  CONFIRM_ADD = 'CONFIRM ADDING',
10
+  CONFIRM_UPDATE = 'CONFIRM UPDATE',
11
+  CONFIRM_DEL = 'CONFIRM DELETION',
12
+  ADD ='IS ADDING',
13
+  ADDED = 'SUCCESSFULLY ADDED',
14
+  EXIST = 'ALREADY EXISTS',
15
+  UPDATE = 'IS UPDATING',
16
+  UPDATED = ' SUCCESSFULLY UPDATED',
17
+  DELETE = 'DELETE',
18
+  DELETED = 'SUCCESSFULLY DELETED'
19
+}

+ 150
- 0
src/app/ngrx/project/project.action.ts Просмотреть файл

@@ -0,0 +1,150 @@
1
+import { ProjectActionTypes } from './project.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { Project } from 'src/app/shared/models/project/project.model';
4
+
5
+//create form to add project
6
+export class CreateFormAddProjectAction implements Action {
7
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_FORM_ADD_PROJECT;
8
+  constructor(public payload: any, public userID: any, public companyID: any) {}
9
+}
10
+export class CreateFormAddProjectActionSuccess implements Action {
11
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_FORM_ADD_PROJECT_SUCCESS;
12
+  constructor(public payload: any, public userID: any, public companyID: any) {}
13
+}
14
+export class CreateFormAddProjectActionError implements Action {
15
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_FORM_ADD_PROJECT_ERROR;
16
+  constructor(
17
+    public payload: string,
18
+    public userID: any,
19
+    public companyID: any
20
+  ) {}
21
+}
22
+
23
+// save new project
24
+export class SaveNewProjectAction implements Action {
25
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_NEW_PROJECT;
26
+  constructor(
27
+    public payload: Project
28
+  ) {}
29
+}
30
+export class SaveNewProjectActionSuccess implements Action {
31
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_NEW_PROJECT_SUCCESS;
32
+  constructor(
33
+    public payload: Project
34
+  ) {}
35
+}
36
+export class SaveNewProjectActionError implements Action {
37
+  type: ProjectActionTypes = ProjectActionTypes.SAVE_NEW_PROJECT_ERROR;
38
+  constructor(
39
+    public payload: string
40
+  ) {}
41
+}
42
+
43
+// get all projects action
44
+export class GetAllProjectAction implements Action {
45
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS;
46
+  constructor(
47
+    public payload: void
48
+  ) {}
49
+}
50
+export class GetAllProjectActionSuccess implements Action {
51
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS_SUCCESS;
52
+  constructor(
53
+    public payload: Array<Project>
54
+  ) {}
55
+}
56
+export class GetAllProjectActionError implements Action {
57
+  type: ProjectActionTypes = ProjectActionTypes.GET_ALL_PROJECTS_ERROR;
58
+  constructor(
59
+    public payload: string
60
+  ) {}
61
+}
62
+
63
+// create form update project
64
+export class CreateFormUpdatedProjectAction implements Action {
65
+  type: ProjectActionTypes = ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT;
66
+  constructor(
67
+    public payload: Project,
68
+    public userID: any,
69
+    public companyID: any
70
+  ) {}
71
+}
72
+export class CreateFormUpdatedProjectActionError implements Action {
73
+  type: ProjectActionTypes =
74
+    ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT_ERROR;
75
+  constructor(
76
+    public payload: string,
77
+    public userID: any,
78
+    public companyID: any
79
+  ) {}
80
+}
81
+export class CreateFormUpdatedProjectActionSuccess implements Action {
82
+  type: ProjectActionTypes =
83
+    ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT_SUCCCESS;
84
+  constructor(
85
+    public payload: Project,
86
+    public userID: any,
87
+    public companyID: any
88
+  ) {}
89
+}
90
+
91
+//update project
92
+export class UpdateProjectAction implements Action {
93
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT;
94
+  constructor(
95
+    public payload: Project
96
+  ) {}
97
+}
98
+export class UpdateProjectActionError implements Action {
99
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT_ERROR;
100
+  constructor(
101
+    public payload: string
102
+  ) {}
103
+}
104
+export class UpdateProjectActionSuccess implements Action {
105
+  type: ProjectActionTypes = ProjectActionTypes.UPDATE_PROJECT_SUCCESS;
106
+  constructor(
107
+    public payload: Project
108
+  ) {}
109
+}
110
+
111
+// delete project
112
+export class DeleteProjectAction implements Action{
113
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT;
114
+  constructor(
115
+    public payload: Project
116
+  ) {}
117
+}
118
+export class DeleteProjectActionSuccess implements Action{
119
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT_SUCCESS;
120
+  constructor(
121
+    public payload: Project
122
+  ) {}
123
+}
124
+export class DeleteProjectActionError implements Action{
125
+  type: ProjectActionTypes = ProjectActionTypes.DELETE_PROJECT_ERROR;
126
+  constructor(
127
+    public payload: string
128
+  ) {}
129
+}
130
+
131
+
132
+export type ProjectActionUnion =
133
+  | CreateFormAddProjectAction
134
+  | CreateFormAddProjectActionSuccess
135
+  | CreateFormAddProjectActionError
136
+  | SaveNewProjectAction
137
+  | SaveNewProjectActionSuccess
138
+  | SaveNewProjectActionError
139
+  | GetAllProjectAction
140
+  | GetAllProjectActionSuccess
141
+  | GetAllProjectActionError
142
+  | CreateFormUpdatedProjectAction
143
+  | CreateFormUpdatedProjectActionSuccess
144
+  | CreateFormUpdatedProjectActionError
145
+  | UpdateProjectAction
146
+  | UpdateProjectActionSuccess
147
+  | UpdateProjectActionError
148
+  | DeleteProjectAction
149
+  | DeleteProjectActionSuccess
150
+  | DeleteProjectActionError;

+ 25
- 0
src/app/ngrx/project/project.action.type.ts Просмотреть файл

@@ -0,0 +1,25 @@
1
+export enum ProjectActionTypes{
2
+  CREATE_FORM_ADD_PROJECT = "[Project] CREATE FORM ADD PROJECT",
3
+  CREATE_FORM_ADD_PROJECT_SUCCESS = "[Project] CREATE FORM ADD PROJECT SUCCESS",
4
+  CREATE_FORM_ADD_PROJECT_ERROR = "[Project] CREATE FORM ADD PROJECT ERROR",
5
+
6
+  SAVE_NEW_PROJECT = "[Project] SAVE NEW PROJECT",
7
+  SAVE_NEW_PROJECT_SUCCESS = "[Project] SAVE NEW PROJECT SUCCESS",
8
+  SAVE_NEW_PROJECT_ERROR = "[Project] SAVE NEW PROJECT ERROR",
9
+
10
+  GET_ALL_PROJECTS = "[Projects] GET ALL PROJECTS",
11
+  GET_ALL_PROJECTS_SUCCESS = "[Projects] GET ALL PROJECTS SUCCESS",
12
+  GET_ALL_PROJECTS_ERROR = "[Projects] GET ALL PROJECTS ERROR",
13
+
14
+  CREATE_FORM_UPDATE_PROJECT = "[Project] CREATE FORM UPDATE PROJECT",
15
+  CREATE_FORM_UPDATE_PROJECT_SUCCCESS = "[Project] CREATE FORM UPDATE PROJECT SUCCCESS",
16
+  CREATE_FORM_UPDATE_PROJECT_ERROR = "[Project] CREATE FORM UPDATE PROJECT ERROR",
17
+
18
+  UPDATE_PROJECT = "[Project] UPDATE PROJECT",
19
+  UPDATE_PROJECT_SUCCESS = "[Project] UPDATE PROJECT SUCCESS",
20
+  UPDATE_PROJECT_ERROR = "[Project] UPDATE PROJECT ERROR",
21
+
22
+  DELETE_PROJECT = "[Project] DELETE PROJECT",
23
+  DELETE_PROJECT_SUCCESS = "[Project] DELETE PROJECT SUCCESS",
24
+  DELETE_PROJECT_ERROR = "[Project] DELETE PROJECT ERROR"
25
+}

+ 60
- 0
src/app/ngrx/project/project.effects.create.ts Просмотреть файл

@@ -0,0 +1,60 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { ProjectActionTypes } from './project.action.type';
3
+import {
4
+  ProjectActionUnion,
5
+  CreateFormAddProjectActionSuccess,
6
+  CreateFormAddProjectActionError,
7
+  SaveNewProjectActionSuccess,
8
+  SaveNewProjectActionError,
9
+} from './project.action';
10
+import { Observable, of, mergeMap } from 'rxjs';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { ProjectService } from './../../shared/services/project.service';
13
+import { Injectable } from '@angular/core';
14
+import { Project } from 'src/app/shared/models/project/project.model';
15
+
16
+@Injectable()
17
+export class ProjectCreateEffects {
18
+  constructor(
19
+    private projectService: ProjectService,
20
+    private projectActions: Actions
21
+  ) {}
22
+
23
+  //create form to add new project
24
+  createFormAddProjectEffect: Observable<ProjectActionUnion> = createEffect(
25
+    () =>
26
+      this.projectActions.pipe(
27
+        ofType(ProjectActionTypes.CREATE_FORM_ADD_PROJECT),
28
+        map(() => new CreateFormAddProjectActionSuccess({}, {}, {})),
29
+        catchError((err) =>
30
+          of(new CreateFormAddProjectActionError(err, {}, {}))
31
+        )
32
+      )
33
+  );
34
+
35
+  //save new project
36
+  saveNewProjectEffect: Observable<ProjectActionUnion> = createEffect(() =>
37
+    this.projectActions.pipe(
38
+      ofType(ProjectActionTypes.SAVE_NEW_PROJECT),
39
+      mergeMap((action: ProjectActionUnion) => {
40
+        return this.projectService
41
+          .createProjectService(action.payload)
42
+          .pipe(
43
+            map(
44
+              (project: Project) =>
45
+                new SaveNewProjectActionSuccess(
46
+                  project
47
+                )
48
+            ),
49
+            catchError((err) =>
50
+              of(
51
+                new SaveNewProjectActionError(
52
+                  err
53
+                )
54
+              )
55
+            )
56
+          );
57
+      })
58
+    )
59
+  );
60
+}

+ 26
- 0
src/app/ngrx/project/project.effects.delete.ts Просмотреть файл

@@ -0,0 +1,26 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { ProjectActionTypes } from './project.action.type';
3
+import { ProjectActionUnion, DeleteProjectActionSuccess, DeleteProjectActionError } from './project.action';
4
+import { Observable, mergeMap, of } from 'rxjs';
5
+import { ProjectService } from './../../shared/services/project.service';
6
+import { Actions, createEffect, ofType } from '@ngrx/effects';
7
+import { Injectable } from "@angular/core";
8
+
9
+@Injectable()
10
+export class ProjectDeleteEffect {
11
+
12
+  constructor(private projectActions: Actions, private projectService: ProjectService){}
13
+
14
+  //delete project effect
15
+  deleteProjectEffect : Observable<ProjectActionUnion> = createEffect(
16
+    ()=> this.projectActions.pipe(
17
+      ofType(ProjectActionTypes.DELETE_PROJECT),
18
+      mergeMap((action: ProjectActionUnion)=>{
19
+        return this.projectService.deleteProject(action.payload.projectID).pipe(
20
+          map( ()=> new DeleteProjectActionSuccess(action.payload)),
21
+          catchError(err => of(new DeleteProjectActionError(err)))
22
+        )
23
+      })
24
+    )
25
+  )
26
+}

+ 29
- 0
src/app/ngrx/project/project.effects.get.ts Просмотреть файл

@@ -0,0 +1,29 @@
1
+import { catchError } from 'rxjs/operators';
2
+import { Project } from 'src/app/shared/models/project/project.model';
3
+import { ProjectActionTypes } from './project.action.type';
4
+import { ProjectActionUnion, GetAllProjectActionSuccess, GetAllProjectActionError } from './project.action';
5
+import { Observable, mergeMap, map, of } from 'rxjs';
6
+import { Actions, createEffect, ofType } from '@ngrx/effects';
7
+import { ProjectService } from './../../shared/services/project.service';
8
+import { Injectable } from '@angular/core';
9
+
10
+@Injectable()
11
+export class ProjectGetEffects {
12
+  constructor(
13
+    private projectService: ProjectService,
14
+    private projectActions: Actions
15
+  ) {}
16
+
17
+  // get all project effect
18
+  getAllProjectEffect : Observable<ProjectActionUnion> = createEffect(
19
+    ()=> this.projectActions.pipe(
20
+      ofType(ProjectActionTypes.GET_ALL_PROJECTS),
21
+      mergeMap( (action: ProjectActionUnion) =>{
22
+        return this.projectService.getAllProjectsService().pipe(
23
+          map ( (projects: Array<Project>) => new GetAllProjectActionSuccess(projects)),
24
+          catchError( err => of(new GetAllProjectActionError(err)))
25
+        )
26
+      })
27
+    )
28
+  );
29
+}

+ 59
- 0
src/app/ngrx/project/project.effects.update.ts Просмотреть файл

@@ -0,0 +1,59 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { ProjectActionTypes } from './project.action.type';
3
+import {
4
+  ProjectActionUnion,
5
+  CreateFormUpdatedProjectActionSuccess,
6
+  CreateFormUpdatedProjectActionError,
7
+  UpdateProjectActionSuccess,
8
+  UpdateProjectActionError,
9
+} from './project.action';
10
+import { Observable, mergeMap, of } from 'rxjs';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { ProjectService } from './../../shared/services/project.service';
13
+import { Injectable } from '@angular/core';
14
+import { Project } from 'src/app/shared/models/project/project.model';
15
+
16
+@Injectable()
17
+export class ProjectUpdateEffect {
18
+  constructor(
19
+    private projectService: ProjectService,
20
+    private projectActions: Actions
21
+  ) {}
22
+
23
+  //create form to update project
24
+  createFormUpdateProject: Observable<ProjectActionUnion> = createEffect(() =>
25
+    this.projectActions.pipe(
26
+      ofType(ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT),
27
+      mergeMap((action: ProjectActionUnion) => {
28
+        return this.projectService
29
+          .getProjectByIDService(action.payload.projectID)
30
+          .pipe(
31
+            map(
32
+              (project: Project) =>
33
+                new CreateFormUpdatedProjectActionSuccess(project, {}, {})
34
+            ),
35
+            catchError((err) =>
36
+              of(new CreateFormUpdatedProjectActionError(err, {}, {}))
37
+            )
38
+          );
39
+      })
40
+    )
41
+  );
42
+
43
+  // update project
44
+  updateProjectEffect: Observable<ProjectActionUnion> = createEffect(() =>
45
+    this.projectActions.pipe(
46
+      ofType(ProjectActionTypes.UPDATE_PROJECT),
47
+      mergeMap((action: ProjectActionUnion) => {
48
+        return this.projectService
49
+          .updateProjectService(action.payload)
50
+          .pipe(
51
+            map((project: Project) =>new UpdateProjectActionSuccess(project)
52
+            ),
53
+            catchError(err=> of (new UpdateProjectActionError(err)))
54
+          );
55
+      })
56
+    )
57
+  );
58
+
59
+}

+ 151
- 0
src/app/ngrx/project/project.reducer.ts Просмотреть файл

@@ -0,0 +1,151 @@
1
+import { ProjectActionTypes } from './project.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { MsgState } from '../msg.state';
4
+import { ProjectState } from './project.state';
5
+import { ProjectActionUnion } from './project.action';
6
+import { Project } from 'src/app/shared/models/project/project.model';
7
+
8
+
9
+const projectInitState: ProjectState = {
10
+  currestProject: null,
11
+  projectsList: [],
12
+  msgState: MsgState.INIT_STATE,
13
+  errorMsg: 'no error'
14
+};
15
+
16
+export function projectReducer(state: ProjectState = projectInitState, action: Action): ProjectState{
17
+
18
+  switch(action.type){
19
+
20
+    //create form to add project
21
+    case ProjectActionTypes.CREATE_FORM_ADD_PROJECT:
22
+      return {
23
+        ...state,
24
+        msgState: MsgState.FORM_LOADING,
25
+      };
26
+    case ProjectActionTypes.CREATE_FORM_ADD_PROJECT_ERROR:
27
+      return {
28
+        ...state,
29
+        msgState: MsgState.ERR,
30
+        errorMsg:(<ProjectActionUnion> action).payload
31
+      };
32
+    case ProjectActionTypes.CREATE_FORM_ADD_PROJECT_SUCCESS:
33
+      return {
34
+        ...state,
35
+        msgState: MsgState.FORM_LOADED
36
+      };
37
+
38
+      //save new project
39
+    case ProjectActionTypes.SAVE_NEW_PROJECT:
40
+      return {
41
+        ...state,
42
+        msgState: MsgState.ADD
43
+      };
44
+    case ProjectActionTypes.SAVE_NEW_PROJECT_SUCCESS:
45
+      let newProject: Project = (<ProjectActionUnion> action).payload;
46
+      let projectsListCopy1: Array<Project> = [...state.projectsList];
47
+      projectsListCopy1.push(newProject);
48
+      return {
49
+        ...state,
50
+        msgState: MsgState.ADDED,
51
+        projectsList: projectsListCopy1,
52
+        currestProject: newProject
53
+      };
54
+
55
+    //get all projects
56
+    case ProjectActionTypes.GET_ALL_PROJECTS:
57
+      return {
58
+        ...state,
59
+        msgState: MsgState.LOADING
60
+      };
61
+    case ProjectActionTypes.GET_ALL_PROJECTS_SUCCESS:
62
+      let projectsListCopy2: Array<Project> = (<ProjectActionUnion> action).payload;
63
+      return {
64
+        ...state,
65
+        msgState:MsgState.LOADED,
66
+        projectsList: projectsListCopy2
67
+      };
68
+    case ProjectActionTypes.GET_ALL_PROJECTS_ERROR:
69
+      return {
70
+        ...state,
71
+        msgState: MsgState.ERR,
72
+        errorMsg:(<ProjectActionUnion> action).payload
73
+      };
74
+
75
+     // create form to update project
76
+    case ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT:
77
+      return {
78
+        ...state,
79
+        msgState: MsgState.FORM_LOADING
80
+      };
81
+    case ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT_SUCCCESS:
82
+      let projectToUpdate: Project = (<ProjectActionUnion> action).payload
83
+      return {
84
+        ...state,
85
+        msgState: MsgState.FORM_LOADED,
86
+        currestProject: projectToUpdate
87
+      };
88
+    case ProjectActionTypes.CREATE_FORM_UPDATE_PROJECT_ERROR:
89
+      let err: string = (<ProjectActionUnion> action).payload;
90
+      return {
91
+        ...state,
92
+        msgState: MsgState.ERR,
93
+        errorMsg:err
94
+      };
95
+
96
+    // update project
97
+    case ProjectActionTypes.UPDATE_PROJECT:
98
+      return {
99
+        ...state,
100
+        msgState: MsgState.UPDATE,
101
+      };
102
+    case ProjectActionTypes.UPDATE_PROJECT_SUCCESS:
103
+      let updatedProject : Project = (<ProjectActionUnion> action).payload;
104
+      let projectsListCopy3: Array<Project> = [...state.projectsList];
105
+      projectsListCopy3.map((project: Project)=>{
106
+        project.projectID === updatedProject.projectID?updatedProject:project;
107
+      })
108
+      return {
109
+        ...state,
110
+        msgState:MsgState.UPDATED,
111
+        currestProject: updatedProject,
112
+        projectsList: projectsListCopy3
113
+      };
114
+    case ProjectActionTypes.UPDATE_PROJECT_ERROR:
115
+      let returnedError: string=(<ProjectActionUnion> action).payload;
116
+      return {
117
+        ...state,
118
+        msgState:MsgState.ERR,
119
+        errorMsg:returnedError
120
+      };
121
+
122
+    // delete project
123
+    case ProjectActionTypes.DELETE_PROJECT:
124
+      return {
125
+        ...state,
126
+        msgState: MsgState.DELETE
127
+      };
128
+    case ProjectActionTypes.DELETE_PROJECT_SUCCESS:
129
+      let deletedProject: Project =(<ProjectActionUnion> action).payload;
130
+      let indexDeleteProj = state.projectsList.indexOf(deletedProject);
131
+      let projectsListCopy4: Array<Project> =[... state.projectsList];
132
+      projectsListCopy4 = projectsListCopy4.splice(indexDeleteProj,1);
133
+      return {
134
+        ...state,
135
+        msgState: MsgState.DELETED,
136
+        currestProject: deletedProject,
137
+        projectsList: projectsListCopy4
138
+      };
139
+    case ProjectActionTypes.DELETE_PROJECT_ERROR:
140
+      return {
141
+        ...state,
142
+        msgState: MsgState.ERR,
143
+        errorMsg: (<ProjectActionUnion> action).payload
144
+      };
145
+    default:
146
+      return {...state};
147
+
148
+    // get projects assigned to user ID
149
+
150
+  }
151
+}

+ 8
- 0
src/app/ngrx/project/project.state.ts Просмотреть файл

@@ -0,0 +1,8 @@
1
+import { MsgState } from 'src/app/ngrx/msg.state';
2
+import { Project } from 'src/app/shared/models/project/project.model';
3
+export class ProjectState{
4
+  currestProject!: Project | null;
5
+  projectsList!: Array<Project>;
6
+  msgState!: MsgState;
7
+  errorMsg!: string;
8
+}

+ 101
- 0
src/app/ngrx/user-s-address/address.action.ts Просмотреть файл

@@ -0,0 +1,101 @@
1
+import { AddressActionTypes } from './address.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { Address } from 'src/app/shared/models/user/address.model';
4
+
5
+export class GetAllAddressesAction implements Action {
6
+  type: AddressActionTypes = AddressActionTypes.GET_ALL_ADDRESSES;
7
+  constructor(public payload: any) {}
8
+}
9
+export class GetAllAddressesActionSuccess implements Action {
10
+  type: AddressActionTypes = AddressActionTypes.GET_ALL_ADDRESSES_SUCCESS;
11
+  constructor(public payload: Array<Address>) {}
12
+}
13
+export class GetAllAddressesActionError implements Action {
14
+  type: AddressActionTypes = AddressActionTypes.GET_ALL_ADDRESSES_ERROR;
15
+  constructor(public payload: string) {}
16
+}
17
+
18
+export class CreateFormAddAddressAction implements Action {
19
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_ADD_ADDRESS;
20
+  constructor(public payload: void) {}
21
+}
22
+export class CreateFormAddAddressActionSuccess implements Action {
23
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_ADD_ADDRESS_SUCCESS;
24
+  constructor(public payload: any) {}
25
+}
26
+export class CreateFormAddAddressActionError implements Action {
27
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_ADD_ADDRESS_ERROR;
28
+  constructor(public payload: string) {}
29
+}
30
+
31
+export class SaveNewAddressAction implements Action {
32
+  type: AddressActionTypes = AddressActionTypes.SAVE_NEW_ADDRESS;
33
+  constructor(public payload: Address) {}
34
+}
35
+export class SaveNewAddressActionSuccess implements Action {
36
+  type: AddressActionTypes = AddressActionTypes.SAVE_NEW_ADDRESS_SUCCESS;
37
+  constructor(public payload: Address) {}
38
+}
39
+export class SaveNewAddressActionError implements Action {
40
+  type: AddressActionTypes = AddressActionTypes.SAVE_NEW_ADDRESS_ERROR;
41
+  constructor(public payload: string) {}
42
+}
43
+
44
+export class CreateFormUpdateAddressAction implements Action{
45
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS;
46
+  constructor(public payload: Address){}
47
+}
48
+export class CreateFormUpdateAddressActionSuccess implements Action{
49
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS_SUCCESS;
50
+  constructor(public payload: Address){}
51
+}
52
+export class CreateFormUpdateAddressActionError implements Action{
53
+  type: AddressActionTypes = AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS_ERROR;
54
+  constructor(public payload: string){}
55
+}
56
+
57
+export class UpdateAddressAction implements Action{
58
+  type: AddressActionTypes = AddressActionTypes.UPDATE_ADDRESS;
59
+  constructor(public payload: Address){}
60
+}
61
+export class UpdateAddressActionSuccess implements Action{
62
+  type: AddressActionTypes = AddressActionTypes.UPDATE_ADDRESS_SUCCESS;
63
+  constructor(public payload: Address){}
64
+}
65
+export class UpdateAddressActionError implements Action{
66
+  type: AddressActionTypes = AddressActionTypes.UPDATE_ADDRESS_ERROR;
67
+  constructor(public payload: string){}
68
+}
69
+
70
+export class DeleteAddressAction implements Action{
71
+  type: AddressActionTypes = AddressActionTypes.DELETE_ADDRESS;
72
+  constructor(public payload: Address){}
73
+}
74
+export class DeleteAddressActionSuccess implements Action{
75
+  type: AddressActionTypes = AddressActionTypes.DELETE_ADDRESS_SUCCESS;
76
+  constructor(public payload: Address){}
77
+}
78
+export class DeleteAddressActionError implements Action{
79
+  type: AddressActionTypes = AddressActionTypes.DELETE_ADDRESS_ERROR;
80
+  constructor(public payload: string){}
81
+}
82
+
83
+export type AddressActionUnion =
84
+  | GetAllAddressesAction
85
+  | GetAllAddressesActionSuccess
86
+  | GetAllAddressesActionError
87
+  | CreateFormAddAddressAction
88
+  | CreateFormAddAddressActionSuccess
89
+  | CreateFormAddAddressActionError
90
+  | SaveNewAddressAction
91
+  | SaveNewAddressActionSuccess
92
+  | SaveNewAddressActionError
93
+  | CreateFormUpdateAddressAction
94
+  | CreateFormUpdateAddressActionSuccess
95
+  | CreateFormUpdateAddressActionError
96
+  | UpdateAddressAction
97
+  | UpdateAddressActionSuccess
98
+  | UpdateAddressActionError
99
+  | DeleteAddressAction
100
+  | DeleteAddressActionSuccess
101
+  | DeleteAddressActionError;

+ 26
- 0
src/app/ngrx/user-s-address/address.action.type.ts Просмотреть файл

@@ -0,0 +1,26 @@
1
+export enum AddressActionTypes{
2
+
3
+  GET_ALL_ADDRESSES = "[Address] GET ALL ADDRESSES",
4
+  GET_ALL_ADDRESSES_SUCCESS = "[Address] GET ALL ADDRESSES SUCCESS",
5
+  GET_ALL_ADDRESSES_ERROR = "[Address] GET ALL ADDRESSES ERROR",
6
+
7
+  CREATE_FORM_ADD_ADDRESS = "[Address] CREATE FORM ADD ADDRESS",
8
+  CREATE_FORM_ADD_ADDRESS_SUCCESS = "[Address] CREATE FORM ADD ADDRESS SUCCESS",
9
+  CREATE_FORM_ADD_ADDRESS_ERROR= "[Address] CREATE FORM ADD ADDRESS ERROR",
10
+
11
+  SAVE_NEW_ADDRESS = "[Address] SAVE NEW ADDRESS",
12
+  SAVE_NEW_ADDRESS_SUCCESS = "[Address] SAVE NEW ADDRESS SUCCESS",
13
+  SAVE_NEW_ADDRESS_ERROR = "[Address] SAVE NEW ADDRESS ERROR",
14
+
15
+  CREATE_FORM_UPDATE_ADDRESS = "[Address] CREATE FORM UPDATE ADDRESS",
16
+  CREATE_FORM_UPDATE_ADDRESS_SUCCESS = "[Address] CREATE FORM UPDATE ADDRESS SUCCESS",
17
+  CREATE_FORM_UPDATE_ADDRESS_ERROR = "[Address] CREATE  FORM UPDATE ADDRESS ERROR",
18
+
19
+  UPDATE_ADDRESS ="[Address] UPDATE ADDRESS",
20
+  UPDATE_ADDRESS_SUCCESS ="[Address] UPDATE ADDRESS SUCCESS",
21
+  UPDATE_ADDRESS_ERROR ="[Address] UPDATE ADDRESS ERROR",
22
+
23
+  DELETE_ADDRESS ="[Address] DELETEADDRESS",
24
+  DELETE_ADDRESS_SUCCESS ="[Address] DELETEADDRESS SUCCESS",
25
+  DELETE_ADDRESS_ERROR ="[Address] DELETEADDRESS ERROR",
26
+}

+ 103
- 0
src/app/ngrx/user-s-address/address.effects.ts Просмотреть файл

@@ -0,0 +1,103 @@
1
+import { catchError } from 'rxjs/operators';
2
+import { AddressActionTypes } from './address.action.type';
3
+import {
4
+  AddressActionUnion,
5
+  GetAllAddressesActionSuccess,
6
+  GetAllAddressesActionError,
7
+  CreateFormAddAddressActionSuccess,
8
+  CreateFormAddAddressActionError,
9
+  SaveNewAddressActionSuccess,
10
+  SaveNewAddressActionError,
11
+  CreateFormUpdateAddressActionSuccess,
12
+  CreateFormUpdateAddressActionError,
13
+  UpdateAddressActionSuccess,
14
+  UpdateAddressActionError,
15
+  DeleteAddressActionError,
16
+  DeleteAddressActionSuccess,
17
+} from './address.action';
18
+import { Observable, mergeMap, map, of } from 'rxjs';
19
+import { Actions, createEffect, ofType } from '@ngrx/effects';
20
+import { AddressService } from '../../shared/services/address.service';
21
+import { Injectable } from '@angular/core';
22
+import { Address } from 'src/app/shared/models/user/address.model';
23
+
24
+@Injectable()
25
+export class AddressEffects {
26
+  constructor(
27
+    private addressService: AddressService,
28
+    private addressActions: Actions
29
+  ) {}
30
+
31
+  getAllAddressEffect: Observable<AddressActionUnion> = createEffect(() =>
32
+    this.addressActions.pipe(
33
+      ofType(AddressActionTypes.GET_ALL_ADDRESSES),
34
+      mergeMap((action: AddressActionUnion) => {
35
+        return this.addressService.getAllAddressesService().pipe(
36
+          map(
37
+            (addresses: Array<Address>) =>
38
+              new GetAllAddressesActionSuccess(addresses)
39
+          ),
40
+          catchError((err) => of(new GetAllAddressesActionError(err)))
41
+        );
42
+      })
43
+    )
44
+  );
45
+
46
+  createFormAddAddressEffect : Observable<AddressActionUnion> = createEffect(
47
+    ()=> this.addressActions.pipe(
48
+      ofType(AddressActionTypes.CREATE_FORM_ADD_ADDRESS),
49
+      map((action: AddressActionUnion) => new CreateFormAddAddressActionSuccess({})),
50
+      catchError(err => of(new CreateFormAddAddressActionError(err)))
51
+
52
+    )
53
+  );
54
+
55
+  saveNewAddressEffect: Observable<AddressActionUnion> = createEffect(
56
+    ()=> this.addressActions.pipe(
57
+      ofType(AddressActionTypes.SAVE_NEW_ADDRESS),
58
+      mergeMap((action:AddressActionUnion)=>{
59
+        return this.addressService.createAddressService(action.payload).pipe(
60
+          map((address: Address) => new SaveNewAddressActionSuccess(address)),
61
+          catchError(err => of(new SaveNewAddressActionError(err)))
62
+        )
63
+      })
64
+    )
65
+  );
66
+
67
+  createFormUpdateAddressEffect : Observable<AddressActionUnion> = createEffect(
68
+    ()=> this.addressActions.pipe(
69
+      ofType(AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS),
70
+      mergeMap((action: AddressActionUnion)=>{
71
+        return this.addressService.getAddressByIDService(action.payload.addressID).pipe(
72
+          map ((address: Address)=> new CreateFormUpdateAddressActionSuccess(address)),
73
+          catchError(err=> of(new CreateFormUpdateAddressActionError(err)))
74
+        )
75
+      })
76
+    )
77
+  );
78
+
79
+  updateAddressEffect : Observable<AddressActionUnion> = createEffect(
80
+    ()=> this.addressActions.pipe(
81
+      ofType(AddressActionTypes.UPDATE_ADDRESS),
82
+      mergeMap( (action: AddressActionUnion)=>{
83
+        return this.addressService.updateAddressService(action.payload).pipe(
84
+          map((address: Address)=> new UpdateAddressActionSuccess(address)),
85
+          catchError(err=> of(new UpdateAddressActionError(err)))
86
+        )
87
+      })
88
+    )
89
+  );
90
+
91
+  deleteUserEffect: Observable<AddressActionUnion> = createEffect(() =>
92
+    this.addressActions.pipe(
93
+      ofType(AddressActionTypes.DELETE_ADDRESS),
94
+      mergeMap((action: AddressActionUnion) => {
95
+        return this.addressService.deleteAddressService(action.payload.addressID).pipe(
96
+          map(() => new DeleteAddressActionSuccess(action.payload)),
97
+          catchError((err) => of(new DeleteAddressActionError(err)))
98
+        );
99
+      })
100
+    )
101
+  );
102
+
103
+}

+ 146
- 0
src/app/ngrx/user-s-address/address.reducer.ts Просмотреть файл

@@ -0,0 +1,146 @@
1
+import { AddressActionTypes } from './address.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { MsgState } from '../msg.state';
4
+import { AddressState } from './address.state';
5
+import { AddressActionUnion } from './address.action';
6
+import { Address } from 'src/app/shared/models/user/address.model';
7
+
8
+const addressInitialState: AddressState = {
9
+  currentAddress: null,
10
+  msgState: MsgState.INIT_STATE,
11
+  addressesList: [],
12
+  errorMsg: 'no error',
13
+};
14
+
15
+export function addressReducer(
16
+  state: AddressState = addressInitialState,
17
+  action: Action
18
+): AddressState {
19
+  switch (action.type) {
20
+
21
+    //get all addresses
22
+    case AddressActionTypes.GET_ALL_ADDRESSES:
23
+      return {
24
+        ...state,
25
+        msgState: MsgState.LOADING,
26
+      };
27
+    case AddressActionTypes.GET_ALL_ADDRESSES_SUCCESS:
28
+      return {
29
+        ...state,
30
+        msgState: MsgState.LOADED,
31
+        addressesList: (<AddressActionUnion>action).payload,
32
+      };
33
+    case AddressActionTypes.GET_ALL_ADDRESSES_ERROR:
34
+      return {
35
+        ...state,
36
+        msgState: MsgState.ERR,
37
+        errorMsg: (<AddressActionUnion>action).payload,
38
+      };
39
+
40
+    // create form to add new address
41
+    case AddressActionTypes.CREATE_FORM_ADD_ADDRESS:
42
+      return {
43
+        ...state,
44
+        msgState: MsgState.FORM_LOADING,
45
+      };
46
+    case AddressActionTypes.CREATE_FORM_ADD_ADDRESS_SUCCESS:
47
+      return {
48
+        ...state,
49
+        msgState: MsgState.FORM_LOADED,
50
+      };
51
+    case AddressActionTypes.CREATE_FORM_ADD_ADDRESS_ERROR:
52
+      return {
53
+        ...state,
54
+        msgState: MsgState.ERR,
55
+        errorMsg: (<AddressActionUnion>action).payload,
56
+      };
57
+
58
+    // save new address
59
+    case AddressActionTypes.SAVE_NEW_ADDRESS:
60
+      return {
61
+        ...state,
62
+        msgState: MsgState.ADD,
63
+      };
64
+    case AddressActionTypes.SAVE_NEW_ADDRESS_SUCCESS:
65
+      let newAddress: Address = (<AddressActionUnion>action).payload;
66
+      let addressesListCopy1 = [...state.addressesList];
67
+      addressesListCopy1.push(newAddress);
68
+      return {
69
+        ...state,
70
+        msgState: MsgState.ADDED,
71
+      };
72
+    case AddressActionTypes.SAVE_NEW_ADDRESS_ERROR:
73
+      return {
74
+        ...state,
75
+        msgState: MsgState.ERR,
76
+        errorMsg: (<AddressActionUnion>action).payload,
77
+      };
78
+
79
+    // create form to update address
80
+    case AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS:
81
+      return {
82
+        ...state,
83
+        msgState: MsgState.FORM_LOADING,
84
+      };
85
+    case AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS_SUCCESS:
86
+      let addressToUpdate: Address = (<AddressActionUnion> action).payload;
87
+      return {
88
+        ...state,
89
+        msgState: MsgState.FORM_LOADED,
90
+        currentAddress:addressToUpdate
91
+      };
92
+    case AddressActionTypes.CREATE_FORM_UPDATE_ADDRESS_ERROR:
93
+      return {
94
+        ...state,
95
+        msgState: MsgState.ERR,
96
+        errorMsg: (<AddressActionUnion>action).payload,
97
+      };
98
+
99
+    //update address
100
+    case AddressActionTypes.UPDATE_ADDRESS:
101
+      return {
102
+        ...state,
103
+        msgState: MsgState.UPDATE,
104
+      };
105
+    case AddressActionTypes.UPDATE_ADDRESS_SUCCESS:
106
+      let updatedAddress: Address = (<AddressActionUnion>action).payload;
107
+      let addressesListCopy2: Array<Address> = [...state.addressesList];
108
+      addressesListCopy2.map((address) =>
109
+        address.addressID == updatedAddress.addressID ? updatedAddress : address
110
+      );
111
+      return{
112
+        ...state,
113
+        msgState: MsgState.UPDATED,
114
+        addressesList: addressesListCopy2
115
+      };
116
+    case AddressActionTypes.UPDATE_ADDRESS_ERROR:
117
+      return{
118
+        ...state,
119
+        msgState:MsgState.ERR,
120
+        errorMsg: (<AddressActionUnion>action).payload,
121
+      };
122
+
123
+    // delete address
124
+    case AddressActionTypes.DELETE_ADDRESS:
125
+      return{
126
+        ...state,
127
+        msgState:MsgState.DELETE,
128
+        currentAddress: (<AddressActionUnion>action).payload
129
+      };
130
+    case AddressActionTypes.DELETE_ADDRESS_SUCCESS:
131
+      let deletedAddress : Address = (<AddressActionUnion> action).payload;
132
+      let deletedAddressIndex = state.addressesList.indexOf(deletedAddress);
133
+      let addressesListCopy3 : Array<Address> = [...state.addressesList];
134
+      addressesListCopy3.splice(deletedAddressIndex,1);
135
+
136
+      return{
137
+        ...state,
138
+        msgState:MsgState.DELETED,
139
+        addressesList: addressesListCopy3,
140
+        currentAddress: deletedAddress
141
+      };
142
+
143
+    default:
144
+      return { ...state };
145
+  }
146
+}

+ 9
- 0
src/app/ngrx/user-s-address/address.state.ts Просмотреть файл

@@ -0,0 +1,9 @@
1
+import { MsgState } from '../msg.state';
2
+import { Address } from '../../shared/models/user/address.model';
3
+export class AddressState{
4
+
5
+  currentAddress!: Address | null;
6
+  msgState!: MsgState;
7
+  addressesList!: Array<Address>;
8
+  errorMsg!: string;
9
+}

+ 29
- 0
src/app/ngrx/user/user.action.type.ts Просмотреть файл

@@ -0,0 +1,29 @@
1
+export enum UserActionTypes {
2
+  GET_ALL_USERS = '[User] GET ALL USERS',
3
+  GET_ALL_USERS_SUCCESS = '[User] GET ALL USERS SUCCESS',
4
+  GET_ALL_USERS_ERROR = '[User] GET ALL USERS ERROR',
5
+
6
+  CREATE_FORM_ADD_USER = '[User] CREATE FORM ADD USER',
7
+  CREATE_FORM_ADD_USER_SUCCESS = '[User] CREATE FORM ADD USER SUCCESS',
8
+  CREATE_FORM_ADD_USER_ERROR = '[User] CREATE FORM ADD USER ERROR',
9
+
10
+  SAVE_NEW_USER = ' [User] SAVE NEW USER',
11
+  SAVE_NEW_USER_SUCCESS = ' [User] SAVE USER NEW SUCCESS',
12
+  SAVE_NEW_USER_ERROR = ' [User] SAVE USER NEW ERROR',
13
+
14
+  DELETE_USER = '[User] DELETE USER',
15
+  DELETE_USER_SUCCCESS = '[User] DELETE USER SUCCCESS',
16
+  DELETE_USER_ERROR = '[User] DELETE USER ERROR',
17
+
18
+  CREATE_FORM_UPDATE_USER = '[User] CREATE_FORM UPDATE USER',
19
+  CREATE_FORM_UPDATE_USER_SUCCESS = '[User] CREATE FORM UPDATE USER SUCCESS',
20
+  CREATE_FORM_UPDATE_USER_ERROR = '[User] CREATE FORM UPDATE USER ERROR',
21
+
22
+  UPDATE_USER = '[User] UPDATE USER',
23
+  UPDATE_USER_SUCCESS = '[User] UPDATE USER SUCCESS',
24
+  UPDATE_USER_ERROR = '[User] UPDATE USER ERROR',
25
+
26
+  GET_PROJECTS_BY_USER = '[User] GET PROJECTS ASSIGNED TO USER',
27
+  GET_PROJECTS_BY_USER_SUCCESS = '[User] GET PROJECTS ASSIGNED TO USER SUCCESS',
28
+  GET_PROJECTS_BY_USER_ERROR = '[User] GET PROJECTS ASSIGNED TO USER ERROR',
29
+}

+ 123
- 0
src/app/ngrx/user/user.actions.ts Просмотреть файл

@@ -0,0 +1,123 @@
1
+import { UserActionTypes } from './user.action.type';
2
+import { Action } from '@ngrx/store';
3
+import { User } from 'src/app/shared/models/user/user.model';
4
+import { Project } from 'src/app/shared/models/project/project.model';
5
+
6
+//get all user action
7
+export class GetAllUsersAction implements Action {
8
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS;
9
+  constructor(public payload: any, public addressID: any) {}
10
+}
11
+export class GetAllUsersActionSuccess implements Action {
12
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS_SUCCESS;
13
+  constructor(public payload: Array<User>, public addressID: any) {}
14
+}
15
+export class GetAllUsersActionError implements Action {
16
+  type: UserActionTypes = UserActionTypes.GET_ALL_USERS_ERROR;
17
+  constructor(public payload: string, public addressID: any) {}
18
+}
19
+
20
+//form to add new user action
21
+export class CreateFormAddUserAction implements Action {
22
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER;
23
+  constructor(public payload: any, public addressID: any) {}
24
+}
25
+export class CreateFormAddUserActionSuccess implements Action {
26
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_SUCCESS;
27
+  constructor(public payload: any, public addressID: any) {}
28
+}
29
+export class CreateFormAddUserActionError implements Action {
30
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_ADD_USER_ERROR;
31
+  constructor(public payload: string, public addressID: any) {}
32
+}
33
+
34
+// save new user action
35
+export class SaveNewUserAction implements Action{
36
+  type: UserActionTypes = UserActionTypes.SAVE_NEW_USER;
37
+  constructor(public payload:User){}
38
+}
39
+export class SaveNewUserActionSuccess implements Action{
40
+  type: UserActionTypes = UserActionTypes.SAVE_NEW_USER_SUCCESS;
41
+  constructor(public payload:User){}
42
+}
43
+export class SaveNewUserActionError implements Action{
44
+  type: UserActionTypes = UserActionTypes.SAVE_NEW_USER_ERROR;
45
+  constructor(public payload: string){}
46
+}
47
+
48
+// delete user action
49
+export class DeleteUserAction implements Action{
50
+  type: UserActionTypes = UserActionTypes.DELETE_USER;
51
+  constructor(public payload: User,  public addressID: any){}
52
+}
53
+export class DeleteUserActionSuccess implements Action{
54
+  type: UserActionTypes = UserActionTypes.DELETE_USER_SUCCCESS;
55
+  constructor(public payload: User,  public addressID: any){}
56
+}
57
+export class DeleteUserActionError implements Action{
58
+  type: UserActionTypes = UserActionTypes.DELETE_USER_ERROR;
59
+  constructor(public payload: string,  public addressID: any){}
60
+}
61
+
62
+// form to update user action
63
+export class CreateFormUpdateUserAction implements Action{
64
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_UPDATE_USER;
65
+  constructor(public payload: User,  public addressID: any){}
66
+}
67
+export class CreateFormUpdateUserActionSuccess implements Action{
68
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_UPDATE_USER_SUCCESS;
69
+  constructor(public payload: User,  public addressID: any){}
70
+}
71
+export class CreateFormUpdateUserActionError implements Action{
72
+  type: UserActionTypes = UserActionTypes.CREATE_FORM_UPDATE_USER_ERROR;
73
+  constructor(public payload: string,  public addressID: any){}
74
+}
75
+
76
+//update user
77
+export class UpdateUserAction implements Action{
78
+  type: UserActionTypes = UserActionTypes.UPDATE_USER;
79
+  constructor(public payload: User){}
80
+}
81
+export class UpdateUserActionSuccess implements Action{
82
+  type: UserActionTypes = UserActionTypes.UPDATE_USER_SUCCESS;
83
+  constructor(public payload: User){}
84
+}
85
+export class UpdateUserActionError implements Action{
86
+  type: UserActionTypes = UserActionTypes.UPDATE_USER_ERROR;
87
+  constructor(public payload: string){}
88
+}
89
+
90
+//get projects assigned to user
91
+export class GetUser_s_Projects implements Action{
92
+  type: UserActionTypes = UserActionTypes.GET_PROJECTS_BY_USER;
93
+  constructor(public payload: any, public addressID: any){}
94
+}
95
+export class GetUser_s_ProjectsSuccess implements Action{
96
+  type: UserActionTypes = UserActionTypes.GET_PROJECTS_BY_USER_SUCCESS;
97
+  constructor(public payload: Array<Project>, public addressID: any){}
98
+}
99
+export class GetUser_s_ProjectsError implements Action{
100
+  type: UserActionTypes = UserActionTypes.GET_PROJECTS_BY_USER_ERROR;
101
+  constructor(public payload: string, public addressID: any){}
102
+}
103
+
104
+export type UserActionUnion =
105
+  | GetAllUsersAction
106
+  | GetAllUsersActionSuccess
107
+  | GetAllUsersActionError
108
+  | CreateFormAddUserAction
109
+  | CreateFormAddUserActionSuccess
110
+  | CreateFormAddUserActionError
111
+  | SaveNewUserAction
112
+  | SaveNewUserActionSuccess
113
+  | SaveNewUserActionError
114
+  | DeleteUserAction
115
+  | DeleteUserActionSuccess
116
+  | DeleteUserActionError
117
+  | CreateFormUpdateUserAction
118
+  | CreateFormUpdateUserActionSuccess
119
+  | CreateFormUpdateUserActionError
120
+  | UpdateUserAction
121
+  | UpdateUserActionSuccess
122
+  | UpdateUserActionError
123
+  ;

+ 46
- 0
src/app/ngrx/user/user.effects.create.ts Просмотреть файл

@@ -0,0 +1,46 @@
1
+import { UserService } from './../../shared/services/user.service';
2
+import { catchError } from 'rxjs/operators';
3
+import { UserActionTypes } from './user.action.type';
4
+import {
5
+  UserActionUnion,
6
+  CreateFormAddUserActionSuccess,
7
+  CreateFormAddUserActionError,
8
+  SaveNewUserActionSuccess,
9
+  SaveNewUserActionError,
10
+} from './user.actions';
11
+import { map, Observable, of, mergeMap } from 'rxjs';
12
+import { Actions, createEffect, ofType } from '@ngrx/effects';
13
+import { Injectable } from '@angular/core';
14
+import { User } from 'src/app/shared/models/user/user.model';
15
+
16
+@Injectable()
17
+export class UserCreateEffects {
18
+  constructor(private actions: Actions, private userService: UserService) {}
19
+
20
+  createUserFormEffect: Observable<UserActionUnion> = createEffect(() =>
21
+    this.actions.pipe(
22
+      ofType(UserActionTypes.CREATE_FORM_ADD_USER),
23
+      map(
24
+        (action: UserActionUnion) => new CreateFormAddUserActionSuccess({}, {})
25
+      ),
26
+      catchError((err) => of(new CreateFormAddUserActionError(err, {})))
27
+    )
28
+  );
29
+
30
+  saveNewUserEffect: Observable<UserActionUnion> = createEffect(() =>
31
+    this.actions.pipe(
32
+      ofType(UserActionTypes.SAVE_NEW_USER),
33
+      mergeMap((action: UserActionUnion) => {
34
+        return this.userService
35
+          .createUserService(action.payload)
36
+          .pipe(
37
+            map(
38
+              (user: User) =>
39
+                new SaveNewUserActionSuccess(user)
40
+            ),
41
+            catchError((err) => of(new SaveNewUserActionError(err.message)))
42
+          );
43
+      })
44
+    )
45
+  );
46
+}

+ 28
- 0
src/app/ngrx/user/user.effects.delete.ts Просмотреть файл

@@ -0,0 +1,28 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { UserActionTypes } from './user.action.type';
3
+import {
4
+  UserActionUnion,
5
+  DeleteUserActionSuccess,
6
+  DeleteUserActionError,
7
+} from './user.actions';
8
+import { Observable, mergeMap, of } from 'rxjs';
9
+import { Actions, createEffect, ofType } from '@ngrx/effects';
10
+import { UserService } from './../../shared/services/user.service';
11
+import { Injectable } from '@angular/core';
12
+
13
+@Injectable()
14
+export class UserDeleteEffect {
15
+  constructor(private userService: UserService, private userActions: Actions) {}
16
+
17
+  deleteUserEffect: Observable<UserActionUnion> = createEffect(() =>
18
+    this.userActions.pipe(
19
+      ofType(UserActionTypes.DELETE_USER),
20
+      mergeMap((action: UserActionUnion) => {
21
+        return this.userService.deleteUserService(action.payload.userID).pipe(
22
+          map(() => new DeleteUserActionSuccess(action.payload,{})),
23
+          catchError((err) => of(new DeleteUserActionError(err,{})))
24
+        );
25
+      })
26
+    )
27
+  );
28
+}

+ 29
- 0
src/app/ngrx/user/user.effects.get.ts Просмотреть файл

@@ -0,0 +1,29 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { UserActionTypes } from './user.action.type';
3
+import {
4
+  UserActionUnion,
5
+  GetAllUsersActionSuccess,
6
+  GetAllUsersActionError,
7
+} from './user.actions';
8
+import { mergeMap, Observable, of } from 'rxjs';
9
+import { UserService } from '../../shared/services/user.service';
10
+import { Injectable } from '@angular/core';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { User } from 'src/app/shared/models/user/user.model';
13
+
14
+@Injectable()
15
+export class UserGetAllEffects {
16
+  constructor(private userservice: UserService, private actions: Actions) {}
17
+
18
+  userGetAllEffect: Observable<UserActionUnion> = createEffect(() =>
19
+    this.actions.pipe(
20
+      ofType(UserActionTypes.GET_ALL_USERS),
21
+      mergeMap((action: UserActionUnion) => {
22
+        return this.userservice.geAllUsersService().pipe(
23
+          map((users: User[]) => new GetAllUsersActionSuccess(users, {})),
24
+          catchError((err) => of(new GetAllUsersActionError(err, {})))
25
+        );
26
+      })
27
+    )
28
+  );
29
+}

+ 45
- 0
src/app/ngrx/user/user.effects.update.ts Просмотреть файл

@@ -0,0 +1,45 @@
1
+import { catchError, map } from 'rxjs/operators';
2
+import { UserActionTypes } from './user.action.type';
3
+import {
4
+  UserActionUnion,
5
+  CreateFormUpdateUserActionSuccess,
6
+  CreateFormUpdateUserActionError,
7
+  UpdateUserActionSuccess,
8
+  UpdateUserActionError,
9
+} from './user.actions';
10
+import { Observable, mergeMap, of } from 'rxjs';
11
+import { Actions, createEffect, ofType } from '@ngrx/effects';
12
+import { UserService } from './../../shared/services/user.service';
13
+import { Injectable } from '@angular/core';
14
+import { User } from 'src/app/shared/models/user/user.model';
15
+
16
+@Injectable()
17
+export class UserUpdateEffects {
18
+  constructor(private userService: UserService, private userActions: Actions) {}
19
+
20
+  //create form to update a user
21
+  createFormUpdateUserEffect: Observable<UserActionUnion> = createEffect(() =>
22
+    this.userActions.pipe(
23
+      ofType(UserActionTypes.CREATE_FORM_UPDATE_USER),
24
+      mergeMap((action: UserActionUnion) => {
25
+        return this.userService.getUserByID(action.payload.userID).pipe(
26
+          map((user: User) => new CreateFormUpdateUserActionSuccess(user,{})),
27
+          catchError((err) => of(new CreateFormUpdateUserActionError(err,{})))
28
+        );
29
+      })
30
+    )
31
+  );
32
+
33
+  //update user
34
+  updateUserEffect : Observable<UserActionUnion> = createEffect(
35
+    ()=> this.userActions.pipe(
36
+      ofType(UserActionTypes.UPDATE_USER),
37
+      mergeMap((action: UserActionUnion) =>{
38
+        return this.userService.updateUserService(action.payload).pipe(
39
+          map ((user: User) => new UpdateUserActionSuccess(user)),
40
+          catchError( err => of(new UpdateUserActionError(err)))
41
+        )
42
+      })
43
+    )
44
+  )
45
+}

+ 150
- 0
src/app/ngrx/user/user.reducer.ts Просмотреть файл

@@ -0,0 +1,150 @@
1
+import { UserActionUnion } from './user.actions';
2
+import { UserActionTypes } from './user.action.type';
3
+import { Action } from '@ngrx/store';
4
+import { MsgState } from '../msg.state';
5
+import { UserState } from './user.state';
6
+import { User } from 'src/app/shared/models/user/user.model';
7
+
8
+const userInitiallState: UserState = {
9
+  currentUser: undefined,
10
+  usersList: [],
11
+  msgState: MsgState.INIT_STATE,
12
+  errorMsg: 'no error',
13
+};
14
+
15
+export function userReducer(
16
+  state: UserState = userInitiallState,
17
+  action: Action
18
+): UserState {
19
+  switch (action.type) {
20
+    //get all users
21
+    case UserActionTypes.GET_ALL_USERS:
22
+      return {
23
+        ...state,
24
+        msgState: MsgState.LOADING,
25
+      };
26
+    case UserActionTypes.GET_ALL_USERS_SUCCESS:
27
+      return {
28
+        ...state,
29
+        msgState: MsgState.LOADED,
30
+        usersList: (<UserActionUnion>action).payload,
31
+      };
32
+    case UserActionTypes.GET_ALL_USERS_ERROR:
33
+      return {
34
+        ...state,
35
+        msgState: MsgState.ERR,
36
+        errorMsg: (<UserActionUnion>action).payload,
37
+      };
38
+
39
+    //create form to add new user
40
+    case UserActionTypes.CREATE_FORM_ADD_USER:
41
+      return{
42
+        ...state,
43
+        msgState: MsgState.FORM_LOADING
44
+      };
45
+    case UserActionTypes.CREATE_FORM_ADD_USER_SUCCESS:
46
+      return{
47
+        ...state,
48
+        msgState: MsgState.FORM_LOADED
49
+      };
50
+    case UserActionTypes.CREATE_FORM_ADD_USER_ERROR:
51
+      return{
52
+        ...state,
53
+        msgState: MsgState.FORM_LOAD_ERR,
54
+        errorMsg: (<UserActionUnion>action).payload,
55
+      };
56
+
57
+    // save new user
58
+    case UserActionTypes.SAVE_NEW_USER:
59
+      return{
60
+        ...state,
61
+        msgState:MsgState.ADD
62
+      }
63
+    case UserActionTypes.SAVE_NEW_USER_SUCCESS:
64
+      let newUser: User = (<UserActionUnion> action).payload;
65
+      let usersListCopy1: Array<User> = [...state.usersList];
66
+      usersListCopy1.push(newUser);
67
+      return{
68
+        ...state,
69
+        msgState: MsgState.ADDED,
70
+        usersList: usersListCopy1
71
+      };
72
+    case UserActionTypes.SAVE_NEW_USER_ERROR:
73
+      return{
74
+        ...state,
75
+        msgState: MsgState.ERR,
76
+        errorMsg:(<UserActionUnion> action).payload
77
+      }
78
+
79
+    //delete user
80
+    case UserActionTypes.DELETE_USER:
81
+      return{
82
+        ...state,
83
+        msgState: MsgState.DELETE
84
+      };
85
+    case UserActionTypes.DELETE_USER_SUCCCESS:
86
+      let deletedUser : User = (<UserActionUnion> action).payload;
87
+      let deletedUserIndex = state.usersList.indexOf(deletedUser);
88
+      let usersListCopy2: Array<User> = [...state.usersList];
89
+      usersListCopy2.splice(deletedUserIndex,1);
90
+      return{
91
+        ...state,
92
+        msgState: MsgState.DELETED,
93
+        usersList:usersListCopy2,
94
+        currentUser: deletedUser
95
+      };
96
+    case UserActionTypes.DELETE_USER_ERROR:
97
+      return{
98
+        ...state,
99
+        msgState: MsgState.ERR,
100
+        errorMsg: (<UserActionUnion> action).payload
101
+      };
102
+
103
+    // create form to update user
104
+    case UserActionTypes.CREATE_FORM_UPDATE_USER:
105
+      return{
106
+        ...state,
107
+        msgState:MsgState.FORM_LOADING
108
+      };
109
+    case UserActionTypes.CREATE_FORM_UPDATE_USER_SUCCESS:
110
+      let userToUpdate = (<UserActionUnion> action).payload;
111
+      return{
112
+        ...state,
113
+        msgState:MsgState.FORM_LOADED,
114
+        currentUser:userToUpdate
115
+      };
116
+    case UserActionTypes.CREATE_FORM_UPDATE_USER_ERROR:
117
+      return{
118
+        ...state,
119
+        msgState: MsgState.ERR,
120
+        errorMsg: (<UserActionUnion> action).payload
121
+      };
122
+
123
+
124
+    // update user
125
+    case UserActionTypes.UPDATE_USER:
126
+      return{
127
+        ...state,
128
+        msgState: MsgState.UPDATE
129
+      };
130
+    case UserActionTypes.UPDATE_USER_SUCCESS:
131
+      let updatedUser: User = (<UserActionUnion> action).payload;
132
+      let usersListCopy3: Array<User> = [...state.usersList];
133
+      usersListCopy3.map(
134
+        (user) => (user.userID==updatedUser.userID)?updatedUser:user
135
+        );
136
+    return {
137
+      ...state,
138
+      msgState: MsgState.UPDATED,
139
+      usersList: usersListCopy3
140
+    };
141
+    case UserActionTypes.UPDATE_USER_ERROR:
142
+      return {
143
+        ...state,
144
+        msgState:MsgState.ERR,
145
+        errorMsg:(<UserActionUnion> action).payload
146
+      };
147
+    default:
148
+      return { ...state };
149
+  }
150
+}

+ 8
- 0
src/app/ngrx/user/user.state.ts Просмотреть файл

@@ -0,0 +1,8 @@
1
+import { MsgState } from '../msg.state';
2
+import { User } from './../../shared/models/user/user.model';
3
+export class UserState{
4
+  currentUser!: User | undefined;
5
+  usersList!: User[];
6
+  msgState!: MsgState;
7
+  errorMsg!: string;
8
+}

+ 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
+}

+ 25
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.html Просмотреть файл

@@ -0,0 +1,25 @@
1
+<mat-sidenav-container class="sidenav-container">
2
+  <mat-sidenav #drawer class="sidenav bg-light" 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='/home'>Home</a>
12
+        <a mat-list-item routerLink="/addresses-management"> Users' Addresses</a>
13
+        <a mat-list-item routerLink="/users-management"> User Manager</a>
14
+        <a mat-list-item routerLink="/companies-management">Company Manager</a>
15
+        <a mat-list-item routerLink="/projects-management">Project Manager</a>
16
+      </mat-nav-list>
17
+  </mat-sidenav>
18
+
19
+  <mat-sidenav-content>
20
+    <mat-toolbar>
21
+      <span>Projects Management</span>
22
+    </mat-toolbar>
23
+    <!-- Add Content Here -->
24
+  </mat-sidenav-content>
25
+</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
+});

+ 21
- 0
src/app/pages/base-nav-menu/base-nav-menu.component.ts Просмотреть файл

@@ -0,0 +1,21 @@
1
+import { Component } from '@angular/core';
2
+import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
3
+import { Observable } from 'rxjs';
4
+import { map, shareReplay } from 'rxjs/operators';
5
+
6
+@Component({
7
+  selector: 'app-base-nav-menu',
8
+  templateUrl: './base-nav-menu.component.html',
9
+  styleUrls: ['./base-nav-menu.component.css']
10
+})
11
+export class BaseNavMenuComponent {
12
+
13
+  isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
14
+    .pipe(
15
+      map(result => result.matches),
16
+      shareReplay()
17
+    );
18
+
19
+  constructor(private breakpointObserver: BreakpointObserver) {}
20
+
21
+}

+ 13
- 0
src/app/pages/base-page-accueil/base-page-accueil-routing.module.ts Просмотреть файл

@@ -0,0 +1,13 @@
1
+import { BasePageAccueilComponent } from './base-page-accueil/base-page-accueil.component';
2
+import { NgModule } from '@angular/core';
3
+import { RouterModule, Routes } from '@angular/router';
4
+
5
+const routes: Routes = [
6
+  {path:"home",component:BasePageAccueilComponent}
7
+];
8
+
9
+@NgModule({
10
+  imports: [RouterModule.forChild(routes)],
11
+  exports: [RouterModule]
12
+})
13
+export class BasePageAccueilRoutingModule { }

+ 17
- 0
src/app/pages/base-page-accueil/base-page-accueil.module.ts Просмотреть файл

@@ -0,0 +1,17 @@
1
+import { NgModule } from '@angular/core';
2
+import { CommonModule } from '@angular/common';
3
+
4
+import { BasePageAccueilRoutingModule } from './base-page-accueil-routing.module';
5
+import { BasePageAccueilComponent } from './base-page-accueil/base-page-accueil.component';
6
+
7
+
8
+@NgModule({
9
+  declarations: [
10
+    BasePageAccueilComponent
11
+  ],
12
+  imports: [
13
+    CommonModule,
14
+    BasePageAccueilRoutingModule
15
+  ]
16
+})
17
+export class BasePageAccueilModule { }

+ 0
- 0
src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.css Просмотреть файл


+ 14
- 0
src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.html Просмотреть файл

@@ -0,0 +1,14 @@
1
+<div class="container">
2
+  <div class="row d-flex justify-content-left">
3
+
4
+    <div>
5
+      <div class="card-body">
6
+        <h4 class="card-title p-2">Welcome to Natan</h4>
7
+        <p class="card-text p-2">NATAN est palindrome</p>
8
+        <p class="card-text p-2">Ce qui fait de NATAN le meilleur</p>
9
+        <p class="card-text">For all collaborators, NATAN wishes you the best</p>
10
+      </div>
11
+    </div>
12
+
13
+  </div>
14
+</div>

+ 25
- 0
src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.spec.ts Просмотреть файл

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

+ 15
- 0
src/app/pages/base-page-accueil/base-page-accueil/base-page-accueil.component.ts Просмотреть файл

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

+ 0
- 0
src/app/pages/company-manager/company-management/companies-list/companies-list.component.css Просмотреть файл


+ 63
- 0
src/app/pages/company-manager/company-management/companies-list/companies-list.component.html Просмотреть файл

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

+ 25
- 0
src/app/pages/company-manager/company-management/companies-list/companies-list.component.spec.ts Просмотреть файл

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

+ 47
- 0
src/app/pages/company-manager/company-management/companies-list/companies-list.component.ts Просмотреть файл

@@ -0,0 +1,47 @@
1
+import { DeleteCompanyAction, GetAllComapaniesAction } from './../../../../ngrx/company/company.actions';
2
+import { CompanyState } from './../../../../ngrx/company/company.state';
3
+import { MsgState } from 'src/app/ngrx/msg.state';
4
+import { Router } from '@angular/router';
5
+import { Company } from 'src/app/shared/models/company/company.model';
6
+import { Component, OnInit, Input } from '@angular/core';
7
+import { Store } from '@ngrx/store';
8
+
9
+@Component({
10
+  selector: 'app-companies-list',
11
+  templateUrl: './companies-list.component.html',
12
+  styleUrls: ['./companies-list.component.css']
13
+})
14
+export class CompaniesListComponent implements OnInit {
15
+
16
+  constructor(private router: Router, private store: Store<{companyReducerSelector: CompanyState}>) { }
17
+
18
+  @ Input () inputCompaniesList!: Array<Company>
19
+
20
+  ngOnInit(): void {
21
+  }
22
+
23
+  onCompanyEdit(company: Company){
24
+    this.router.navigateByUrl("/company-update/"+company.companyID);
25
+  }
26
+
27
+  onCompanyDelete(company:Company){
28
+    if(window.confirm(MsgState.CONFIRM_DEL)){
29
+      this.store.dispatch(new DeleteCompanyAction(company));
30
+    }
31
+  }
32
+
33
+  companyName!: string;
34
+
35
+  onSearch() {
36
+    if(this.companyName==''){
37
+      this.store.dispatch(new GetAllComapaniesAction({})); //refresh
38
+    }
39
+    else{
40
+      this.inputCompaniesList = this.inputCompaniesList.filter((company: Company) => {
41
+        return company.companyName
42
+          .toLocaleLowerCase()
43
+          .match(this.companyName.toLocaleLowerCase());
44
+      });
45
+    }
46
+  }
47
+}

+ 0
- 0
src/app/pages/company-manager/company-management/company-create/company-create.component.css Просмотреть файл


+ 100
- 0
src/app/pages/company-manager/company-management/company-create/company-create.component.html Просмотреть файл

@@ -0,0 +1,100 @@
1
+<div class="container p-3" *ngIf="companyFormGroup">
2
+  <ng-container [ngSwitch]="companyState.msgState">
3
+    <ng-container *ngSwitchCase="msgState.FORM_LOADING">
4
+      {{ companyState.msgState }}
5
+    </ng-container>
6
+
7
+    <ng-container *ngSwitchCase="msgState.FORM_LOAD_ERR">
8
+      {{ companyState.msgState }}
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.FORM_LOADED">
12
+      <div class="card mt-3">
13
+        <div class="card-header"><h1>New Company</h1></div>
14
+
15
+        <div class="card-body">
16
+          <form
17
+            [formGroup]="companyFormGroup"
18
+            (ngSubmit)="onCompanyCreate(); companyFormGroup.reset()"
19
+          >
20
+            <div class="col-md-auto mb-3">
21
+              <label for="companyName">Company name</label>
22
+              <input
23
+                type="text"
24
+                formControlName="companyName"
25
+                class="form-control"
26
+                [ngClass]="{
27
+                  'is-invalid':
28
+                    companyFormGroup.controls['companyName'].touched &&
29
+                    !companyFormGroup.controls['companyName'].valid
30
+                }"
31
+              />
32
+              <div class="invalid-feedback">
33
+                <span
34
+                  *ngIf="companyFormGroup.controls['companyName'].errors?.['required']"
35
+                >
36
+                  required
37
+                </span>
38
+                <span
39
+                  *ngIf="companyFormGroup.controls['companyName'].errors?.['minlength']"
40
+                >
41
+                  min nbr chars 5
42
+                </span>
43
+              </div>
44
+            </div>
45
+
46
+            <div class="col-md-auto mb-3">
47
+              <label for="type1">Company type 1</label>
48
+              <select formControlName="companyType1" class="form-control">
49
+                <option
50
+                  *ngFor="let companyType of companyTypes1 | keyvalue"
51
+                  [ngValue]="companyType.value"
52
+                >
53
+                  {{ companyType.value }}
54
+                </option>
55
+              </select>
56
+            </div>
57
+
58
+            <div class="col-md-auto mb-3">
59
+              <label for="type2">Company type 2</label>
60
+              <select formControlName="companyType2" class="form-control">
61
+                <option
62
+                  *ngFor="let companyType of companyTypes2 | keyvalue"
63
+                  [ngValue]="companyType.value"
64
+                >
65
+                  {{ companyType.value }}
66
+                </option>
67
+              </select>
68
+            </div>
69
+
70
+            <div class="text-center col-md-auto mt-3">
71
+              <button
72
+                class="btn btn-outline-primary"
73
+                type="submit"
74
+                [disabled]="!companyFormGroup.valid"
75
+              >
76
+                save
77
+              </button>
78
+              &nbsp;
79
+              <button class="btn btn-outline-danger" type="reset">reset</button>
80
+            </div>
81
+          </form>
82
+        </div>
83
+      </div>
84
+    </ng-container>
85
+
86
+    <ng-container *ngSwitchCase="msgState.ADDED">
87
+      <div class="alert-success container p-3 m-3" style="width: 30em">
88
+        <span> {{ companyState.msgState }}</span> &nbsp;&nbsp;
89
+        <button class="btn btn-success" (click)="onSaveOk()">OK</button>
90
+      </div>
91
+    </ng-container>
92
+
93
+    <ng-container *ngSwitchCase="msgState.ERR">
94
+      <div class="alert-danger container p-3 m-3" style="width: 30em">
95
+        <span> {{ companyState.msgState }}</span>
96
+      </div>
97
+    </ng-container>
98
+
99
+  </ng-container>
100
+</div>

+ 25
- 0
src/app/pages/company-manager/company-management/company-create/company-create.component.spec.ts Просмотреть файл

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

+ 62
- 0
src/app/pages/company-manager/company-management/company-create/company-create.component.ts Просмотреть файл

@@ -0,0 +1,62 @@
1
+import { Router } from '@angular/router';
2
+import { MsgState } from './../../../../ngrx/msg.state';
3
+import { CompanyType1 } from '../../../../shared/models/company/company.type1';
4
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
5
+import { CreateFormAddCompanyAction, SaveNewCompanyAction } from './../../../../ngrx/company/company.actions';
6
+import { CompanyState } from './../../../../ngrx/company/company.state';
7
+import { Component, OnInit } from '@angular/core';
8
+import { Store } from '@ngrx/store';
9
+import { CompanyType2 } from 'src/app/shared/models/company/company.type2';
10
+
11
+@Component({
12
+  selector: 'app-company-create',
13
+  templateUrl: './company-create.component.html',
14
+  styleUrls: ['./company-create.component.css'],
15
+})
16
+export class CompanyCreateComponent implements OnInit {
17
+  constructor(
18
+    private store: Store<{ companyReducerSelector: CompanyState }>,
19
+    private fb: FormBuilder,
20
+    private router: Router
21
+  ) {}
22
+
23
+  companyState!: CompanyState;
24
+  companyFormGroup!: FormGroup;
25
+  companyTypes1 = CompanyType1;
26
+  companyTypes2 = CompanyType2;
27
+  msgState = MsgState;
28
+
29
+  ngOnInit(): void {
30
+    this.store.dispatch(new CreateFormAddCompanyAction({}));
31
+    this.store.subscribe({
32
+      next: (state) => {
33
+        this.companyState = state.companyReducerSelector;
34
+
35
+        this.companyFormGroup = this.fb.group({
36
+          id: [0, Validators.required],
37
+          companyName: [
38
+            '',
39
+            [
40
+              Validators.required,
41
+              Validators.minLength(4),
42
+              Validators.maxLength(20),
43
+            ],
44
+          ],
45
+          companyType1: ['', Validators.required],
46
+          companyType2: ['', Validators.required],
47
+          creationDate: [''],
48
+        });
49
+      },
50
+      error: (err) => {},
51
+    });
52
+  }
53
+
54
+  onCompanyCreate(){
55
+    if(window.confirm(this.msgState.CONFIRM_ADD)){
56
+      this.store.dispatch(new SaveNewCompanyAction(this.companyFormGroup.value))
57
+    }
58
+  }
59
+  onSaveOk(){
60
+    this.router.navigateByUrl("/companies-management")
61
+  }
62
+}

+ 0
- 0
src/app/pages/company-manager/company-management/company-management.component.css Просмотреть файл


+ 30
- 0
src/app/pages/company-manager/company-management/company-management.component.html Просмотреть файл

@@ -0,0 +1,30 @@
1
+<app-company-navbar></app-company-navbar>
2
+<div class="container">
3
+  <ng-container
4
+    *ngIf="companyState$ | async as companyState"
5
+    [ngSwitch]="companyState.msgState"
6
+  >
7
+    <ng-container *ngSwitchCase="msgState.LOADING">
8
+      {{ companyState.msgState }}
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.LOADED">
12
+      <app-companies-list
13
+        [inputCompaniesList]="companyState.companiesList"
14
+      ></app-companies-list>
15
+    </ng-container>
16
+
17
+    <ng-container *ngSwitchCase="msgState.ERR">
18
+      <div class="text-danger">
19
+        {{ companyState.msgState }}
20
+      </div>
21
+    </ng-container>
22
+
23
+    <ng-container *ngSwitchCase="msgState.DELETED">
24
+      <div class="alert-success container p-3 m-3" style="width: 30em">
25
+        <span> {{ companyState.msgState }}</span>
26
+      </div>
27
+    </ng-container>
28
+
29
+  </ng-container>
30
+</div>

+ 25
- 0
src/app/pages/company-manager/company-management/company-management.component.spec.ts Просмотреть файл

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

+ 23
- 0
src/app/pages/company-manager/company-management/company-management.component.ts Просмотреть файл

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

+ 0
- 0
src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.css Просмотреть файл


+ 21
- 0
src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.html Просмотреть файл

@@ -0,0 +1,21 @@
1
+<div class="container">
2
+  <nav class="navbar navbar-expand-sm">
3
+    <div class="collapse navbar-collapse" id="navbarNav">
4
+      <button
5
+        pButton
6
+        type="button"
7
+        label="create company"
8
+        class="btn btn-outline-primary"
9
+        (click)="onCompanyCreate()"
10
+      ></button>
11
+      &nbsp;
12
+      <button
13
+        pButton
14
+        type="button"
15
+        label="all companies"
16
+        (click)="onCompanyGetAll()"
17
+        class="btn btn-outline-primary"
18
+      ></button>
19
+    </div>
20
+  </nav>
21
+</div>

+ 25
- 0
src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.spec.ts Просмотреть файл

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

+ 25
- 0
src/app/pages/company-manager/company-management/company-navbar/company-navbar.component.ts Просмотреть файл

@@ -0,0 +1,25 @@
1
+import { GetAllComapaniesAction } from './../../../../ngrx/company/company.actions';
2
+import { CompanyState } from './../../../../ngrx/company/company.state';
3
+import { Router } from '@angular/router';
4
+import { Component, OnInit } from '@angular/core';
5
+import { Store } from '@ngrx/store';
6
+
7
+@Component({
8
+  selector: 'app-company-navbar',
9
+  templateUrl: './company-navbar.component.html',
10
+  styleUrls: ['./company-navbar.component.css'],
11
+})
12
+export class CompanyNavbarComponent implements OnInit {
13
+  constructor(
14
+    private router: Router,
15
+    private store: Store<{ companyReducerSelector: CompanyState }>
16
+  ) {}
17
+
18
+  ngOnInit(): void {}
19
+  onCompanyCreate() {
20
+    this.router.navigateByUrl('/company-create');
21
+  }
22
+  onCompanyGetAll() {
23
+    this.store.dispatch(new GetAllComapaniesAction({}));
24
+  }
25
+}

+ 0
- 0
src/app/pages/company-manager/company-management/company-update/company-update.component.css Просмотреть файл


+ 96
- 0
src/app/pages/company-manager/company-management/company-update/company-update.component.html Просмотреть файл

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

+ 25
- 0
src/app/pages/company-manager/company-management/company-update/company-update.component.spec.ts Просмотреть файл

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

+ 71
- 0
src/app/pages/company-manager/company-management/company-update/company-update.component.ts Просмотреть файл

@@ -0,0 +1,71 @@
1
+import { CompanyType1 } from '../../../../shared/models/company/company.type1';
2
+import { MsgState } from 'src/app/ngrx/msg.state';
3
+import { CreateFormUpdateCompanyAction, UpdateCompanyAction } from './../../../../ngrx/company/company.actions';
4
+import { CompanyState } from './../../../../ngrx/company/company.state';
5
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
6
+import { CompanyService } from './../../../../shared/services/company.service';
7
+import { ActivatedRoute, Router } from '@angular/router';
8
+import { Component, OnInit } from '@angular/core';
9
+import { Store } from '@ngrx/store';
10
+import { CompanyType2 } from 'src/app/shared/models/company/company.type2';
11
+
12
+@Component({
13
+  selector: 'app-company-update',
14
+  templateUrl: './company-update.component.html',
15
+  styleUrls: ['./company-update.component.css'],
16
+})
17
+export class CompanyUpdateComponent implements OnInit {
18
+  companyID: number;
19
+
20
+  constructor(
21
+    activedRoute: ActivatedRoute,
22
+    private companyService: CompanyService,
23
+    private store: Store<{companyReducerSelector: CompanyState}>,
24
+    private fb: FormBuilder,
25
+    private router: Router
26
+  ) {
27
+    this.companyID = activedRoute.snapshot.params["companyID"];
28
+  }
29
+
30
+  companyState!: CompanyState;
31
+  companyFormGroup!: FormGroup;
32
+  msgState = MsgState;
33
+  companyTypes1 = CompanyType1;
34
+  companyTypes2 = CompanyType2;
35
+
36
+  ngOnInit(): void {
37
+    this.companyService.getCompanyByIDService(this.companyID).subscribe(
38
+      (company)=>{
39
+        this.store.dispatch(new CreateFormUpdateCompanyAction(company));
40
+        this.store.subscribe((state)=>{
41
+          this.companyState = state.companyReducerSelector;
42
+
43
+          this.companyFormGroup = this.fb.group({
44
+            companyID: [this.companyState.currentCompany?.companyID],
45
+            companyName: [
46
+              this.companyState.currentCompany?.companyName,
47
+              [
48
+                Validators.required,
49
+                Validators.minLength(4),
50
+                Validators.maxLength(20),
51
+              ],
52
+            ],
53
+            companyType1: [this.companyState.currentCompany?.companyType1, Validators.required],
54
+            companyType2: [this.companyState.currentCompany?.companyType2, Validators.required],
55
+            creationDate: [this.companyState.currentCompany?.connectionDate],
56
+          });
57
+        });
58
+      }
59
+    );
60
+  }
61
+
62
+  onCompanyUpdate(){
63
+    if(window.confirm(this.msgState.CONFIRM_UPDATE)){
64
+      this.store.dispatch(new UpdateCompanyAction(this.companyFormGroup.value));
65
+    }
66
+  }
67
+
68
+  onUpdateOk(){
69
+    this.router.navigateByUrl("/companies-management")
70
+  }
71
+}

+ 17
- 0
src/app/pages/company-manager/company-manager-routing.module.ts Просмотреть файл

@@ -0,0 +1,17 @@
1
+import { CompanyUpdateComponent } from './company-management/company-update/company-update.component';
2
+import { CompanyCreateComponent } from './company-management/company-create/company-create.component';
3
+import { NgModule } from '@angular/core';
4
+import { RouterModule, Routes } from '@angular/router';
5
+import { CompanyManagementComponent } from './company-management/company-management.component';
6
+
7
+const routes: Routes = [
8
+  { path: 'companies-management', component: CompanyManagementComponent },
9
+  { path: 'company-create', component: CompanyCreateComponent },
10
+  { path:'company-update/:companyID', component: CompanyUpdateComponent}
11
+];
12
+
13
+@NgModule({
14
+  imports: [RouterModule.forChild(routes)],
15
+  exports: [RouterModule],
16
+})
17
+export class CompanyManagerRoutingModule {}

+ 34
- 0
src/app/pages/company-manager/company-manager.module.ts Просмотреть файл

@@ -0,0 +1,34 @@
1
+import { TableModule } from 'primeng/table';
2
+import {  FormsModule, ReactiveFormsModule } from '@angular/forms';
3
+import { ButtonModule } from 'primeng/button';
4
+import { NgModule } from '@angular/core';
5
+import { CommonModule } from '@angular/common';
6
+
7
+import { CompanyManagerRoutingModule } from './company-manager-routing.module';
8
+import { CompanyManagementComponent } from './company-management/company-management.component';
9
+import { CompanyNavbarComponent } from './company-management/company-navbar/company-navbar.component';
10
+import { CompanyCreateComponent } from './company-management/company-create/company-create.component';
11
+import { CompaniesListComponent } from './company-management/companies-list/companies-list.component';
12
+import { CompanyUpdateComponent } from './company-management/company-update/company-update.component';
13
+
14
+
15
+@NgModule({
16
+  declarations: [
17
+
18
+
19
+    CompanyManagementComponent,
20
+        CompanyNavbarComponent,
21
+        CompanyCreateComponent,
22
+        CompaniesListComponent,
23
+        CompanyUpdateComponent
24
+  ],
25
+  imports: [
26
+    CommonModule,
27
+    CompanyManagerRoutingModule,
28
+    ButtonModule,
29
+    ReactiveFormsModule,
30
+    TableModule,
31
+    FormsModule
32
+  ]
33
+})
34
+export class CompanyManagerModule { }

+ 0
- 0
src/app/pages/project-manager/project-management/project-create/project-create.component.css Просмотреть файл


+ 165
- 0
src/app/pages/project-manager/project-management/project-create/project-create.component.html Просмотреть файл

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

+ 25
- 0
src/app/pages/project-manager/project-management/project-create/project-create.component.spec.ts Просмотреть файл

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

+ 98
- 0
src/app/pages/project-manager/project-management/project-create/project-create.component.ts Просмотреть файл

@@ -0,0 +1,98 @@
1
+import { ProjState } from './../../../../shared/models/project/project.state';
2
+import { Priority } from 'src/app/shared/models/project/project.priority';
3
+import { Router } from '@angular/router';
4
+import { Project } from 'src/app/shared/models/project/project.model';
5
+import { MsgState } from './../../../../ngrx/msg.state';
6
+import { GetAllComapaniesAction } from './../../../../ngrx/company/company.actions';
7
+import { GetAllUsersAction } from './../../../../ngrx/user/user.actions';
8
+import { CompanyState } from './../../../../ngrx/company/company.state';
9
+import { UserState } from './../../../../ngrx/user/user.state';
10
+import { CreateFormAddProjectAction, SaveNewProjectAction } from './../../../../ngrx/project/project.action';
11
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
12
+import { ProjectState } from './../../../../ngrx/project/project.state';
13
+import { Component, OnInit } from '@angular/core';
14
+import { Store } from '@ngrx/store';
15
+
16
+@Component({
17
+  selector: 'app-project-create',
18
+  templateUrl: './project-create.component.html',
19
+  styleUrls: ['./project-create.component.css'],
20
+})
21
+export class ProjectCreateComponent implements OnInit {
22
+  constructor(
23
+    private store: Store<{
24
+      projectReducerSelector: ProjectState;
25
+      userReducerSelector: UserState;
26
+      companyReducerSelector: CompanyState;
27
+    }>,
28
+    private formBuilder: FormBuilder,
29
+    private router: Router
30
+  ) {}
31
+
32
+  userState!: UserState;
33
+  companyState!: CompanyState;
34
+
35
+  projectFormGroup!: FormGroup;
36
+  projectState!: ProjectState;
37
+  projStates = ProjState;
38
+  priorities = Priority;
39
+  msgState = MsgState;
40
+
41
+  ngOnInit(): void {
42
+    this.store.dispatch(new GetAllUsersAction({}, {}));
43
+    this.store.dispatch(new GetAllComapaniesAction({}));
44
+    this.store.subscribe(
45
+      (state) => (this.userState = state.userReducerSelector)
46
+    );
47
+    this.store.subscribe(
48
+      (state) => (this.companyState = state.companyReducerSelector)
49
+    );
50
+
51
+    this.store.dispatch(new CreateFormAddProjectAction({}, {}, {}));
52
+    this.store.subscribe((state) => {
53
+      this.projectState = state.projectReducerSelector;
54
+
55
+      this.projectFormGroup = this.formBuilder.group({
56
+        projectName: [
57
+          '',
58
+          [
59
+            Validators.required,
60
+            Validators.minLength(5),
61
+            Validators.maxLength(20),
62
+          ],
63
+        ],
64
+        priority: ['', Validators.required],
65
+        description: ['', [Validators.required, Validators.minLength(25)]],
66
+        projState: ['', Validators.required],
67
+        userID: ['', Validators.required],
68
+        companyID: ['', Validators.required],
69
+      });
70
+    });
71
+  }
72
+
73
+  onProjectSave() {
74
+    if(window.confirm(this.msgState.CONFIRM_ADD)){
75
+
76
+      let formModel = this.projectFormGroup.value;
77
+      //project model
78
+      let project: Project = new Project();
79
+      project.projectName= formModel.projectName;
80
+      project.priority = formModel.priority;
81
+      project.createdDate = formModel.createdDate;
82
+      project.description = formModel.description;
83
+      project.projState = formModel.projState;
84
+      project.companyID=formModel.companyID;
85
+      project.userID = formModel.userID;
86
+
87
+      // user and company id needed to create project
88
+      let userID: number = formModel.userID;
89
+      let companyID: number = formModel.companyID;
90
+
91
+      this.store.dispatch(new SaveNewProjectAction(project));
92
+    }
93
+  }
94
+
95
+  onSaveSuccess(){
96
+    this.router.navigateByUrl("/projects-management")
97
+  }
98
+}

+ 0
- 0
src/app/pages/project-manager/project-management/project-management.component.css Просмотреть файл


+ 21
- 0
src/app/pages/project-manager/project-management/project-management.component.html Просмотреть файл

@@ -0,0 +1,21 @@
1
+<app-project-navbar></app-project-navbar>
2
+<div class="container">
3
+  <ng-container
4
+    *ngIf="projectState$ | async as projState"
5
+    [ngSwitch]="projState.msgState"
6
+  >
7
+    <ng-container *ngSwitchCase="msgState.LOADING">
8
+      {{ projState.msgState }}
9
+    </ng-container>
10
+
11
+    <ng-container *ngSwitchCase="msgState.ERR">
12
+      {{ projState.msgState }}
13
+    </ng-container>
14
+
15
+    <ng-container *ngSwitchCase="msgState.LOADED">
16
+      <app-projects-list
17
+        [inputProjectsList]="projState.projectsList"
18
+      ></app-projects-list>
19
+    </ng-container>
20
+  </ng-container>
21
+</div>

+ 25
- 0
src/app/pages/project-manager/project-management/project-management.component.spec.ts Просмотреть файл

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

+ 22
- 0
src/app/pages/project-manager/project-management/project-management.component.ts Просмотреть файл

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

+ 0
- 0
src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.css Просмотреть файл


+ 21
- 0
src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.html Просмотреть файл

@@ -0,0 +1,21 @@
1
+  <div class="container">
2
+    <nav class="navbar navbar-expand-sm">
3
+      <div class="collapse navbar-collapse" id="navbarNav">
4
+        <button
5
+          pButton
6
+          type="button"
7
+          label="create project"
8
+          class="btn btn-outline-primary"
9
+          (click)="onProjectCreate()"
10
+        ></button>
11
+        &nbsp;
12
+        <button
13
+          pButton
14
+          type="button"
15
+          label="all projects"
16
+
17
+          class="btn btn-outline-primary"
18
+        ></button>
19
+      </div>
20
+    </nav>
21
+  </div>

+ 25
- 0
src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.spec.ts Просмотреть файл

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

+ 25
- 0
src/app/pages/project-manager/project-management/project-navbar/project-navbar.component.ts Просмотреть файл

@@ -0,0 +1,25 @@
1
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
2
+import { Router } from '@angular/router';
3
+import { Component, OnInit } from '@angular/core';
4
+
5
+@Component({
6
+  selector: 'app-project-navbar',
7
+  templateUrl: './project-navbar.component.html',
8
+  styleUrls: ['./project-navbar.component.css']
9
+})
10
+export class ProjectNavbarComponent implements OnInit {
11
+
12
+  formSearch!: FormGroup;
13
+
14
+  constructor(private router: Router, private fb: FormBuilder) { }
15
+
16
+  ngOnInit(): void {
17
+    this.formSearch= this.fb.group({
18
+      userID:['', Validators.required]
19
+    })
20
+  }
21
+
22
+  onProjectCreate(){
23
+    this.router.navigateByUrl("/project-create")
24
+  }
25
+}

+ 0
- 0
src/app/pages/project-manager/project-management/project-update/project-update.component.css Просмотреть файл


+ 167
- 0
src/app/pages/project-manager/project-management/project-update/project-update.component.html Просмотреть файл

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

+ 25
- 0
src/app/pages/project-manager/project-management/project-update/project-update.component.spec.ts Просмотреть файл

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

+ 123
- 0
src/app/pages/project-manager/project-management/project-update/project-update.component.ts Просмотреть файл

@@ -0,0 +1,123 @@
1
+import { ProjState } from './../../../../shared/models/project/project.state';
2
+import { Project } from 'src/app/shared/models/project/project.model';
3
+import { GetAllComapaniesAction } from './../../../../ngrx/company/company.actions';
4
+import { GetAllUsersAction } from 'src/app/ngrx/user/user.actions';
5
+import { CreateFormUpdatedProjectAction, UpdateProjectAction } from './../../../../ngrx/project/project.action';
6
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
7
+import { ProjectState } from './../../../../ngrx/project/project.state';
8
+import { ProjectService } from './../../../../shared/services/project.service';
9
+import { ActivatedRoute, Router } from '@angular/router';
10
+import { Component, OnInit } from '@angular/core';
11
+import { Store } from '@ngrx/store';
12
+import { UserState } from 'src/app/ngrx/user/user.state';
13
+import { CompanyState } from 'src/app/ngrx/company/company.state';
14
+import { Priority } from 'src/app/shared/models/project/project.priority';
15
+import { MsgState } from 'src/app/ngrx/msg.state';
16
+
17
+@Component({
18
+  selector: 'app-project-update',
19
+  templateUrl: './project-update.component.html',
20
+  styleUrls: ['./project-update.component.css'],
21
+})
22
+export class ProjectUpdateComponent implements OnInit {
23
+  projectID: number;
24
+
25
+  constructor(
26
+    activatedRoute: ActivatedRoute,
27
+    private projectService: ProjectService,
28
+    private store: Store<{
29
+      projectReducerSelector: ProjectState;
30
+      userReducerSelector: UserState;
31
+      companyReducerSelector: CompanyState;
32
+    }>,
33
+    private formBuilder: FormBuilder,
34
+    private router: Router
35
+  ) {
36
+    this.projectID = activatedRoute.snapshot.params['projectID'];
37
+  }
38
+
39
+  userState!: UserState;
40
+  companyState!: CompanyState;
41
+
42
+  projectFormGroup!: FormGroup;
43
+  projectState!: ProjectState;
44
+  priorities = Priority;
45
+  projStates = ProjState;
46
+  msgState = MsgState;
47
+
48
+  ngOnInit(): void {
49
+    this.store.dispatch(new GetAllUsersAction({}, {}));
50
+    this.store.subscribe((state) => {
51
+      this.userState = state.userReducerSelector;
52
+    });
53
+    this.store.dispatch(new GetAllComapaniesAction({}));
54
+    this.store.subscribe((state) => {
55
+      this.companyState = state.companyReducerSelector;
56
+    });
57
+
58
+    this.projectService
59
+      .getProjectByIDService(this.projectID)
60
+      .subscribe((project) => {
61
+        this.store.dispatch(
62
+          new CreateFormUpdatedProjectAction(project, {}, {})
63
+        );
64
+        this.store.subscribe((state) => {
65
+          this.projectState = state.projectReducerSelector;
66
+
67
+          this.projectFormGroup = this.formBuilder.group({
68
+            projectID: [this.projectState.currestProject?.projectID],
69
+            projectName: [
70
+              this.projectState.currestProject?.projectName,
71
+              [
72
+                Validators.required,
73
+                Validators.minLength(5),
74
+                Validators.maxLength(20),
75
+              ],
76
+            ],
77
+            priority: [
78
+              this.projectState.currestProject?.priority,
79
+              Validators.required,
80
+            ],
81
+            createdDate: [this.projectState.currestProject?.createdDate],
82
+            description: [
83
+              this.projectState.currestProject?.description,
84
+              [Validators.required, Validators.minLength(25)],
85
+            ],
86
+            projState: [
87
+              this.projectState.currestProject?.projState,
88
+              Validators.required,
89
+            ],
90
+            userID: [
91
+              this.projectState.currestProject?.user.userID,
92
+              Validators.required,
93
+            ],
94
+            companyID: [
95
+              this.projectState.currestProject?.company.companyID,
96
+              Validators.required,
97
+            ],
98
+          });
99
+        });
100
+      });
101
+  }
102
+
103
+  onProjectUpdate() {
104
+
105
+    let projectFormModel = this.projectFormGroup.value;
106
+    let project : Project = new Project();
107
+    project.projectID = projectFormModel.projectID;
108
+    project.projectName = projectFormModel.projectName;
109
+    project.priority = projectFormModel.priority;
110
+    project.companyID = projectFormModel.companyID;
111
+    project.description = projectFormModel.description;
112
+    project.projState = projectFormModel.projState;
113
+    project.userID = projectFormModel.userID;
114
+
115
+    if(window.confirm(this.msgState.CONFIRM_UPDATE)){
116
+      this.store.dispatch(new UpdateProjectAction(project));
117
+    }
118
+
119
+  }
120
+  onUpdateSuccess() {
121
+    this.router.navigateByUrl("/projects-management");
122
+  }
123
+}

+ 0
- 0
src/app/pages/project-manager/project-management/projects-list/projects-list.component.css Просмотреть файл


+ 98
- 0
src/app/pages/project-manager/project-management/projects-list/projects-list.component.html Просмотреть файл

@@ -0,0 +1,98 @@
1
+<span class="p-input-icon-right">
2
+  <i class="pi pi-search"></i>
3
+  <input
4
+    type="text"
5
+    class="form-control"
6
+    pInputText
7
+    [(ngModel)]="projectName"
8
+    (ngModelChange)="onSearch1()"
9
+    placeholder="search a project by name"
10
+  />
11
+</span> &nbsp;
12
+<span class="p-input-icon-right">
13
+  <i class="pi pi-search"></i>
14
+  <input
15
+    type="text"
16
+    class="form-control"
17
+    pInputText
18
+    [(ngModel)]="userLastname"
19
+    (ngModelChange)="onSearch2()"
20
+    placeholder="projects of user lastname"
21
+  />
22
+</span>
23
+
24
+  &nbsp;
25
+<span class="p-input-icon-right">
26
+  <i class="pi pi-search"></i>
27
+  <input
28
+    type="text"
29
+    class="form-control"
30
+    pInputText
31
+    [(ngModel)]="companyName"
32
+    (ngModelChange)="onSearch3()"
33
+    placeholder="projects of company"
34
+  />
35
+</span>
36
+
37
+<p-table
38
+    [value]="inputProjectsList"
39
+    responsiveLayout="scroll"
40
+    *ngIf="inputProjectsList.length>0"
41
+    styleClass="p-datatable-striped"
42
+    [paginator]="true"
43
+    [rows]="5"
44
+    [showCurrentPageReport]="true"
45
+    currentPageReportTemplate="{first} - {last} of {totalRecords} projects"
46
+    [rowsPerPageOptions]="[5, 8, 10]"
47
+
48
+  >
49
+    <ng-template pTemplate="header">
50
+      <tr>
51
+        <th>ID</th>
52
+        <th>Name</th>
53
+        <th>Priority</th>
54
+        <th> Created Date</th>
55
+        <th>Description</th>
56
+        <th>state</th>
57
+        <th>User assigned</th>
58
+        <th>Company</th>
59
+        <th>action1</th>
60
+        <th>action2</th>
61
+      </tr>
62
+    </ng-template>
63
+    <ng-template pTemplate="body" let-project>
64
+      <tr>
65
+        <td>{{ project.projectID }}</td>
66
+        <td>{{ project.projectName }}</td>
67
+        <td>{{ project.priority }}</td>
68
+        <td>{{project.createdDate}}</td>
69
+        <td>{{ project.description }}</td>
70
+        <td>{{ project.state }}</td>
71
+        <td>
72
+          <ul>
73
+            <li>{{ project.user.firstname}} {{ project.user.lastname}}</li>
74
+            <li>{{ project.user.email}}</li>
75
+            <li>{{ project.user.address.numHouse }} {{ project.user.address.streetName }}
76
+            <li>{{ project.user.address.pb }} {{ project.user.address.city }}, {{ project.user.address.country }}</li>
77
+
78
+          </ul>
79
+        </td>
80
+        <td>
81
+          <ul>
82
+            <li>{{project.company.companyName}}</li>
83
+            <li>{{project.company.companyType}}</li>
84
+          </ul>
85
+        </td>
86
+        <td>
87
+          <button class="btn">
88
+            <i class="fa fa-pencil" style="color:mediumturquoise" (click)="onEditProject(project)"></i>
89
+          </button>
90
+        </td>
91
+        <td>
92
+          <button class="btn">
93
+            <i class="fa fa-trash" style="color:red" (click)="onProjectDelete(project)"></i>
94
+          </button>
95
+        </td>
96
+      </tr>
97
+    </ng-template>
98
+  </p-table>

+ 25
- 0
src/app/pages/project-manager/project-management/projects-list/projects-list.component.spec.ts Просмотреть файл

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

+ 73
- 0
src/app/pages/project-manager/project-management/projects-list/projects-list.component.ts Просмотреть файл

@@ -0,0 +1,73 @@
1
+import { DeleteProjectAction, GetAllProjectAction } from './../../../../ngrx/project/project.action';
2
+import { ProjectState } from './../../../../ngrx/project/project.state';
3
+import { MsgState } from 'src/app/ngrx/msg.state';
4
+import { Router } from '@angular/router';
5
+import { Project } from 'src/app/shared/models/project/project.model';
6
+import { Component, OnInit, Input } from '@angular/core';
7
+import { Store } from '@ngrx/store';
8
+
9
+@Component({
10
+  selector: 'app-projects-list',
11
+  templateUrl: './projects-list.component.html',
12
+  styleUrls: ['./projects-list.component.css']
13
+})
14
+export class ProjectsListComponent implements OnInit {
15
+
16
+  constructor(private router: Router, private store : Store<{projectReducerSelector: ProjectState}>) { }
17
+
18
+  @ Input () inputProjectsList!: Array<Project>;
19
+  ngOnInit(): void {
20
+  }
21
+
22
+  onEditProject(project: Project){
23
+    this.router.navigateByUrl("/project-update/"+project.projectID);
24
+  }
25
+  onProjectDelete(project:Project){
26
+    if(window.confirm(MsgState.CONFIRM_DEL)){
27
+      this.store.dispatch(new DeleteProjectAction(project))
28
+    }
29
+  }
30
+
31
+  projectName!: string;
32
+
33
+  onSearch1() {
34
+    if(this.projectName==''){
35
+      this.store.dispatch(new GetAllProjectAction()); //refresh
36
+    }
37
+    else{
38
+      this.inputProjectsList = this.inputProjectsList.filter((project: Project) => {
39
+        return project.projectName
40
+          .toLocaleLowerCase()
41
+          .match(this.projectName.toLocaleLowerCase());
42
+      });
43
+    }
44
+  }
45
+
46
+  userLastname!:string;
47
+  onSearch2() {
48
+    if(this.userLastname==''){
49
+      this.store.dispatch(new GetAllProjectAction()); //refresh
50
+    }
51
+    else{
52
+      this.inputProjectsList = this.inputProjectsList.filter((project: Project) => {
53
+        return project.user.lastname
54
+          .toLocaleLowerCase()
55
+          .match(this.userLastname.toLocaleLowerCase());
56
+      });
57
+    }
58
+  }
59
+
60
+  companyName!:string;
61
+  onSearch3() {
62
+    if(this.companyName==''){
63
+      this.store.dispatch(new GetAllProjectAction()); //refresh
64
+    }
65
+    else{
66
+      this.inputProjectsList = this.inputProjectsList.filter((project: Project) => {
67
+        return project.company.companyName
68
+          .toLocaleLowerCase()
69
+          .match(this.companyName.toLocaleLowerCase());
70
+      });
71
+    }
72
+  }
73
+}

+ 0
- 0
src/app/pages/project-manager/project-manager-routing.module.ts Просмотреть файл


Некоторые файлы не были показаны из-за большого количества измененных файлов

Powered by TurnKey Linux.