prettify search
This commit is contained in:
parent
ab8b3f760a
commit
eff3a6dc09
@ -1,11 +1,11 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService } from '@iqser/common-ui';
|
||||
import { ISearchInput, ISearchRequest, ISearchResponse } from '@red/domain';
|
||||
import { from, Observable, of, zip } from 'rxjs';
|
||||
import { IMatchedDocument, ISearchInput, ISearchRequest, ISearchResponse } from '@red/domain';
|
||||
import { Observable, of, zip } from 'rxjs';
|
||||
import { mapTo, switchMap } from 'rxjs/operators';
|
||||
import { AppStateService } from '../../../../state/app-state.service';
|
||||
import { DossiersService } from '../../../../services/entity-services/dossiers.service';
|
||||
import { FilesMapService } from '../../../../services/entity-services/files-map.service';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DossiersService } from '@services/entity-services/dossiers.service';
|
||||
import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||
|
||||
@Injectable()
|
||||
export class PlatformSearchService extends GenericService<ISearchResponse> {
|
||||
@ -26,28 +26,28 @@ export class PlatformSearchService extends GenericService<ISearchResponse> {
|
||||
});
|
||||
}
|
||||
|
||||
return this._post({
|
||||
const body: ISearchRequest = {
|
||||
dossierIds,
|
||||
queryString: query ?? '',
|
||||
page: 1,
|
||||
returnSections: false,
|
||||
pageSize: 300,
|
||||
} as ISearchRequest).pipe(switchMap(searchValue => this._loadFiles$(searchValue)));
|
||||
};
|
||||
|
||||
return this._post(body).pipe(switchMap(searchValue => this._loadMissingFiles$(searchValue)));
|
||||
}
|
||||
|
||||
private _loadFiles$(searchResponse: ISearchResponse): Observable<ISearchResponse> {
|
||||
const responseDossierIds = Array.from(
|
||||
searchResponse.matchedDocuments
|
||||
.filter(document => this._dossiersService.has(document.dossierId))
|
||||
.filter(document => !this._filesMapService.get(document.dossierId, document.fileId))
|
||||
.reduce((set, document) => set.add(document.dossierId), new Set<string>()),
|
||||
);
|
||||
return responseDossierIds.length
|
||||
? zip(...responseDossierIds.map(dossierId => this._filesForDossier$(dossierId))).pipe(mapTo(searchResponse))
|
||||
: of(searchResponse);
|
||||
private _loadMissingFiles$(searchResponse: ISearchResponse): Observable<ISearchResponse> {
|
||||
const documentsOfActiveDossiers = searchResponse.matchedDocuments.filter(document => this._dossiersService.has(document.dossierId));
|
||||
const fileNotLoaded = ({ dossierId, fileId }: IMatchedDocument) => !this._filesMapService.get(dossierId, fileId);
|
||||
const dossiersWithNotLoadedFiles = documentsOfActiveDossiers.filter(fileNotLoaded).map(document => document.dossierId);
|
||||
|
||||
const dossierIds = Array.from(new Set(dossiersWithNotLoadedFiles));
|
||||
return dossierIds.length ? this._loadFilesFor$(dossierIds).pipe(mapTo(searchResponse)) : of(searchResponse);
|
||||
}
|
||||
|
||||
private _filesForDossier$(dossierId: string): Observable<any> {
|
||||
return from(this._appStateService.getFiles(this._dossiersService.find(dossierId)));
|
||||
private _loadFilesFor$(dossierIds: string[]) {
|
||||
const dossiers = dossierIds.map(dossierId => this._dossiersService.find(dossierId));
|
||||
return zip(...dossiers.map(dossier => this._appStateService.getFiles(dossier)));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user