RED-2670: Fix 2

This commit is contained in:
Adina Țeudan 2021-12-10 13:44:16 +02:00
parent 283abfd5bf
commit 92e7644dfd
2 changed files with 29 additions and 37 deletions

View File

@ -68,7 +68,7 @@ export class BaseScreenComponent {
{
text: this._translateService.instant('search.entire-platform'),
icon: 'red:enter',
action: (query): void => this._search(query),
action: (query): void => this._search(query, []),
},
];
private readonly _navigationStart$ = this._router.events.pipe(
@ -105,17 +105,17 @@ export class BaseScreenComponent {
return item.name;
}
private _search(query: string, dossierId?: string) {
const queryParams = { query, dossierId };
private _search(query: string, dossierIds: string[]) {
const queryParams = { query, dossierIds: dossierIds.join(',') };
this._router.navigate(['main/dossiers/search'], { queryParams }).then();
}
private _searchThisDossier(query: string) {
const routerLink = this.breadcrumbsService.breadcrumbs[1]?.routerLink;
if (!routerLink) {
return this._search(query);
return this._search(query, []);
}
const dossierId = routerLink[2];
return this._search(query, dossierId);
return this._search(query, [dossierId]);
}
}

View File

@ -3,7 +3,6 @@ import {
DefaultListingServices,
IFilterGroup,
keyChecker,
List,
ListingComponent,
LoadingService,
NestedFilter,
@ -11,25 +10,18 @@ import {
SortingOrders,
TableColumnConfig,
} from '@iqser/common-ui';
import { merge, Observable } from 'rxjs';
import { debounceTime, map, skip, startWith, switchMap, tap } from 'rxjs/operators';
import { combineLatest, Observable } from 'rxjs';
import { debounceTime, map, startWith, switchMap, tap } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { workflowFileStatusTranslations } from '../../translations/file-status-translations';
import { TranslateService } from '@ngx-translate/core';
import { RouterHistoryService } from '@services/router-history.service';
import { DossiersService } from '@services/entity-services/dossiers.service';
import { Dossier, IMatchedDocument, ISearchInput, ISearchListItem, ISearchResponse } from '@red/domain';
import { Dossier, IMatchedDocument, ISearchListItem, ISearchResponse } from '@red/domain';
import { FilesMapService } from '@services/entity-services/files-map.service';
import { PlatformSearchService } from '@services/entity-services/platform-search.service';
function toSearchInput(query: string, dossierIds: List | string): ISearchInput {
return {
query,
dossierIds: dossierIds ? (typeof dossierIds === 'string' ? [dossierIds] : dossierIds) : [],
};
}
@Component({
templateUrl: './search-screen.component.html',
styleUrls: ['./search-screen.component.scss'],
@ -48,12 +40,10 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
{ label: _('search-screen.cols.pages'), width: 'auto' },
];
readonly searchResults$ = merge(this._searchChanged$, this._filtersChanged$).pipe(
startWith(this._routeQuery),
tap(value => (this.searchService.searchValue = value.query)),
readonly searchResults$ = combineLatest([this._queryChanged, this._filtersChanged$]).pipe(
tap(() => this._loadingService.start()),
tap(value => this._updateNavigation(value.query)),
switchMap(query => this._platformSearchService.search(query)),
tap(([query, dossierIds]) => this._updateNavigation(query, dossierIds)),
switchMap(([query, dossierIds]) => this._platformSearchService.search({ query, dossierIds })),
map(searchResult => this._toMatchedDocuments(searchResult)),
map(docs => this._toListItems(docs)),
tap(result => this.entitiesService.setEntities(result)),
@ -75,9 +65,9 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
this.searchService.skip = true;
this.sortingService.setSortingOption({ column: 'searchKey', order: SortingOrders.desc });
const dossierId = _activatedRoute.snapshot.queryParamMap.get('dossierId');
const dossierIds = this._routeDossierIds;
const dossierToFilter = ({ dossierName, id }: Dossier) => {
const checked = id === dossierId;
const checked = dossierIds.includes(id);
return new NestedFilter({ id, label: dossierName, checked });
};
const dossierNameFilter: IFilterGroup = {
@ -91,35 +81,37 @@ export class SearchScreenComponent extends ListingComponent<ISearchListItem> imp
this.filterService.addFilterGroups([dossierNameFilter]);
}
private get _searchChanged$(): Observable<ISearchInput> {
private get _routeDossierIds(): string[] {
return this._activatedRoute.snapshot.queryParamMap.get('dossierIds').split(',');
}
private get _routeQuery(): string {
return this._activatedRoute.snapshot.queryParamMap.get('query');
}
private get _queryChanged(): Observable<string> {
return this.searchService.valueChanges$.pipe(
skip(1),
startWith(this._routeQuery),
tap(query => (this.searchService.searchValue = query)),
debounceTime(300),
map(value => ({ query: value, dossierIds: [] })),
);
}
private get _filtersChanged$() {
private get _filtersChanged$(): Observable<string[]> {
return this.filterService.filterGroups$.pipe(
skip(1),
map(groups => groups[0].filters.filter(v => v.checked).map(v => v.id)),
map(dossierIds => toSearchInput(this.searchService.searchValue, dossierIds)),
startWith(this._routeDossierIds),
);
}
private get _routeQuery(): ISearchInput {
const query = this._activatedRoute.snapshot.queryParamMap.get('query');
const dossierId = this._activatedRoute.snapshot.queryParamMap.get('dossierId');
return { query, dossierIds: dossierId ? [dossierId] : [] };
}
mustContain(value: string) {
const newQuery = this.searchService.searchValue.replace(value, `"${value}"`);
this.searchService.searchValue = newQuery ?? '';
}
private _updateNavigation(query: string) {
return this._router.navigate([], { queryParams: { query } });
private _updateNavigation(query?: string, dossierIds?: string[]): Promise<boolean> {
const queryParams = { query, dossierIds: dossierIds.join(',') };
return this._router.navigate([], { queryParams, replaceUrl: true });
}
private _toMatchedDocuments({ matchedDocuments }: ISearchResponse): IMatchedDocument[] {