File

src/app/app-root/admin-starter/admin-starter.component.ts

Implements

OnInit OnDestroy

Metadata

styles mat-card {margin: 10px;},.mat-card-box {background-color: var(--tc-box-background)}
templateUrl ./admin-starter.component.html

Index

Properties
Methods

Constructor

constructor(router: Router, bs: BackendService, mds: MainDataService)
Parameters :
Name Type Optional
router Router No
bs BackendService No
mds MainDataService No

Methods

buttonGotoWorkspaceAdmin
buttonGotoWorkspaceAdmin(ws: WorkspaceData)
Parameters :
Name Type Optional
ws WorkspaceData No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
resetLogin
resetLogin()
Returns : void

Properties

Private getWorkspaceDataSubscription
Type : Subscription
Default value : null
isSuperAdmin
Default value : false
Public mds
Type : MainDataService
workspaces
Type : WorkspaceData[]
Default value : []
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { from, Subscription } from 'rxjs';
import { concatMap } from 'rxjs/operators';
import { BackendService } from '../../backend.service';
import { AuthAccessKeyType, AuthData, WorkspaceData } from '../../app.interfaces';
import { MainDataService } from '../../maindata.service';

@Component({
  templateUrl: './admin-starter.component.html',
  styles: [
    'mat-card {margin: 10px;}',
    '.mat-card-box {background-color: var(--tc-box-background)}'
  ]
})

export class AdminStarterComponent implements OnInit, OnDestroy {
  workspaces: WorkspaceData[] = [];
  isSuperAdmin = false;
  private getWorkspaceDataSubscription: Subscription = null;

  constructor(
    private router: Router,
    private bs: BackendService,
    public mds: MainDataService
  ) { }

  ngOnInit(): void {
    setTimeout(() => {
      this.mds.appSubTitle$.next('Verwaltung: Bitte Arbeitsbereich wählen');
      this.mds.setSpinnerOn();
      this.bs.getSessionData().subscribe(authDataUntyped => {
        if (this.getWorkspaceDataSubscription !== null) {
          this.getWorkspaceDataSubscription.unsubscribe();
        }

        if (typeof authDataUntyped !== 'number') {
          const authData = authDataUntyped as AuthData;
          if (authData) {
            if (authData.token) {
              if (authData.access[AuthAccessKeyType.SUPER_ADMIN]) {
                this.isSuperAdmin = true;
              }
              if (authData.access[AuthAccessKeyType.WORKSPACE_ADMIN]) {
                this.workspaces = [];
                this.getWorkspaceDataSubscription = from(authData.access[AuthAccessKeyType.WORKSPACE_ADMIN])
                  .pipe(
                    concatMap(workspaceId => this.bs.getWorkspaceData(workspaceId))
                  ).subscribe(
                    wsData => this.workspaces.push(wsData),
                    () => this.mds.setSpinnerOff(),
                    () => this.mds.setSpinnerOff()
                  );
              } else {
                this.mds.setSpinnerOff();
              }
              this.mds.setAuthData(authData);
            } else {
              this.mds.setAuthData();
              this.mds.setSpinnerOff();
            }
          } else {
            this.mds.setAuthData();
            this.mds.setSpinnerOff();
          }
        } else {
          this.mds.setSpinnerOff();
        }
      });
    });
  }

  buttonGotoWorkspaceAdmin(ws: WorkspaceData): void {
    this.router.navigateByUrl(`/admin/${ws.id.toString()}/files`);
  }

  resetLogin(): void {
    this.mds.setAuthData();
    this.router.navigate(['/']);
  }

  ngOnDestroy(): void {
    if (this.getWorkspaceDataSubscription !== null) {
      this.getWorkspaceDataSubscription.unsubscribe();
    }
  }
}
<div fxLayout="row wrap" fxLayoutAlign="center stretch">
  <mat-card fxFlex="0 0 400px" fxLayout="column">
    <mat-card-title>Verwaltung</mat-card-title>
    <mat-card-subtitle>Bitte Arbeitsbereich wählen</mat-card-subtitle>
    <mat-card-content>
      <div fxLayoutGap="10px" fxLayout="column">
        <p *ngIf="workspaces.length === 0">
          Sie sind mit Administrator-Funktionen angemeldet. Aktuell sind keine Studien für Sie freigegeben.
        </p>
        <button mat-raised-button color="primary" (click)="buttonGotoWorkspaceAdmin(ws)"
                *ngFor="let ws of workspaces">
          {{ws.name}}
        </button>
      </div>
    </mat-card-content>
    <mat-card-actions>
      <button mat-raised-button color="foreground" *ngIf="isSuperAdmin" [routerLink]="['/superadmin']">System-Admin</button>
      <button mat-raised-button color="foreground" (click)="resetLogin()">Neu anmelden</button>
    </mat-card-actions>
  </mat-card>

  <mat-card fxFlex="0 0 400px" class="mat-card-box">
    <mat-card-title>{{mds.appTitle$ | async}}</mat-card-title>
    <mat-card-subtitle>{{mds.appSubTitle$ | async}}</mat-card-subtitle>
    <mat-card-content>
      <status-card></status-card>
    </mat-card-content>
  </mat-card>
</div>
mat-card {margin: 10px;}
.mat-card-box {background-color: var(--tc-box-background)}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""