Angular Web App
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

172 lines
5.7 KiB

  1. import { Component, OnInit } from '@angular/core';
  2. type State = 'VIEW INITIAL DETAILS'|'ENTER MORE DETAILS'|'ASSIGN COMMITTEE'|'REVIEW NON COMPLIANCE'|'CONCUR COMPLIANCE REVIEW'|'CLOSING REMARKS'|'PREPARE PRELIMINARY LETTER'|'RESPOND TO PRELIMINARY LETTER';
  3. type Role = 'Investigator'|'Hod'|'Panel'|'Customer';
  4. @Component({
  5. selector: 'app-investigate-business-entities-and-individuals',
  6. templateUrl: './investigate-business-entities-and-individuals.component.html',
  7. styleUrls: ['./investigate-business-entities-and-individuals.component.scss']
  8. })
  9. export class InvestigateBusinessEntitiesAndIndividualsComponent implements OnInit {
  10. hasEnoughData = false;
  11. isNonCompliant = false;
  12. isPanelConcurring = true;
  13. panelRemarks = '';
  14. state: State;
  15. stateHistory: Array<State> = [];
  16. loginRole: Role;
  17. canExecute: boolean;
  18. executingRole: Role;
  19. constructor() {
  20. const panelRemarks = localStorage.getItem('panelRemarks');
  21. if (panelRemarks) {
  22. this.panelRemarks = panelRemarks;
  23. }
  24. this.isNonCompliant = localStorage.getItem('isNonCompliant') === 'true';
  25. const loginEmail = localStorage.getItem('loginEmail');
  26. if (loginEmail && loginEmail.toLocaleLowerCase().startsWith('hod')) {
  27. this.loginRole = 'Hod';
  28. } else if (loginEmail && loginEmail.toLocaleLowerCase().startsWith('panel')) {
  29. this.loginRole = 'Panel';
  30. } else if (loginEmail && loginEmail.toLocaleLowerCase().startsWith('customer')) {
  31. this.loginRole = 'Customer';
  32. } else {
  33. this.loginRole = 'Investigator';
  34. }
  35. const savedState = localStorage.getItem('state');
  36. switch (savedState) {
  37. case 'ENTER MORE DETAILS':
  38. this.state = 'ENTER MORE DETAILS';
  39. this.executingRole = 'Investigator';
  40. break;
  41. case 'ASSIGN COMMITTEE':
  42. this.state = 'ASSIGN COMMITTEE';
  43. this.executingRole = 'Hod';
  44. break;
  45. case 'REVIEW NON COMPLIANCE':
  46. this.state = 'REVIEW NON COMPLIANCE';
  47. this.executingRole = 'Investigator';
  48. break;
  49. case 'CONCUR COMPLIANCE REVIEW':
  50. this.state = 'CONCUR COMPLIANCE REVIEW';
  51. this.executingRole = 'Panel';
  52. break;
  53. case 'CLOSING REMARKS':
  54. this.state = 'CLOSING REMARKS';
  55. this.executingRole = 'Investigator';
  56. break;
  57. case 'PREPARE PRELIMINARY LETTER':
  58. this.state = 'PREPARE PRELIMINARY LETTER';
  59. this.executingRole = 'Investigator';
  60. break;
  61. case 'RESPOND TO PRELIMINARY LETTER':
  62. this.state = 'RESPOND TO PRELIMINARY LETTER';
  63. this.executingRole = 'Customer';
  64. break;
  65. default:
  66. this.state = 'VIEW INITIAL DETAILS';
  67. this.executingRole = 'Investigator';
  68. }
  69. this.canExecute = this.loginRole === this.executingRole;
  70. }
  71. updateIsNonCompliant(isNonCompliant: boolean) {
  72. this.isNonCompliant = isNonCompliant;
  73. localStorage.setItem('isNonCompliant', String(isNonCompliant));
  74. }
  75. updatePanelRemarks(remarks: string) {
  76. this.panelRemarks = remarks;
  77. localStorage.setItem('panelRemarks', remarks);
  78. }
  79. proceed() {
  80. this.stateHistory.push(this.state);
  81. switch (this.state) {
  82. case 'VIEW INITIAL DETAILS':
  83. if (this.hasEnoughData) {
  84. this.state = 'ASSIGN COMMITTEE';
  85. this.executingRole = 'Hod';
  86. } else {
  87. this.state = 'ENTER MORE DETAILS';
  88. this.executingRole = 'Investigator';
  89. }
  90. break;
  91. case 'ENTER MORE DETAILS':
  92. this.state = 'ASSIGN COMMITTEE';
  93. this.executingRole = 'Hod';
  94. break;
  95. case 'ASSIGN COMMITTEE':
  96. this.state = 'REVIEW NON COMPLIANCE';
  97. this.executingRole = 'Investigator';
  98. break;
  99. case 'REVIEW NON COMPLIANCE':
  100. this.state = 'CONCUR COMPLIANCE REVIEW';
  101. this.executingRole = 'Panel';
  102. break;
  103. case 'CONCUR COMPLIANCE REVIEW':
  104. if (!this.isPanelConcurring) {
  105. this.state = 'REVIEW NON COMPLIANCE';
  106. } else {
  107. if (this.isNonCompliant) {
  108. this.state = 'PREPARE PRELIMINARY LETTER';
  109. } else {
  110. this.state = 'CLOSING REMARKS';
  111. }
  112. }
  113. this.executingRole = 'Investigator';
  114. break;
  115. case 'PREPARE PRELIMINARY LETTER':
  116. this.state = 'RESPOND TO PRELIMINARY LETTER';
  117. this.executingRole = 'Customer';
  118. break;
  119. }
  120. localStorage.setItem('state', this.state);
  121. this.canExecute = this.loginRole === this.executingRole;
  122. }
  123. goBack() {
  124. const state = this.stateHistory.pop();
  125. if (state) {
  126. this.state = state;
  127. }
  128. switch (this.state) {
  129. case 'ASSIGN COMMITTEE':
  130. this.executingRole = 'Hod';
  131. break;
  132. case 'CONCUR COMPLIANCE REVIEW':
  133. this.executingRole = 'Panel';
  134. break;
  135. default:
  136. this.executingRole = 'Investigator';
  137. }
  138. localStorage.setItem('state', this.state);
  139. this.canExecute = this.loginRole === this.executingRole;
  140. }
  141. ngOnInit(): void {
  142. }
  143. }