File

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

Index

Properties
Methods

Constructor

constructor(entityMapper: EntityMapperService, entities: EntityRegistry, syncState: SyncStateSubject, sanitizer: DomSanitizer)
Parameters :
Name Type Optional
entityMapper EntityMapperService No
entities EntityRegistry No
syncState SyncStateSubject No
sanitizer DomSanitizer No

Methods

Protected getShowFileUrl
getShowFileUrl(entity: Entity, property: string)
Inherited from FileService
Defined in FileService:42
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : string
loadFile
loadFile(entity: Entity, property: string)
Inherited from FileService
Defined in FileService:46
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : Observable<SafeUrl>
removeAllFiles
removeAllFiles(entity: Entity)
Inherited from FileService
Defined in FileService:33
Parameters :
Name Type Optional
entity Entity No
Returns : Observable<any>
removeFile
removeFile(entity: Entity, property: string)
Inherited from FileService
Defined in FileService:28
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : Observable<any>
showFile
showFile(entity: Entity, property: string)
Inherited from FileService
Defined in FileService:37
Parameters :
Name Type Optional
entity Entity No
property string No
Returns : void
uploadFile
uploadFile(file: File, entity: Entity, property: string)
Inherited from FileService
Defined in FileService:51
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
Defined in FileService:149
Parameters :
Name Type Optional
message string No
obs Observable<HttpEvent | any> No
Returns : void

Properties

Protected dialog
Type : MatDialog
Default value : inject(MatDialog)
Inherited from FileService
Defined in FileService:31
Protected httpClient
Type : HttpClient
Default value : inject(HttpClient, { optional: true, })
Inherited from FileService
Defined in FileService:32
Protected snackbar
Type : MatSnackBar
Default value : inject(MatSnackBar)
Inherited from FileService
Defined in FileService:30
import { Injectable } from "@angular/core";
import { Entity } from "../../core/entity/model/entity";
import { EMPTY, Observable, of } from "rxjs";
import { FileService } from "./file.service";
import { EntityMapperService } from "../../core/entity/entity-mapper/entity-mapper.service";
import { EntityRegistry } from "../../core/entity/database-entity.decorator";
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
import { SyncStateSubject } from "../../core/session/session-type";

/**
 * 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 fileMap = new Map<string, string>();

  constructor(
    entityMapper: EntityMapperService,
    entities: EntityRegistry,
    syncState: SyncStateSubject,
    private sanitizer: DomSanitizer,
  ) {
    super(entityMapper, entities, syncState);
  }

  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 ""