All files / src/app/workspace-admin workspacedata.service.ts

69.23% Statements 9/13
0% Branches 0/3
50% Functions 2/4
69.23% Lines 9/13

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                            1x 4x 4x       4x       4x 4x 4x 4x   4x                            
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BehaviorSubject } from 'rxjs';
import { BackendService } from './backend.service';
import { ReportType } from './workspace.interfaces';
import { FileService } from '../shared/services/file.service';
import { MessageService } from '../shared/services/message.service';
 
@Injectable({
  providedIn: 'root'
})
 
@Injectable()
export class WorkspaceDataService {
  wsRole = 'RW';
  wsName = '';
  workspaceId$: BehaviorSubject<number>;
 
  get workspaceId(): number {
    return this.workspaceId$.getValue();
  }
 
  constructor(
    private backendService: BackendService,
    private deleteConfirmDialog: MatDialog,
    private messageService: MessageService,
    public snackBar: MatSnackBar
  ) {
    this.workspaceId$ = new BehaviorSubject<number>(-1);
  }
 
  downloadReport(dataIds: string[], reportType: ReportType, filename: string, useNewVersion: boolean = false): void {
    this.backendService.getReport(this.workspaceId, reportType, dataIds, useNewVersion)
      .subscribe((response: Blob) => {
        if (response.size > 0) {
          FileService.saveBlobToFile(response, filename);
        } else {
          this.messageService.showError('Keine Daten verfügbar.');
        }
      });
  }
}