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 |
|
constructor(entityMapper: EntityMapperService, entities: EntityRegistry, syncState: SyncStateSubject, sanitizer: DomSanitizer)
|
|||||||||||||||
Parameters :
|
Protected getShowFileUrl |
getShowFileUrl(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:42
|
Returns :
string
|
loadFile |
loadFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:46
|
Returns :
Observable<SafeUrl>
|
removeAllFiles | ||||||
removeAllFiles(entity: Entity)
|
||||||
Inherited from
FileService
|
||||||
Defined in
FileService:33
|
||||||
Parameters :
Returns :
Observable<any>
|
removeFile |
removeFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:28
|
Returns :
Observable<any>
|
showFile |
showFile(entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:37
|
Returns :
void
|
uploadFile |
uploadFile(file: File, entity: Entity, property: string)
|
Inherited from
FileService
|
Defined in
FileService:51
|
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: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 });
}
}