src/app/features/file/mock-file.service.ts
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
Properties |
|
Methods |
|
Protected getShowFileUrl |
getShowFileUrl(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:32
|
Returns :
string
|
loadFile |
loadFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:36
|
Returns :
Observable<SafeUrl>
|
removeAllFiles | ||||||
removeAllFiles(entity: Entity)
|
||||||
Inherited from
FileService
|
||||||
Defined in
FileService:23
|
||||||
Parameters :
Returns :
Observable<any>
|
removeFile |
removeFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:18
|
Returns :
Observable<any>
|
showFile |
showFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:27
|
Returns :
void
|
uploadFile |
uploadFile(file: File, entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:41
|
Returns :
Observable<any>
|
Protected reportProgress | |||||||||
reportProgress(message: string, obs: Observable
|
|||||||||
Inherited from
FileService
|
|||||||||
Defined in
FileService:149
|
|||||||||
Parameters :
Returns :
void
|
Protected dialog |
Type : MatDialog
|
Default value : inject(MatDialog)
|
Inherited from
FileService
|
Defined in
FileService:32
|
Protected entities |
Default value : inject(EntityRegistry)
|
Inherited from
FileService
|
Defined in
FileService:37
|
Protected entityMapper |
Default value : inject(EntityMapperService)
|
Inherited from
FileService
|
Defined in
FileService:36
|
Protected httpClient |
Type : HttpClient
|
Default value : inject(HttpClient, {
optional: true,
})
|
Inherited from
FileService
|
Defined in
FileService:33
|
Protected snackbar |
Type : MatSnackBar
|
Default value : inject(MatSnackBar)
|
Inherited from
FileService
|
Defined in
FileService:31
|
Protected syncState |
Default value : inject(SyncStateSubject)
|
Inherited from
FileService
|
Defined in
FileService:38
|
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 });
}
}