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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | 1x | /* eslint-disable no-console */ import { Injectable, Inject, SkipSelf } from '@angular/core'; import { HttpClient, HttpEvent, HttpEventType } from '@angular/common/http'; import { Observable, of } from 'rxjs'; import { catchError, filter, map } from 'rxjs/operators'; import { GetFileResponseData, SysCheckStatistics, ResultData, ReportType } from './workspace.interfaces'; import { FileDeletionReport, UploadReport, UploadResponse, UploadStatus } from './files/files.interfaces'; import { AppError } from '../app.interfaces'; @Injectable({ providedIn: 'root' }) export class BackendService { constructor( @Inject('BACKEND_URL') private readonly serverUrl: string, @SkipSelf() private http: HttpClient ) { } getFiles(workspaceId: number): Observable<GetFileResponseData> { return this.http.get<GetFileResponseData>(`${this.serverUrl}workspace/${workspaceId}/files`); } deleteFiles(workspaceId: number, filesToDelete: Array<string>): Observable<FileDeletionReport> { return this.http.request<FileDeletionReport>( 'delete', `${this.serverUrl}workspace/${workspaceId}/files`, { body: { f: filesToDelete } } ); } getResults(workspaceId: number): Observable<ResultData[]> { return this.http.get<ResultData[]>(`${this.serverUrl}workspace/${workspaceId}/results`, {}); } deleteResponses(workspaceId: number, groups: string[]): Observable<void> { return this.http .request<void>('delete', `${this.serverUrl}workspace/${workspaceId}/responses`, { body: { groups } }); } getSysCheckReportsOverview(workspaceId: number): Observable<SysCheckStatistics[]> { return this.http.get<SysCheckStatistics[]>(`${this.serverUrl}workspace/${workspaceId}/sys-check/reports/overview`); } deleteSysCheckReports(workspaceId: number, checkIds: string[]): Observable<FileDeletionReport> { return this.http.request<FileDeletionReport>( 'delete', `${this.serverUrl}workspace/${workspaceId}/sys-check/reports`, { body: { checkIds } } ); } getReport(workspaceId: number, reportType: ReportType, dataIds: string[], useNewVersion: boolean) : Observable<Blob> { return this.http .get( `${this.serverUrl}workspace/${workspaceId}/report/${reportType}`, { params: { dataIds: dataIds.join(','), useNewVersion: useNewVersion }, headers: { Accept: 'text/csv' }, responseType: 'blob' } ); } getFile(workspaceId: number, fileType: string, fileName: string): Observable<Blob> { return this.http .get(`${this.serverUrl}workspace/${workspaceId}/file/${fileType}/${fileName}`, { responseType: 'blob' }); } postFile(workspaceId: number, formData: FormData): Observable<UploadResponse> { return this.http.post<UploadReport>( `${this.serverUrl}workspace/${workspaceId}/file`, formData, { // TODO de-comment, if backend UploadedFilesHandler.class.php l. 47 was fixed // headers: new HttpHeaders().set('Content-Type', 'multipart/form-data'), observe: 'events', reportProgress: true, responseType: 'json' } ) .pipe( catchError((err: AppError) => of({ progress: 0, status: UploadStatus.error, report: { Upload: { error: [err.description] } } })), map((event: HttpEvent<UploadReport> | UploadResponse): UploadResponse | null => { Iif ('progress' in event) { return event; } Iif (event.type === HttpEventType.UploadProgress) { return { progress: event.total ? Math.floor((event.loaded * 100) / event.total) : 0, status: UploadStatus.busy, report: {} }; } Iif (event.type === HttpEventType.Response) { return { progress: 100, status: UploadStatus.ok, report: event.body ?? {} }; } return null; }), filter((response: UploadResponse | null): response is UploadResponse => (response !== null) ) ); } getFilesWithDependencies(workspaceId: number, ...files: string[]): Observable<GetFileResponseData> { return this.http .post<GetFileResponseData>( `${this.serverUrl}workspace/${workspaceId}/files-dependencies`, { body: files } ); } } |