Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply restrictions programatically to search sources #418

Merged
merged 8 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/geo/src/lib/query/shared/query-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class QuerySearchSource extends SearchSource {
return QuerySearchSource.id;
}

getType(): string {
return QuerySearchSource.type;
}

protected getDefaultOptions(): SearchSourceOptions {
return {
title: 'Carte'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
16 changes: 13 additions & 3 deletions packages/geo/src/lib/search/shared/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ export class SearchService {
console.log(response.message);
}

const sources = this.searchSourceService
.getEnabledSources()
.filter(sourceCanSearch);
let sources = this.searchSourceService
.getEnabledSources();

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 || {});
}

Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/lib/search/shared/sources/coordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions packages/geo/src/lib/search/shared/sources/icherche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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é)',
Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/lib/search/shared/sources/ilayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/lib/search/shared/sources/nominatim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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 {
Expand Down
7 changes: 7 additions & 0 deletions packages/geo/src/lib/search/shared/sources/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/geo/src/lib/search/shared/sources/storedqueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)',
Expand Down