Skip to content

Commit

Permalink
feat(search-source): clean search-source return
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Sep 13, 2017
1 parent 886d074 commit 158c7e0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/lib/datasource/shared/datasources/wms-datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class WMSDataSource
options.coordinates, options.resolution, options.projection, {
'INFO_FORMAT': this.queryInfoFormat,
'QUERY_LAYERS': this.params.layers,
'FEATURE_COUNT': '10'
'FEATURE_COUNT': this.params.feature_count || '5'
});

return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<td>
{{property.key}}
</td>
<td [innerHTML]=property.value></td>
<td *ngIf="!isObject(property.value)"
[innerHTML]="property.value">
</td>
<td *ngIf="isObject(property.value)"
[innerHTML]="property.value | json">
</td>
</tr>
</tbody>
</table>
4 changes: 4 additions & 0 deletions src/lib/feature/feature-details/feature-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export class FeatureDetailsComponent {

constructor(private cdRef: ChangeDetectorRef) { }

isObject(value) {
return typeof value === 'object';
}

}
3 changes: 3 additions & 0 deletions src/lib/feature/shared/feature.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AnyDataSourceContext } from '../../datasource';

import { FeatureType, FeatureFormat } from './feature.enum';

export interface Feature {
Expand All @@ -13,6 +15,7 @@ export interface Feature {
geometry?: FeatureGeometry;
extent?: ol.Extent;
properties?: {[key: string]: any};
layer?: AnyDataSourceContext;
}

export interface FeatureGeometry {
Expand Down
1 change: 1 addition & 0 deletions src/lib/feature/shared/feature.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class FeatureService {
}

updateFeatures(features: Feature[], source: string, sourcesToKeep?: string[]) {

const features_ = this.features$.value
.filter(feature => {
return feature.source !== source &&
Expand Down
8 changes: 7 additions & 1 deletion src/lib/language.extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ _('igo.print');
_('igo.searchResults');
_('igo.timeAnalysis');


_('igo.bookmarkButton.dialog.createTitle');
_('igo.bookmarkButton.dialog.createMsg');

Expand Down Expand Up @@ -40,6 +39,13 @@ _('igo.poiButton.dialog.confirmDelete');
_('igo.printForm.landscape');
_('igo.printForm.portrait');

_('igo.search.dataSources.name');
_('igo.search.dataSources.properties.title');
_('igo.search.dataSources.properties.groupTitle');
_('igo.search.dataSources.properties.abstract');
_('igo.search.dataSources.properties.url');
_('igo.search.dataSources.properties.type');

_('igo.tool.dialog.addTitle');
_('igo.tool.dialog.addMsg');
_('igo.tool.dialog.deleteTitle');
Expand Down
40 changes: 28 additions & 12 deletions src/lib/search/search-sources/datasource-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { Response, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Observable';

import { ConfigService, Message } from '../../core';
import { ConfigService, Message, LanguageService } from '../../core';
import { AuthHttp } from '../../auth';
import { Feature, FeatureType } from '../../feature';

Expand All @@ -16,21 +16,22 @@ export class DataSourceSearchSource extends SearchSource {
get enabled(): boolean { return this.options.enabled !== false; }
set enabled(value: boolean) { this.options.enabled = value; }

static _name: string = 'Data Sources';
static _name: string = 'igo.search.dataSources.name';

private searchUrl: string = 'https://geoegl.msp.gouv.qc.ca/igo2/api/layers/search';
private options: SearchSourceOptions;

constructor(private authHttp: AuthHttp,
private config: ConfigService) {
private config: ConfigService,
private languageService: LanguageService) {
super();

this.options = this.config.getConfig('searchSources.datasource') || {};
this.searchUrl = this.options.url || this.searchUrl;
}

getName(): string {
return DataSourceSearchSource._name;
return this.languageService.translate.instant(DataSourceSearchSource._name);
}

search(term?: string): Observable<Feature[] | Message[]> {
Expand All @@ -42,7 +43,9 @@ export class DataSourceSearchSource extends SearchSource {
}

private extractData(response: Response): Feature[] {
return response.json().items.map(this.formatResult);
return response.json().items.map(
(res) => this.formatResult(res)
);
}

private getSearchParams(term: string): URLSearchParams {
Expand All @@ -57,19 +60,32 @@ export class DataSourceSearchSource extends SearchSource {
}

private formatResult(result: any): Feature {
const t = this.languageService.translate;
const properties = {};
const prefix = 'igo.search.dataSources.properties.';
properties[t.instant(prefix + 'title')] = result.source.title;
properties[t.instant(prefix + 'group')] = result.source.groupTitle;
properties[t.instant(prefix + 'abstract')] = result.source.abstract;
properties[t.instant(prefix + 'type')] = result.source.format;
properties[t.instant(prefix + 'url')] = result.source.url;

const layer = Object.assign({}, result.source, {
type: result.source.format,
properties: properties,
params: {
layers: result.source.name
}
});

return {
id: result.id,
source: DataSourceSearchSource._name,
source: this.getName(),
type: FeatureType.DataSource,
title: result.source.title,
title_html: result.highlight.title,
icon: result.source.type === 'Layer' ? 'layers' : 'map',
properties: Object.assign({}, result.source, {
type: result.source.format,
params: {
layers: result.source.name
}
})
properties: properties,
layer: layer
};
}

Expand Down
13 changes: 10 additions & 3 deletions src/lib/search/search-sources/icherche-search-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export class IChercheSearchSource extends SearchSource {
}

private formatResult(result: any): Feature {
const properties = Object.assign({
type: result.doc_type
}, result.properties);
delete properties['@timestamp'];
delete properties['@version'];
delete properties.recherche;
delete properties.id;
delete properties.cote;

return {
id: result._id,
source: IChercheSearchSource._name,
Expand All @@ -66,9 +75,7 @@ export class IChercheSearchSource extends SearchSource {
title_html: result.highlight,
icon: 'place',
projection: 'EPSG:4326',
properties: Object.assign({
type: result.doc_type
}, result.properties),
properties: properties,
geometry: result.geometry,
extent: result.bbox
};
Expand Down
9 changes: 5 additions & 4 deletions src/lib/search/search-sources/search-source.provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Http, Jsonp } from '@angular/http';

import { ConfigService } from '../../core';
import { ConfigService, LanguageService } from '../../core';
import { AuthHttp } from '../../auth';

import { SearchSource } from './search-source';
Expand Down Expand Up @@ -37,15 +37,16 @@ export function provideIChercheSearchSource() {
}


export function dataSourceSearchSourcesFactory(authHttp: AuthHttp, config: ConfigService) {
return new DataSourceSearchSource(authHttp, config);
export function dataSourceSearchSourcesFactory(
authHttp: AuthHttp, config: ConfigService, languageService: LanguageService) {
return new DataSourceSearchSource(authHttp, config, languageService);
}

export function provideDataSourceSearchSource() {
return {
provide: SearchSource,
useFactory: (dataSourceSearchSourcesFactory),
multi: true,
deps: [AuthHttp, ConfigService]
deps: [AuthHttp, ConfigService, LanguageService]
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export class SearchResultsToolComponent {

if (map !== undefined) {
this.dataSourceService
.createAsyncDataSource(feature.properties as AnyDataSourceContext)
.createAsyncDataSource(feature.layer as AnyDataSourceContext)
.subscribe(dataSource => {
map.addLayer(
this.layerService.createLayer(dataSource, feature.properties));
this.layerService.createLayer(dataSource, feature.layer));
});
}
}
Expand Down

0 comments on commit 158c7e0

Please sign in to comment.