From 285da06067affe2e1b6f198cafdcadb4c7422bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:06:04 -0400 Subject: [PATCH 1/7] feat(search-source) Get the source type(getType()) --- packages/geo/src/lib/search/shared/sources/coordinates.ts | 4 ++++ packages/geo/src/lib/search/shared/sources/icherche.ts | 8 ++++++++ packages/geo/src/lib/search/shared/sources/ilayer.ts | 4 ++++ packages/geo/src/lib/search/shared/sources/nominatim.ts | 4 ++++ packages/geo/src/lib/search/shared/sources/source.ts | 7 +++++++ .../geo/src/lib/search/shared/sources/storedqueries.ts | 8 ++++++++ 6 files changed, 35 insertions(+) diff --git a/packages/geo/src/lib/search/shared/sources/coordinates.ts b/packages/geo/src/lib/search/shared/sources/coordinates.ts index 4023baba4f..8a0085b5e9 100644 --- a/packages/geo/src/lib/search/shared/sources/coordinates.ts +++ b/packages/geo/src/lib/search/shared/sources/coordinates.ts @@ -48,6 +48,10 @@ export class CoordinatesReverseSearchSource extends SearchSource return CoordinatesReverseSearchSource.id; } + getType(): string { + return CoordinatesReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'igo.geo.search.coordinates.name', diff --git a/packages/geo/src/lib/search/shared/sources/icherche.ts b/packages/geo/src/lib/search/shared/sources/icherche.ts index 1c60d7a6fd..e247fadfa6 100644 --- a/packages/geo/src/lib/search/shared/sources/icherche.ts +++ b/packages/geo/src/lib/search/shared/sources/icherche.ts @@ -66,6 +66,10 @@ export class IChercheSearchSource extends SearchSource implements TextSearch { return IChercheSearchSource.id; } + getType(): string { + return IChercheSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'iCherche', @@ -394,6 +398,10 @@ export class IChercheReverseSearchSource extends SearchSource return IChercheReverseSearchSource.id; } + getType(): string { + return IChercheReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Territoire (Géocodage inversé)', diff --git a/packages/geo/src/lib/search/shared/sources/ilayer.ts b/packages/geo/src/lib/search/shared/sources/ilayer.ts index 082180c785..5c7d80717f 100644 --- a/packages/geo/src/lib/search/shared/sources/ilayer.ts +++ b/packages/geo/src/lib/search/shared/sources/ilayer.ts @@ -82,6 +82,10 @@ export class ILayerSearchSource extends SearchSource implements TextSearch { return ILayerSearchSource.id; } + getType(): string { + return ILayerSearchSource.type; + } + protected getDefaultOptions(): ILayerSearchSourceOptions { return { title: 'igo.geo.search.ilayer.name', diff --git a/packages/geo/src/lib/search/shared/sources/nominatim.ts b/packages/geo/src/lib/search/shared/sources/nominatim.ts index 113686c5f5..e5c86f698b 100644 --- a/packages/geo/src/lib/search/shared/sources/nominatim.ts +++ b/packages/geo/src/lib/search/shared/sources/nominatim.ts @@ -30,6 +30,10 @@ export class NominatimSearchSource extends SearchSource implements TextSearch { return NominatimSearchSource.id; } + getType(): string { + return NominatimSearchSource.type; + } + /* * Source : https://wiki.openstreetmap.org/wiki/Key:amenity */ diff --git a/packages/geo/src/lib/search/shared/sources/source.ts b/packages/geo/src/lib/search/shared/sources/source.ts index 25e11c09b7..f4e56d6be3 100644 --- a/packages/geo/src/lib/search/shared/sources/source.ts +++ b/packages/geo/src/lib/search/shared/sources/source.ts @@ -37,6 +37,13 @@ export class SearchSource { getId(): string { throw new Error('You have to implement the method "getId".'); } + /** + * Get search source's type + * @returns Search source's type + */ + getType(): string { + throw new Error('You have to implement the method "getType".'); + } /** * Get search source's default options diff --git a/packages/geo/src/lib/search/shared/sources/storedqueries.ts b/packages/geo/src/lib/search/shared/sources/storedqueries.ts index b495cf3855..8024fff5d3 100644 --- a/packages/geo/src/lib/search/shared/sources/storedqueries.ts +++ b/packages/geo/src/lib/search/shared/sources/storedqueries.ts @@ -88,6 +88,10 @@ export class StoredQueriesSearchSource extends SearchSource implements TextSearc return StoredQueriesSearchSource.id; } + getType(): string { + return StoredQueriesSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Stored Queries', @@ -295,6 +299,10 @@ export class StoredQueriesReverseSearchSource extends SearchSource return StoredQueriesReverseSearchSource.id; } + getType(): string { + return StoredQueriesReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Stored Queries (reverse)', From eeddde580082d373db5c8a02b96339fc74fc59ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:08:23 -0400 Subject: [PATCH 2/7] feat(search-service)Way to control calls's type --- packages/geo/src/lib/search/shared/search.service.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/search/shared/search.service.ts b/packages/geo/src/lib/search/shared/search.service.ts index 81059a7bab..f3b5d66f49 100644 --- a/packages/geo/src/lib/search/shared/search.service.ts +++ b/packages/geo/src/lib/search/shared/search.service.ts @@ -45,10 +45,13 @@ export class SearchService { console.log(response.message); } - const sources = this.searchSourceService + let sources = this.searchSourceService .getEnabledSources() - .filter(sourceCanSearch); + .filter(sourceCanSearch) + if (options && options.searchType) { + sources = sources.filter(source => source.getType() === options.searchType ) + } return this.searchSources(sources, term, options || {}); } From 2420fedeb9a333fcf82bc1348cae2e48c36f234c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:09:06 -0400 Subject: [PATCH 3/7] feat(source) An option to control the call type --- packages/geo/src/lib/search/shared/sources/source.interfaces.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts index 2a89d1c484..3011916e27 100644 --- a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts +++ b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts @@ -28,6 +28,7 @@ export interface SettingOptions { export interface TextSearchOptions { params?: { [key: string]: string }; + searchType?: 'Feature' | 'Layer'; // refer to search.enum.ts SEARCH_TYPES = [FEATURE, LAYER]; } export interface ReverseSearchOptions { From fce7278844a4bd532801570ce126fdb21da64f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:12:25 -0400 Subject: [PATCH 4/7] refactor(routing) Restrict search to Features --- .../geo/src/lib/routing/routing-form/routing-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 4b0ae48578..e76df32e4e 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -923,7 +923,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { private handleTermChanged(term: string) { if (term !== undefined || term.length !== 0) { const searchProposals = []; - const researches = this.searchService.search(term); + const researches = this.searchService.search(term, {searchType: 'Feature'}); researches.map(res => this.routesQueries$$.push( res.request.subscribe(results => { From 05cd75b598f4e7c3d5d6873223d270b4302c1b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:37:40 -0400 Subject: [PATCH 5/7] feat(source)Option to honor the user configuration --- packages/geo/src/lib/search/shared/sources/source.interfaces.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts index 3011916e27..5e5e411d3d 100644 --- a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts +++ b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts @@ -29,6 +29,7 @@ export interface SettingOptions { export interface TextSearchOptions { params?: { [key: string]: string }; searchType?: 'Feature' | 'Layer'; // refer to search.enum.ts SEARCH_TYPES = [FEATURE, LAYER]; + getEnabledOnly?: boolean; } export interface ReverseSearchOptions { From 4dff0bfd6f7ffc0993e356ee2920f2fa9604fef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:40:03 -0400 Subject: [PATCH 6/7] feat(search-source) Get the source type(getType()) --- packages/geo/src/lib/query/shared/query-search-source.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/geo/src/lib/query/shared/query-search-source.ts b/packages/geo/src/lib/query/shared/query-search-source.ts index 0a51f01abb..f8548d8ce0 100644 --- a/packages/geo/src/lib/query/shared/query-search-source.ts +++ b/packages/geo/src/lib/query/shared/query-search-source.ts @@ -20,6 +20,10 @@ export class QuerySearchSource extends SearchSource { return QuerySearchSource.id; } + getType(): string { + return QuerySearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Carte' From 11598015d480b247b56f3d5b8b760b4418cc9261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Wed, 18 Sep 2019 16:46:37 -0400 Subject: [PATCH 7/7] feat(search) honor or not user's enabled sources. --- .../geo/src/lib/search/shared/search.service.ts | 15 +++++++++++---- .../geo/src/lib/search/shared/sources/icherche.ts | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/geo/src/lib/search/shared/search.service.ts b/packages/geo/src/lib/search/shared/search.service.ts index f3b5d66f49..e34afee6f6 100644 --- a/packages/geo/src/lib/search/shared/search.service.ts +++ b/packages/geo/src/lib/search/shared/search.service.ts @@ -46,12 +46,19 @@ export class SearchService { } let sources = this.searchSourceService - .getEnabledSources() - .filter(sourceCanSearch) + .getEnabledSources(); - if (options && options.searchType) { - sources = sources.filter(source => source.getType() === options.searchType ) + if (options) { + if (options.getEnabledOnly || options.getEnabledOnly === undefined) { + sources = this.searchSourceService.getEnabledSources(); + } else { + sources = this.searchSourceService.getSources(); + } + if (options.searchType) { + sources = sources.filter(source => source.getType() === options.searchType); + } } + sources = sources.filter(sourceCanSearch); return this.searchSources(sources, term, options || {}); } diff --git a/packages/geo/src/lib/search/shared/sources/icherche.ts b/packages/geo/src/lib/search/shared/sources/icherche.ts index e247fadfa6..df0764d90c 100644 --- a/packages/geo/src/lib/search/shared/sources/icherche.ts +++ b/packages/geo/src/lib/search/shared/sources/icherche.ts @@ -401,7 +401,7 @@ export class IChercheReverseSearchSource extends SearchSource getType(): string { return IChercheReverseSearchSource.type; } - + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Territoire (Géocodage inversé)',