Skip to content

Commit

Permalink
display more results lasts modifs (get by source id)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeLafreniere18 committed Jan 15, 2020
1 parent cbe67c5 commit d66b497
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Feature } from './../../feature/shared/feature.interfaces';
import {
Component,
Input,
Expand All @@ -18,8 +17,6 @@ import { debounce, map } from 'rxjs/operators';
import { EntityStore, EntityStoreWatcher } from '@igo2/common';

import { IgoMap } from '../../map';
import { LAYER } from '../../layer/shared/layer.enums';
import { FEATURE } from '../../feature/shared/feature.enums';

import { TextSearchOptions } from '../shared/sources/source.interfaces';
import { SearchService } from '../shared/search.service';
Expand Down Expand Up @@ -53,7 +50,7 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
*/
private watcher: EntityStoreWatcher<SearchResult>;

public pageIterator = { Layer: 1, Feature: 1};
public pageIterator: {sourceId: string}[] = [];

@Input() map: IgoMap;

Expand Down Expand Up @@ -86,8 +83,7 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
}
set term(value: string) {
this._term = value;
this.pageIterator.Layer = 1;
this.pageIterator.Feature = 1;
this.pageIterator = [];
}
public _term: string;

Expand Down Expand Up @@ -235,13 +231,16 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
});

return Array.from(grouped.keys()).map((source: SearchSource) => {
if (this.pageIterator[source.getId()] === undefined) {
this.pageIterator[source.getId()] = 1
};
return {source, results: grouped.get(source)};
});
}

isMoreResults(group: {source: SearchSource; results: SearchResult[]}) {
if (group.results) {
if (group.results[group.results.length - 1].meta.nextPage === false) {
if (group.results[group.results.length - 1].meta.nextPage !== true) {
return false;
}
return true;
Expand All @@ -250,11 +249,9 @@ export class SearchResultsComponent implements OnInit, OnDestroy {
}

displayMoreResults(group: {source: SearchSource; results: SearchResult[]}) {
const searchTypeFeature: 'Feature' = FEATURE;
const searchTypeLayer: 'Layer' = LAYER;
const options: TextSearchOptions = {
searchType: group.results[0].meta.dataType === 'Layer' ? searchTypeLayer : searchTypeFeature,
page: ++this.pageIterator[group.results[0].meta.dataType]
sourceId: group.source.getId(),
page: ++this.pageIterator[group.source.getId()]
};

const researches = this.searchService.search(this.term, options);
Expand Down
9 changes: 7 additions & 2 deletions packages/geo/src/lib/search/shared/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ export class SearchService {
.getMap()
.viewController.getExtent('EPSG:4326');

let sources = this.searchSourceService.getEnabledSources();
let sources;

if (options.getEnabledOnly || options.getEnabledOnly === undefined) {
sources = this.searchSourceService.getEnabledSources();
} else {
sources = this.searchSourceService.getSources();
}
if (options.searchType) {

if (options.sourceId) {
sources = sources.filter(
source => source.getId() === options.sourceId
);
} else if (options.searchType) {
sources = sources.filter(
source => source.getType() === options.searchType
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface TextSearchOptions {
getEnabledOnly?: boolean;
extent?: [number, number, number, number];
page?: number;
sourceId?: string;
}

export interface ReverseSearchOptions {
Expand Down

0 comments on commit d66b497

Please sign in to comment.