Skip to content

Commit

Permalink
Merge pull request #162 from sipcapture/devel
Browse files Browse the repository at this point in the history
fix: sipcapture/homer-app#289 Display resul…
  • Loading branch information
adubovikov authored Feb 14, 2020
2 parents 774e23d + a19d787 commit d306c40
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@ export class SearchGridCallComponent implements OnInit, OnDestroy, AfterViewInit
}
async initSearchSlider() {
try {
const mappings: Array<any> = (await this._pmps.getAll().toPromise() as any).data as Array<any>;
const query = this.searchService.getLocalStorageQuery();
if (!query || !query.protocol_id) {
return;
}
const mappings: Array<any> = (await this._pmps.getAll().toPromise() as any).data as Array<any>;
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
Expand Down
27 changes: 15 additions & 12 deletions src/app/services/search.service.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
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;
search: any;
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) {
Expand All @@ -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);
Expand Down

0 comments on commit d306c40

Please sign in to comment.