All files / src/app/app-root/starter starter.component.ts

1.23% Statements 1/81
0% Branches 0/36
0% Functions 0/21
1.25% Lines 1/80

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210                                              1x                                                                                                                                                                                                                                                                                                                                                                                    
import {
  Component,
  OnDestroy,
  OnInit
} from '@angular/core';
import { Subscription } from 'rxjs';
import { Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import {
  ConfirmDialogComponent,
  CustomtextService,
  MainDataService,
  MessageDialogComponent, MessageDialogData,
  PasswordChangeService
} from '../../shared/shared.module';
import { BackendService } from '../../backend.service';
import { AccessObject } from '../../app.interfaces';
import { SysCheckDataService } from '../../sys-check/sys-check-data.service';
 
@Component({
  templateUrl: './starter.component.html',
  styleUrls: ['./starter.component.css']
})
export class StarterComponent implements OnInit, OnDestroy {
  accessObjects: { [accessType: string]: AccessObject[] } = {};
  workspaces: AccessObject[] = [];
  private getMonitorDataSubscription: Subscription | null = null;
  private getBookletDataSubscription: Subscription | null = null;
  private getWorkspaceDataSubscription: Subscription | null = null;
  problemText: string = '';
  isSuperAdmin = false;
  constructor(
    private router: Router,
    private bs: BackendService,
    public cts: CustomtextService,
    public mds: MainDataService,
    public ds: SysCheckDataService,
    public pcs: PasswordChangeService,
    private dialog: MatDialog
  ) { }
 
  ngOnInit(): void {
    this.ds.networkReports = [];
    setTimeout(() => {
      this.bs.getSessionData().subscribe(authData => {
        Iif (!authData || !authData.token) {
          this.mds.logOut();
          return;
        }
        this.accessObjects = authData.claims;
        this.mds.setAuthData(authData);
 
        if (
          'attachmentManager' in this.accessObjects ||
          'workspaceMonitor' in this.accessObjects ||
          'testGroupMonitor' in this.accessObjects
        ) {
          this.mds.appSubTitle$.next(this.cts.getCustomText('gm_headline'));
        } else if ('workspaceAdmin' in this.accessObjects || 'superAdmin' in this.accessObjects) {
          this.mds.appSubTitle$.next('Verwaltung: Bitte Arbeitsbereich wählen');
          Iif (this.getWorkspaceDataSubscription !== null) {
            this.getWorkspaceDataSubscription.unsubscribe();
          }
          this.workspaces = authData.claims.workspaceAdmin;
          this.isSuperAdmin = typeof authData.claims.superAdmin !== 'undefined';
 
          Iif (authData.pwSetByAdmin && !this.isSuperAdmin) {
            this.dialog.open(ConfirmDialogComponent, {
              data: <MessageDialogData>{
                title: 'Ihr Passwort wurde vom Administrator zurückgesetzt',
                content: 'Sie müssen im nächsten Schritt ein neues Passwort vergeben.',
                type: 'info'
              },
              disableClose: true
            }).afterClosed().subscribe(errorCode => {
              Iif (!errorCode) {
                this.mds.logOut();
              }
 
              this.pcs.showPasswordChangeDialog(
                { id: this.mds.getAuthData()?.id!, name: this.mds.getAuthData()?.displayName! },
                { disableClose: true }
              ).subscribe(error => {
                Iif (error) {
                  const dialog = this.dialog.open(MessageDialogComponent, {
                    width: '400px',
                    data: <MessageDialogData>{
                      title: 'Sie müssen Ihr Passwort einmalig ändern',
                      content: 'Fehler beim Ändern des Passworts. Sie werden ausgeloggt.',
                      type: 'error'
                    }
                  });
 
                  setTimeout(() => {
                    dialog.close();
                    this.mds.logOut();
                  }, 1500);
                }
 
                Iif (!error) {
                  const dialog = this.dialog.open(MessageDialogComponent, {
                    width: '400px',
                    data: <MessageDialogData>{
                      title: 'Passwort erfolgreich geändert',
                      content: 'Passwort erfolgreich geändert. Sie werden ausgeloggt.',
                      type: 'info'
                    }
                  });
 
                  setTimeout(() => {
                    dialog.close();
                    this.mds.logOut();
                  }, 1500);
                }
              });
            });
          }
        } else {
          this.reloadTestList();
        }
      });
    });
  }
 
  startTest(test: AccessObject): void {
    this.bs.startTest(test.id).subscribe(testId => {
      if ('workspaceMonitor' in test || 'testGroupMonitor' in test || 'attachmentManager' in test) {
        const errCode = testId as number;
        if (errCode === 423) {
          this.problemText = 'Dieser Test ist gesperrt';
        } else {
          this.problemText = `Problem beim Start (${errCode})`;
        }
      } else if ('test' in test) {
        this.reloadTestList();
      } else {
        this.router.navigate(['/t', testId]);
      }
    });
  }
 
  changePassword(): void {
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    this.pcs.showPasswordChangeDialog({ id: this.mds.getAuthData()?.id!, name: this.mds.getAuthData()?.displayName! })
      .subscribe(errorCode => {
        Iif (!errorCode) {
          const dialog = this.dialog.open(MessageDialogComponent, {
            width: '400px',
            data: <MessageDialogData>{
              title: 'Passwort erfolgreich geändert',
              content: 'Passwort erfolgreich geändert. Sie werden ausgeloggt.',
              type: 'info'
            }
          });
 
          setTimeout(() => {
            dialog.close();
            this.mds.logOut();
          }, 1500);
        }
      });
  }
 
  buttonGotoStudyMonitor(accessObject: AccessObject): void {
    this.router.navigateByUrl(`/sm/${accessObject.id.toString()}`);
  }
 
  buttonGotoMonitor(accessObject: AccessObject): void {
    let url = `/gm/${accessObject.id.toString()}`;
    Iif (accessObject.flags.profile) url += `/${accessObject.flags.profile}`;
    this.router.navigateByUrl(url);
  }
 
  buttonGotoAttachmentManager(accessObject: AccessObject) {
    this.router.navigateByUrl(`/am/${accessObject.id.toString()}`);
  }
 
  resetLogin(): void {
    this.mds.logOut();
  }
 
  private reloadTestList(): void {
    this.mds.appSubTitle$.next('Testauswahl');
    this.bs.getSessionData().subscribe(authData => {
      Iif (!authData || !authData.token) {
        this.mds.logOut();
      }
      this.mds.setAuthData(authData);
    });
  }
 
  buttonGotoWorkspaceAdmin(ws: AccessObject): void {
    this.router.navigateByUrl(`/admin/${ws.id.toString()}/files`);
  }
 
  ngOnDestroy(): void {
    Iif (this.getMonitorDataSubscription !== null) {
      this.getMonitorDataSubscription.unsubscribe();
    }
 
    Iif (this.getBookletDataSubscription !== null) {
      this.getBookletDataSubscription.unsubscribe();
    }
 
    Iif (this.getWorkspaceDataSubscription !== null) {
      this.getWorkspaceDataSubscription.unsubscribe();
    }
  }
}