Application de gestion de projets. Un projet doit affecté à un utilisateur et une société qui existent

project-create.component.ts 3.4KB

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

Powered by TurnKey Linux.