Angular Web App
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

investigate-business-entities-and-individuals.component.ts 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Component, OnInit } from '@angular/core';
  2. type State = 'VIEW INITIAL DETAILS'|'ENTER MORE DETAILS'|'ASSIGN COMMITTEE';
  3. type Role = 'Investigator'|'Hod'|'Panel';
  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. state: State;
  12. stateHistory: Array<State> = [];
  13. loginRole: Role;
  14. canExecute: boolean;
  15. executingRole: Role;
  16. constructor() {
  17. const loginEmail = localStorage.getItem('loginEmail');
  18. if (loginEmail && loginEmail.toLocaleLowerCase().startsWith('hod')) {
  19. this.loginRole = 'Hod';
  20. } else if (loginEmail && loginEmail.toLocaleLowerCase().startsWith('panel')) {
  21. this.loginRole = 'Panel';
  22. } else {
  23. this.loginRole = 'Investigator';
  24. }
  25. const savedState = localStorage.getItem('state');
  26. switch (savedState) {
  27. case 'ENTER MORE DETAILS':
  28. this.state = 'ENTER MORE DETAILS';
  29. this.executingRole = 'Investigator';
  30. break;
  31. case 'ASSIGN COMMITTEE':
  32. this.state = 'ASSIGN COMMITTEE';
  33. this.executingRole = 'Hod';
  34. break;
  35. default:
  36. this.state = 'VIEW INITIAL DETAILS';
  37. this.executingRole = 'Investigator';
  38. }
  39. this.canExecute = this.loginRole === this.executingRole;
  40. }
  41. proceed() {
  42. this.stateHistory.push(this.state);
  43. switch (this.state) {
  44. case 'VIEW INITIAL DETAILS':
  45. if (this.hasEnoughData) {
  46. this.state = 'ASSIGN COMMITTEE';
  47. this.executingRole = 'Hod';
  48. } else {
  49. this.state = 'ENTER MORE DETAILS';
  50. this.executingRole = 'Investigator';
  51. }
  52. break;
  53. case 'ENTER MORE DETAILS':
  54. this.state = 'ASSIGN COMMITTEE';
  55. this.executingRole = 'Hod';
  56. break;
  57. }
  58. localStorage.setItem('state', this.state);
  59. this.canExecute = this.loginRole === this.executingRole;
  60. }
  61. goBack() {
  62. const state = this.stateHistory.pop();
  63. if (state) {
  64. this.state = state;
  65. }
  66. }
  67. ngOnInit(): void {
  68. }
  69. }