From a19d7875099cd2ce0c334c2041484942521eeaad Mon Sep 17 00:00:00 2001 From: Eduard Klimenko Date: Fri, 14 Feb 2020 15:43:12 +0200 Subject: [PATCH] fix: https://github.com/sipcapture/homer-app/issues/289 Display result not showing --- .../search-grid-call.component.ts | 5 +++- .../protosearch-widget.component.ts | 15 ++++++----- src/app/services/search.service.ts | 27 ++++++++++--------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/app/components/search-grid-call/search-grid-call.component.ts b/src/app/components/search-grid-call/search-grid-call.component.ts index e2baa590..d0e37ee6 100644 --- a/src/app/components/search-grid-call/search-grid-call.component.ts +++ b/src/app/components/search-grid-call/search-grid-call.component.ts @@ -255,8 +255,11 @@ export class SearchGridCallComponent implements OnInit, OnDestroy, AfterViewInit } async initSearchSlider() { try { - const mappings: Array = (await this._pmps.getAll().toPromise() as any).data as Array; const query = this.searchService.getLocalStorageQuery(); + if (!query || !query.protocol_id) { + return; + } + const mappings: Array = (await this._pmps.getAll().toPromise() as any).data as Array; const mapping = Functions.cloneObject(mappings.filter(i => i.profile === query.protocol_id.split('_')[1])[0].fields_mapping); mapping.push({ id: ConstValue.LIMIT, name: 'Query Limit' }); console.log( diff --git a/src/app/components/widgets/protosearch-widget/protosearch-widget.component.ts b/src/app/components/widgets/protosearch-widget/protosearch-widget.component.ts index 29f305aa..7e0b27bd 100644 --- a/src/app/components/widgets/protosearch-widget/protosearch-widget.component.ts +++ b/src/app/components/widgets/protosearch-widget/protosearch-widget.component.ts @@ -165,13 +165,14 @@ export class ProtosearchWidgetComponent implements IWidget { if (item.field_name === ConstValue.CONTAINER && item.value !== '') { this.targetResultsContainerValue.setValue(item.value); } - - if (cacheQuery.location && - cacheQuery.location.mapping && - item.field_name === cacheQuery.location.mapping && - item.form_default - ) { - item.value = cacheQuery.location.value.map(i => item.form_default.filter(j => j.value === i)[0].name); + if (cacheQuery) { + if (cacheQuery.location && + cacheQuery.location.mapping && + item.field_name === cacheQuery.location.mapping && + item.form_default + ) { + item.value = cacheQuery.location.value.map(i => item.form_default.filter(j => j.value === i)[0].name); + } } }); } diff --git a/src/app/services/search.service.ts b/src/app/services/search.service.ts index fe414053..942c304d 100644 --- a/src/app/services/search.service.ts +++ b/src/app/services/search.service.ts @@ -1,16 +1,15 @@ import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; -import { environment } from '@environments/environment'; -import { PreferenceMapping, ConstValue } from '@app/models'; +import { ConstValue } from '@app/models'; import { Functions } from '@app/helpers/functions'; -import { Observable } from 'rxjs'; + import { DateTimeRangeService } from './data-time-range.service'; +import { AlertService } from './alert.service'; @Injectable({ providedIn: 'root' }) export class SearchService { - currentQuery: any; + currentQuery: any = {}; isLoki = false; location: any; protocol: any; @@ -18,18 +17,15 @@ export class SearchService { target: any; constructor ( - private _dtrs: DateTimeRangeService + private _dtrs: DateTimeRangeService, + private alertService: AlertService ) { this.currentQuery = this.getLocalStorageQuery() || { protocol_id: null, - location: this.location || {} + location: this.location }; this.protocol = this.currentQuery.protocol_id || this.protocol; this.location = this.currentQuery.location || this.location; - - if (!this.protocol) { - console.error('this.protocol is undefined') - } } public setLocalStorageQuery(query: any) { @@ -42,13 +38,20 @@ export class SearchService { this.protocol = query.protocol; } else { this.currentQuery.protocol = this.protocol; + if (this.currentQuery.protocol) { + this.alertService.error('./homer-app -populate-table-db-config -force-populate -populate-table=mapping_schema') + } } this.currentQuery = Functions.cloneObject(query); localStorage.setItem(ConstValue.SEARCH_QUERY, JSON.stringify(query)); } public getLocalStorageQuery() { - this.currentQuery = JSON.parse(localStorage.getItem(ConstValue.SEARCH_QUERY)); + this.currentQuery = JSON.parse(localStorage.getItem(ConstValue.SEARCH_QUERY)) || { + protocol_id: null, + location: this.location + }; + const localData = Functions.cloneObject(this.currentQuery); if (localData && localData.fields && localData.fields instanceof Array) { localData.fields = localData.fields.filter(i => i.name !== ConstValue.CONTAINER);