src/app/features/file/mock-file.service.ts

Description

A mock implementation of the file service which only stores the file temporarily in the browser. This can be used in the demo mode. NO FILES ARE UPLOADED OR DOWNLOADED

Extends

FileService

Relationships

Used by

Depends on

Index

Properties
Methods

Methods

Protected getShowFileUrl
getShowFileUrl(entity: Entity, property: string)
Inherited from FileService
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : string
loadFile
loadFile(entity: Entity, property: string)
Inherited from FileService
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : Observable<SafeUrl>
removeAllFiles
removeAllFiles(entity: Entity)
Inherited from FileService
Parameters :
Name Type Optional
entity Entity No
Returns : Observable<any>
removeFile
removeFile(entity: Entity, property: string)
Inherited from FileService
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : Observable<any>
showFile
showFile(entity: Entity, property: string)
Inherited from FileService
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : void
uploadFile
uploadFile(file: File, entity: Entity, property: string)
Inherited from FileService
Parameters :
Name Type Optional
file File No
entity Entity No
property string No
Returns : Observable<any>
Protected reportProgress
reportProgress(message: string, obs: Observable)
Inherited from FileService
Parameters :
Name Type Optional
message string No
obs Observable<HttpEvent | any> No
Returns : void

Properties

Protected alertService
Type : unknown
Default value : inject(AlertService)
Inherited from FileService
Protected dialog
Type : MatDialog
Default value : inject(MatDialog)
Inherited from FileService
Protected entities
Type : unknown
Default value : inject(EntityRegistry)
Inherited from FileService
Protected entityMapper
Type : unknown
Default value : inject(EntityMapperService)
Inherited from FileService
Protected httpClient
Type : HttpClient
Default value : inject(HttpClient, { optional: true, })
Inherited from FileService
Protected schemaService
Type : unknown
Default value : inject(EntitySchemaService)
Inherited from FileService
Protected snackbar
Type : MatSnackBar
Default value : inject(MatSnackBar)
Inherited from FileService
Protected syncState
Type : unknown
Default value : inject(SyncStateSubject)
Inherited from FileService
import { inject, Injectable } from "@angular/core";
import { Entity } from "../../core/entity/model/entity";
import { EMPTY, Observable, of } from "rxjs";
import { FileService } from "./file.service";
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";

/**
 * A mock implementation of the file service which only stores the file temporarily in the browser.
 * This can be used in the demo mode.
 * NO FILES ARE UPLOADED OR DOWNLOADED
 */
@Injectable()
export class MockFileService extends FileService {
  private sanitizer = inject(DomSanitizer);

  private fileMap = new Map<string, string>();

  removeFile(entity: Entity, property: string): Observable<any> {
    this.fileMap.delete(`${entity.getId()}:${property}`);
    return of({ ok: true });
  }

  removeAllFiles(entity: Entity): Observable<any> {
    return EMPTY;
  }

  override showFile(entity: Entity, property: string): void {
    const url = this.fileMap.get(`${entity.getId()}:${property}`);
    window.open(url, "_blank");
  }

  protected override getShowFileUrl(entity: Entity, property: string): string {
    return "";
  }

  loadFile(entity: Entity, property: string): Observable<SafeUrl> {
    const url = this.fileMap.get(`${entity.getId()}:${property}`);
    return of(this.sanitizer.bypassSecurityTrustUrl(url));
  }

  uploadFile(file: File, entity: Entity, property: string): Observable<any> {
    const fileURL = URL.createObjectURL(file);
    this.fileMap.set(`${entity.getId()}:${property}`, fileURL);
    return of({ ok: true });
  }
}

results matching ""

    No results matching ""